SlideShare a Scribd company logo
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting Linux and PaX ASLR’s weaknesses
on 32- and 64-bit systems
Hector Marco-Gisbert, Ismael Ripoll
Universitat Polit`ecnica de Val`encia (Spain)
http://cybersecurity.upv.es
Black Hat Asia
March 29 - April 1, 2016
1 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Table of contents
1 ASLR overview & background
2 Linux and PaX ASLR weaknesses
Too low entropy
Non-uniform distribution
Correlation between objects
Inheritance
3 Exploiting the Correlation weakness: offset2lib
Example: Offset2lib in stack buffer overflows
Demo: Root shell in < 1 sec.
Mitigations
4 ASLR-NG: ASLR Next Generation
New randomisation forms
ASLRA: ASLR Analyzer
Linux vs PaX vs ASLR-NG
5 Conclusions
2 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR overview & background
What have we done ?
We have deeply analyzed the ASLR of Linux and PaX and:
Found some weaknesses and limitations on the current implementations:
1 Too low entropy
2 Non-uniform distribution
3 Correlation between objects
4 Inheritance
Built attacks which exploit these weaknesses:
Offset2lib: bypasses the NX, SSP and ASLR in in < 1 sec.
Also, other attack vectors (exploiting other weaknesses)
We have contributed to Linux kernel by:
Fixing the Offset2lib weakness.
Sketches a working in progress version of the ASLR → ASLR-NG.
Also some mitigation techniques will be presented (RenewSSP)
We present ASLRA, a suit tool to analyze the entropy of Linux ASLR
implementations.
3 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR overview & background
ASLR Background
ASLR does not remove vulnerabilities but make more difficult to
exploit them.
ASLR deters exploits which relays on knowing the memory map.
ASLR is effective when all memory areas are randomise. Otherwise,
the attacker can use these non-random areas.
Full ASLR is achieved when:
Applications are compiled with PIE (-fpie -pie).
The kernel is configured with randomize va space = 2
(stack, VDSO, shared memory, data segment)
4 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR overview & background
What is ASLR ?
ASLR is a protection provided by the kernel
to applications which:
It loads the stack, executable, libraries
and heap at random locations.
It tries to deter attacks that rely on
knowing the location of the target data
or code.
It makes vulnerabilities more difficult to
exploit.
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
5 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR overview & background
How the ASLR works: A simple example
The attacker redirects the execution to the
exec() library function (lib1):
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
6 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR overview & background
How the ASLR works: A simple example
The attacker redirects the execution to the
exec() library function (lib1):
Trivial if ASLR is off.
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
6 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR overview & background
How the ASLR works: A simple example
The attacker redirects the execution to the
exec() library function (lib1):
Trivial if ASLR is off.
But it fails when the ASLR is on.
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
6 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR overview & background
How the ASLR works: A simple example
The attacker redirects the execution to the
exec() library function (lib1):
Trivial if ASLR is off.
But it fails when the ASLR is on.
Not only the libraries but all other memory
areas are randomized:
→ How difficult is to predict the target ?
• Depends on the entropy.
→ Are there other attack vectors ?
• Yes, We have found new weaknesses.
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
6 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Linux and PaX ASLR weaknesses
Linux and PaX ASLR weaknesses
Current ASLR was designed considering that
some zones are growable but:
Cannot be used safely because collisions
with other allocations cannot be avoided.
Currently, only used in the Stack and the
Heap.
Growable objects impose strong limitations
on ASLR design:
Linux places each object as separately as
possible (Stack and Heap)
Unfortunately, this introduce weaknesses.
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
7 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Linux and PaX ASLR weaknesses
Weakness 1) Too low entropy
Brute force attacks to bypass ASLR:
x86 Entropy 100% Mean
Linux
32-bit 28
(256) < 1 sec < 1 sec
64-bit 228
(260M.) 74 Hours 37 Hours
ASLR entropy and cost time (1000 trials/sec).
→ ASLR in 32-bit is almost useless (very low entropy).
→ In 64-bit the attack is feasible in some scenarios.
→ The weakness is present since the first Linux ASLR.
Flowredirect
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
?
8 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Linux and PaX ASLR weaknesses
Weakness 2) Non-uniform distribution
0
0.002
0.004
0.006
0.008
0.01
0.012
0.014
0.016
0.018
0.02
0 20 40 60 80 100
Probability
Bins
Expected
i386
PaX Libraries distribution in i386
0
0.005
0.01
0.015
0.02
0 20 40 60 80 100
Probability
Bins
Expected
x86_64
PaX Libraries distribution in x86 64
Libraries are not uniformly distributed:
Faster attacks by focusing on the most frequent (likely) addresses.
Other objects are also affected.
9 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Linux and PaX ASLR weaknesses
Weakness 3) Correlation between objects
Instead of de-randomizing the target object, first de-randomize an
intermediate object and then use it to de-randomize the target
→ We made the first demonstration [Offset2lib]
The Offset2lib attack vector:
It bypass the full Linux ASLR on any architecture in < 1 sec.
It does not use the GOT or PLT.
It works even with NX and SSP enabled.
It exploits a stack buffer overflow.
10 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Linux and PaX ASLR weaknesses
Weakness 3) Correlation between objects
We have developed a PoC to exploit the
Offset2lib weakness:
1 De-randomize the executable exploiting a
stack buffer overflow.
2 Calculate (offline) the constant distance to
the target libraries.
3 The libraries are now de-randomized.
stack
lib1
lib2
exec
heap
LOW
HIGH
VM space
FlowredirectConstant !
11 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Linux and PaX ASLR weaknesses
Weakness 3) Correlation between objects
Memory map of an application PIE compiled.
The ld is loaded consecutively to the app.: 0x7f36c6feb000
12 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Linux and PaX ASLR weaknesses
Weakness 4) Inheritance
Again, all child processes share the same
memory layout !
New allocations belonging only to a
child can be predicted by its parent and
siblings !
Example: Child 1 can easily guess where
the private file 2 has been
mapped.
stack
lib1
lib2
private file 1
heap
exec
LOW
HIGH
VM space
Flowredirect
Child 1
stack
lib1
lib2
private file 2
heap
exec
LOW
HIGH
VM space
Flowredirect
Child n
13 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
Loading shared objects
The problem appears when the application is compiled with PIE because the
GNU/Linux algorithm for loading shared objects works as follows:
The first shared object is loaded at a random position.
The next object is located right below (lower addresses) the last object.
...
libc-2.19.so
ld-2.19.so
server 64 PIE
...
Stack
...
All libraries are located ”side by side” at a single random place.
0x000000000000
0x7FFFFFFFFFFF
mmap base
Executable Base
Dynamic Linker Base
Libc Base
14 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
Offset2lib
$ cat /proc/<pid>/server 64 PIE
7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so
7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so
7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so
7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so
7fd1b4510000-7fd1b4515000 rw-p
7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so
7fd1b4718000-7fd1b471b000 rw-p
7fd1b4734000-7fd1b4737000 rw-p
7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so
7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so
7fd1b4739000-7fd1b473a000 rw-p
7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE
7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE
7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE
7fff981fa000-7fff9821b000 rw-p [stack]
7fff983fe000-7fff98400000 r-xp [vdso]
15 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
Offset2lib
$ cat /proc/<pid>/server 64 PIE
7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so
7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so
7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so
7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so
7fd1b4510000-7fd1b4515000 rw-p
7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so
7fd1b4718000-7fd1b471b000 rw-p
7fd1b4734000-7fd1b4737000 rw-p
7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so
7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so
7fd1b4739000-7fd1b473a000 rw-p
7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE
7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE
7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE
7fff981fa000-7fff9821b000 rw-p [stack]
7fff983fe000-7fff98400000 r-xp [vdso]
0x5eb000
15 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
Offset2lib
$ cat /proc/<pid>/server 64 PIE
7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so
7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so
7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so
7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so
7fd1b4510000-7fd1b4515000 rw-p
7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so
7fd1b4718000-7fd1b471b000 rw-p
7fd1b4734000-7fd1b4737000 rw-p
7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so
7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so
7fd1b4739000-7fd1b473a000 rw-p
7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE
7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE
7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE
7fff981fa000-7fff9821b000 rw-p [stack]
7fff983fe000-7fff98400000 r-xp [vdso]
0x5eb000
0x225000
15 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
Offset2lib
7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so
7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so
7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so
7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so
7fd1b4510000-7fd1b4515000 rw-p
7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so
7fd1b4718000-7fd1b471b000 rw-p
7fd1b4734000-7fd1b4737000 rw-p
7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so
7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so
7fd1b4739000-7fd1b473a000 rw-p
7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE
7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE
7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE
7fff981fa000-7fff9821b000 rw-p [stack]
7fff983fe000-7fff98400000 r-xp [vdso]
offset2lib
offset2lib
We named this invariant distance offset2lib which:
It is a constant distance between two shared objects even in different
executions of the application.
16 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
Offset2lib
7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so
7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so
7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so
7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so
7fd1b4510000-7fd1b4515000 rw-p
7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so
7fd1b4718000-7fd1b471b000 rw-p
7fd1b4734000-7fd1b4737000 rw-p
7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so
7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so
7fd1b4739000-7fd1b473a000 rw-p
7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE
7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE
7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE
7fff981fa000-7fff9821b000 rw-p [stack]
7fff983fe000-7fff98400000 r-xp [vdso]
offset2lib
offset2lib
We named this invariant distance offset2lib which:
It is a constant distance between two shared objects even in different
executions of the application.
Any address of the app. → de-randomize all mmapped areas !!!
16 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
Why the Offset2lib is dangerous ?
Offset2lib scope:
Realistic; applications are more prone than libraries to errors.
Makes some vulnerabilities faster, easier and more reliable to
exploit them.
It is not a self-exploitable vulnerability but an ASLR-design weakness
exploitable.
It opens new (and old) attack vectors.
17 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
Why the Offset2lib is dangerous ?
Offset2lib scope:
Realistic; applications are more prone than libraries to errors.
Makes some vulnerabilities faster, easier and more reliable to
exploit them.
It is not a self-exploitable vulnerability but an ASLR-design weakness
exploitable.
It opens new (and old) attack vectors.
Next example:
Offset2lib on a standard stack buffer overflow.
17 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
Building the attack
The steps to build the attack are:
1 Extracting static information
2 Brute force part of saved-IP
3 Calculate base app. address
4 Calculate library offsets
5 Obtain mmapped areas
18 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
1) Extracting static information
→ Our goal is to obtain an address belonging to the application.
→ We are going to obtain the saved-IP of vulnerable function caller.
Offset2lib with saved-IP ⇒ all mmapped areas.
STACK
0000000000001063 <attend_client>:
1063: 55 push %rbp
1064: 48 89 e5 mov %rsp,%rbp
1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp
106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
1075: 00 00
..... ..... .....
12d7: 48 89 c7 mov %rax,%rdi
12da: e8 1c fc ff ff callq efb <vuln func>
12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax
12e6: 48 89 c7 mov %rax,%rdi
..... ..... .....
...
BUFFER
RBP
0x???????????????
...
Stackgrowsdown
19 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
1) Extracting static information
→ Our goal is to obtain an address belonging to the application.
→ We are going to obtain the saved-IP of vulnerable function caller.
Offset2lib with saved-IP ⇒ all mmapped areas.
STACK
0000000000001063 <attend_client>:
1063: 55 push %rbp
1064: 48 89 e5 mov %rsp,%rbp
1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp
106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
1075: 00 00
..... ..... .....
12d7: 48 89 c7 mov %rax,%rdi
12da: e8 1c fc ff ff callq efb <vuln func>
12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax
12e6: 48 89 c7 mov %rax,%rdi
..... ..... .....
...
BUFFER
RBP
0x???????????????
...
Stackgrowsdown
19 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
1) Extracting static information
→ Our goal is to obtain an address belonging to the application.
→ We are going to obtain the saved-IP of vulnerable function caller.
Offset2lib with saved-IP ⇒ all mmapped areas.
STACK
0000000000001063 <attend_client>:
1063: 55 push %rbp
1064: 48 89 e5 mov %rsp,%rbp
1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp
106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
1075: 00 00
..... ..... .....
12d7: 48 89 c7 mov %rax,%rdi
12da: e8 1c fc ff ff callq efb <vuln func>
12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax
12e6: 48 89 c7 mov %rax,%rdi
..... ..... .....
...
BUFFER
RBP
0x???????????????
...
Stackgrowsdown
Next IP
19 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
1) Extracting static information
→ Our goal is to obtain an address belonging to the application.
→ We are going to obtain the saved-IP of vulnerable function caller.
Offset2lib with saved-IP ⇒ all mmapped areas.
STACK
0000000000001063 <attend_client>:
1063: 55 push %rbp
1064: 48 89 e5 mov %rsp,%rbp
1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp
106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
1075: 00 00
..... ..... .....
12d7: 48 89 c7 mov %rax,%rdi
12da: e8 1c fc ff ff callq efb <vuln func>
12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax
12e6: 48 89 c7 mov %rax,%rdi
..... ..... .....
...
BUFFER
RBP
0x???????????????
...
Stackgrowsdown
Next IP
Address point to
19 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
1) Extracting static information
Memory map STACK
7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so
7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so
7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so
7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so
7fd1b4510000-7fd1b4515000 rw-p
7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so
7fd1b4718000-7fd1b471b000 rw-p
7fd1b4734000-7fd1b4737000 rw-p
7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so
7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so
7fd1b4739000-7fd1b473a000 rw-p
7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE
7fd1b493b000-7fd1b493c000 r--p /root/server 64 PIE
7fd1b493c000-7fd1b493d000 rw-p /root/server 64 PIE
7fff981fa000-7fff9821b000 rw-p [stack]
7fff983fe000-7fff98400000 r-xp [vdso]
...
BUFFER
RBP
0x????????????????
...
Stackgrowsdown
This value (0x00007F) can be obtained:
1 Running the application and showing the memory map.
2 Checking the source code if set any limit to stack.
20 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
1) Extracting static information
Memory map STACK
7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so
7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so
7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so
7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so
7fd1b4510000-7fd1b4515000 rw-p
7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so
7fd1b4718000-7fd1b471b000 rw-p
7fd1b4734000-7fd1b4737000 rw-p
7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so
7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so
7fd1b4739000-7fd1b473a000 rw-p
7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE
7fd1b493b000-7fd1b493c000 r--p /root/server 64 PIE
7fd1b493c000-7fd1b493d000 rw-p /root/server 64 PIE
7fff981fa000-7fff9821b000 rw-p [stack]
7fff983fe000-7fff98400000 r-xp [vdso]
...
BUFFER
RBP
0x00007F??????????
...
Stackgrowsdown
Highest 24 bits
This value (0x00007F) can be obtained:
1 Running the application and showing the memory map.
2 Checking the source code if set any limit to stack.
20 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
1) Extracting static information
Since the executable has to be PAGE SIZE aligned, the 12 lower bits will
not change when the executable is randomly loaded.
ASM Code STACK
0000000000001063 <attend_client>:
1063: 55 push %rbp
1064: 48 89 e5 mov %rsp,%rbp
1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp
106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
1075: 00 00
1077: 48 89 45 f8 mov %rax,-0x8(%rbp)
107b: 31 c0 xor %eax,%eax
..... ..... .....
12d7: 48 89 c7 mov %rax,%rdi
12da: e8 1c fc ff ff callq efb <vuln_func>
12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax
12e6: 48 89 c7 mov %rax,%rdi
..... ..... [From the ELF] .....
...
BUFFER
RBP
0x0007F??????????
...
Stackgrowsdown
21 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
1) Extracting static information
Since the executable has to be PAGE SIZE aligned, the 12 lower bits will
not change when the executable is randomly loaded.
ASM Code STACK
0000000000001063 <attend_client>:
1063: 55 push %rbp
1064: 48 89 e5 mov %rsp,%rbp
1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp
106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
1075: 00 00
1077: 48 89 45 f8 mov %rax,-0x8(%rbp)
107b: 31 c0 xor %eax,%eax
..... ..... .....
12d7: 48 89 c7 mov %rax,%rdi
12da: e8 1c fc ff ff callq efb <vuln_func>
12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax
12e6: 48 89 c7 mov %rax,%rdi
..... ..... [From the ELF] .....
...
BUFFER
RBP
0x0007F???????2DF
...
Lower 12 bits
Stackgrowsdown
21 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
2) Brute forcing Saved-IP address
STACKvoid vuln_func(char *str, int lstr){
char buff[48];
int i = 0;
...
for (i = 0; i < lstr; i++) {
if (str[i] != ’n’)
buff[lbuff++] = str[i];
...
}
The unknown 28 random bits: “byte-for-byte” attack.
The first byte is “special”, we know the lowest 4 bits:
0x?216 → ??102 → 24 = 16 attempts
{0x02, 0x12, 0x22 ... 0xC2, 0xD2, 0xE2, 0xF2}
...
BUFFER
RBP
0x0007F???????2DF
...
Stackgrowsdown
22 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
2) Brute forcing Saved-IP address
STACKvoid vuln_func(char *str, int lstr){
char buff[48];
int i = 0;
...
for (i = 0; i < lstr; i++) {
if (str[i] != ’n’)
buff[lbuff++] = str[i];
...
}
The unknown 28 random bits: “byte-for-byte” attack.
The first byte is “special”, we know the lowest 4 bits:
0x?216 → ??102 → 24 = 16 attempts
{0x02, 0x12, 0x22 ... 0xC2, 0xD2, 0xE2, 0xF2}
...
BUFFER
RBP
0x0007F??????C2DF
...
Stackgrowsdown
half-byte
22 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
2) Brute forcing Saved-IP address
STACKvoid vuln_func(char *str, int lstr){
char buff[48];
int i = 0;
...
for (i = 0; i < lstr; i++) {
if (str[i] != ’n’)
buff[lbuff++] = str[i];
...
}
The unknown 28 random bits: “byte-for-byte” attack.
The first byte is “special”, we know the lowest 4 bits:
0x?216 → ??102 → 24 = 16 attempts
{0x02, 0x12, 0x22 ... 0xC2, 0xD2, 0xE2, 0xF2}
The remaining 3 bytes → standard “byte-for-byte” attack
3x28 = 768 attempts.
After execute the byte-for-byte we obtained 0x36C6FE
...
BUFFER
RBP
0x0007F??????C2DF
...
Stackgrowsdown
22 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
2) Brute forcing Saved-IP address
STACKvoid vuln_func(char *str, int lstr){
char buff[48];
int i = 0;
...
for (i = 0; i < lstr; i++) {
if (str[i] != ’n’)
buff[lbuff++] = str[i];
...
}
The unknown 28 random bits: “byte-for-byte” attack.
The first byte is “special”, we know the lowest 4 bits:
0x?216 → ??102 → 24 = 16 attempts
{0x02, 0x12, 0x22 ... 0xC2, 0xD2, 0xE2, 0xF2}
The remaining 3 bytes → standard “byte-for-byte” attack
3x28 = 768 attempts.
After execute the byte-for-byte we obtained 0x36C6FE
...
BUFFER
RBP
0x0007F36C6FEC2DF
...
Stackgrowsdown
Brute
forced
bytes
22 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
2) Brute forcing Saved-IP address
STACKvoid vuln_func(char *str, int lstr){
char buff[48];
int i = 0;
...
for (i = 0; i < lstr; i++) {
if (str[i] != ’n’)
buff[lbuff++] = str[i];
...
}
The unknown 28 random bits: “byte-for-byte” attack.
The first byte is “special”, we know the lowest 4 bits:
0x?216 → ??102 → 24 = 16 attempts
{0x02, 0x12, 0x22 ... 0xC2, 0xD2, 0xE2, 0xF2}
The remaining 3 bytes → standard “byte-for-byte” attack
3x28 = 768 attempts.
After execute the byte-for-byte we obtained 0x36C6FE
We need to perform 24
+3∗28
2
= 392 attempts on average.
...
BUFFER
RBP
0x0007F36C6FEC2DF
...
Stackgrowsdown
22 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
3) Calculating base application address
STACK0000000000001063 <attend_client>:
1063: 55 push %rbp
1064: 48 89 e5 mov %rsp,%rbp
1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp
106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
1075: 00 00
1077: 48 89 45 f8 mov %rax,-0x8(%rbp)
107b: 31 c0 xor %eax,%eax
..... ..... .....
12d7: 48 89 c7 mov %rax,%rdi
12da: e8 1c fc ff ff callq efb <vuln_func>
12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax
12e6: 48 89 c7 mov %rax,%rdi
..... ..... .....
App base=(savedIP & 0xFFF)-(CALLER PAGE OFFSET << 12)
evitar movientos entre animaciones
...
BUFFER
RBP
0x0007F36C6FEC2DF
...
Stackgrowsdown
23 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
3) Calculating base application address
STACK0000000000001063 <attend_client>:
1063: 55 push %rbp
1064: 48 89 e5 mov %rsp,%rbp
1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp
106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
1075: 00 00
1077: 48 89 45 f8 mov %rax,-0x8(%rbp)
107b: 31 c0 xor %eax,%eax
..... ..... .....
12d7: 48 89 c7 mov %rax,%rdi
12da: e8 1c fc ff ff callq efb <vuln_func>
12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax
12e6: 48 89 c7 mov %rax,%rdi
..... ..... .....
App base=(savedIP & 0xFFF)-(CALLER PAGE OFFSET << 12)
evitar movientos entre animaciones
...
BUFFER
RBP
0x0007F36C6FEC2DF
...
Stackgrowsdown
23 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
3) Calculating base application address
STACK0000000000001063 <attend_client>:
1063: 55 push %rbp
1064: 48 89 e5 mov %rsp,%rbp
1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp
106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
1075: 00 00
1077: 48 89 45 f8 mov %rax,-0x8(%rbp)
107b: 31 c0 xor %eax,%eax
..... ..... .....
12d7: 48 89 c7 mov %rax,%rdi
12da: e8 1c fc ff ff callq efb <vuln_func>
12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax
12e6: 48 89 c7 mov %rax,%rdi
..... ..... .....
App base=(savedIP & 0xFFF)-(CALLER PAGE OFFSET << 12)
0x7F36C6fEB000=(0x7f36C6FEC2DF & 0xFFF)-(0x1000)
...
BUFFER
RBP
0x0007F36C6FEC2DF
...
Stackgrowsdown
23 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
3) Calculating base application address
STACK0000000000001063 <attend_client>:
1063: 55 push %rbp
1064: 48 89 e5 mov %rsp,%rbp
1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp
106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
1075: 00 00
1077: 48 89 45 f8 mov %rax,-0x8(%rbp)
107b: 31 c0 xor %eax,%eax
..... ..... .....
12d7: 48 89 c7 mov %rax,%rdi
12da: e8 1c fc ff ff callq efb <vuln_func>
12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax
12e6: 48 89 c7 mov %rax,%rdi
..... ..... .....
App base=(savedIP & 0xFFF)-(CALLER PAGE OFFSET << 12)
0x7F36C6fEB000=(0x7f36C6FEC2DF & 0xFFF)-(0x1000)
App. Base = 0x7F36C6fEB000
...
BUFFER
RBP
0x0007F36C6FEC2DF
...
Stackgrowsdown
23 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
4) Calculating library offsets
7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so
7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so
7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so
7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so
7fd1b4510000-7fd1b4515000 rw-p
7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so
7fd1b4718000-7fd1b471b000 rw-p
7fd1b4734000-7fd1b4737000 rw-p
7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so
7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so
7fd1b4739000-7fd1b473a000 rw-p
7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE
7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE
7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE
7fff981fa000-7fff9821b000 rw-p [stack]
7fff983fe000-7fff98400000 r-xp [vdso]
offset2lib
Distribution Libc version Offset2lib (bytes)
CentOS 6.5 2.12 0x5b6000
Debian 7.1 2.13 0x5ac000
Ubuntu 12.04 LTS 2.15 0x5e4000
Ubuntu 12.10 2.15 0x5e4000
Ubuntu 13.10 2.17 0x5ed000
openSUSE 13.1 2.18 0x5d1000
Ubuntu 14.04.1 LTS 2.19 0x5eb000
24 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
5) Getting app. process mapping
Obtaining library base addresses:
Application Base = 0x7FD1B473A000
Offset2lib (libc) = 0x5eb000
Offset2lib (ld) = 0x225000
...
libc-2.19.so
ld-2.19.so
server 64 PIE
...
0x000000000000
0x7FFFFFFFFFFF
mmap base
Libc Base
ld Base
Application Base
25 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
5) Getting app. process mapping
Obtaining library base addresses:
Application Base = 0x7FD1B473A000
Offset2lib (libc) = 0x5eb000
Offset2lib (ld) = 0x225000
...
libc-2.19.so
ld-2.19.so
server 64 PIE
...
Libc Base = 0x7FD1B473A000 - 0x5eb000 = 0x7FD1B414F000
0x5eb000
0x000000000000
0x7FFFFFFFFFFF
mmap base
Libc Base
ld Base
Application Base
25 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
5) Getting app. process mapping
Obtaining library base addresses:
Application Base = 0x7FD1B473A000
Offset2lib (libc) = 0x5eb000
Offset2lib (ld) = 0x225000
...
libc-2.19.so
ld-2.19.so
server 64 PIE
...
Libc Base = 0x7FD1B473A000 - 0x5eb000 = 0x7FD1B414F000
0x5eb000
ld Base = 0x7FD1B473A000 - 0x225000 = 0x7fd1b4515000
0x2225000
0x000000000000
0x7FFFFFFFFFFF
mmap base
Libc Base
ld Base
Application Base
25 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
The vulnerable server
To show a more realistic PoC:
Bypass NX, SSP, ASLR, FORTIFY or RELRO.
We do not use GOT neither PLT.
Valid for any application (Gadgets only from libraries)
We use a fully updated Linux.
Parameter Comment Configuration
App. relocatable Yes -fpie -pie
Lib. relocatable Yes -Fpic
ASLR config. Enabled randomize va space = 2
SSP Enabled -fstack-protector-all
Arch. 64 bits x86 64 GNU/Linux
NX Enabled PAE or x64
RELRO Full -wl,-z,-relro,-z,now
FORTIFY Yes -D FORTIFY SOURCE=2
Optimisation Yes -O2
26 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
Bypassing NX, SSP and ASLR on 64-bit Linux
Demo: Bypass NX, SSP and ASLR in < 1 sec.
27 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
How to prevent exploitation
There are many vectors to exploit this weakness: Imagination is the
limit. Basically, an attacker needs:
1 The knowledge (information leak).
2 A way to use it.
There are many solutions to address this weakness:
Avoid information leaks at once:
Don’t design weak applications/protocols.
Don’t write code with errors.
. . .
Make the leaked information useless:
PaX patch
Linux Kenrel >= 4.1
RenewSSP: Improve stack-smashing-protector.
28 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
Solutions overview
PaX
The Offset2lib weakness
Solved with
RenewSSP
ASLR patch :
Linux >= 4.1
Solved with
The Offset2lib attack
All weaknesses are only solved by the ASLR-NG
29 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
With Linux Kernel < 4.1
# echo 2 > /proc/sys/kernel/randomize_va_space
# hello_world_dynamic_pie
7f621ffbb000-7f6220176000 r-xp 00000000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6
7f6220176000-7f6220376000 ---p 001bb000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6
7f6220376000-7f622037a000 r--p 001bb000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6
7f622037a000-7f622037c000 rw-p 001bf000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6
7f622037c000-7f6220381000 rw-p 00000000 00:00 0
7f6220381000-7f62203a4000 r-xp 00000000 00:02 4917 /lib64/ld-linux-x86-64.so.2
7f622059c000-7f622059d000 rw-p 00000000 00:00 0
7f622059d000-7f622059e000 r-xp 00000000 00:00 0
7f622059e000-7f62205a3000 rw-p 00000000 00:00 0
7f62205a3000-7f62205a4000 r--p 00022000 00:02 4917 /lib64/ld-linux-x86-64.so.2
7f62205a4000-7f62205a5000 rw-p 00023000 00:02 4917 /lib64/ld-linux-x86-64.so.2
7f62205a5000-7f62205a6000 rw-p 00000000 00:00 0
7f62205a6000-7f62205a7000 r-xp 00000000 00:02 4896 /bin/hello world dynamic pie
7f62207a6000-7f62207a7000 r--p 00000000 00:02 4896 /bin/hello world dynamic pie
7f62207a7000-7f62207a8000 rw-p 00001000 00:02 4896 /bin/hello world dynamic pie
7fff47e15000-7fff47e36000 rw-p 00000000 00:00 0 [stack]
7fff47e63000-7fff47e65000 r--p 00000000 00:00 0 [vvar]
7fff47e65000-7fff47e67000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
30 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Exploiting the Correlation weakness: offset2lib
With Linux Kernel >= 4.1
# hello_world_dynamic_pie
54859ccd6000-54859ccd7000 r-xp 00000000 00:02 4896 /bin/hello world dynamic pie
54859ced6000-54859ced7000 r--p 00000000 00:02 4896 /bin/hello world dynamic pie
54859ced7000-54859ced8000 rw-p 00001000 00:02 4896 /bin/hello world dynamic pie
7f75be764000-7f75be91f000 r-xp 00000000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6
7f75be91f000-7f75beb1f000 ---p 001bb000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6
7f75beb1f000-7f75beb23000 r--p 001bb000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6
7f75beb23000-7f75beb25000 rw-p 001bf000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6
7f75beb25000-7f75beb2a000 rw-p 00000000 00:00 0
7f75beb2a000-7f75beb4d000 r-xp 00000000 00:02 4917 /lib64/ld-linux-x86-64.so.2
7f75bed45000-7f75bed46000 rw-p 00000000 00:00 0
7f75bed46000-7f75bed47000 r-xp 00000000 00:00 0
7f75bed47000-7f75bed4c000 rw-p 00000000 00:00 0
7f75bed4c000-7f75bed4d000 r--p 00022000 00:02 4917 /lib64/ld-linux-x86-64.so.2
7f75bed4d000-7f75bed4e000 rw-p 00023000 00:02 4917 /lib64/ld-linux-x86-64.so.2
7f75bed4e000-7f75bed4f000 rw-p 00000000 00:00 0
7fffb3741000-7fffb3762000 rw-p 00000000 00:00 0 [stack]
7fffb377b000-7fffb377d000 r--p 00000000 00:00 0 [vvar]
7fffb377d000-7fffb377f000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
31 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
Addressing the ASLR weaknesses
ASLR-NG addresses all these weaknesses but because of the urgency to
fix the Offset2lib weakness, it was fixed in current Linux.
It can be seen as a minor part of the ASLR-NG.
It does not remove the correlation problem between all objects.
How we addressed the Offset2lib weakness ?
32 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
The particular Offset2lib fix
Offset2lib fix:
We have removed the correlation between
the executable ↔ libraries
stack
lib1
lib2
exec
heap
LOW
HIGH
VM space
FlowredirectConstant !
stack
lib1
lib2
exec
heap
LOW
HIGH
VM space
Flowredirect
Random !
33 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
The particular Offset2lib fix
Offset2lib fix:
We have removed the correlation between
the executable ↔ libraries
Attack rewarded by Packet Storm Security:
Offset2lib was classified as 1-day vulnerability
stack
lib1
lib2
exec
heap
LOW
HIGH
VM space
FlowredirectConstant !
stack
lib1
lib2
exec
heap
LOW
HIGH
VM space
Flowredirect
Random !
33 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
The particular Offset2lib fix
Offset2lib fix:
We have removed the correlation between
the executable ↔ libraries
Attack rewarded by Packet Storm Security:
Offset2lib was classified as 1-day vulnerability
Linux Kernel 4.1 patch:
We have created and sent a patch to Linux,
which was considered urgent.
stack
lib1
lib2
exec
heap
LOW
HIGH
VM space
FlowredirectConstant !
stack
lib1
lib2
exec
heap
LOW
HIGH
VM space
Flowredirect
Random !
33 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
ASLR-NG: Address Space Layout
Randomization Next Generation
34 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
ASLR-NG: The core ideas
A deep analysis of growable objects shows
that they (stack and heap) can be bounded.
This key idea allowed me to load objects:
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
Linux ASLR
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
Linux ASLR-NG
35 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
ASLR-NG: The core ideas
A deep analysis of growable objects shows
that they (stack and heap) can be bounded.
This key idea allowed me to load objects:
Freely along the VM:
→ Huge increment of entropy.
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
Linux ASLR
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
Linux ASLR-NG
35 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
ASLR-NG: The core ideas
A deep analysis of growable objects shows
that they (stack and heap) can be bounded.
This key idea allowed me to load objects:
Freely along the VM:
→ Huge increment of entropy.
Uniformly distributed:
→ No more likely addresses.
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
Linux ASLR
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
Linux ASLR-NG
35 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
ASLR-NG: The core ideas
A deep analysis of growable objects shows
that they (stack and heap) can be bounded.
This key idea allowed me to load objects:
Freely along the VM:
→ Huge increment of entropy.
Uniformly distributed:
→ No more likely addresses.
Uncorrelated:
→ No more correlated attacks.
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
Linux ASLR
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
Linux ASLR-NG
35 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
ASLR-NG: The core ideas
A deep analysis of growable objects shows
that they (stack and heap) can be bounded.
This key idea allowed me to load objects:
Freely along the VM:
→ Huge increment of entropy.
Uniformly distributed:
→ No more likely addresses.
Uncorrelated:
→ No more correlated attacks.
Have different VM layout:
→ Forking model more secure.
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
Linux ASLR
stack
lib1
lib2
mmap files
heap
exec
LOW
HIGH
VM space
Flowredirect
Linux ASLR-NG
35 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
ASLR-NG: New randomisation forms
We have categorized and designed new randomization forms:
Feature Description
When
Per-boot Every time the system is booted.
Per-exec Every time a new image is executed.
Per-fork Every time a new process is spawned. new!
Per-object Every time a new object is created. new!
What
Stack Stack of the main process.
LD Dynamic linker/loader.
Executable Loadable segments (text, data, bss, ...).
Heap Old-fashioned dynamic memory of the process: brk(). improved !
vDSO/VVAR Objects exported by the kernel to the user space.
Mmaps/libs Objects allocated calling mmap(). improved !
How
Partial VM A sub-range of the VM space is used to map the object.
Full VM The full VM space is used to map the object. new!
Isolated-object The object is randomised independently from any other. new!
Sub-page Page offset bits are randomised. new!
Bit-slicing Different slices of the address are randomised at different times. Google!
Direction Topdown/downtop search side used on a first-fit allocation strategy. new!
Specific-zone A base address and a direction where objects are allocated together. new!
36 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
ASLR-NG: Profile modes
stack thread3
stack thread3
stack thread3
stack thread1
Libc.so
mmap file a
Executable
stack
Heap (brk)
ld.so
vDSO
stack thread2
VM space
mmap_base
stack thread1
Libc.so
mmap file a
Executable
stack
Heap (brk)
ld.so
vDSO
stack thread2
VM space
stack thread1
Libc.so
mmap file a
Executable
stack
Heap (brk)
ld.so
vDSO
stack thread2
VM space
stack thread1
Libc.so
mmap file a
Executable
stack
Heap (brk)
ld.so
vDSO
stack thread2
VM space
(a) Concentrated (b) Conservative (c) Extended (d) Paranoid
LOW_ADDR
HIGH_ADDR
ASLR-NG: Profile mode examples. 37 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
ASLR-NG: Evaluation
We have developed ASLRA, a test suit to analyze the entropy of objects.
ASLRA is composed of three tools:
1 Simulator:
→ Simulates several ASLRs, including the proposed ASLR-NG.
2 Sampler:
→ An application which generate million of samples (address of
mapped objects) and saves the raw data.
3 Analyzer:
→ Performs the statistical analysis.
→ Individual byte, Shannon entropy, flipping bits, etc.
38 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
ASLR-NG: Evaluation
We have developed ASLRA, a test suit to analyze the entropy of objects.
ASLRA is composed of three tools:
1 Simulator:
→ Simulates several ASLRs, including the proposed ASLR-NG.
2 Sampler:
→ An application which generate million of samples (address of
mapped objects) and saves the raw data.
3 Analyzer:
→ Performs the statistical analysis.
→ Individual byte, Shannon entropy, flipping bits, etc.
↓
H(X) = −
x∈X
p(x) log2 p(x)
The most interesting!
38 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
ASLR-NG: ASLR analyzer tool
ASLR analyser: Screenshot of a Heap (brk)
39 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
ASLR-NG: ASLR Next Generation
Linux vs PaX vs ASLR-NG
32-bits 64-bits
Object Linux PaX ASLR-NG Linux PaX ASLR-NG
ARGV 11 27 31.5 22 39 47
Main stack 19 23 27.5 30 35 43
Heap (brk) 13 23.3 27.5 28 35 43
Heap (mmap) 8 15.7 27.5 28 28.5 43
Thread stacks 8 15.7 27.5 28 28.5 43
Sub-page object - - 27.5 - - 43
Regular mmaps 8 15.7 19.5 28 28.5 35
Libraries 8 15.7 19.5 28 28.5 35
vDSO 8 15.7 19.5 21.4 28.5 35
Executable 8 15 19.5 28 27 35
Huge pages 0 5.7 9.5 19 19.5 26
Comparative summary of bits of entropy.
40 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Conclusions
ASLR-NG: Benefits
The main features of ASLR-NG are:
Uses full memory space to randomise objects, which in turn provides
maximum entropy.
A novel solution for reducing fragmentation, without reducing entropy.
Objects containing sensitive information are automatically isolated.
Sequentially loaded libraries are randomised.
It provides a strong protection against absolute and correlation attacks.
Effectively removes the four weaknesses previously identified.
During the design of the ASLR-NG we have fixed three vulnerabilities in the
Linux ASLR that were rewarded by Google.
The Offset2lib attack was rewarded by Packet Storm Security classified as a
1-day vulnerability.
41 / 42
Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco
Questions ?
* Hector Marco-Gisbert http://hmarco.org
* Ismael Ripoll Ripoll http://personales.upv.es/iripoll
* Cyber-security research group at http://cybersecurity.upv.es
42 / 42

