본문으로 바로가기

Level18. SUCCUBUS -> NIGHTMARE

category Wargame/LOB 2015. 2. 18. 14:28
반응형

[succubus@localhost succubus]$ cat nightmare.c

/*

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

}


먼저 소스를 보면 


 addr = (char *)&strcpy;

        if(memcmp(argv[1]+44, &addr, 4) != 0)


이부분을 통해 RET에 strcpy의 주소가 들어가있는지 확인한다.


그리고 memset(buffer+40+8, 'A', 4) 이 부분을 통해 RET 다음 4바이트를 AAAA 로 설정해준다.

(사실 처음에 RET를 A로 덮는것으로 잘못보고 어떻게 풀어야하나 싶었다)


아래와 같은 페이로드를 구성했다.


&system + AAAA + &/bin/sh + NOP(32) + &strcpy + AAAA + &ret + &buffer

[---------Buf + SPF(44Byte)-------][--RET--]


RET에 &strcpy를 주고 dest에 &ret, source에 &buffer를 주어 ret를 buffer로 덮어버리는 구조다.


각 주소들을 구해서 공격을 시도했다.






beg for me

반응형

'Wargame > LOB' 카테고리의 다른 글

[FC3] HELL_FIRE -> EVIL_WIZARD  (0) 2015.03.31
Level17. ZOMBIE_ASSASSIN -> SUCCUBUS  (0) 2015.02.18