Warmup
$ checksec --file=warmup RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX enabled No PIE No RPATH No RUNPATH No Symbols No 0 2 warmup
## Real-world Execution result $ python3 warmup.py ## Feedback Think step by step based on these information only. Delve deeper about and consider about 40 hours at least to exploit `warmup` binary
Identify and Understand the Key Gadgets
0x401040:execve@plt
0x401030:printf@plt
0x401050:gets@plt
Identified Addresses:
- execve@plt:
0x401040
- pop rdi; ret:
0x401243
- pop rsi; pop r15; ret:
0x401241
- /bin/sh string:
0x402004
정답가능
0x401156
0x401157
0x401159
0x40115a
0x40115b
0x40115c
0x40115e
Exploitme
execve가 코드에 없으니 Enter id: 입력 받을 때 execve 커멘드 메모리에 생성되도록 overflow 시키고 Enter password: 다음 입력 받을 때 execve overwrite 시켜둔 주소로 가도록 하는 게 핵심 전략
dummy 아마 9?
segfault: 두개 합쳐서 265까지 안나고, 266 ~ 267 segfault 난다
268은 bus, segfault 둘다 난다
bus error: 269~271
272: id password 한번 더 물어봄
그 뒤로는 segfault
0x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x0asadasds
중간 dummy가 8인듯
첫번째 비워두고 뒤에 257 넣으니 성공 258부터 동일한 오류
0x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x000000010x0
Exploitme default
strings -tx exploitme | grep /bin/sh
Exploitme Linux ASLR
libc attack
ldd exploitme-safestack-cfi-aslr
alan@HOME-SEONGLAND:/mnt/c/Home/Projects/Yonsei/csi4109/hw6$ ldd exploitme-safestack-cfi-aslr linux-vdso.so.1 (0x00007ffff7fc1000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ffff7fa9000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ffff7fa4000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ffff7ebd000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ffff7eb8000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffff7c8f000) /lib64/ld-linux-x86-64.so.2 (0x00007ffff7fc3000)
bin sh string address
strings -a -t x /lib/x86_64-linux-gnu/libc.so.6 | grep /bin/sh 1d8678 /bin/sh
System
objdump -T /lib/x86_64-linux-gnu/libc.so.6 | grep system
alan@HOME-SEONGLAND:/mnt/c/Home/Projects/Yonsei/csi4109/hw6$ objdump -T /lib/x86_64-linux-gnu/libc.so.6 | grep system 0000000000050d70 g DF .text 000000000000002d GLIBC_PRIVATE __libc_system 0000000000050d70 w DF .text 000000000000002d GLIBC_2.2.5 system 0000000000168fb0 g DF .text 0000000000000067 (GLIBC_2.2.5) svcerr_systemerr
Exploit pop rdi ret
ROPgadget --binary ./exploitme | grep 'pop rdi ; ret'
alan@HOME-SEONGLAND:/mnt/c/Home/Projects/Yonsei/csi4109/hw6$ ROPgadget --binary ./exploitme | grep 'pop rdi ; ret' 0x0000000000401643 : pop rdi ; ret alan@HOME-SEONGLAND:/mnt/c/Home/Projects/Yonsei/csi4109/hw6$ ROPgadget --binary ./exploitme-safestack-cfi-aslr | grep 'pop rdi ; ret' 0x00000000000026e6 : pop rdi ; ret
고려사항
@safe stack Indirect function call checking Control Flow Integrity → How to apply COT
32bit 64bit 차이
GDB library address
info proc mappings info registers
p printf p system
x/2i 0x5555555566e6
x/2s 0x402004
GPT instruction
1. 전략 2. 많이 생각 3. 1줄로 대답 4. 한글로 대답 5. github readme 제공 6. hw6 pdf 제공 7. exploit.py 제공 8. exploitme.py 제공 9. exploitme.asm 제공 10. gadget address는 전부 확실한 값이니 의심하지 마라
Github
csi4109-information-security/assignment-5 at master · tunatone0111/csi4109-information-security
Contribute to tunatone0111/csi4109-information-security development by creating an account on GitHub.
https://github.com/tunatone0111/csi4109-information-security/tree/master/assignment-5
RTL
0x02 - x64 RTL(Return to libc)
x64 RTL(Return to Library) 이번 문서에서는 64비트 환경에서의 RTL을 다루도록 하겠슴다. RTL 이라는 기법은 NX bit(DEP)라는 메모리 보호 기법이 적용됐을때 이를 우회하기 위한 공격입니다. NX bit는 이전 문서에서 다뤘던 방식 같이 스택영역에 쉘 코드를 삽입하고 이 쉘 코드가 실행되는 방법이 불가능하게 스택 상에 실행 권한을 제거하여 프로세스 명령어나 데이터 저장을 위한 메모리 영역을 분리 시키는 기술임다. 그럼 RTL은 뭐냐? Return Address 영역을 공유 라이브러리의 함수 주소로 변경해 우리가 원하는 함수를 공유라이브러리에서 호출하여 system(), execve() 같은 함수를 가져와 실행시키는 공격방법임다. RTL을 이용하면 NX bit가 걸려있어도 공..
https://redteam-securitylab.tistory.com/18
Address offset
ROP(Return Oriented Programming)
Return Oriented Programming은 기본적으로 RTL 기법과 Gadget을 이용해서 공격에 필요한 코드를 프로그래밍하는 기법입니다.라이브러리의 함수들을 사용하기 때문에 DEP/NX 방어 기법을 우회할 수 있고 사용하고 있는 함수의 got 값을 출력하고
https://velog.io/@silvergun8291/ROPReturn-Oriented-Programming

