首页 文章

MASM shellcode和NASM shellcode之间是否存在差异

提问于
浏览
6

我是StackOverflow的新手 . 最近,我开始研究汇编,对于汇编来说还是一个新手,对shellcode来说是全新的 . 我正在使用RadAsm使用MASM汇编程序进行编译,我尝试从这个网站学习shellcode Shellcoding for Linux and Windows

我在Windows 64位上使用RadAsm . 我使用的代码几乎相同,只是我使用函数的绝对名称而不是DLL中函数的地址 . shellcode应该使用带参数 5000 的sleep函数 .

这是我在MASM中使用的代码 .

.386
.model flat, stdcall
option casemap:none

include kernel32.inc
includelib kernel32.lib

.code
_start:
    xor eax, eax    ; zero out eax
    mov ebx, Sleep  ; function sleep goes in ebx
    mov ax, 5000    ; parameter goes in ax
    push eax        ; parameter on stack
    call ebx        ; call Sleep
end _start
end

这在MASM中没有错误地组装 .

生成的shellcode具有空值,与网站略有不同 . 它如下 .

我使用 objdump -d nameofexecutable.exe 来进行反汇编 .

Disassembly of section .text
 00401000 <.text>:
  401000:       33 c0                   xor    %eax,%eax
  401002:       bb 0e 10 40 00          mov    $0x40100e,%
  401007:       66 b8 88 13             mov    $0x1388,%ax
  40100b:       50                      push   %eax
  40100c:       ff d3                   call   *%ebx
  40100e:       ff 25 00 20 40 00       jmp    *0x402000

但在网站上,没有 00 十六进制代码 .

Disassembly of section .text:

08048080 <_start>:
 8048080:       31 c0                   xor    %eax,%eax
 8048082:       bb ea 1b e6 77          mov    $0x77e61bea,%ebx
 8048087:       66 b8 88 13             mov    $0x1388,%ax
 804808b:       50                      push   %eax
 804808c:       ff d3                   call   *%ebx

可能是因为我使用x64编译或因为我间接调用函数?

任何帮助将不胜感激,谢谢 .

2 回答

  • 3

    简单的答案是MASM很糟糕!

    引自here "In the past I had developed 32-bit shellcode using the free and open-source Netwide Assembler (NASM), but when going through the exercise of learning the 64-bit variety I figured I would try it out with the Microsoft Assembler (MASM) instead. One problem quickly became apparent: MASM offers no way (that I know of) to generate raw binary machine code as opposed to an .exe file! All is not lost though, the code bytes can be extracted from the .exe file easily enough (but in the future I might go back to NASM).",创建shellcode更加困难 .

    我使用NASM为一个程序创建shellcode,该程序说明了你在windows x64上提供的链接,这是我实现的结果,没有空字节 . 原来睡眠的例子可能无法正常工作,但第二个例子是完全正常的 .

    "\x31\xc0\x31\xdb\x31\xc9\x31\xd2\xeb\x2f\x59\x88\x51\x0a"
    "\xbb\x82\xf8\x60\x77\x51\xff\xd3\xeb\x31\x59\x31\xd2"
    "\x88\x51\x0b\x51\x50\xbb\xe6\x4d\x61\x77\x59\x31\xd2"
    "\x88\x51\x03\x31\xd2\x52\x51\x51\x52\x31\x32\xd2\x50"
    "\xb8\xca\x3a\x61\x77\xe8\xcc\xff\xff\xff\x75\x73\x65"
    "\x72\x33\x32\x2e\x64\x6c\x6c\x4e\xe8\xca\xff\xff\xff"
    "\x4d\x65\x73\x73\x61\x67\x65\x42\x6f\x78\x41\x4e\xe8"
    "\xc6\xff\xff\xff\x48\x65\x79\x4e"
    

    NOTE: use nameofexecutable.o with objdump

    即 . objdump -o nameofexecutable.o获取shellcode而不是nameofexecutable.exe

  • 4

    您的代码被组装为在0x00401000运行,因此所有地址的最高字节最终为0x00 . 他们的代码组装在0x08048080,因此所有地址的最高字节最终为0x08 .

    这是你所有的零来自哪里 .

相关问题