Compiling C Code
by - Thursday, January 1, 1970 at 12:00 AM
Hey guys, I’m trying to compile a source code from breaking security. It is a tool for running .bin files in memory. Anyway I used GCC for compiling it and I get some errors, I don’t really have much experience in programming in general so any help telling me how to fix it and compile it my self would be much appreciated[code]// ________________________________________________//// ShellLoad.c//// PURPOSE:// Useful tool to test shellcodes.// The program will load the shellcode from file and execute it into its own process memory.// 3 different shellcode loading methods are provided as option.//// USAGE:// Execute the program passing the shellcode file path as parameter.// 2° parameter is optional and lets you define the preferred shellcode loading method:// 1 = Inline ASM (Default)// 2 = C Function// 3 = CallWindowProc////// RELEASE NOTES:// v1.0.0// 27 Jul 2021//// AUTHOR:// © BreakingSecurity.net // https://BreakingSecurity.net// ________________________________________________#include #include // Shellcode Entrypoint function prototype// TIP: We can edit this function to support different return types and parameterstypedef INT(*ShellEntry)();#define METHOD_INLINEASM 1#define METHOD_CFUNCTION 2#define METHOD_CALLWINDOWPROC 3int main(int argc, char *argv[]){ int ret = 0; int mtd = 1; int err = 0; DWORD fsize = 0; printf(""); printf("-------------------------"); printf(" Shellcode Loader v1.0.0"); printf(" BreakingSecurity.net"); printf("-------------------------"); printf(""); if (argc < 2) { printf("USAGE MODE:"); printf("ShellLoad.exe path"); printf("ShellLoad.exe path method"); printf(""); printf("METHODS:"); printf("1 = Inline ASM (default)"); printf("2 = C Function"); printf("3 = CallWindowProc"); printf("EXAMPLE (default method): ShellLoad.exe \"C:\\shellcode.file\" "); printf("EXAMPLE (select method): ShellLoad.exe \"C:\\shellcode.file\" 1"); printf("------------------------"); printf("[-] ERROR: No parameter passed. Path to shellcode is required."); _getch(); return 0; } if (argc > 2) { mtd = atoi(argv[2]); } printf("[+] Opening file: %s", argv[1]); HANDLE hFile = CreateFileA(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { err = GetLastError(); printf("[-] ERROR: Unable to open file. Error %i", err); return 0; } fsize = GetFileSize(hFile, NULL); if (fsize == INVALID_FILE_SIZE) { err = GetLastError(); printf("[-] ERROR: GetFileSize error %i", err); CloseHandle(hFile); return 0; } printf("[+] File Size: %i bytes", fsize); printf("[+] Allocating memory buffer..."); void* pShellcode = VirtualAlloc(NULL, fsize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (pShellcode == NULL) { err = GetLastError(); printf("[-] ERROR: VirtualAlloc error %i", err); CloseHandle(hFile); return 0; } printf("[+] Reading file..."); DWORD nBytesRead = 0; ReadFile(hFile, pShellcode, fsize, &nBytesRead, NULL); CloseHandle(hFile); switch (mtd) { case METHOD_INLINEASM: { printf("[+] Executing shellcode (method: Inline ASM)"); __asm { call pShellcode // Execute shellcode entrypoint mov ret, eax // Retrieve return value } break; } case METHOD_CFUNCTION: { printf("[+] Executing shellcode (method: C Function)"); ShellEntry fShellcode = (ShellEntry)pShellcode; ret = fShellcode(); break; } case METHOD_CALLWINDOWPROC: { printf("[+] Executing shellcode (method: CallWindowProc)"); // TIP: we can use CallWindowProc parameters to pass arguments to our function ret = CallWindowProcA((WNDPROC)pShellcode, 0, 0, 0, 0); break; } } printf("[+] Shellcode executed!"); _getch(); // Keep shellcode running return ret;}[/code]This is the source: https://breakingsecurity.net/shellcodeloader/Thanks in advance.
Reply


 Users viewing this thread: Compiling C Code: No users currently viewing.