[System Security] 기말고사 정리
ASLR 해제 명령
sudo sysctl kernel.randomize_va_space=0 (default=2)
gcc 디버깅 정보 추가 옵션
gcc -o stackbof stackbof.c -fno-stack-protector -mpreferred-stack-boundary=2 -g
stackexploit1
1. ./stackexploit1 512
2. Heap에 512만큼 (NOP sled + shell code) 작성
3. stack에 (12*A + 추측한 주소) 작성
4. execl("./stackbof1, stackbof1, 스택버퍼, 힙버퍼, NULL)
1. 스택버퍼로 받은 인자를 스택에 저장
2. 출력
3. main return시 조작된 주소로 return
heapexploit1
1. ./heapexploit1 512
2. Heap에 512만큼 (NOP sled + shell code) 작성
3. stack에 (64*A + 추측한 주소) 작성
4. execl("./heapbof1, heapbof1, 스택버퍼, 힙버퍼, NULL)
1. 스택버퍼로 받은 인자를 스택에 저장 (strncpy)
2. 함수 호출하면 조작된 주소(스택)로 호출
heapexploit2
1. ./heapexploit1 512
2. Heap에 512만큼 (NOP sled + shell code) 작성
3. stack에 (64*A + 추측한 주소) 작성
4. execl("./heapbof2, heapbof2, 스택버퍼, 힙버퍼, NULL)
1. 스택버퍼로 받은 인자를 힙에 저장
2. 함수 호출하면 조작된 주소(힙)로 return
fmtstr
1. eggshell 실행
2. 위와 동일
컴파일시 NX 스택 기능 해제
gcc -o stackbof stackbof.c -fno-stack-protector -mpreferred-stack-boundary=2 -W1,-z,execstack
Canary 해제
gcc -o stackbof stackbof.c -fno-stack-protector
소스코드 Fortify + 최적화
gcc -D_fortify_source=2 -O2
소스코드 Format String 에러 방지
gcc -Wformat-security
gcc -Wno-format-security : 해제
gcc -Werror=fomat-security
ASLR 기술 2가지
sudo sysctl kernal.randomize_va_space=2
gcc -o sample sample.c -fPIE -pie
gdb 옵션 정리
-q : quite, 조용히
-g : 디버깅 정보 추가
gdb 명령어 정리
list : 소스코드 출력
b # : #라인에 Break
r AAAAAAA : AAAAAAA 입력하고 계속하기
p &buffer : buffer의 주소를 출력
info reg $esp : esp 값을 출력
x/8wx $esp : esp주소부터 word 8개 출력