|
http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=1589 [복사]
실습 내용처럼 RET(리턴 어드레스)를 0xdeadbeef로 바꾸려고 합니다.
소스코드는 아래와 같습니다.
Jack2@SchoolPC ~/BOF/12
$ cat ex3.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dumpcode.h"
int main(int argc, char *argv[])
{
char buffer[20] = {0,}; //0으로 초기화
int *pointer_to_ret = (int *)(buffer+24); //ret를 출력하기 위한 포인터
if(argc < 2)
{
printf("argument error\n");
exit(-1);
}
//dumpcode로 메모리 덤프
dumpcode(buffer, 28);
printf("[+] BEFORE : the return address is 0x%08x\n\n", *pointer_to_ret);
//buffer overflow 발생!!
strcpy(buffer, argv[1]);
//dumpcode로 메모리 덤프
dumpcode(buffer, 28);
printf("[+] AFTER : the return address is 0x%08x\n\n", *pointer_to_ret);
}
막상 0xdeadbeef로 바꾸려고 하는데 아래와 같은 결과가 나타납니다.
Jack2@SchoolPC ~/BOF/12
$ ./ex3 aaaaaaaaaaaaaaaaaaaaaaaa`python -c 'print "\xef\xbe\xad\xde"'`
0x0022ac78 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0x0022ac88 00 00 00 00 90 ac 22 00 2f 00 00 00 ......"./...
[+] BEFORE : the return address is 0x0000002f
0x0022ac78 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 aaaaaaaaaaaaaaaa
0x0022ac88 61 61 61 61 61 61 61 61 ef be ad de aaaaaaaa....
Segmentation fault (core dumped)
즉 , printf("[+] AFTER : the return address is 0x%08x\n\n", *pointer_to_ret);
이 코드가 실행되지 않는데요...
혹시나 하는 생각에 ftz 서버에 접속을 한 뒤 같은 소스코드를 컴파일 한 결과
[guest@ftz practice]$ ./ex3 aaaaaaaaaaaaaaaaaaaaaaaa`python -c 'print "\xef\xbe\xad\xde"'`
0xbffffa90 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0xbffffaa0 00 00 00 00 04 fb ff bf b8 fa ff bf ............
[+] BEFORE : the return address is 0xbffffab8
0xbffffa90 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 aaaaaaaaaaaaaaaa
0xbffffaa0 61 61 61 61 61 61 61 61 ef be ad de aaaaaaaa....
[+] AFTER : the return address is 0xdeadbeef
다음과 같이 잘 나타납니다.
제가 실습한 환경이 windows xp cygwin 환경에서 컴파일을 했습니다.
그래서 문제가 생긴것 같은데
자세한 원인 아시는 분 있으시면 답변 좀 부탁드릴께요
|
Hit : 4406 Date : 2012/06/27 01:55
|