level1
0x01 分析
查看文件类型、启用的安全机制,可以发现基本没有开启什么安全机制
查看汇编代码
a. 首先查看main函数,发现main函数调用了一个vulnerable_function函数:
b. 查看vulnerable_function函数:
分析一下这段很短的汇编代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
190x0804847b <+0>: push ebp
0x0804847c <+1>: mov ebp,esp
0x0804847e <+3>: sub esp,0x88;申请栈空间,大小为0x88
0x08048484 <+9>: sub esp,0x8;
0x08048487 <+12>: lea eax,[ebp-0x88]; eax points to the buf
0x0804848d <+18>: push eax;
0x0804848e <+19>: push 0x8048570;
0x08048493 <+24>: call 0x8048340 <printf@plt> ;printf("What's this:%p", &buf)
0x08048498 <+29>: add esp,0x10; 平衡栈,回收刚才printf的两个参数以及<+9>抬高的栈
0x0804849b <+32>: sub esp,0x4;
0x0804849e <+35>: push 0x100
0x080484a3 <+40>: lea eax,[ebp-0x88]; eax再次指向buf
0x080484a9 <+46>: push eax
0x080484aa <+47>: push 0x0
0x080484ac <+49>: call 0x8048330 <read@plt>;read(0, &buf, 0x100u); 存在溢出
0x080484b1 <+54>: add esp,0x10; 平衡栈,回收read的三个参数以及<+32>太高的栈
0x080484b4 <+57>: nop
0x080484b5 <+58>: leave
0x080484b6 <+59>: ret现在这么一分析,漏洞呼之欲出,写成C代码就是用IDA分析的结果:
0x02 利用思路
1. 方法1:将shellcode写在栈上,然后将返回地址覆盖为shellcode的地址:
1 | #!/usr/bin/env python |