시스템 해킹

 1576, 1/79 회원가입  로그인  
   짹잭이
   http://jack2.tistory.com
   [BOF] Hackerschool Handbook#1 BOF 왕기초편 p.121에서

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



    
cd80 코어파일에서 확인해보셔야 할 것 같네요
세그폴이 일어났을땐 printf함수가 실행중일테니 일단 코어파일에서 스택에 뭐가 푸쉬됐나 보신 후안나온다 싶으면 gdb로 직접 실행시키면서 printf 의 인자로 뭐가 푸쉬되있나 확인해보세요
2012/06/28