Shellcode 加载器

用于测试 shellcode 的开源工具。

Shellcode 加载器 是一个用于测试 shellcode 的命令行实用程序。
这个小型开源实用程序将自定义 shellcode 注入到它自己进程的内存中。

Shellcode Loader 是用 C 语言编写并提供开源的。
适用于从 WinXP 到 Win11 的任何 Windows。

Shellcode Loader 提供了 3 种不同的 shellcode 加载方法:

  • 内联 ASM
  • C 函数
  • 调用窗口过程
用法:
  1. 打开 cmd.exe 或 Windows Powershell
  2. 输入 ShellLoad + 你的 shellcode 文件的路径。
    示例:ShellLoad “C:\Shellcode.file”
  3. 按 Enter。 shellcode 将被加载并执行。
    信息和错误消息将显示在控制台上。
  4. 如果要查看使用帮助和高级设置(如shellcode执行方式),
    不带任何参数执行 ShellLoad.exe。
Shellcode 加载器

下载“Shellcode 加载器” ShellcodeLoader.zip – 下载 858 次 – 55 KB


套餐包含:
ShellLoad.exe(已编译)
ShellLoad.c (C 源代码)

源代码:

ShellLoad.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
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// ________________________________________________
//
// 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 <Windows.h>
#include <stdio.h>
// Shellcode Entrypoint function prototype
// TIP: We can edit this function to support different return types and parameters
typedef INT(*ShellEntry)();
#define METHOD_INLINEASM 1
#define METHOD_CFUNCTION 2
#define METHOD_CALLWINDOWPROC 3

int main(int argc, char *argv[])
{
	int ret = 0;
	int mtd = 1;
	int err = 0;
	DWORD fsize = 0;
	printf("\n");
	printf("-------------------------\n");
	printf(" Shellcode Loader v1.0.0\n");
	printf(" BreakingSecurity.net\n");
	printf("-------------------------\n");
	printf("\n");
	if (argc < 2)
	{
		printf("USAGE MODE:\n");
		printf("ShellLoad.exe path\n");
		printf("ShellLoad.exe path method\n");
		printf("\n");
		printf("METHODS:\n");
		printf("1 = Inline ASM (default)\n");
		printf("2 = C Function\n");
		printf("3 = CallWindowProc\n\n");
		printf("EXAMPLE (default method): ShellLoad.exe \"C:\\shellcode.file\" \n");
		printf("EXAMPLE (select method): ShellLoad.exe \"C:\\shellcode.file\" 1\n");
		printf("------------------------\n");
		printf("\n[-] ERROR: No parameter passed. Path to shellcode is required.\n\n");
		_getch();
		return 0;
	}
	if (argc > 2)
	{
		mtd = atoi(argv[2]);
	}
	printf("[+] Opening file: %s\n", 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\n", err);
		return 0;
	}
	fsize = GetFileSize(hFile, NULL);
	if (fsize == INVALID_FILE_SIZE) 
	{
		err = GetLastError();
		printf("[-] ERROR: GetFileSize error %i\n", err);
		CloseHandle(hFile);
		return 0;
	}
	printf("[+] File Size: %i bytes\n", fsize);
	printf("[+] Allocating memory buffer...\n");
	void* pShellcode = VirtualAlloc(NULL, fsize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
	if (pShellcode == NULL) 
	{
		err = GetLastError();
		printf("[-] ERROR: VirtualAlloc error %i\n", err);
		CloseHandle(hFile);
		return 0;
	}
	printf("[+] Reading file...\n");
	DWORD nBytesRead = 0;
	ReadFile(hFile, pShellcode, fsize, &nBytesRead, NULL);
	CloseHandle(hFile);
	switch (mtd)
	{
		case METHOD_INLINEASM:
		{
			printf("[+] Executing shellcode (method: Inline ASM)\n");
			__asm
			{
				call pShellcode	// Execute shellcode entrypoint
				mov ret, eax	// Retrieve return value
			}
			break;
		}
		case METHOD_CFUNCTION:
		{
			printf("[+] Executing shellcode (method: C Function)\n");
			ShellEntry fShellcode = (ShellEntry)pShellcode;
			ret = fShellcode();
			break;
		}
		case METHOD_CALLWINDOWPROC:
		{
			printf("[+] Executing shellcode (method: CallWindowProc)\n");
			// TIP: we can use CallWindowProc parameters to pass arguments to our function
			ret = CallWindowProcA((WNDPROC)pShellcode, 0, 0, 0, 0);
			break;
		}
	}
	printf("[+] Shellcode executed!\n");
	_getch(); // Keep shellcode running
	return ret;
}
菜单