参考资料:
- 安全客,前六题的题解:https://www.anquanke.com/post/id/150359
- Linux Syscall Reference:http://syscalls.kernelgrok.com/
- Assembly Reference: https://www.felixcloutier.com/x86/
首先检查安全保护等级:
|
|
查看汇编代码:
|
|
我们分析这个汇编代码的结构:
观察这个函数的开始段,它并没有诸如押入
ebp
等栈操作。一直到0x804806c
这个地址,函数做了一些初始化的事情,并且把四个寄存器置 0;0x804806e - 0x8048082
这段地址向栈中存入了字符串(小端存储、栈从高到低增长):1 2
print(b'\x4c\x65\x74\x27\x73\x20\x73\x74\x61\x72\x74\x20\x74\x68\x65\x20\x43\x54\x46\x3a') # b"Let's start the CTF:"
0x8048087 - 0x804808f
这段代码调用了int 80h
中断,查询网址,知道 4 号中断是sys_write()
:1
sys_write(unsigned int fd = 1, const char __user *buf = $esp, int count = 0x14)
0x8048091 - 0x8048097
这段代码调用了int 80h
的 3 号中断sys_read()
:1
sys_read(unsigned int fd = 0, const char __user *buf = $esp, int count = 0x3c)
然后程序在
0x8048099
将栈顶指针上移了0x14
个字节。然后程序执行
ret
指令(ret
指令只做一件事情,将程序的执行权交给栈顶esp
指向的地址)。
exp.py
如下:
|
|