PIE 가 걸린 바이너리를 GDB 에서 디버깅하면서 proc maps 를 보면 항상 PIE 베이스주소가 고정되어있다. 그 이유를 알아보니, 리눅스에서 proc/sys/kernel/randomize_va_addr 로 ASLR 이 전역적으로 걸려있더라도, 프로세스 설정으로서 ASLR 을 끌 수 있었다. 실제로 GDB 로 디버깅하는 프로세스의 메모리 레이아웃은 PIE 베이스뿐만 아니라 모든 라이브러리에 대해서도 항상 고정되어 있었다.
To temporarily disable ASLR for a particular program you can always issue the following (no need for sudo)
setarch `uname -m` -R ./yourProgram
http://stackoverflow.com/questions/5194666/disable-randomization-of-memory-addresses)
1회째 메모리 레이아웃
root@ubuntu:/tmp# cat /proc/9765/maps
80000000-80001000 r-xp 00000000 08:01 14942231 /tmp/a
80001000-80002000 r--p 00000000 08:01 14942231 /tmp/a
80002000-80003000 rw-p 00001000 08:01 14942231 /tmp/a
b7e12000-b7e13000 rw-p 00000000 00:00 0
b7e13000-b7fc1000 r-xp 00000000 08:01 10749216 /lib/i386-linux-gnu/libc-2.17.so
b7fc1000-b7fc3000 r--p 001ae000 08:01 10749216 /lib/i386-linux-gnu/libc-2.17.so
b7fc3000-b7fc4000 rw-p 001b0000 08:01 10749216 /lib/i386-linux-gnu/libc-2.17.so
b7fc4000-b7fc7000 rw-p 00000000 00:00 0
b7fdb000-b7fdd000 rw-p 00000000 00:00 0
b7fdd000-b7fde000 r-xp 00000000 00:00 0 [vdso]
b7fde000-b7ffe000 r-xp 00000000 08:01 10749212 /lib/i386-linux-gnu/ld-2.17.so
b7ffe000-b7fff000 r--p 0001f000 08:01 10749212 /lib/i386-linux-gnu/ld-2.17.so
b7fff000-b8000000 rw-p 00020000 08:01 10749212 /lib/i386-linux-gnu/ld-2.17.so
bffdf000-c0000000 rw-p 00000000 00:00 0 [stack]
root@ubuntu:/tmp# ps aux | tail
meltdown 8695 0.0 0.2 6436 2764 pts/4 Ss 05:17 0:00 bash
root 8762 0.0 0.1 6136 1860 pts/4 S 05:18 0:00 su
root 8773 0.0 0.1 5732 2020 pts/4 S 05:18 0:00 bash
root 9339 0.0 0.0 0 0 ? S 06:47 0:00 [kworker/u16:2]
root 9469 0.0 0.0 0 0 ? S 07:09 0:00 [kworker/u16:0]
root 9584 0.0 0.0 0 0 ? S 07:22 0:00 [kworker/u16:1]
root 9775 1.5 1.7 27784 18152 pts/4 S+ 07:24 0:00 gdb a
root 9777 0.0 0.0 2044 288 pts/4 t 07:25 0:00 /tmp/a
root 9781 0.0 0.1 5240 1172 pts/3 R+ 07:25 0:00 ps aux
root 9782 0.0 0.0 4288 588 pts/3 S+ 07:25 0:00 tail
2회째 메모리 레이아웃
root@ubuntu:/tmp# cat /proc/9777/maps
80000000-80001000 r-xp 00000000 08:01 14942231 /tmp/a
80001000-80002000 r--p 00000000 08:01 14942231 /tmp/a
80002000-80003000 rw-p 00001000 08:01 14942231 /tmp/a
b7e12000-b7e13000 rw-p 00000000 00:00 0
b7e13000-b7fc1000 r-xp 00000000 08:01 10749216 /lib/i386-linux-gnu/libc-2.17.so
b7fc1000-b7fc3000 r--p 001ae000 08:01 10749216 /lib/i386-linux-gnu/libc-2.17.so
b7fc3000-b7fc4000 rw-p 001b0000 08:01 10749216 /lib/i386-linux-gnu/libc-2.17.so
b7fc4000-b7fc7000 rw-p 00000000 00:00 0
b7fdb000-b7fdd000 rw-p 00000000 00:00 0
b7fdd000-b7fde000 r-xp 00000000 00:00 0 [vdso]
b7fde000-b7ffe000 r-xp 00000000 08:01 10749212 /lib/i386-linux-gnu/ld-2.17.so
b7ffe000-b7fff000 r--p 0001f000 08:01 10749212 /lib/i386-linux-gnu/ld-2.17.so
b7fff000-b8000000 rw-p 00020000 08:01 10749212 /lib/i386-linux-gnu/ld-2.17.so
bffdf000-c0000000 rw-p 00000000 00:00 0 [stack]
root@ubuntu:/tmp#
'Programming' 카테고리의 다른 글
Linux DDD Debuger (0) | 2014.03.13 |
---|---|
Intel PIN Tutorial (1) | 2014.03.06 |
IDA/gdb Debugging After Attaching (0) | 2014.03.03 |
Building KVM from source in Ubuntu (1) | 2014.02.13 |
Linux Kernel compile and update (0) | 2014.01.07 |