运行 windows shell 命令 NASM X86 汇编语言

Running windows shell commands NASM X86 Assembly language

我正在编写一个简单的汇编程序,它将只执行 windows 命令。我将在下面附上当前的工作代码。如果我硬编码 WinExec 的基地址(来自 Kernel32.dll 的函数),代码就可以工作,我使用另一个名为 Arwin 的程序来定位该地址。但是,由于 windows 内存保护地址 Space 布局随机化 (ASLR)

,重新启动会中断此操作

我想要做的是找到一种方法来执行 windows shell 命令,而不必将内存地址硬编码到我的代码中,该地址将在下次重新启动时更改。我发现了类似的代码,但没有任何我理解或符合目的的代码。我知道这可以用 C 语言编写,但我专门使用汇编程序来保持尽可能小的大小。

谢谢你advice/help。

;Just runs a simple netstat command.
;compile with nasm -f bin cmd.asm -o cmd.bin

[BITS 32]

global _start

section .text

_start:
jmp short command        


function:                 ;Label 
;WinExec("Command to execute",NULL)
pop     ecx
xor     eax,eax
push    eax
push    ecx
mov     eax,0x77e6e5fd  ;Address found by arwin for WinExec in Kernel32.dll
call    eax

xor eax,eax
push    eax
mov eax,0x7c81cafa
call    eax

command:                  ;Label
call function
db "cmd.exe /c netstat /naob"
db 0x00

只是更新说我找到了一种方法来引用 windows API 哈希来执行堆栈中我想要的任何操作。这消除了对内存地址进行硬编码的需要,并允许您编写动态 shellcode。

有针对此的防御措施,但是这仍然适用于仍然存在的无数未打补丁和过时的机器。

以下两个站点对我查找所需内容很有用:

http://blog.harmonysecurity.com/2009_08_01_archive.html

https://www.scriptjunkie.us/2010/03/shellcode-api-hashes/