1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-03-30 22:19:17 +02:00

Use temp storage for URL parsing

This removes the issue where URLs were truncated during parsing,
resulting in them not working later on when transports are changed.
This commit is contained in:
OJ 2015-07-10 14:53:36 +10:00
parent 15ca2a90fb
commit d16e5276c5

@ -937,6 +937,7 @@ static void transport_reset_tcp(Transport* transport, BOOL shuttingDown) {
static BOOL configure_tcp_connection(Transport* transport) { static BOOL configure_tcp_connection(Transport* transport) {
DWORD result = ERROR_SUCCESS; DWORD result = ERROR_SUCCESS;
size_t charsConverted; size_t charsConverted;
char tempUrl[512] = {0};
TcpTransportContext* ctx = (TcpTransportContext*)transport->ctx; TcpTransportContext* ctx = (TcpTransportContext*)transport->ctx;
// check if comms is already open via a staged payload // check if comms is already open via a staged payload
@ -946,15 +947,20 @@ static BOOL configure_tcp_connection(Transport* transport) {
else { else {
dprintf("[TCP CONFIGURE] Url: %s", transport->url); dprintf("[TCP CONFIGURE] Url: %s", transport->url);
// copy the URL to the temp location and work from there
// so that we don't damage the original URL while breaking
// it up into its individual parts.
strncpy(tempUrl, transport->url, sizeof(tempUrl) - 1);
//transport->start_time = current_unix_timestamp(); //transport->start_time = current_unix_timestamp();
transport->comms_last_packet = current_unix_timestamp(); transport->comms_last_packet = current_unix_timestamp();
if (strncmp(transport->url, "tcp", 3) == 0) { if (strncmp(tempUrl, "tcp", 3) == 0) {
char* pHost = strstr(transport->url, "//") + 2; char* pHost = strstr(tempUrl, "//") + 2;
char* pPort = strrchr(pHost, ':') + 1; char* pPort = strrchr(pHost, ':') + 1;
// check if we're using IPv6 // check if we're using IPv6
if (transport->url[3] == '6') { if (tempUrl[3] == '6') {
char* pScopeId = strrchr(pHost, '?') + 1; char* pScopeId = strrchr(pHost, '?') + 1;
*(pScopeId - 1) = '\0'; *(pScopeId - 1) = '\0';
*(pPort - 1) = '\0'; *(pPort - 1) = '\0';