More Related Content

Similar to Exploiting Linux On 32-bit and 64-bit Systems

Linux binary analysis and exploitation
Linux binary analysis and exploitationLinux binary analysis and exploitation
Linux binary analysis and exploitation
Dharmalingam Ganesan
 
Report on hacking blind
Report on hacking blindReport on hacking blind
Report on hacking blind
NikitaAndhale
 
Lightweight Virtualization in Linux
Lightweight Virtualization in LinuxLightweight Virtualization in Linux
Lightweight Virtualization in Linux
Sadegh Dorri N.
 
Linux Kernel Library - Reusing Monolithic Kernel
Linux Kernel Library - Reusing Monolithic KernelLinux Kernel Library - Reusing Monolithic Kernel
Linux Kernel Library - Reusing Monolithic Kernel
Hajime Tazaki
 
Let your Mach-O fly, Black Hat DC 2009
Let your Mach-O fly, Black Hat DC 2009Let your Mach-O fly, Black Hat DC 2009
Let your Mach-O fly, Black Hat DC 2009
Vincenzo Iozzo
 
Hacking Blind
Hacking BlindHacking Blind
Hacking Blind
NikitaAndhale
 
Hacking blind
Hacking blindHacking blind
Hacking blind
NikitaAndhale
 
Shellcoding, an Introduction
Shellcoding, an IntroductionShellcoding, an Introduction
Shellcoding, an Introduction
Daniele Bellavista
 
