'2011/06/15'에 해당되는 글 2건
- 2011.06.15 [LEVEL19] nightmare -> xavis (fgets + destroyers)
- 2011.06.15 [LEVEL18] succubus -> nightmare (plt)
[view source] |
/* The Lord of the BOF : The Fellowship of the BOF - xavius - arg */ #include <stdio.h> #include <stdlib.h> #include <dumpcode.h>
main() { char buffer[40]; char *ret_addr;
// overflow! fgets(buffer, 256, stdin); printf("%s\n", buffer);
if(*(buffer+47) == '\xbf') { printf("stack retbayed you!\n"); exit(0); }
if(*(buffer+47) == '\x08') { printf("binary image retbayed you, too!!\n"); exit(0); }
// check if the ret_addr is library function or not memcpy(&ret_addr, buffer+44, 4); while(memcmp(ret_addr, "\x90\x90", 2) != 0) // end point of function { if(*ret_addr == '\xc9'){ // leave if(*(ret_addr+1) == '\xc3'){ // ret printf("You cannot use library function!\n"); exit(0); } } ret_addr++; }
// stack destroyer memset(buffer, 0, 44); memset(buffer+48, 0, 0xbfffffff - (int)(buffer+48));
// LD_* eraser // 40 : extra space for memset function memset(buffer-3000, 0, 3000-40); } |
♧ 사용 할 수 있는 공간이 별루 없다. |
[ summary ] | ||||
① strace ./사본으로 내용을 보면 fgets()는 내부 시스템콜 read()를 호출하는데
② gdb로 fgets를 호출 후 바로 확인해 보면 입력한 "DDDD~"가 0x40015000부터 들어가는 것을 볼 수 있다.
|
[ Attack ] | ||
※(0x40015000은 마지막 "00"이 널로 취급 때문에 NOP썰매가 있는 곳으로 수정)
성공!!! |
nightmare : "beg for me"
'워게임(WarGame) > BOF원정대(LOF)' 카테고리의 다른 글
[LEVEL20] xavis -> death_knight (remote BOF) (0) | 2011.06.18 |
---|---|
[LEVEL18] succubus -> nightmare (plt) (0) | 2011.06.15 |
[LEVEL17] zombie_assassin -> succubus (function calls) (0) | 2011.06.12 |
[LEVEL16] assassin -> zombie_assassin (fake ebp) (0) | 2011.06.11 |
[LEVEL15] giant -> assassin (no stack, no RTL) (0) | 2011.06.10 |
[view source] |
/* The Lord of the BOF : The Fellowship of the BOF - nightmare - PLT */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dumpcode.h>
main(int argc, char *argv[]) { char buffer[40]; char *addr;
if(argc < 2){ printf("argv error\n"); exit(0); }
// check address addr = (char *)&strcpy; if(memcmp(argv[1]+44, &addr, 4) != 0){ printf("You must fall in love with strcpy()\n"); exit(0); }
// overflow! strcpy(buffer, argv[1]); printf("%s\n", buffer);
// dangerous waterfall memset(buffer+40+8, 'A', 4); } |
♧ RET부분이 strcpy주소로 시작을 하는지 check하고 있다. |
♧ GOT와 PLT [ 참조 ] |
GOT는 Global Offset Table(전역 오프셋 테이블)약자며 실행 후, libc.so내 실제 함수 주소가 담기는 저장소이다. 이 내용 참조를 통해 _dl_runtime_resolve가 수행되고, 실제 시스템 라이브러리 호출이 이루어지게 된다. (매 번이 아닌, 한 번만 수행되고 나면, 그 다음부터는 GOT에 기록된 내용만 참조하여 수행) 이를 실제 시스템 라이브러리 주소를 호출하기 위해 필요한 정보 테이블이라 보면 될 것 같다. |
[ summary ] |
♧ strcpy()를 이용해 argv[2]에 있는 system()를 리턴 주소(strcpy호출 다음)에 복사하여 실행 흐름을 변경한다.
|
[ Attack ] | |||
① 필요한 주소 구하기.
② ∑xploit
|
※ 사전에 chsh명령 -> bash2로 변경 후 재로그인 함
succubus : "here to stay"
'워게임(WarGame) > BOF원정대(LOF)' 카테고리의 다른 글
[LEVEL20] xavis -> death_knight (remote BOF) (0) | 2011.06.18 |
---|---|
[LEVEL19] nightmare -> xavis (fgets + destroyers) (0) | 2011.06.15 |
[LEVEL17] zombie_assassin -> succubus (function calls) (0) | 2011.06.12 |
[LEVEL16] assassin -> zombie_assassin (fake ebp) (0) | 2011.06.11 |
[LEVEL15] giant -> assassin (no stack, no RTL) (0) | 2011.06.10 |