【问题标题】:Running windows shell commands NASM X86 Assembly language运行 windows shell 命令 NASM X86 汇编语言
【发布时间】:2016-04-19 05:32:24
【问题描述】:

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

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

感谢您的建议/帮助。

;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

【问题讨论】:

  • 你是如何运行这个程序的?
  • 如果我想手动运行它,我会将它与 ld 链接到 windows .exe 中。但是我主要使用.bin文件来简单地生成十六进制代码。

标签: security assembly nasm aslr


【解决方案1】:

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

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

以下两个网站有助于我找到所需内容:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-14
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多