/kernel-exploit-factory

Linux kernel CVE exploit analysis report and relative debug environment. You don't need to compile Linux kernel and configure your environment anymore.

Primary LanguageC

kernel-exploit-factory

Keep updating......

Linux kernel CVE exploit analysis report and relative debug environment. You don't need to compile Linux kernel and configure your environment anymore.

This repository is to extract all Linux kernel exploit and relative debug environment. You can use Qemu to boot the kernel and test the exploit.


Example

# Eg, test CVE-2017-11176, finally you levate privileges and get the shell
john@john-virtual-machine:~/Desktop/kernel-exploit-factory/CVE-2017-11176$ ./start.sh 
chmod: /dev/csaw: No such file or directory
ifconfig: SIOCSIFADDR: No such device
route: SIOCADDRT: No such device
/ $ uname -a
Linux (none) 4.11.9 #1 SMP Sat Feb 20 21:52:39 CST 2021 x86_64 GNU/Linux
/ $ id
uid=1000(chal) gid=1000(chal) groups=1000(chal)
/ $ cd exp
/exp $ ./exp-slab-4119
[*] sk_rmem_alloc > sk_rcvbuf ==> ok
[*] mq_notify start
[*] wake up thread 1
... ...
/exp # id
uid=0(root) gid=0(root)
/exp # 

Catalog

  1. CVE-2015-8550
  2. 4-20-BPF-integer
  3. CVE-2017-5123
  4. CVE-2017-7308
  5. CVE-2017-8890
  6. CVE-2017-11176
  7. CVE-2017-16995
  8. CVE-2017-1000112
  9. CVE-2019-9213 & CVE-2019-8956
  10. CVE-2020-8835
  11. CVE-2020-27194
  12. CVE-2021-3156
  13. CVE-2021-31440

Detail

1.CVE-2015-8550

writeup

Test version: Linux-4.19.65

Protection: 开启kaslr/SMEP,未开启SMAP。

Vulnerability: gcc 编译优化导致的Double-Fetch漏洞,可直接劫持控制流。

2. 4-20-BPF-integer

writeup

Test version: Linux-4.20.0-rc3

Protection: 开启SMEP,未开启kaslr/SMAP。

Vulnerability: Linux ebpf 模块中queue_stack_map_alloc()整数溢出漏洞,导致堆溢出。修改虚表指针劫持控制流到xchg eax, esp

3.CVE-2017-5123

writeup

Test version: Linux 4.14-rc4

Protection: 开启 SMEP / SMAP,关闭KASLR。

Vulnerability: /kernel/exit.c中的waitid的实现,在调用unsafe_put_user()将内核数据拷贝到用户空间地址时,没有调用access_ok()检测用户空间地址的合法性,导致实际可以往内核空间地址拷贝数据。 waitid未检测用户地址合法性 导致 null 任意地址写。可执行0地址shellcode 或 覆盖某猜测范围的cred 来提权。

4.CVE-2017-7308

writeup reference

Test version: Linux-4.10.6

Protection: 开启 SMEP / SMAP,关闭KASLR。

Vulnerability: net/packet/af_packet.c中的packet_set_ring()函数没有正确检查块size,长度判断条件错误,导致堆溢出,需要CAP_NET_RAW 权限。两次劫持函数指针,先关闭SMEP/SMAP防护,再提权。

5.CVE-2017-8890

writeup reference

Test version: Linux-4.10.15

Protection: 开启SMEP,关闭kASLR、SMAP。

Vulnerability: net/ipv4/inet_connection_sock.c文件中的inet_csk_clone_lock()函数存在Double-Free漏洞。利用Double-Free来篡改RCU的回调函数指针,关闭SMEP并跳转到shellcode来修改cred。

6.CVE-2017-11176

writeup

Test version: Linux-4.11.9

Protection: 开启SMEP,关闭kASLR、SMAP。

Vulnerability: Linux内核中的POSIX消息队列的实现,mq_notify()函数没有把sock指针置为null,导致UAF。实际上是由于竞争导致的Double-Free漏洞,但竞态的时间可以无限延长。

7.CVE-2017-16995

writeup

Test version: Linux-4.4.110

Protection: 开启SMEP/SMAP/kaslr。

Vulnerability: Linux ebpf 模块整数扩展问题,主要问题是二者寄存器值类型不同,导致check函数和真正的函数的执行方法不一致。本漏洞不包含堆栈攻击或控制流劫持,仅用系统调用数据进行提权,是Data-Oriented Attacks在linux内核上的一个典型应用。

8. CVE-2017-1000112

writeup reference

Test version: Linux-4.12.6

Protection: 开启SMEP,关闭SMAP/kaslr。

Vulnerability: net/ipv4/ip_output.c 中的__ip_append_data() 没有保证UDP报文处理的一致性,导致两次send报文时,可从UFO路径切换为non-UFO路径,导致堆溢出。利用时可通过覆盖skb_shared_info->destructor_arg->callback劫持控制流。

9. CVE-2019-9213 & CVE-2019-8956

CVE-2019-9213-writeup CVE-2019-8956-writeup

Test version: Linux-4.20.0 32位

Protection: 开启SMEP,关闭SMAP/kaslr。

Vulnerability:

  • CVE-2019-9213:mm/mmap.c中的expand_downwards()对mmap最小地址的检查出错,对错误的task进行了capability检查,导致绕过了mmap_min_addr的限制,逻辑漏洞。利用LD_DEBUG=help /bin/su 1>&%d命令执行write操作,本来应检测exp的cred,结果错误检测了write进程的cred,就将低地址标记为特权可访问。只有32位系统能成功利用漏洞,原因不详。
  • CVE-2019-8956:net/sctp/socket.c中的 sctp_sendmsg() 函数在处理SCTP_SENDALL flag时出现空指针引用漏洞。结合CVE-2019-9213,绕过mmap_min_addr的限制,可以mmap到低地址0xd4并伪造结构,劫持控制流。

10. CVE-2020-8835

writeup reference

Test version: Linux-5.5.0

Protection: 开启SMEP/SMAP/kaslr。

Vulnerability: kernel/bpf/verifier.c没有正确将64位值转换为32位(直接取低32位),发生整数截断,使得BPF代码验证阶段和实际执行阶段不一致,导致越界读写。

11. CVE-2020-27194

writeup reference

Test version: Linux-5.8.14

Protection: 开启SMEP/SMAP/kaslr。

Vulnerability: eBPF验证程序中进行or操作时,scalar32_min_max_or()函数将64位的值赋值到32位的变量上,导致整数截断,进而错误计算了寄存器的范围,从而绕过bpf的检查,导致越界读写。

12. CVE-2021-3156

writeup exploit

Test version: Ubuntu 19.04、Sudo 1.8.27

Protection: 开启SMEP/SMAP/kaslr。

Vulnerability: sudo在处理命令行参数时,处理单个反斜杠结尾的命令时,发生逻辑错误,导致堆溢出

13. CVE-2021-31440

writeup exploit

Test version: Linux-5.11

Protection: 开启SMEP/SMAP/kaslr。

Vulnerability: eBPF模块—kernel/bpf/verifier.c__reg_combine_64_into_32() 函数,寄存器计算错误。利用verifier阶段与实际执行阶段的不一致性,进行越界读写。泄露内核基址、伪造函数表、实现任意读写后篡改本线程的cred。