Failure Of DEP And ASLR
Failure Of DEP And ASLRFailure Of DEP And ASLR
Failure Of DEP And ASLR
n|u - The Open Security Community
 
Rasperry pi Part 7
Rasperry pi Part 7Rasperry pi Part 7
Rasperry pi Part 7
Techvilla
 
Buffer Overflows
Buffer OverflowsBuffer Overflows
Buffer Overflows
JustAnotherAbstraction
 
SHA-1 backdooring & exploitation
SHA-1 backdooring & exploitationSHA-1 backdooring & exploitation
SHA-1 backdooring & exploitation
Ange Albertini
 
Linux one vs x86
Linux one vs x86 Linux one vs x86
Linux one vs x86
Diego Rodriguez
 
Linux one vs x86 18 july
Linux one vs x86 18 julyLinux one vs x86 18 july
Linux one vs x86 18 july
Diego Rodriguez
 
Intel Briefing Notes
Intel Briefing NotesIntel Briefing Notes
Intel Briefing Notes
Graham Lee
 
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
Databricks
 
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
Databricks
 
Linux@assignment ppt
Linux@assignment pptLinux@assignment ppt
Linux@assignment ppt
Rama .
 
μ-Kernel Evolution
μ-Kernel Evolutionμ-Kernel Evolution
μ-Kernel Evolution
Sergio Shevchenko
 
