CD's second night

WIZ-2025竞标赛-第二期(Contain Me If You Can)

type
status
date
slug
summary
tags
category
icon
password
💡
You've found yourself in a containerized environment.
To get the flag, you must move laterally and escape your container. Can you do it?
The flag is placed at /flag on the host's file system.
Good luck! 文章提示涉及到容器逃逸,我们得想办法进行容器逃逸

内网渗透

看到是bash终端,又提示容器,可以用主机和容器的扫描检测工具快速扫一下(ctf形式下可以这么打 实战中需要涉及样本和危险动作替代)这里我用cdk跑一下看一下结果。
notion image
 
可以看到 当前bash是在容器环境中,其它没什么可以明显利用的姿势,上来也不可能cdk就成功。
官方可以花钱购买提示说可以从网络应用层入手。
notion image
netstat -ano 和 netstat -ato 可以发现同网段内存在pgsql连接。
tcpdump抓包看一下是否存在明文:
tcpdump -i any -s0 -w package.pcap
tcpdump -r package.pcap -X
notion image
全都是select 表明这个进程是一直在主动连接的 但是没有其它可靠的明文思路。
再加上之前在netstat的鸡国看到keeplive
这里尝试去触发主动断连看会不会触发重连机制,重连中可能产生明文连接:
(ps:由于官方平台老是重置环境。期间反复尝试多次,为了确保稳定性,写下了sh脚本)
tcpdump -r auth_capture.pcap -X
notion image
这里存在pgsql账号密码
登录进去尝试是否能RCE
notion image
确实可以执行命令,这时候我们弹一个反弹shell出来 方便帮助我们后面进行逃逸。这里先用Tmux新建一个窗口用于接收反弹shell 安装并执行 screen 创建会话
💡
执行nc -lvvp 8080 监听
然后开始反弹
notion image
成功接收到反弹shell
notion image
sudo -l发现是sudoer组权限 直接sudo su
不过这时候不是交互的 需要升级到TTY 这里下载一个python然后进入tty
notion image
现在还是下载cdk一把梭
但是扫描完之后 无法使用滚轮 进而导致无法浏览扫描结果
notion image
notion image
notion image
这里我们可以用curl将结果传出 比如快链等平台 如果是实战的话就是vps或者你的存储桶(适合数据量大的情况)。
 

proc逃逸

根据扫描结果能看到core_pattern能利用到宿主主机,这里尝试proc 逃逸
一样也是screen新开一个窗口并开启nc监听
notion image
Ctrl + a 然后 " (双引号), 会列出所有窗口让你选。
notion image
回到sql-root-session进行触发逃逸
notion image
notion image
notion image
成功接收到shell
notion image
flag在根目录中

uevent_helper逃逸

原理:
  • uevent_helper 允许管理员指定一个用户态程序,当内核触发 uevent(如设备插入、移除等)时,内核会以 root 权限宿主机上下文调用该程序。
  • 如果容器有权限写入 /sys/kernel/uevent_helper(例如,运行在特权模式或具有 SYS_ADMIN 权能的容器),攻击者可以设置一个恶意脚本路径(如 $host_path/evil-helper)。
  • 由于 uevent_helper 是在宿主机上下文以 root 权限执行的,攻击者可以通过此机制在宿主机上运行任意命令,突破容器隔离。
  • event_helper 逃逸有分很多种, 本例中,event_helper 逃逸(通过 uevent_helper)依赖于 procfs(/etc/mtab),因此它同时是 procf 逃逸的一种。
 
从manesec大佬的文章学习到了另一种逃逸办法,详见:https://manesec.github.io/2025/08/24/2025/61-WIZ-Contain-Me-If-You-Can/
将反弹shell写到host目录中
原理
  • uevent 是 Linux 内核用于通知用户态设备状态变化(如设备添加、移除)的机制。
  • 写入 /sys/class/mem/null/uevent 会触发一个无害的 uevent(例如与 /dev/null 相关的状态变化)。
  • 内核在处理 uevent 时会调用 /sys/kernel/uevent_helper 中指定的程序(即 $host_path/evil-helper),并以 root 权限宿主机上下文执行。
  • 这导致 /evil-helper 中的命令(例如 ps > /output 或反向 shell)在宿主机上运行。
notion image
新建screen监听8081
notion image
触发
notion image
成功拿到反弹shell
notion image
 
针对event_helper逃逸这一类手法 后续会做更多延申和专项文章、靶场。 期待师傅指导
Loading...