Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1000 CNY

100.0%

CVE-2014-0038 PoC — Linux kernel‘compat_sys_recvmmsg’函数输入验证错误漏洞

Source
Associated Vulnerability
Title:Linux kernel‘compat_sys_recvmmsg’函数输入验证错误漏洞 (CVE-2014-0038)
Description:Linux kernel是美国Linux基金会发布的开源操作系统Linux所使用的内核。NFSv4 implementation是其中的一个分布式文件系统协议。 Linux kernel 3.13.1及之前的版本中的net/compat.c文件中的‘compat_sys_recvmmsg’函数中存在输入验证漏洞。当内核配置选项设置为‘CONFIG_X86_X32’时,本地攻击者可通过带有‘timeout pointer’参数的recvmmsg系统调用利用该漏洞获取特权。
Description
Linux local root exploit for CVE-2014-0038
Readme
Local root exploit for CVE-2014-0038
====================================

Bug:
----
The X86_X32 recvmmsg syscall does not properly sanitize the timeout pointer
passed from userspace.

Exploit primitive:
------------------
Pass a pointer to a kernel address as timeout for recvmmsg,
if the original byte at that address is known it can be overwritten
with known data.
If the least significant byte is 0xff, waiting 255 seconds will turn it into a 0x00.

Restrictions:
-------------
The first long at the passed address (tv_sec) has to be positive
and the second long (tv_nsec) has to be smaller than 1000000000.

Overview:
---------
Target the release function pointer of the ptmx_fops structure located in
non initialized (and thus writable) kernel memory. Zero out the three most
significant bytes and thus turn it into a pointer to an address mappable in
user space.
The release pointer is used as it is followed by 16 0x00 bytes (so the tv_nsec
is valid).
Open /dev/ptmx, close it and enjoy.

Not very beautiful but should be fairly reliable if symbols can be resolved.

Tested on Ubuntu 13.10

See also http://blog.includesecurity.com/2014/03/exploit-CVE-2014-0038-x32-recvmmsg-kernel-vulnerablity.html

Run:
----
Retrieve addresses from `/proc/kallsyms` and run the exploit:

    ./build.sh && ./timeoutpwn

If you would like to build the binary for a remote server, try this:

    ssh user@host 'cat /proc/kallsyms' > syms.txt
    CFLAGS=-static ./build.sh syms.txt
    scp timeoutpwn user@host:
    ...

If `ptmx_fops` cannot be found in kallsyms, try extracting it from the vmlinux
as provided with the headers package (`linux-headers` on Arch Linux):

    nm /lib/modules/$(uname -r)/build/vmlinux > syms.txt
File Snapshot

[4.0K] /data/pocs/aeaaca3851b583f699f285384c5d61f1f6b55f39 ├── [1.4K] addresses ├── [ 597] build.sh ├── [1.7K] README.md └── [6.2K] timeoutpwn.c 0 directories, 4 files
Shenlong Bot has cached this for you
Remarks
    1. It is advised to access via the original source first.
    2. If the original source is unavailable, please email f.jinxu#gmail.com for a local snapshot (replace # with @).
    3. Shenlong has snapshotted the POC code for you. To support long-term maintenance, please consider donating. Thank you for your support.