Meltdown and Spectre
Meltdown and SpectreMeltdown and Spectre
Meltdown and Spectre
yeokm1
 

Similar to Exploiting Linux On 32-bit and 64-bit Systems (20)

Linux binary analysis and exploitation
Linux binary analysis and exploitationLinux binary analysis and exploitation
Linux binary analysis and exploitation
 
Report on hacking blind
Report on hacking blindReport on hacking blind
Report on hacking blind
 
Lightweight Virtualization in Linux
Lightweight Virtualization in LinuxLightweight Virtualization in Linux
Lightweight Virtualization in Linux
 
Linux Kernel Library - Reusing Monolithic Kernel
Linux Kernel Library - Reusing Monolithic KernelLinux Kernel Library - Reusing Monolithic Kernel
Linux Kernel Library - Reusing Monolithic Kernel
 
Let your Mach-O fly, Black Hat DC 2009
Let your Mach-O fly, Black Hat DC 2009Let your Mach-O fly, Black Hat DC 2009
Let your Mach-O fly, Black Hat DC 2009
 
Hacking Blind
Hacking BlindHacking Blind
Hacking Blind
 
Hacking blind
Hacking blindHacking blind
Hacking blind
 
Shellcoding, an Introduction
Shellcoding, an IntroductionShellcoding, an Introduction
Shellcoding, an Introduction
 
Failure Of DEP And ASLR
Failure Of DEP And ASLRFailure Of DEP And ASLR
Failure Of DEP And ASLR
 
Rasperry pi Part 7
Rasperry pi Part 7Rasperry pi Part 7
Rasperry pi Part 7
 
Buffer Overflows
Buffer OverflowsBuffer Overflows
Buffer Overflows
 
SHA-1 backdooring & exploitation
SHA-1 backdooring & exploitationSHA-1 backdooring & exploitation
SHA-1 backdooring & exploitation
 
Linux one vs x86
Linux one vs x86 Linux one vs x86
Linux one vs x86
 
Linux one vs x86 18 july
Linux one vs x86 18 julyLinux one vs x86 18 july
Linux one vs x86 18 july
 
Intel Briefing Notes
Intel Briefing NotesIntel Briefing Notes
Intel Briefing Notes
 
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
 
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
Apache Spark on Supercomputers: A Tale of the Storage Hierarchy with Costin I...
 
Linux@assignment ppt
Linux@assignment pptLinux@assignment ppt
Linux@assignment ppt
 
μ-Kernel Evolution
μ-Kernel Evolutionμ-Kernel Evolution
μ-Kernel Evolution
 
Meltdown and Spectre
Meltdown and SpectreMeltdown and Spectre
Meltdown and Spectre
 

More from E Hacking

CEH and Security+ Training Outline - EH Academy
CEH and Security+ Training Outline - EH AcademyCEH and Security+ Training Outline - EH Academy
CEH and Security+ Training Outline - EH Academy
E Hacking
 
Threats against the next billion devices
Threats against the next billion devicesThreats against the next billion devices
Threats against the next billion devices
E Hacking
 
High Definition Fuzzing; Exploring HDMI vulnerabilities
High Definition Fuzzing; Exploring HDMI vulnerabilitiesHigh Definition Fuzzing; Exploring HDMI vulnerabilities
High Definition Fuzzing; Exploring HDMI vulnerabilities
E Hacking
 
Most Important steps to become a hacker
Most Important steps to become a hackerMost Important steps to become a hacker
Most Important steps to become a hacker
E Hacking
 
Penetrating the Perimeter - Tales from the Battlefield
Penetrating the Perimeter - Tales from the BattlefieldPenetrating the Perimeter - Tales from the Battlefield
Penetrating the Perimeter - Tales from the Battlefield
E Hacking
 
Website fingerprinting on TOR
Website fingerprinting on TORWebsite fingerprinting on TOR
Website fingerprinting on TOR
E Hacking
 
Fuzzing the Media Framework in Android
Fuzzing the Media Framework in AndroidFuzzing the Media Framework in Android
Fuzzing the Media Framework in Android
E Hacking
 
Stalking a City for Fun and Frivolity" Defcon Talk
Stalking a City for Fun and Frivolity" Defcon TalkStalking a City for Fun and Frivolity" Defcon Talk
Stalking a City for Fun and Frivolity" Defcon TalkE Hacking
 
Hacking Wireless World, RFID hacking
Hacking Wireless World, RFID hackingHacking Wireless World, RFID hacking
Hacking Wireless World, RFID hacking
E Hacking
 
