BSidesLJ_GuideToLinuxKernelExploitation
BSidesLJ_GuideToLinuxKernelExploitation
exploitation
Ivor Canjuga
# whoami
Twitter: @santaclzz
Intern at Viris
Why this presentation
To challenge myself
To share knowledge
Jk
To get a ticket before others :)
Kernel exploits: where are they used
Still evolving
https://en.wikipedia.org/wiki/Kernel_(operating_system)
Differences from userspace
More instructions
More registers
More patience
Persistence / stealth
Goal of exploitation
commit_creds(prepare_kernel_cred(0))
run_cmd(“/path_to_command”)
Attack surface
Kernel modules - read, write, ioctl
File system
Network drivers
USB device
Setup
Build the Linux kernel with debug symbols
c. Ensure that kernel hacking --> Compile-time checks and compiler options -->
Compile the kernel with debug symbols is checked.
d. make
Setup
filesystem
busybox
qemu
gdb
Debug (gdb) b *0x401d05
From userspace
From kernelspace
Symbols in /proc/kallsyms
-s Shorthand for -gdb tcp::1234, i.e. open a gdbserver on TCP port 1234.
Shellcode
Write kernel module
Compile it
Reverse engineer it
syscalls
Kernel Heap
SLOB, SLUB, SLAB allocator
https://github.com/a13xp0p0v/linux-kernel-defence-map
Ret2user
Bypass everything
Return to userland
syscall call
swapgs leave
iretq ret
Side channel attacks
spectre & meltdown
/proc/cpuinfo
Fuzzing
KCOV
KASAN
AFL
Syzkaller
Syzbot
Buzzer - eBPF
References
https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/
https://sam4k.com/linternals-memory-allocators-0x02/
https://lkmidas.github.io/posts/20210205-linux-kernel-pwn-part-3/
https://seal9055.com/blog/kernel/return_oriented_programming
https://breaking-bits.gitbook.io/breaking-bits/exploit-development/linux-kernel-exploit-development/kernel-page-table-isolation-kpti#kpti-trampoline
https://ptr-yudai.hatenablog.com/entry/2020/03/16/165628
https://pwn.college/system-security/kernel-security
https://github.com/google/syzkaller/
https://research.nccgroup.com/2018/09/11/ncc-groups-exploit-development-capability-why-and-what/
https://lwn.net/Articles/824307/
https://meltdownattack.com/meltdown.pdf