【问题标题】:How to compile Intel x86 assembly code to get hex dump?如何编译 Intel x86 汇编代码以获得十六进制转储?
【发布时间】:2014-12-02 08:32:46
【问题描述】:

我有以下汇编代码可以从 Erickson 的漏洞利用书中生成一个 shell:

; execve(const char *filename, char *const argv [], char *const envp[])
xor eax, eax ; Zero out eax.
push eax ; Push some nulls for string termination.
push 0x68732f2f ; Push "//sh" to the stack.
push 0x6e69622f ; Push "/bin" to the stack.
mov ebx, esp ; Put the address of "/bin//sh" into ebx, via esp.
push eax ; Push 32-bit null terminator to stack.
mov edx, esp ; This is an empty array for envp.
push ebx ; Push string addr to stack above null terminator.
mov ecx, esp ; This is the argv array with string ptr.
mov al, 11 ; Syscall #11.
int 0x80 ; Do it.

但是,我的 linux 机器没有 nasm,要获得它需要我让管理员下载软件包。还有其他方法可以将其转换为十六进制吗?我知道 GCC 使用 AT&T,但我不知道任何支持 Intel x86 的方法。

【问题讨论】:

  • 请参阅stackoverflow.com/questions/9347909/… 如果这不起作用,并且您觉得让您的管理员让您下载 nasm 太麻烦,您可以用 AT&T 语法重写代码。
  • 原谅我的 Linux foo,但那会是 gcc assem.s -masm=intel objFileToGetHexed.o 吗?我正在运行 .o 文件的 No such 文件或目录,这对我来说没有意义......
  • 不,我相信您会在源文件中添加它。
  • 你不能安装nasm,也许是从源代码编译它并安装在你的私有目录中(例如你的$HOME/bin/)??

标签: linux assembly hexdump


【解决方案1】:

要仅获取十六进制转储,您不需要有效的可执行文件。在您的情况下(没有重定位),我认为在家中使用您的操作系统上的汇编程序组装代码没有问题,获取十六进制转储并在目标系统上使用它。只需注意架构(i386 或 x86_64)。

以下是在 Linux 上获取 hex-dump 的步骤:

test.s(小写“.s”)

.intel_syntax noprefix
.text
.global _start
_start:

xor eax, eax # Zero out eax.
push eax # Push some nulls for string termination.
push 0x68732f2f # Push "//sh" to the stack.
push 0x6e69622f # Push "/bin" to the stack.
mov ebx, esp # Put the address of "/bin//sh" into ebx, via esp.
push eax # Push 32-bit null terminator to stack.
mov edx, esp # This is an empty array for envp.
push ebx # Push string addr to stack above null terminator.
mov ecx, esp # This is the argv array with string ptr.
mov al, 11 # Syscall #11.
int 0x80 # Do it.

考虑将评论符号;改为#

构建并获取十六进制转储:

gcc -m32 -c test.s
objdump -F -s -j.text test.o

您也可以使用gdb test.odisass/r _start

【讨论】:

    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2012-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      相关资源
      最近更新 更多