-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
50 lines (40 loc) · 1.62 KB
/
main.cc
File metadata and controls
50 lines (40 loc) · 1.62 KB
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
//==============================================================================
// Title : Example of a relocatable shellcode
// Author : South
// Date : 2017.5.2
// Description :
// This shellcode is for System and Network Security lab's seminar.
// I try to show that there are a lots of ways to build shellcode.
// With this example shellcode, you can found out that it is possible
// to make shellcode without *.asm file
// I hope that after this seminar, all System and Netowrk Security lab's
// members understand the principal of relocatable shellcode and
// have their own shellcode framework.
//==============================================================================
#include <windows.h>
#include <stdio.h>
extern void MoveShellCode(PVOID ShellCodeBuf);
// This global variable will be usee in sc.cc
char *gTARGET_PROG_PATH = "F:/GIT/hello/hello/main.exe";
ULONG gTARGET_PROG_LEN = 0;
int main(int argc, char *argv[])
{
char *sc = NULL;
// allocate a virtual memory for shellcode
// porperty : read/write/execute
sc = (char *) VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (sc == NULL) {
printf("[-] VirtualAlloc fails: Error Code[%x]\n", GetLastError());
return -1;
}
// initialize the buffer and global variable
ZeroMemory(sc, 0x1000);
gTARGET_PROG_LEN = (ULONG)strlen(gTARGET_PROG_PATH) + 1; //including null-char
// move shellcode from text section to buffer memory
MoveShellCode(sc);
// type casting from char buffer to function pointer
// then just use this variable like function.
((void (*)(void))sc)();
char ch = getchar();
return 0;
}//end of main