Write up/Pwnable.tw
[Pwnablw.tw] dubblesort
ipwn
2018. 11. 2. 14:11
보호기법
모든 보호기법이 다 걸려있음.
분석
int __cdecl main(int argc, const char **argv, const char **envp) { int sort_num; // eax unsigned int *buf_pointer; // edi unsigned int sort_cnt; // esi unsigned int idx; // esi unsigned int content; // ST08_4 int result; // eax unsigned int num; // [esp+18h] [ebp-74h] unsigned int sort_buf[8]; // [esp+1Ch] [ebp-70h] char name[64]; // [esp+3Ch] [ebp-50h] unsigned int canary; // [esp+7Ch] [ebp-10h] canary = __readgsdword(0x14u); set(); __printf_chk(1, "What your name :"); read(0, name, 0x40u); __printf_chk(1, "Hello %s,How many numbers do you what to sort :"); __isoc99_scanf("%u", &num); sort_num = num; if ( num ) { buf_pointer = sort_buf; sort_cnt = 0; do { __printf_chk(1, "Enter the %d number : "); fflush(stdout); __isoc99_scanf("%u", buf_pointer); ++sort_cnt; sort_num = num; ++buf_pointer; } while ( num > sort_cnt ); } sort(sort_buf, sort_num); puts("Result :"); if ( num ) { idx = 0; do { content = sort_buf[idx]; __printf_chk(1, "%u "); ++idx; } while ( num > idx ); } result = 0; if ( __readgsdword(0x14u) != canary ) sub_BA0(); return result; } |
vuln :
기본적으로 그냥 바로 overflow가 발생하는 걸 알 수 있음.
근데 또 name입력 때 uninitialized stack을 통해서 libc leak도 가능.
vector :
scanf가 "%d" 등등의 포맷스트링으로 수를 입력받을 때는 '+'와 같은 연산자를 입력해서 아무 입력을 하지 않을 수 있음.
이를 통해서 머리를 잘 굴리면 system("/bin/sh")가능.