Abusing Microsoft Kerberos - Sorry you guys don’t get it
Abusing Microsoft Kerberos - Sorry you guys don’t get itAbusing Microsoft Kerberos - Sorry you guys don’t get it
Abusing Microsoft Kerberos - Sorry you guys don’t get itE Hacking
 
Malicious Domain Profiling
Malicious Domain Profiling Malicious Domain Profiling
Malicious Domain Profiling
E Hacking
 
Searching Shodan For Fun And Profit
Searching Shodan For Fun And ProfitSearching Shodan For Fun And Profit
Searching Shodan For Fun And Profit
E Hacking
 
The Machines that Betrayed their Masters
The Machines that Betrayed their MastersThe Machines that Betrayed their Masters
The Machines that Betrayed their Masters
E Hacking
 
Detecting Bluetooth Surveillance Systems
Detecting Bluetooth Surveillance SystemsDetecting Bluetooth Surveillance Systems
Detecting Bluetooth Surveillance Systems
E Hacking
 
Unmasking or De-Anonymizing You
Unmasking or De-Anonymizing YouUnmasking or De-Anonymizing You
Unmasking or De-Anonymizing You
E Hacking
 
WhatsApp Chat Hacking/Stealing POC
WhatsApp Chat Hacking/Stealing POCWhatsApp Chat Hacking/Stealing POC
WhatsApp Chat Hacking/Stealing POC
E Hacking
 
Building Trojan Hardware at Home
Building Trojan Hardware at HomeBuilding Trojan Hardware at Home
Building Trojan Hardware at Home
E Hacking
 
Social Media Monitoring tools as an OSINT platform for intelligence
Social Media Monitoring tools as an OSINT platform for intelligenceSocial Media Monitoring tools as an OSINT platform for intelligence
Social Media Monitoring tools as an OSINT platform for intelligence
E Hacking
 
LDAP Injections & Blind LDAP Injections Paper
LDAP Injections & Blind LDAP Injections PaperLDAP Injections & Blind LDAP Injections Paper
LDAP Injections & Blind LDAP Injections Paper
E Hacking
 
Reversing and Malware Analysis
Reversing and Malware Analysis Reversing and Malware Analysis
Reversing and Malware Analysis
E Hacking
 

More from E Hacking (20)

CEH and Security+ Training Outline - EH Academy
CEH and Security+ Training Outline - EH AcademyCEH and Security+ Training Outline - EH Academy
CEH and Security+ Training Outline - EH Academy
 
Threats against the next billion devices
Threats against the next billion devicesThreats against the next billion devices
Threats against the next billion devices
 
High Definition Fuzzing; Exploring HDMI vulnerabilities
High Definition Fuzzing; Exploring HDMI vulnerabilitiesHigh Definition Fuzzing; Exploring HDMI vulnerabilities
High Definition Fuzzing; Exploring HDMI vulnerabilities
 
Most Important steps to become a hacker
Most Important steps to become a hackerMost Important steps to become a hacker
Most Important steps to become a hacker
 
Penetrating the Perimeter - Tales from the Battlefield
Penetrating the Perimeter - Tales from the BattlefieldPenetrating the Perimeter - Tales from the Battlefield
Penetrating the Perimeter - Tales from the Battlefield
 
Website fingerprinting on TOR
Website fingerprinting on TORWebsite fingerprinting on TOR
Website fingerprinting on TOR
 
Fuzzing the Media Framework in Android
Fuzzing the Media Framework in AndroidFuzzing the Media Framework in Android
Fuzzing the Media Framework in Android
 
Stalking a City for Fun and Frivolity" Defcon Talk
Stalking a City for Fun and Frivolity" Defcon TalkStalking a City for Fun and Frivolity" Defcon Talk
Stalking a City for Fun and Frivolity" Defcon Talk
 
Hacking Wireless World, RFID hacking
Hacking Wireless World, RFID hackingHacking Wireless World, RFID hacking
Hacking Wireless World, RFID hacking
 
Abusing Microsoft Kerberos - Sorry you guys don’t get it
Abusing Microsoft Kerberos - Sorry you guys don’t get itAbusing Microsoft Kerberos - Sorry you guys don’t get it
Abusing Microsoft Kerberos - Sorry you guys don’t get it
 
Malicious Domain Profiling
Malicious Domain Profiling Malicious Domain Profiling
Malicious Domain Profiling
 
Searching Shodan For Fun And Profit
Searching Shodan For Fun And ProfitSearching Shodan For Fun And Profit
Searching Shodan For Fun And Profit
 
The Machines that Betrayed their Masters
The Machines that Betrayed their MastersThe Machines that Betrayed their Masters
The Machines that Betrayed their Masters
 
Detecting Bluetooth Surveillance Systems
Detecting Bluetooth Surveillance SystemsDetecting Bluetooth Surveillance Systems
Detecting Bluetooth Surveillance Systems
 
Unmasking or De-Anonymizing You
Unmasking or De-Anonymizing YouUnmasking or De-Anonymizing You
Unmasking or De-Anonymizing You
 
WhatsApp Chat Hacking/Stealing POC
WhatsApp Chat Hacking/Stealing POCWhatsApp Chat Hacking/Stealing POC
WhatsApp Chat Hacking/Stealing POC
 
Building Trojan Hardware at Home
Building Trojan Hardware at HomeBuilding Trojan Hardware at Home
Building Trojan Hardware at Home
 
Social Media Monitoring tools as an OSINT platform for intelligence
Social Media Monitoring tools as an OSINT platform for intelligenceSocial Media Monitoring tools as an OSINT platform for intelligence
Social Media Monitoring tools as an OSINT platform for intelligence
 
LDAP Injections & Blind LDAP Injections Paper
LDAP Injections & Blind LDAP Injections PaperLDAP Injections & Blind LDAP Injections Paper
LDAP Injections & Blind LDAP Injections Paper
 
Reversing and Malware Analysis
Reversing and Malware Analysis Reversing and Malware Analysis
Reversing and Malware Analysis
 

Recently uploaded

Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Sanjeev Rampal
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
GTProductions1
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
Javier Lasa
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
keoku
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
VivekSinghShekhawat2
 

Recently uploaded (20)

Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
 

