first order of business - repository.root-me.orgrepository.root-me.org/exploitation -...

104

Upload: others

Post on 25-Jul-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 2: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

First order of Business

Page 3: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

First order of Business

Page 4: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

You probably feel like this

MBE TA’s

Page 5: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 6: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 7: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 8: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 9: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 10: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 11: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 12: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Hardware Enforced Model

0: Privileged, Kernelspace

3: Restricted, Userspace

Page 13: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Hardware Enforced Model

0: Privileged, Kernelspace

3: Restricted, Userspace

Ring 1 and Ring 2 are not utilized by most popular/modern Operating Systems (Linux / Windows / OSX)

Page 14: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 15: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 16: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 17: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 18: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 19: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 20: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 21: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 22: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 23: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 24: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 25: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 26: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 27: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 28: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

You already know how to find these!

Page 29: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

You already know how to find these!

Kernel vulnerabilities are almost exactly the same as userland vulnerabilities.

Page 30: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

You already know how to find these!

Kernel vulnerabilities are almost exactly the same as userland vulnerabilities.

1. Buffer Overflows2. Signedness issues3. Partial Overwrites4. Use-After-Free

By now, finding these should be a familiar process

Page 31: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

The most common place to find vulnerabilities is inside of Loadable Kernel Modules (LKMs).

Page 32: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

The most common place to find vulnerabilities is inside of Loadable Kernel Modules (LKMs).

LKMs are like executables that run in Kernel Space.A few common uses are listed below:

> Device Drivers> Filesystem Drivers> Networking Drivers> Executable Interpreters> Kernel Extensions> ( rootkits :P )

Page 33: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

LKMs are just binary blobs like your familiar ELF’s, EXE’s and MACH-O’s. (On Linux, they even use the ELF format)

Page 34: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

LKMs are just binary blobs like your familiar ELF’s, EXE’s and MACH-O’s. (On Linux, they even use the ELF format)

You can drop them into IDA and reverse-engineer them like you’re used to already.

Page 35: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

There’s a few useful commands that deal with LKMs on Linux.

Page 36: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

There’s a few useful commands that deal with LKMs on Linux.

insmod ---> Insert a module into the running kernelrmmod ---> Remove a module from the running kernellsmod ---> List currently loaded modules

Page 37: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

There’s a few useful commands that deal with LKMs on Linux.

insmod ---> Insert a module into the running kernelrmmod ---> Remove a module from the running kernellsmod ---> List currently loaded modules

A general familiarity with these is helpful

Page 38: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 39: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 40: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 41: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 42: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 43: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 44: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 45: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 46: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 47: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 48: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 49: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 50: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation
Page 51: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyElevate Privileges

Remember: The Kernel manages running processes

Page 52: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyElevate Privileges

Remember: The Kernel manages running processes

Therefore: The Kernel keeps track of permissions

Page 54: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyElevate Privileges

Conveniently, the Linux Kernel has a wrapper for updating process credentials!

Page 55: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyElevate Privileges

Conveniently, the Linux Kernel has a wrapper for updating process credentials!

Page 56: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyElevate Privileges

Conveniently, the Linux Kernel has a wrapper for updating process credentials!

We just need to create a valid cred struct!

Page 57: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyElevate Privileges

The kernel is helpful again!

Page 58: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyElevate Privileges

The kernel is helpful again!

Page 59: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyElevate Privileges

Great! Now we can map out what we need to do

Page 60: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyElevate Privileges

Great! Now we can map out what we need to do

1. Create a “root” “struct creds” by calling prepare_kernel_cred( NULL );

2. Call commit_creds(root cred *);

Page 61: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyElevate Privileges

Great! Now we can map out what we need to do

1. Create a “root” “struct creds” by calling prepare_kernel_cred( NULL );

2. Call commit_creds(root cred *);3. Enjoy our new root privileges!

Page 62: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyReturning To UserSpace

Why bother returning to Userspace?

Page 63: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyReturning To UserSpace

Why bother returning to Userspace?

Most useful things we want to do are much easier from userland.

Page 64: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyReturning To UserSpace

Why bother returning to Userspace?

Most useful things we want to do are much easier from userland.

In KernelSpace, there’s no easy way to:

> Modify the filesystem> Create a new process> Create network connections

Page 65: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyReturning To UserSpace

How does the kernel do it?

Page 66: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyReturning To UserSpace

How does the kernel do it?

Page 67: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyReturning To UserSpace

How does the kernel do it?

This will usually get you out of “Kernel Mode” safely.

