/proc/sys/kernel/randomize_va_space의 값을 2에서 0으로 바꾸면 ASLR OFF 가능
$ cat /proc/sys/kernel/randomize_va_space
0
$ echo 2 > /proc/sys/kernel/randomize_va_space
scanf로 payload 입력하는데 @plt 주소에 whitespace(\x20 등) 포함되어있을 때
puts@plt 대신 puts@plt+6 를 호출해도 동일함. 입력 종료 방지하기 위해 @plt 대신 @plt+6 사용
(gdb) x/4i $eip
=> 0x8048320 <puts@plt>: jmp DWORD PTR ds:0x804a00c
0x8048326 <puts@plt+6>: push 0x0
0x804832b <puts@plt+11>: jmp 0x8048310
64bit 함수 호출 시 인자 순서: RDI, RSI, RDX, RCX, R8, R9, Stack ~
FSB에서 %ln, %n 을 이용해 값 덮어쓸 때 TIMEOUT 발생할 수 있다
=> 2바이트, 혹은 1바이트씩 나눠 덮어쓰면 해결
pwntools에 FSB용 유용한 함수 존재한다 => fmtstr_payload
# 64bit일 경우 context.bits = 64 추가
Writes = {
[덮을 대상의 주소1]: [덮을 값],
[덮을 대상의 주소2]: [덮을 값]
}
# write_size는 byte, short, int 중 선택가능 (hhn, hn, n)
payload = fmtstr_payload(FSB_Offset , Writes, write_size='byte')
https://docs.pwntools.com/en/stable/fmtstr.html#pwnlib.fmtstr.fmtstr_payload
pwnlib.fmtstr — Format string bug exploitation tools — pwntools 4.10.0 documentation
Takes a list of atoms and merges consecutive atoms to reduce the number of atoms. For example if you have two atoms AtomWrite(0, 1, 1) and AtomWrite(1, 1, 1) they can be merged into a single atom AtomWrite(0, 2, 0x0101) to produce a short format string. Pa
docs.pwntools.com
실행중인 프로세스 디버깅 using process attach
1. 바이너리 실행 후 PID 구하기
ps -aux | grep read_write
pidof read_write
2. gdb에 해당 프로세스 attach하기
gdb -q -p 50353
gdb 사용 시 유용한 명령어들(잘 안썼던 것들 위주)
- info func ... 말고 다 쓰는 것들??
SSP(Stack Smashing Protector). 함수에서 스택을 사용할 때 카나리가 생성된다
main 함수 호출 전 생성된 canary는 스레드 별 전역 변수로 사용되는 TLS(Thread Local Storage)에 저장된다 = Master Canary = 32bit에선 gs:0x14 , 64bit에선 fs:0x28
TLS는 tcbhead_t 구조체를 가진다 (fs:0x28 = header.stack_guard = Master Canary)
typedef struct
{
void *tcb; /* Pointer to the TCB. Not necessarily the
thread descriptor used by libpthread. */
dtv_t *dtv;
void *self; /* Pointer to the thread descriptor. */
int multiple_threads;
uintptr_t sysinfo;
uintptr_t stack_guard;
// 이하 생략
} tcbhead_t;
seccomp-tools : SECCOMP 적용된 바이너리 분석, BPF 어셈블러/디스어셈블러 제공
=> CTF에서 매우 유용하게 사용되는 도구라네
'security > 포너블 - dreamhack' 카테고리의 다른 글
[Dreamhack Wargame] Bypass SECCOMP-1 (0) | 2023.06.18 |
---|---|
[Dreamhack Wargame] validator (0) | 2023.06.16 |
[Dreamhack Wargame] Cat-Jump (0) | 2023.06.15 |
[Dreamhack Wargame] STB-lsExecutor (0) | 2023.06.15 |
[Dreamhack Wargame] awesome_basic (0) | 2023.06.15 |