Exploiting Linux On 32-bit and 64-bit Systems

  • 1. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco-Gisbert, Ismael Ripoll Universitat Polit`ecnica de Val`encia (Spain) http://cybersecurity.upv.es Black Hat Asia March 29 - April 1, 2016 1 / 42
  • 2. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Table of contents 1 ASLR overview & background 2 Linux and PaX ASLR weaknesses Too low entropy Non-uniform distribution Correlation between objects Inheritance 3 Exploiting the Correlation weakness: offset2lib Example: Offset2lib in stack buffer overflows Demo: Root shell in < 1 sec. Mitigations 4 ASLR-NG: ASLR Next Generation New randomisation forms ASLRA: ASLR Analyzer Linux vs PaX vs ASLR-NG 5 Conclusions 2 / 42
  • 3. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR overview & background What have we done ? We have deeply analyzed the ASLR of Linux and PaX and: Found some weaknesses and limitations on the current implementations: 1 Too low entropy 2 Non-uniform distribution 3 Correlation between objects 4 Inheritance Built attacks which exploit these weaknesses: Offset2lib: bypasses the NX, SSP and ASLR in in < 1 sec. Also, other attack vectors (exploiting other weaknesses) We have contributed to Linux kernel by: Fixing the Offset2lib weakness. Sketches a working in progress version of the ASLR → ASLR-NG. Also some mitigation techniques will be presented (RenewSSP) We present ASLRA, a suit tool to analyze the entropy of Linux ASLR implementations. 3 / 42
  • 4. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR overview & background ASLR Background ASLR does not remove vulnerabilities but make more difficult to exploit them. ASLR deters exploits which relays on knowing the memory map. ASLR is effective when all memory areas are randomise. Otherwise, the attacker can use these non-random areas. Full ASLR is achieved when: Applications are compiled with PIE (-fpie -pie). The kernel is configured with randomize va space = 2 (stack, VDSO, shared memory, data segment) 4 / 42
  • 5. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR overview & background What is ASLR ? ASLR is a protection provided by the kernel to applications which: It loads the stack, executable, libraries and heap at random locations. It tries to deter attacks that rely on knowing the location of the target data or code. It makes vulnerabilities more difficult to exploit. stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect 5 / 42
  • 6. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR overview & background How the ASLR works: A simple example The attacker redirects the execution to the exec() library function (lib1): stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect 6 / 42
  • 7. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR overview & background How the ASLR works: A simple example The attacker redirects the execution to the exec() library function (lib1): Trivial if ASLR is off. stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect 6 / 42
  • 8. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR overview & background How the ASLR works: A simple example The attacker redirects the execution to the exec() library function (lib1): Trivial if ASLR is off. But it fails when the ASLR is on. stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect 6 / 42
  • 9. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR overview & background How the ASLR works: A simple example The attacker redirects the execution to the exec() library function (lib1): Trivial if ASLR is off. But it fails when the ASLR is on. Not only the libraries but all other memory areas are randomized: → How difficult is to predict the target ? • Depends on the entropy. → Are there other attack vectors ? • Yes, We have found new weaknesses. stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect 6 / 42
  • 10. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Linux and PaX ASLR weaknesses Linux and PaX ASLR weaknesses Current ASLR was designed considering that some zones are growable but: Cannot be used safely because collisions with other allocations cannot be avoided. Currently, only used in the Stack and the Heap. Growable objects impose strong limitations on ASLR design: Linux places each object as separately as possible (Stack and Heap) Unfortunately, this introduce weaknesses. stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect 7 / 42
  • 11. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Linux and PaX ASLR weaknesses Weakness 1) Too low entropy Brute force attacks to bypass ASLR: x86 Entropy 100% Mean Linux 32-bit 28 (256) < 1 sec < 1 sec 64-bit 228 (260M.) 74 Hours 37 Hours ASLR entropy and cost time (1000 trials/sec). → ASLR in 32-bit is almost useless (very low entropy). → In 64-bit the attack is feasible in some scenarios. → The weakness is present since the first Linux ASLR. Flowredirect stack lib1 lib2 mmap files heap exec LOW HIGH VM space ? 8 / 42
  • 12. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Linux and PaX ASLR weaknesses Weakness 2) Non-uniform distribution 0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02 0 20 40 60 80 100 Probability Bins Expected i386 PaX Libraries distribution in i386 0 0.005 0.01 0.015 0.02 0 20 40 60 80 100 Probability Bins Expected x86_64 PaX Libraries distribution in x86 64 Libraries are not uniformly distributed: Faster attacks by focusing on the most frequent (likely) addresses. Other objects are also affected. 9 / 42
  • 13. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Linux and PaX ASLR weaknesses Weakness 3) Correlation between objects Instead of de-randomizing the target object, first de-randomize an intermediate object and then use it to de-randomize the target → We made the first demonstration [Offset2lib] The Offset2lib attack vector: It bypass the full Linux ASLR on any architecture in < 1 sec. It does not use the GOT or PLT. It works even with NX and SSP enabled. It exploits a stack buffer overflow. 10 / 42
  • 14. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Linux and PaX ASLR weaknesses Weakness 3) Correlation between objects We have developed a PoC to exploit the Offset2lib weakness: 1 De-randomize the executable exploiting a stack buffer overflow. 2 Calculate (offline) the constant distance to the target libraries. 3 The libraries are now de-randomized. stack lib1 lib2 exec heap LOW HIGH VM space FlowredirectConstant ! 11 / 42
  • 15. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Linux and PaX ASLR weaknesses Weakness 3) Correlation between objects Memory map of an application PIE compiled. The ld is loaded consecutively to the app.: 0x7f36c6feb000 12 / 42
  • 16. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Linux and PaX ASLR weaknesses Weakness 4) Inheritance Again, all child processes share the same memory layout ! New allocations belonging only to a child can be predicted by its parent and siblings ! Example: Child 1 can easily guess where the private file 2 has been mapped. stack lib1 lib2 private file 1 heap exec LOW HIGH VM space Flowredirect Child 1 stack lib1 lib2 private file 2 heap exec LOW HIGH VM space Flowredirect Child n 13 / 42
  • 17. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib Loading shared objects The problem appears when the application is compiled with PIE because the GNU/Linux algorithm for loading shared objects works as follows: The first shared object is loaded at a random position. The next object is located right below (lower addresses) the last object. ... libc-2.19.so ld-2.19.so server 64 PIE ... Stack ... All libraries are located ”side by side” at a single random place. 0x000000000000 0x7FFFFFFFFFFF mmap base Executable Base Dynamic Linker Base Libc Base 14 / 42
  • 18. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib Offset2lib $ cat /proc/<pid>/server 64 PIE 7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so 7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so 7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so 7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so 7fd1b4510000-7fd1b4515000 rw-p 7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so 7fd1b4718000-7fd1b471b000 rw-p 7fd1b4734000-7fd1b4737000 rw-p 7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so 7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so 7fd1b4739000-7fd1b473a000 rw-p 7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE 7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE 7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE 7fff981fa000-7fff9821b000 rw-p [stack] 7fff983fe000-7fff98400000 r-xp [vdso] 15 / 42
  • 19. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib Offset2lib $ cat /proc/<pid>/server 64 PIE 7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so 7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so 7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so 7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so 7fd1b4510000-7fd1b4515000 rw-p 7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so 7fd1b4718000-7fd1b471b000 rw-p 7fd1b4734000-7fd1b4737000 rw-p 7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so 7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so 7fd1b4739000-7fd1b473a000 rw-p 7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE 7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE 7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE 7fff981fa000-7fff9821b000 rw-p [stack] 7fff983fe000-7fff98400000 r-xp [vdso] 0x5eb000 15 / 42
  • 20. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib Offset2lib $ cat /proc/<pid>/server 64 PIE 7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so 7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so 7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so 7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so 7fd1b4510000-7fd1b4515000 rw-p 7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so 7fd1b4718000-7fd1b471b000 rw-p 7fd1b4734000-7fd1b4737000 rw-p 7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so 7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so 7fd1b4739000-7fd1b473a000 rw-p 7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE 7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE 7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE 7fff981fa000-7fff9821b000 rw-p [stack] 7fff983fe000-7fff98400000 r-xp [vdso] 0x5eb000 0x225000 15 / 42
  • 21. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib Offset2lib 7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so 7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so 7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so 7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so 7fd1b4510000-7fd1b4515000 rw-p 7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so 7fd1b4718000-7fd1b471b000 rw-p 7fd1b4734000-7fd1b4737000 rw-p 7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so 7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so 7fd1b4739000-7fd1b473a000 rw-p 7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE 7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE 7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE 7fff981fa000-7fff9821b000 rw-p [stack] 7fff983fe000-7fff98400000 r-xp [vdso] offset2lib offset2lib We named this invariant distance offset2lib which: It is a constant distance between two shared objects even in different executions of the application. 16 / 42
  • 22. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib Offset2lib 7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so 7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so 7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so 7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so 7fd1b4510000-7fd1b4515000 rw-p 7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so 7fd1b4718000-7fd1b471b000 rw-p 7fd1b4734000-7fd1b4737000 rw-p 7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so 7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so 7fd1b4739000-7fd1b473a000 rw-p 7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE 7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE 7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE 7fff981fa000-7fff9821b000 rw-p [stack] 7fff983fe000-7fff98400000 r-xp [vdso] offset2lib offset2lib We named this invariant distance offset2lib which: It is a constant distance between two shared objects even in different executions of the application. Any address of the app. → de-randomize all mmapped areas !!! 16 / 42
  • 23. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib Why the Offset2lib is dangerous ? Offset2lib scope: Realistic; applications are more prone than libraries to errors. Makes some vulnerabilities faster, easier and more reliable to exploit them. It is not a self-exploitable vulnerability but an ASLR-design weakness exploitable. It opens new (and old) attack vectors. 17 / 42
  • 24. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib Why the Offset2lib is dangerous ? Offset2lib scope: Realistic; applications are more prone than libraries to errors. Makes some vulnerabilities faster, easier and more reliable to exploit them. It is not a self-exploitable vulnerability but an ASLR-design weakness exploitable. It opens new (and old) attack vectors. Next example: Offset2lib on a standard stack buffer overflow. 17 / 42
  • 25. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib Building the attack The steps to build the attack are: 1 Extracting static information 2 Brute force part of saved-IP 3 Calculate base app. address 4 Calculate library offsets 5 Obtain mmapped areas 18 / 42
  • 26. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 1) Extracting static information → Our goal is to obtain an address belonging to the application. → We are going to obtain the saved-IP of vulnerable function caller. Offset2lib with saved-IP ⇒ all mmapped areas. STACK 0000000000001063 <attend_client>: 1063: 55 push %rbp 1064: 48 89 e5 mov %rsp,%rbp 1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp 106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1075: 00 00 ..... ..... ..... 12d7: 48 89 c7 mov %rax,%rdi 12da: e8 1c fc ff ff callq efb <vuln func> 12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax 12e6: 48 89 c7 mov %rax,%rdi ..... ..... ..... ... BUFFER RBP 0x??????????????? ... Stackgrowsdown 19 / 42
  • 27. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 1) Extracting static information → Our goal is to obtain an address belonging to the application. → We are going to obtain the saved-IP of vulnerable function caller. Offset2lib with saved-IP ⇒ all mmapped areas. STACK 0000000000001063 <attend_client>: 1063: 55 push %rbp 1064: 48 89 e5 mov %rsp,%rbp 1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp 106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1075: 00 00 ..... ..... ..... 12d7: 48 89 c7 mov %rax,%rdi 12da: e8 1c fc ff ff callq efb <vuln func> 12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax 12e6: 48 89 c7 mov %rax,%rdi ..... ..... ..... ... BUFFER RBP 0x??????????????? ... Stackgrowsdown 19 / 42
  • 28. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 1) Extracting static information → Our goal is to obtain an address belonging to the application. → We are going to obtain the saved-IP of vulnerable function caller. Offset2lib with saved-IP ⇒ all mmapped areas. STACK 0000000000001063 <attend_client>: 1063: 55 push %rbp 1064: 48 89 e5 mov %rsp,%rbp 1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp 106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1075: 00 00 ..... ..... ..... 12d7: 48 89 c7 mov %rax,%rdi 12da: e8 1c fc ff ff callq efb <vuln func> 12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax 12e6: 48 89 c7 mov %rax,%rdi ..... ..... ..... ... BUFFER RBP 0x??????????????? ... Stackgrowsdown Next IP 19 / 42
  • 29. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 1) Extracting static information → Our goal is to obtain an address belonging to the application. → We are going to obtain the saved-IP of vulnerable function caller. Offset2lib with saved-IP ⇒ all mmapped areas. STACK 0000000000001063 <attend_client>: 1063: 55 push %rbp 1064: 48 89 e5 mov %rsp,%rbp 1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp 106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1075: 00 00 ..... ..... ..... 12d7: 48 89 c7 mov %rax,%rdi 12da: e8 1c fc ff ff callq efb <vuln func> 12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax 12e6: 48 89 c7 mov %rax,%rdi ..... ..... ..... ... BUFFER RBP 0x??????????????? ... Stackgrowsdown Next IP Address point to 19 / 42
  • 30. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 1) Extracting static information Memory map STACK 7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so 7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so 7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so 7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so 7fd1b4510000-7fd1b4515000 rw-p 7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so 7fd1b4718000-7fd1b471b000 rw-p 7fd1b4734000-7fd1b4737000 rw-p 7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so 7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so 7fd1b4739000-7fd1b473a000 rw-p 7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE 7fd1b493b000-7fd1b493c000 r--p /root/server 64 PIE 7fd1b493c000-7fd1b493d000 rw-p /root/server 64 PIE 7fff981fa000-7fff9821b000 rw-p [stack] 7fff983fe000-7fff98400000 r-xp [vdso] ... BUFFER RBP 0x???????????????? ... Stackgrowsdown This value (0x00007F) can be obtained: 1 Running the application and showing the memory map. 2 Checking the source code if set any limit to stack. 20 / 42
  • 31. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 1) Extracting static information Memory map STACK 7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so 7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so 7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so 7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so 7fd1b4510000-7fd1b4515000 rw-p 7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so 7fd1b4718000-7fd1b471b000 rw-p 7fd1b4734000-7fd1b4737000 rw-p 7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so 7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so 7fd1b4739000-7fd1b473a000 rw-p 7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE 7fd1b493b000-7fd1b493c000 r--p /root/server 64 PIE 7fd1b493c000-7fd1b493d000 rw-p /root/server 64 PIE 7fff981fa000-7fff9821b000 rw-p [stack] 7fff983fe000-7fff98400000 r-xp [vdso] ... BUFFER RBP 0x00007F?????????? ... Stackgrowsdown Highest 24 bits This value (0x00007F) can be obtained: 1 Running the application and showing the memory map. 2 Checking the source code if set any limit to stack. 20 / 42
  • 32. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 1) Extracting static information Since the executable has to be PAGE SIZE aligned, the 12 lower bits will not change when the executable is randomly loaded. ASM Code STACK 0000000000001063 <attend_client>: 1063: 55 push %rbp 1064: 48 89 e5 mov %rsp,%rbp 1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp 106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1075: 00 00 1077: 48 89 45 f8 mov %rax,-0x8(%rbp) 107b: 31 c0 xor %eax,%eax ..... ..... ..... 12d7: 48 89 c7 mov %rax,%rdi 12da: e8 1c fc ff ff callq efb <vuln_func> 12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax 12e6: 48 89 c7 mov %rax,%rdi ..... ..... [From the ELF] ..... ... BUFFER RBP 0x0007F?????????? ... Stackgrowsdown 21 / 42
  • 33. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 1) Extracting static information Since the executable has to be PAGE SIZE aligned, the 12 lower bits will not change when the executable is randomly loaded. ASM Code STACK 0000000000001063 <attend_client>: 1063: 55 push %rbp 1064: 48 89 e5 mov %rsp,%rbp 1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp 106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1075: 00 00 1077: 48 89 45 f8 mov %rax,-0x8(%rbp) 107b: 31 c0 xor %eax,%eax ..... ..... ..... 12d7: 48 89 c7 mov %rax,%rdi 12da: e8 1c fc ff ff callq efb <vuln_func> 12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax 12e6: 48 89 c7 mov %rax,%rdi ..... ..... [From the ELF] ..... ... BUFFER RBP 0x0007F???????2DF ... Lower 12 bits Stackgrowsdown 21 / 42
  • 34. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 2) Brute forcing Saved-IP address STACKvoid vuln_func(char *str, int lstr){ char buff[48]; int i = 0; ... for (i = 0; i < lstr; i++) { if (str[i] != ’n’) buff[lbuff++] = str[i]; ... } The unknown 28 random bits: “byte-for-byte” attack. The first byte is “special”, we know the lowest 4 bits: 0x?216 → ??102 → 24 = 16 attempts {0x02, 0x12, 0x22 ... 0xC2, 0xD2, 0xE2, 0xF2} ... BUFFER RBP 0x0007F???????2DF ... Stackgrowsdown 22 / 42
  • 35. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 2) Brute forcing Saved-IP address STACKvoid vuln_func(char *str, int lstr){ char buff[48]; int i = 0; ... for (i = 0; i < lstr; i++) { if (str[i] != ’n’) buff[lbuff++] = str[i]; ... } The unknown 28 random bits: “byte-for-byte” attack. The first byte is “special”, we know the lowest 4 bits: 0x?216 → ??102 → 24 = 16 attempts {0x02, 0x12, 0x22 ... 0xC2, 0xD2, 0xE2, 0xF2} ... BUFFER RBP 0x0007F??????C2DF ... Stackgrowsdown half-byte 22 / 42
  • 36. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 2) Brute forcing Saved-IP address STACKvoid vuln_func(char *str, int lstr){ char buff[48]; int i = 0; ... for (i = 0; i < lstr; i++) { if (str[i] != ’n’) buff[lbuff++] = str[i]; ... } The unknown 28 random bits: “byte-for-byte” attack. The first byte is “special”, we know the lowest 4 bits: 0x?216 → ??102 → 24 = 16 attempts {0x02, 0x12, 0x22 ... 0xC2, 0xD2, 0xE2, 0xF2} The remaining 3 bytes → standard “byte-for-byte” attack 3x28 = 768 attempts. After execute the byte-for-byte we obtained 0x36C6FE ... BUFFER RBP 0x0007F??????C2DF ... Stackgrowsdown 22 / 42
  • 37. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 2) Brute forcing Saved-IP address STACKvoid vuln_func(char *str, int lstr){ char buff[48]; int i = 0; ... for (i = 0; i < lstr; i++) { if (str[i] != ’n’) buff[lbuff++] = str[i]; ... } The unknown 28 random bits: “byte-for-byte” attack. The first byte is “special”, we know the lowest 4 bits: 0x?216 → ??102 → 24 = 16 attempts {0x02, 0x12, 0x22 ... 0xC2, 0xD2, 0xE2, 0xF2} The remaining 3 bytes → standard “byte-for-byte” attack 3x28 = 768 attempts. After execute the byte-for-byte we obtained 0x36C6FE ... BUFFER RBP 0x0007F36C6FEC2DF ... Stackgrowsdown Brute forced bytes 22 / 42
  • 38. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 2) Brute forcing Saved-IP address STACKvoid vuln_func(char *str, int lstr){ char buff[48]; int i = 0; ... for (i = 0; i < lstr; i++) { if (str[i] != ’n’) buff[lbuff++] = str[i]; ... } The unknown 28 random bits: “byte-for-byte” attack. The first byte is “special”, we know the lowest 4 bits: 0x?216 → ??102 → 24 = 16 attempts {0x02, 0x12, 0x22 ... 0xC2, 0xD2, 0xE2, 0xF2} The remaining 3 bytes → standard “byte-for-byte” attack 3x28 = 768 attempts. After execute the byte-for-byte we obtained 0x36C6FE We need to perform 24 +3∗28 2 = 392 attempts on average. ... BUFFER RBP 0x0007F36C6FEC2DF ... Stackgrowsdown 22 / 42
  • 39. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 3) Calculating base application address STACK0000000000001063 <attend_client>: 1063: 55 push %rbp 1064: 48 89 e5 mov %rsp,%rbp 1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp 106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1075: 00 00 1077: 48 89 45 f8 mov %rax,-0x8(%rbp) 107b: 31 c0 xor %eax,%eax ..... ..... ..... 12d7: 48 89 c7 mov %rax,%rdi 12da: e8 1c fc ff ff callq efb <vuln_func> 12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax 12e6: 48 89 c7 mov %rax,%rdi ..... ..... ..... App base=(savedIP & 0xFFF)-(CALLER PAGE OFFSET << 12) evitar movientos entre animaciones ... BUFFER RBP 0x0007F36C6FEC2DF ... Stackgrowsdown 23 / 42
  • 40. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 3) Calculating base application address STACK0000000000001063 <attend_client>: 1063: 55 push %rbp 1064: 48 89 e5 mov %rsp,%rbp 1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp 106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1075: 00 00 1077: 48 89 45 f8 mov %rax,-0x8(%rbp) 107b: 31 c0 xor %eax,%eax ..... ..... ..... 12d7: 48 89 c7 mov %rax,%rdi 12da: e8 1c fc ff ff callq efb <vuln_func> 12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax 12e6: 48 89 c7 mov %rax,%rdi ..... ..... ..... App base=(savedIP & 0xFFF)-(CALLER PAGE OFFSET << 12) evitar movientos entre animaciones ... BUFFER RBP 0x0007F36C6FEC2DF ... Stackgrowsdown 23 / 42
  • 41. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 3) Calculating base application address STACK0000000000001063 <attend_client>: 1063: 55 push %rbp 1064: 48 89 e5 mov %rsp,%rbp 1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp 106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1075: 00 00 1077: 48 89 45 f8 mov %rax,-0x8(%rbp) 107b: 31 c0 xor %eax,%eax ..... ..... ..... 12d7: 48 89 c7 mov %rax,%rdi 12da: e8 1c fc ff ff callq efb <vuln_func> 12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax 12e6: 48 89 c7 mov %rax,%rdi ..... ..... ..... App base=(savedIP & 0xFFF)-(CALLER PAGE OFFSET << 12) 0x7F36C6fEB000=(0x7f36C6FEC2DF & 0xFFF)-(0x1000) ... BUFFER RBP 0x0007F36C6FEC2DF ... Stackgrowsdown 23 / 42
  • 42. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 3) Calculating base application address STACK0000000000001063 <attend_client>: 1063: 55 push %rbp 1064: 48 89 e5 mov %rsp,%rbp 1067: 48 81 ec 60 04 00 00 sub $0x460,%rsp 106e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1075: 00 00 1077: 48 89 45 f8 mov %rax,-0x8(%rbp) 107b: 31 c0 xor %eax,%eax ..... ..... ..... 12d7: 48 89 c7 mov %rax,%rdi 12da: e8 1c fc ff ff callq efb <vuln_func> 12df: 48 8d 85 c0 fb ff ff lea -0x440(%rbp),%rax 12e6: 48 89 c7 mov %rax,%rdi ..... ..... ..... App base=(savedIP & 0xFFF)-(CALLER PAGE OFFSET << 12) 0x7F36C6fEB000=(0x7f36C6FEC2DF & 0xFFF)-(0x1000) App. Base = 0x7F36C6fEB000 ... BUFFER RBP 0x0007F36C6FEC2DF ... Stackgrowsdown 23 / 42
  • 43. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 4) Calculating library offsets 7fd1b414f000-7fd1b430a000 r-xp /lib/.../libc-2.19.so 7fd1b430a000-7fd1b450a000 ---p /lib/.../libc-2.19.so 7fd1b450a000-7fd1b450e000 r--p /lib/.../libc-2.19.so 7fd1b450e000-7fd1b4510000 rw-p /lib/.../libc-2.19.so 7fd1b4510000-7fd1b4515000 rw-p 7fd1b4515000-7fd1b4538000 r-xp /lib/.../ld-2.19.so 7fd1b4718000-7fd1b471b000 rw-p 7fd1b4734000-7fd1b4737000 rw-p 7fd1b4737000-7fd1b4738000 r--p /lib/.../ld-2.19.so 7fd1b4738000-7fd1b4739000 rw-p /lib/.../ld-2.19.so 7fd1b4739000-7fd1b473a000 rw-p 7fd1b473a000-7fd1b473c000 r-xp /root/server 64 PIE 7fd1b493b000-7fd1b493c000 r--p /root/server_64_PIE 7fd1b493c000-7fd1b493d000 rw-p /root/server_64_PIE 7fff981fa000-7fff9821b000 rw-p [stack] 7fff983fe000-7fff98400000 r-xp [vdso] offset2lib Distribution Libc version Offset2lib (bytes) CentOS 6.5 2.12 0x5b6000 Debian 7.1 2.13 0x5ac000 Ubuntu 12.04 LTS 2.15 0x5e4000 Ubuntu 12.10 2.15 0x5e4000 Ubuntu 13.10 2.17 0x5ed000 openSUSE 13.1 2.18 0x5d1000 Ubuntu 14.04.1 LTS 2.19 0x5eb000 24 / 42
  • 44. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 5) Getting app. process mapping Obtaining library base addresses: Application Base = 0x7FD1B473A000 Offset2lib (libc) = 0x5eb000 Offset2lib (ld) = 0x225000 ... libc-2.19.so ld-2.19.so server 64 PIE ... 0x000000000000 0x7FFFFFFFFFFF mmap base Libc Base ld Base Application Base 25 / 42
  • 45. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 5) Getting app. process mapping Obtaining library base addresses: Application Base = 0x7FD1B473A000 Offset2lib (libc) = 0x5eb000 Offset2lib (ld) = 0x225000 ... libc-2.19.so ld-2.19.so server 64 PIE ... Libc Base = 0x7FD1B473A000 - 0x5eb000 = 0x7FD1B414F000 0x5eb000 0x000000000000 0x7FFFFFFFFFFF mmap base Libc Base ld Base Application Base 25 / 42
  • 46. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib 5) Getting app. process mapping Obtaining library base addresses: Application Base = 0x7FD1B473A000 Offset2lib (libc) = 0x5eb000 Offset2lib (ld) = 0x225000 ... libc-2.19.so ld-2.19.so server 64 PIE ... Libc Base = 0x7FD1B473A000 - 0x5eb000 = 0x7FD1B414F000 0x5eb000 ld Base = 0x7FD1B473A000 - 0x225000 = 0x7fd1b4515000 0x2225000 0x000000000000 0x7FFFFFFFFFFF mmap base Libc Base ld Base Application Base 25 / 42
  • 47. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib The vulnerable server To show a more realistic PoC: Bypass NX, SSP, ASLR, FORTIFY or RELRO. We do not use GOT neither PLT. Valid for any application (Gadgets only from libraries) We use a fully updated Linux. Parameter Comment Configuration App. relocatable Yes -fpie -pie Lib. relocatable Yes -Fpic ASLR config. Enabled randomize va space = 2 SSP Enabled -fstack-protector-all Arch. 64 bits x86 64 GNU/Linux NX Enabled PAE or x64 RELRO Full -wl,-z,-relro,-z,now FORTIFY Yes -D FORTIFY SOURCE=2 Optimisation Yes -O2 26 / 42
  • 48. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib Bypassing NX, SSP and ASLR on 64-bit Linux Demo: Bypass NX, SSP and ASLR in < 1 sec. 27 / 42
  • 49. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib How to prevent exploitation There are many vectors to exploit this weakness: Imagination is the limit. Basically, an attacker needs: 1 The knowledge (information leak). 2 A way to use it. There are many solutions to address this weakness: Avoid information leaks at once: Don’t design weak applications/protocols. Don’t write code with errors. . . . Make the leaked information useless: PaX patch Linux Kenrel >= 4.1 RenewSSP: Improve stack-smashing-protector. 28 / 42
  • 50. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib Solutions overview PaX The Offset2lib weakness Solved with RenewSSP ASLR patch : Linux >= 4.1 Solved with The Offset2lib attack All weaknesses are only solved by the ASLR-NG 29 / 42
  • 51. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib With Linux Kernel < 4.1 # echo 2 > /proc/sys/kernel/randomize_va_space # hello_world_dynamic_pie 7f621ffbb000-7f6220176000 r-xp 00000000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6 7f6220176000-7f6220376000 ---p 001bb000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6 7f6220376000-7f622037a000 r--p 001bb000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6 7f622037a000-7f622037c000 rw-p 001bf000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6 7f622037c000-7f6220381000 rw-p 00000000 00:00 0 7f6220381000-7f62203a4000 r-xp 00000000 00:02 4917 /lib64/ld-linux-x86-64.so.2 7f622059c000-7f622059d000 rw-p 00000000 00:00 0 7f622059d000-7f622059e000 r-xp 00000000 00:00 0 7f622059e000-7f62205a3000 rw-p 00000000 00:00 0 7f62205a3000-7f62205a4000 r--p 00022000 00:02 4917 /lib64/ld-linux-x86-64.so.2 7f62205a4000-7f62205a5000 rw-p 00023000 00:02 4917 /lib64/ld-linux-x86-64.so.2 7f62205a5000-7f62205a6000 rw-p 00000000 00:00 0 7f62205a6000-7f62205a7000 r-xp 00000000 00:02 4896 /bin/hello world dynamic pie 7f62207a6000-7f62207a7000 r--p 00000000 00:02 4896 /bin/hello world dynamic pie 7f62207a7000-7f62207a8000 rw-p 00001000 00:02 4896 /bin/hello world dynamic pie 7fff47e15000-7fff47e36000 rw-p 00000000 00:00 0 [stack] 7fff47e63000-7fff47e65000 r--p 00000000 00:00 0 [vvar] 7fff47e65000-7fff47e67000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] 30 / 42
  • 52. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Exploiting the Correlation weakness: offset2lib With Linux Kernel >= 4.1 # hello_world_dynamic_pie 54859ccd6000-54859ccd7000 r-xp 00000000 00:02 4896 /bin/hello world dynamic pie 54859ced6000-54859ced7000 r--p 00000000 00:02 4896 /bin/hello world dynamic pie 54859ced7000-54859ced8000 rw-p 00001000 00:02 4896 /bin/hello world dynamic pie 7f75be764000-7f75be91f000 r-xp 00000000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6 7f75be91f000-7f75beb1f000 ---p 001bb000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6 7f75beb1f000-7f75beb23000 r--p 001bb000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6 7f75beb23000-7f75beb25000 rw-p 001bf000 00:02 5192 /lib/x86_64-linux-gnu/libc.so.6 7f75beb25000-7f75beb2a000 rw-p 00000000 00:00 0 7f75beb2a000-7f75beb4d000 r-xp 00000000 00:02 4917 /lib64/ld-linux-x86-64.so.2 7f75bed45000-7f75bed46000 rw-p 00000000 00:00 0 7f75bed46000-7f75bed47000 r-xp 00000000 00:00 0 7f75bed47000-7f75bed4c000 rw-p 00000000 00:00 0 7f75bed4c000-7f75bed4d000 r--p 00022000 00:02 4917 /lib64/ld-linux-x86-64.so.2 7f75bed4d000-7f75bed4e000 rw-p 00023000 00:02 4917 /lib64/ld-linux-x86-64.so.2 7f75bed4e000-7f75bed4f000 rw-p 00000000 00:00 0 7fffb3741000-7fffb3762000 rw-p 00000000 00:00 0 [stack] 7fffb377b000-7fffb377d000 r--p 00000000 00:00 0 [vvar] 7fffb377d000-7fffb377f000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] 31 / 42
  • 53. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation Addressing the ASLR weaknesses ASLR-NG addresses all these weaknesses but because of the urgency to fix the Offset2lib weakness, it was fixed in current Linux. It can be seen as a minor part of the ASLR-NG. It does not remove the correlation problem between all objects. How we addressed the Offset2lib weakness ? 32 / 42
  • 54. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation The particular Offset2lib fix Offset2lib fix: We have removed the correlation between the executable ↔ libraries stack lib1 lib2 exec heap LOW HIGH VM space FlowredirectConstant ! stack lib1 lib2 exec heap LOW HIGH VM space Flowredirect Random ! 33 / 42
  • 55. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation The particular Offset2lib fix Offset2lib fix: We have removed the correlation between the executable ↔ libraries Attack rewarded by Packet Storm Security: Offset2lib was classified as 1-day vulnerability stack lib1 lib2 exec heap LOW HIGH VM space FlowredirectConstant ! stack lib1 lib2 exec heap LOW HIGH VM space Flowredirect Random ! 33 / 42
  • 56. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation The particular Offset2lib fix Offset2lib fix: We have removed the correlation between the executable ↔ libraries Attack rewarded by Packet Storm Security: Offset2lib was classified as 1-day vulnerability Linux Kernel 4.1 patch: We have created and sent a patch to Linux, which was considered urgent. stack lib1 lib2 exec heap LOW HIGH VM space FlowredirectConstant ! stack lib1 lib2 exec heap LOW HIGH VM space Flowredirect Random ! 33 / 42
  • 57. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation ASLR-NG: Address Space Layout Randomization Next Generation 34 / 42
  • 58. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation ASLR-NG: The core ideas A deep analysis of growable objects shows that they (stack and heap) can be bounded. This key idea allowed me to load objects: stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect Linux ASLR stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect Linux ASLR-NG 35 / 42
  • 59. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation ASLR-NG: The core ideas A deep analysis of growable objects shows that they (stack and heap) can be bounded. This key idea allowed me to load objects: Freely along the VM: → Huge increment of entropy. stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect Linux ASLR stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect Linux ASLR-NG 35 / 42
  • 60. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation ASLR-NG: The core ideas A deep analysis of growable objects shows that they (stack and heap) can be bounded. This key idea allowed me to load objects: Freely along the VM: → Huge increment of entropy. Uniformly distributed: → No more likely addresses. stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect Linux ASLR stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect Linux ASLR-NG 35 / 42
  • 61. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation ASLR-NG: The core ideas A deep analysis of growable objects shows that they (stack and heap) can be bounded. This key idea allowed me to load objects: Freely along the VM: → Huge increment of entropy. Uniformly distributed: → No more likely addresses. Uncorrelated: → No more correlated attacks. stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect Linux ASLR stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect Linux ASLR-NG 35 / 42
  • 62. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation ASLR-NG: The core ideas A deep analysis of growable objects shows that they (stack and heap) can be bounded. This key idea allowed me to load objects: Freely along the VM: → Huge increment of entropy. Uniformly distributed: → No more likely addresses. Uncorrelated: → No more correlated attacks. Have different VM layout: → Forking model more secure. stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect Linux ASLR stack lib1 lib2 mmap files heap exec LOW HIGH VM space Flowredirect Linux ASLR-NG 35 / 42
  • 63. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation ASLR-NG: New randomisation forms We have categorized and designed new randomization forms: Feature Description When Per-boot Every time the system is booted. Per-exec Every time a new image is executed. Per-fork Every time a new process is spawned. new! Per-object Every time a new object is created. new! What Stack Stack of the main process. LD Dynamic linker/loader. Executable Loadable segments (text, data, bss, ...). Heap Old-fashioned dynamic memory of the process: brk(). improved ! vDSO/VVAR Objects exported by the kernel to the user space. Mmaps/libs Objects allocated calling mmap(). improved ! How Partial VM A sub-range of the VM space is used to map the object. Full VM The full VM space is used to map the object. new! Isolated-object The object is randomised independently from any other. new! Sub-page Page offset bits are randomised. new! Bit-slicing Different slices of the address are randomised at different times. Google! Direction Topdown/downtop search side used on a first-fit allocation strategy. new! Specific-zone A base address and a direction where objects are allocated together. new! 36 / 42
  • 64. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation ASLR-NG: Profile modes stack thread3 stack thread3 stack thread3 stack thread1 Libc.so mmap file a Executable stack Heap (brk) ld.so vDSO stack thread2 VM space mmap_base stack thread1 Libc.so mmap file a Executable stack Heap (brk) ld.so vDSO stack thread2 VM space stack thread1 Libc.so mmap file a Executable stack Heap (brk) ld.so vDSO stack thread2 VM space stack thread1 Libc.so mmap file a Executable stack Heap (brk) ld.so vDSO stack thread2 VM space (a) Concentrated (b) Conservative (c) Extended (d) Paranoid LOW_ADDR HIGH_ADDR ASLR-NG: Profile mode examples. 37 / 42
  • 65. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation ASLR-NG: Evaluation We have developed ASLRA, a test suit to analyze the entropy of objects. ASLRA is composed of three tools: 1 Simulator: → Simulates several ASLRs, including the proposed ASLR-NG. 2 Sampler: → An application which generate million of samples (address of mapped objects) and saves the raw data. 3 Analyzer: → Performs the statistical analysis. → Individual byte, Shannon entropy, flipping bits, etc. 38 / 42
  • 66. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation ASLR-NG: Evaluation We have developed ASLRA, a test suit to analyze the entropy of objects. ASLRA is composed of three tools: 1 Simulator: → Simulates several ASLRs, including the proposed ASLR-NG. 2 Sampler: → An application which generate million of samples (address of mapped objects) and saves the raw data. 3 Analyzer: → Performs the statistical analysis. → Individual byte, Shannon entropy, flipping bits, etc. ↓ H(X) = − x∈X p(x) log2 p(x) The most interesting! 38 / 42
  • 67. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation ASLR-NG: ASLR analyzer tool ASLR analyser: Screenshot of a Heap (brk) 39 / 42
  • 68. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco ASLR-NG: ASLR Next Generation Linux vs PaX vs ASLR-NG 32-bits 64-bits Object Linux PaX ASLR-NG Linux PaX ASLR-NG ARGV 11 27 31.5 22 39 47 Main stack 19 23 27.5 30 35 43 Heap (brk) 13 23.3 27.5 28 35 43 Heap (mmap) 8 15.7 27.5 28 28.5 43 Thread stacks 8 15.7 27.5 28 28.5 43 Sub-page object - - 27.5 - - 43 Regular mmaps 8 15.7 19.5 28 28.5 35 Libraries 8 15.7 19.5 28 28.5 35 vDSO 8 15.7 19.5 21.4 28.5 35 Executable 8 15 19.5 28 27 35 Huge pages 0 5.7 9.5 19 19.5 26 Comparative summary of bits of entropy. 40 / 42
  • 69. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Conclusions ASLR-NG: Benefits The main features of ASLR-NG are: Uses full memory space to randomise objects, which in turn provides maximum entropy. A novel solution for reducing fragmentation, without reducing entropy. Objects containing sensitive information are automatically isolated. Sequentially loaded libraries are randomised. It provides a strong protection against absolute and correlation attacks. Effectively removes the four weaknesses previously identified. During the design of the ASLR-NG we have fixed three vulnerabilities in the Linux ASLR that were rewarded by Google. The Offset2lib attack was rewarded by Packet Storm Security classified as a 1-day vulnerability. 41 / 42
  • 70. Exploiting Linux and PaX ASLR’s weaknesses on 32- and 64-bit systems Hector Marco Questions ? * Hector Marco-Gisbert http://hmarco.org * Ismael Ripoll Ripoll http://personales.upv.es/iripoll * Cyber-security research group at http://cybersecurity.upv.es 42 / 42