Page 68: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyReturning To UserSpace

For exploitation, the easiest strategy is highjacking execution, and letting the kernel return by itself.

Page 69: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyReturning To UserSpace

For exploitation, the easiest strategy is highjacking execution, and letting the kernel return by itself.

> Function Pointer Overwrites> Syscall Table Highjacking> Use-After-Free

Page 70: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyReturning To UserSpace

For exploitation, the easiest strategy is highjacking execution, and letting the kernel return by itself.

> Function Pointer Overwrites> Syscall Table Highjacking> Use-After-Free

You need to be very careful about destroying Kernel state.

A segfault probably means a reboot!

Page 71: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyEnjoying our Root Privs

If we make it back to userland, our process should be running with root privileges.

Page 72: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Basic Exploitation StrategyEnjoying our Root Privs

If we make it back to userland, our process should be running with root privileges.

We can do whatever we want!

Page 73: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protections

By now, you’re familiar with the alphabet soup of exploit mitigations

Page 74: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protections

By now, you’re familiar with the alphabet soup of exploit mitigations

DEPASLRPIECanariesRELROetc...

Page 75: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protections

By now, you’re familiar with the alphabet soup of exploit mitigations

DEP Green: Present in Kernel SpaceASLR Yellow: Present, with caveatsPIE Red: Not directly applicableCanariesRELROetc...

Page 76: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protections

By now, you’re familiar with the alphabet soup of exploit mitigations

DEP Green: Present in Kernel SpaceASLR Yellow: Present, with caveatsPIE Red: Not directly applicableCanariesRELROetc...There’s a whole new alphabet soup for Kernel Mitigations!

Page 77: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protections

Some new words in our soup

MMAP_MIN_ADDRKALLSYMSRANDSTACKSTACKLEAKSMEP / SMAP

Page 78: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protections

Some new words in our soup (There’s plenty more...)

MMAP_MIN_ADDRKALLSYMSRANDSTACKSTACKLEAKSMEP / SMAP

Most of these will be off for the labs!

Page 79: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protectionsmmap_min_addr

This makes exploiting NULL pointer dereferences harder.

Page 80: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protectionsmmap_min_addr

This makes exploiting NULL pointer dereferences harder.

Low

Memory

0xffffffff

Malicious Program

Page 81: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protectionsmmap_min_addr

This makes exploiting NULL pointer dereferences harder.

Low Memory

0xffffffff

Malicious Program

0x000000 Program does mmap(0,....)

Page 82: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protectionsmmap_min_addr

This makes exploiting NULL pointer dereferences harder.

Low Memory

0xffffffff

Malicious Program

0x000000 Program does mmap(0,....)

Program writes malicious Code

Page 83: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protectionsmmap_min_addr

This makes exploiting NULL pointer dereferences harder.

Low Memory

0xffffffff

Malicious Program

0x000000 Program does mmap(0,....)

Program writes malicious Code

Program triggers Kernel Bug

Kernel Memory

Page 84: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protectionsmmap_min_addr

This makes exploiting NULL pointer dereferences harder.

Low Memory

0xffffffff

Malicious Program

0x000000 Program does mmap(0,....)

Program writes malicious Code

Program triggers Kernel Bug

Kernel starts executing malicious Code

Kernel Memory

Page 85: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protectionsmmap_min_addr

This makes exploiting NULL pointer dereferences harder.

Low Memory

0xffffffff

Malicious Program

0x000000 mmap_min_addr disallows programs from allocating low memory.

Makes it much more difficult to exploit a simple NULL pointer dereference in the kernel.

Kernel Memory

Page 86: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protectionskallsyms

/proc/kallsyms gives the address of all symbols in the kernel.

We need this information to write reliable exploits without an info-leak!

Page 87: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protectionskallsyms

/proc/kallsyms gives the address of all symbols in the kernel.

We need this information to write reliable exploits without an info-leak!

$: cat /proc/kallsyms | grep commit_creds

ffffffff810908c0 T commit_credsffffffff81b01390 R __ksymtab_commit_credsffffffff81b1cf38 r __kcrctab_commit_credsffffffff81b2c33b r __kstrtab_commit_creds

Page 88: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space Protectionskallsyms

kallsyms used to be world-readable.

Now, it returns 0’s for unprivileged users

$: cat /proc/kallsyms | grep commit_creds

0000000000000000 T commit_creds0000000000000000 R __ksymtab_commit_creds0000000000000000 r __kcrctab_commit_creds0000000000000000 r __kstrtab_commit_creds