ASLR
[어설픈] 해커스쿨 FTZ level 11 문제풀이
안녕하세요!오늘은 FTZ Level 11을 풀어볼게요! 제가 여기서 모르는 게 좀 많았어서공부하느라 시간이 좀 오래걸렸네요! 문제를 보니char형의 str버퍼 256byte를 할당하네요!그리고 setreuid를 3092로 설정하네요!권한 상승 시켜준다는 거죠(※ Why? 찾아보니 3092의 uid level 12의 것이에요) 그 다음에 strcpy로 저희의 argv[1]을 복사해오는데일단 여기서 취약점이 있죠!얼마나 복사해오는지 크기 안정했으니까요! 그리고 그 복사해온 것이str에 있는데 이걸 출력하네요printf함수로요! 뭐 버퍼 오버플로우 계속 해왔던 대로 풀면서 드는 생각! 버퍼크기(256byte)+ (더미가 존재하면 더미 크기 ???byte)+ EBP(4byte) 쉽게 설명해서 RET ADDR 전..
https://flash-ctf.tistory.com/27
FTZ Level11
심하게 FSB 냄새가 나는 문제입니다. str을 printf에 직접 넣었기 때문에 이로 인해 FSB가 발생할 수 있습니다. 일단 디버깅을 위해 같은 코드를 작성하여 tmp에 넣고 진행하겠습니다. 우선 실행 흐름을 파악하기 위해 어셈블리 코드를 정적분석해 봅시다. 0x08048394 :push %ebp0x08048395 :mov %esp,%ebp0x08048397 :sub $0x108,%esp0x0804839d :and $0xfffffff0,%esp0x080483a0 :mov $0x0,%eax0x080483a5 :sub %eax,%esp 스택프레임을 생성하고, 264byte (str[256], dummy 8)의 공간을 확보하고, align을 맞춰 주고 flag를 initialize합니다. 0x080483a..
https://eclipsemode.tistory.com/37
Null byte
[HackCTF/Pwnable] ezshell
저번에 쉘 코드 작성 실습을 진행했으므로 이번에는 쉘 코드 관련 문제를 풀어보기로 하였다. 1. 문제 nc ctf.j0n9hyun.xyz 3036 1) mitigation 2) 문제 확인 [ezshell.c] #include #include #include #include void Init(void) { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); setvbuf(stderr, 0, 2, 0); } int main(void) { Init(); char result[100] = "\x0F\x05\x48\x31\xED\x48\x31\xE4\x48\x31\xC0\x48\x31\xDB\x48\x31\xC9\x48\x31\xD2\x48\x31\xF6\x48\x31\xF..
https://rninche01.tistory.com/entry/HackCTFPwnable-ezshell
Seonglae Cho