我是否应该能够从一个基本的(经过测试和工作的)Win7-64 消息框应用程序中提取 shellcode 并将提取的 shellcode 放入经过测试和工作的汇编语言编码器/解码器中并期望它能够工作?(Windows 的组装和链接,而不是 linux 的链接)
我已经使用下面列出的步骤在 linux 上成功测试了一个简单的 XOR 编码器/解码器。简而言之,我有一个 WORKING XOR 编码器/解码器系统,我尝试将 win764 消息框 shellcode 与我的编码/解码系统一起使用。
我只是将 Win7 消息框中提取的 shellcode 替换到我的编码/解码系统中。与 nasm -fwin64 组装,然后与 Windows 上的 golink 链接以获取 exe,并且每次都崩溃。(没有编码器的测试步骤和组装/链接/执行工作完美)
- 我正在为 windows 组装 XOR 解码器 - nasm -fwin64(粘贴了消息框 shellcode)
- 使用 golink 链接 Windows
- 无法在 Windows 上执行
这是非常有效的 Linux XOR 编码/解码方法。
- 使用 HelloWorld.nasm
- 组装 - nasm -felf64 HelloWorld.nasm -o HelloWorld.o
- 使用 - for i in $(objdump -d [binary-or-objectfile] |grep "^ " |cut -f2); 提取 shellcode; 做回声 -n '\x'$i; 完成;回声
将 HelloWorld shellcode 放在 C 包装器中
#include<stdio.h> #include<string.h> unsigned char code[] = \ "\xeb\x1e\x5e\x48\x31\xc0\xb0\x01\x48\x89\xc7\x48\x89\xfa\x48\x83\xc2\x22\x0f\x05\x48\x31\xc0\x48\x83\xc0\x3c\x48\x31\xff\x0f\x05\xe8\xdd\xff\xff\xff\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x20\x0a"; int main() { printf("Shellcode Length: %d\n", (int)strlen(code)); int (*ret)() = (int(*)())code; ret(); }运行 ./HelloWorld(验证 shellcode 在 C 包装器中工作)
现在,我使用带有 python 的简单 XOR 编码器对 HelloWorld shellcode 进行 XOR。
1.python XOREncoder.py
为 nasm 输出格式化的异或 HelloWorld shellcode:
0x41,0xb4,0xf4,0xe2,0x9b,0x6a,0x1a,0xab,0xe2,0x23,0x6d,0xe2,0x23,0x50,0xe2,0x29,0x68,0x88,0xa5,0xaf,0xe2,0x9b,0x6a,0xe2,0x29,0x6a,0x96,0xe2,0x9b,0x55,0xa5,0xaf,0x42,0x77,0x55,0x55,0x55,0xe2,0xcf,0xc6,0xc6,0xc5,0x8a,0xfd,0xc5,0xd8,0xc6,0xce,0x8a,0xa0
像这样将 XORed shellcode 放在 XORdecoder.nasm 中:
global _start section .text _start: start: jmp find_address decoder: pop rdi xor rcx, rcx add cl, 50 decode: xor byte [rdi], 0xAA inc rdi loop decode jmp short encoded_shellcode find_address: call decoder encoded_shellcode: db 0x41,0xb4,0xf4,0xe2,0x9b,0x6a,0x1a,0xab,0xe2,0x23,0x6d,0xe2,0x23,0x50,0xe2,0x29,0x68,0x88,0xa5,0xaf,0xe2,0x9b,0x6a,0xe2,0x29,0x6a,0x96,0xe2,0x9b,0x55,0xa5,0xaf,0x42,0x77,0x55,0x55,0x55,0xe2,0xcf,0xc6,0xc6,0xc5,0x8a,0xfd,0xc5,0xd8,0xc6,0xce,0x8a,0xa0- 组装有 - nasm -felf64 HelloWorldEncoded.nasm -o HelloWorldEncoded.o
- 用 GCC 编译并测试。作品!
现在,这是 Windows 7 64 上的问题
我找到了一个 WIN 7 64 位 messagebox.nasm 的一个很好的例子,它只是在这里弹出一个消息框。所以很自然地我想测试我的 XOR 解码器。所以我尝试为这样的窗口组装和链接我的解码器。
我使用链接中描述的这些步骤对此进行了测试:
NASM -f Win64平台messageBox64bit.asm -o messageBox64bit.obj
golink /控制台 messageBox64bit.obj
- 在 Win764 上执行 ./messageBox64bit.exe
伟大的!messageBox64bit.exe 弹出消息框。现在是问题。
- 我用 nasm 组装了 messageBox64bit.nasm
- 通过 XOR 编码器运行提取的消息框 shellcode
- 将 asm 友好的 XOR 编码的 shellcode 粘贴到解码器中
- 为新的 shellcode 长度调整 RCX (cl) 计数器
- 带有 -fwin64 选项的带有 nasm 的组装解码器
- 与 golink /console messageBox64bit.obj 链接
尝试在 WIN 7 64 上执行。
每次该死的时候它都会崩溃 这里有什么问题吗?
编辑1:
在 Windbg 中 XOR 函数崩溃:
Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
xordecoder2+0x1009:
00000000`00401009 8037aa xor byte ptr [rdi],0AAh ds:00000000`00401018=e7
0:000> t
ds:00000000`00401018=e7
0:000> t
编辑2。按照下面 Igor 的建议,我编辑了 EXE 以使 .text 部分可写。显然 .text 部分对于 Windows EXE 是不可写的。现在错误更改为:
(1f08.1af0): Unknown exception - code c0000096 (first chance)
(1f08.1af0): Unknown exception - code c0000096 (!!! second chance !!!)
*** ERROR: Module load completed but symbols could not be loaded for C:\data_section_xorencoder7.exe
data_section_xorencoder7+0x1016:
00000000`00401016 e7ff out 0FFh,eax
编辑 Nasm 代码。异或 shellcode。
bits 64
section .text
global start
start:
jmp find_address
decoder:
pop rdi
xor rcx, rcx
add cx, 260
decode:
xor byte [rdi], 0xAA
inc rdi
loop decode
jmp short encoded_shellcode
find_address:
call decoder
encoded_shellcode: 0xe2,0x29,0x46,0x82,0xe2,0x29,0x4e,0x5a,0xcf,0xe6,0x21,0x8e,0x8f,0xca,0xaa,0xaa,0xaa,0xe7,0x21,0xce,0x8e,0xb2,0xe7,0x21,0xce,0x8e,0x8a,0xe7,0x21,0x8e,0x8e,0xe7,0x21,0xd6,0x8e,0x8a,0xe7,0x21,0x8e,0x8e,0xe7,0x21,0xce,0x8e,0x8a,0x10,0x24,0xe4,0xa4,0x46,0xe6,0x23,0x4b,0x42,0xc2,0xaa,0xaa,0xaa,0x41,0x9e,0xf3,0x55,0x7a,0x10,0x02,0x08,0xe7,0x16,0xe2,0x23,0x6b,0x42,0xfc,0xaa,0xaa,0xaa,0xe2,0x23,0x69,0xe7,0x9b,0x63,0x41,0x94,0xeb,0xf2,0x41,0x82,0xf0,0xe2,0x9b,0x63,0x55,0x79,0x10,0xda,0x67,0x95,0x87,0xe6,0x23,0x53,0x42,0x9d,0xaa,0xaa,0xaa,0xe2,0x9b,0x63,0x55,0x7a,0x42,0x6d,0x55,0x55,0x55,0xdf,0xd9,0xcf,0xd8,0x99,0x98,0x84,0xce,0xc6,0xc6,0x42,0x79,0x55,0x55,0x55,0xfe,0xc2,0xc3,0xd9,0x8a,0xc3,0xd9,0x8a,0xcc,0xdf,0xc4,0x8b,0xaa,0x42,0x17,0x55,0x55,0x55,0x9a,0xd2,0xce,0xcf,0xcb,0xce,0xc8,0xcf,0xcf,0xcc,0xe3,0x23,0x67,0xcd,0xeb,0x21,0xef,0x96,0xcd,0xef,0x21,0x1e,0xaf,0x22,0xaa,0xaa,0xaa,0xef,0xab,0x44,0xcd,0xef,0x21,0xfc,0xb2,0xcd,0xeb,0x21,0xf4,0x8a,0xee,0xab,0x41,0xcd,0x49,0x95,0xeb,0x55,0x60,0xcd,0xe8,0x21,0x9e,0x39,0xee,0xab,0x44,0x9b,0x55,0x9b,0x6a,0x56,0x06,0x2e,0x6a,0xde,0xad,0x6b,0x65,0xa7,0xab,0x6d,0x41,0x5e,0x93,0x7d,0xdf,0x77,0xcd,0xeb,0x21,0xf4,0x8e,0xee,0xab,0x41,0x9b,0x63,0xcc,0xcd,0xe8,0x21,0xa6,0xf9,0xcd,0xeb,0x21,0xf4,0xb6,0xee,0xab,0x41,0xcd,0x21,0xae,0x21,0xee,0xab,0x42,0x69