Can still be a useful source of information on older systems

Page 89: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space ProtectionsSMEP / SMAP

SMEP: Supervisor Mode Execution Protection

Introduced in Intel IvyBridge

SMAP: Supervisor Mode Access Protection

Introduced in Intel Haswell

Page 90: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space ProtectionsSMEP / SMAP

Common Exploitation Technique: Supply your own “get root” code.

Low Memory

Malicious Program

0x000000Kernel

Memory

0xffffffff

Page 91: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space ProtectionsSMEP / SMAP

Common Exploitation Technique: Supply your own “get root” code.

Low Memory

Malicious Program

0x000000Kernel

Memory

0xffffffff

void get_r00t() {commit_creds(prepare_kernel_cred(0));

}

int main(int argc, char * argv) {…trigger_fp_overwrite(&get_r00t);…//trigger fp usetrigger_vuln_fp();// Kernel Executes get_r00t...// Now we have rootsystem(“/bin/sh”);

}

Page 92: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space ProtectionsSMEP / SMAP

Common Exploitation Technique: Supply your own “get root” code.

Low Memory

Malicious Program

0x000000Kernel

Memory

0xffffffff

void get_r00t() {commit_creds(prepare_kernel_cred(0));

}

int main(int argc, char * argv) {…trigger_fp_overwrite(&get_r00t);…//trigger fp usetrigger_vuln_fp();// Kernel Executes get_r00t()...// Now we have rootsystem(“/bin/sh”);

}

Page 93: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space ProtectionsSMEP / SMAP

Common Exploitation Technique: Supply your own “get root” code.

Low Memory

Malicious Program

0x000000Kernel

Memory

0xffffffff

void get_r00t() {commit_creds(prepare_kernel_cred(0));

}

int main(int argc, char * argv) {…trigger_fp_overwrite(&get_r00t);…//trigger fp usetrigger_vuln_fp();// Kernel Executes get_r00t()...// Now we have rootsystem(“/bin/sh”);

}

Page 94: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space ProtectionsSMEP / SMAP

Common Exploitation Technique: Supply your own “get root” code.

Low Memory

Malicious Program

0x000000Kernel

Memory

0xffffffff

void get_r00t() {commit_creds(prepare_kernel_cred(0));

}

int main(int argc, char * argv) {…trigger_fp_overwrite(&get_r00t);…//trigger fp usetrigger_vuln_fp();// Kernel Executes get_r00t()...// Now we have rootsystem(“/bin/sh”);

}

Page 95: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space ProtectionsSMEP / SMAP

Common Exploitation Technique: Supply your own “get root” code.

Low Memory

Malicious Program

0x000000Kernel

Memory

0xffffffff

void get_r00t() {commit_creds(prepare_kernel_cred(0));

}

int main(int argc, char * argv) {…trigger_fp_overwrite(&get_r00t);…//trigger fp usetrigger_vuln_fp();// Kernel Executes get_r00t()...// Now we have rootsystem(“/bin/sh”);

}

Page 96: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space ProtectionsSMEP / SMAP

SMEP prevents this type of attack by triggering a page fault if the processor tries to execute memory that has the “user” bit set while in “ring 0”.

Page 97: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space ProtectionsSMEP / SMAP

SMEP prevents this type of attack by triggering a page fault if the processor tries to execute memory that has the “user” bit set while in “ring 0”.

SMAP works similarly, but for data access in general

Page 98: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space ProtectionsSMEP / SMAP

SMEP prevents this type of attack by triggering a page fault if the processor tries to execute memory that has the “user” bit set while in “ring 0”.

SMAP works similarly, but for data access in general

This doesn’t prevent vulnerabilities, but it adds considerable work to developing a working exploit

Page 99: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Kernel Space ProtectionsSMEP / SMAP

SMEP prevents this type of attack by triggering a page fault if the processor tries to execute memory that has the “user” bit set while in “ring 0”.

SMAP works similarly, but for data access in general

This doesn’t prevent vulnerabilities, but it adds considerable work to developing a working exploit

We need to use ROP, or somehow get executable code into kernel memory.

Page 100: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Example

We’ll walk through a short example of a backdoored LKM to get a feel for dealing with the kernel.

Page 101: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Conclusion

Page 102: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Conclusion

Page 103: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Conclusion

Page 104: First order of Business - repository.root-me.orgrepository.root-me.org/Exploitation - Système/Unix/EN - Linux Kernel... · Kernel Space Protections SMEP / SMAP Common Exploitation

Conclusion