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

Goal: 1000 CNY · Raised: 1000 CNY

100.0%

CVE-2023-25136 PoC — OpenSSH 资源管理错误漏洞

Source
Associated Vulnerability
Title:OpenSSH 资源管理错误漏洞 (CVE-2023-25136)
Description:OpenSSH(OpenBSD Secure Shell)是加拿大OpenBSD计划组的一套用于安全访问远程计算机的连接工具。该工具是SSH协议的开源实现,支持对所有的传输进行加密,可有效阻止窃听、连接劫持以及其他网络级的攻击。 OpenSSH 存在资源管理错误漏洞,该漏洞源于options.kex_algorithms 处理期间引入了双重释放漏洞。
Readme
# CVE-2023-25136 漏洞复现

本项目提供一个最小化的本地实验环境,用于复现 **OpenSSH 9.1p1 预认证 double free 内存破坏漏洞(CVE-2023-25136)**,并观察到服务端进程崩溃(DoS)效果。

> 说明:官方与主流分析均认为该漏洞在默认安全配置下“难以实际利用为远程代码执行”,本环境主要用于演示内存错误与拒绝服务效果。



## 环境说明

- **靶机(Target)**:
  - 运行在 Docker 容器中的 **OpenSSH 9.1p1** 服务器
  - 已配置特权分离用户 `sshd`
  - 为了便于观察 double free 崩溃,构建时使用 `--with-sandbox=no` 关闭了 seccomp 沙箱
  - 容器内部监听 `22` 端口,对外映射到宿主机(WSL)上的 `2222` 端口

- **攻击机(Attacker)**:
  - 与靶机在同一台主机 / WSL 中
  - 使用 Python3 + `paramiko` 运行 PoC,构造特定 SSH 客户端标识并发起预认证握手

目录结构:

- `Dockerfile`:构建 OpenSSH 9.1p1 漏洞环境的镜像
- `poc.py`:最小 PoC 客户端,用于触发预认证阶段 double free



## 前置条件

在本目录下进行以下操作前,请确保:

- 已安装 **Docker**(在 WSL2 下建议使用 Docker Desktop 或直接在 WSL 中安装 Docker)
- 已安装 **Python 3** 和 `pip`



## 一、靶机搭建(Docker 内的 OpenSSH 9.1p1)

1. **构建镜像**

在本目录下执行:

```bash
docker build -t sshd-9.1p1-vuln .
```

2. **启动容器**

```bash
docker run --rm -d --name sshd-vuln -p 2222:22 sshd-9.1p1-vuln
```

说明:

- `--rm`:容器退出后自动删除
- `--name sshd-vuln`:容器名称
- `-p 2222:22`:将容器内 `22` 端口映射到宿主机 `2222` 端口

3. **确认 sshd 运行状态**

```bash
docker ps
```

应能看到类似:

```text
CONTAINER ID   IMAGE              COMMAND               STATUS          PORTS
xxxxxx         sshd-9.1p1-vuln    "/usr/sbin/sshd -D…"  Up ...          0.0.0.0:2222->22/tcp
```



## 二、攻击机 PoC 使用方法

### 1. 安装 PoC 依赖

在本目录中执行:

```bash
pip install paramiko
```

### 2. PoC 脚本说明(poc.py)

`poc.py` 使用 `paramiko.Transport` 主动与目标 SSH 服务器建立连接,并在预认证阶段伪造客户端标识,尝试触发 double free。

关键特性:

- 默认目标:`127.0.0.1:2222`(即本机 Docker 容器)
- 默认客户端标识:`SSH-2.0-PuTTY_Release_0.64`
- 提供简单的命令行参数:
  - `-t/--target`:目标 IP(默认 `127.0.0.1`)
  - `-p/--port`:目标端口(默认 `2222`)
  - `-c/--client-id`:伪造的 SSH client 标识
  - `--timeout`:超时时间(秒)
  - `-v/--verbose`:输出详细错误信息

### 3. 运行 PoC

在保证容器 `sshd-vuln` 已启动的前提下,在本目录执行:

```bash
python3 poc.py
```

或显式指定参数:

```bash
python3 poc.py -t 127.0.0.1 -p 2222 -v
```

客户端预期输出示例:

```text
==============================================
   CVE-2023-25136 OpenSSH Pre-Auth Double Free
              Minimal PoC Client
==============================================
[2024-xx-xx xx:xx:xx] Target: 127.0.0.1:2222, ClientID: SSH-2.0-PuTTY_Release_0.64
[+] Sending crafted pre-auth handshake...
[-] Authentication failed or connection closed early.
    请在服务端 sshd 日志中查看是否出现 'free(): double free detected' 等信息,以确认是否触发 CVE-2023-25136。
```

说明:

- 客户端这里报 `Authentication failed` 或 `connection closed` 是预期行为,因为服务端预认证子进程在处理过程中可能崩溃或主动关闭连接。



## 三、预期结果与验证方式

### 1. 服务端(容器)日志

运行 PoC 后,在宿主机查看容器日志:

```bash
docker logs sshd-vuln
```

预期可看到类似输出:

```text
Server listening on 0.0.0.0 port 22.
Server listening on :: port 22.
Invalid user  from 172.17.0.1 port xxxxx
free(): double free detected in tcache 2
```

其中:

- `Invalid user`:由于 PoC 使用空用户名,OpenSSH 记录了非法用户尝试
- `free(): double free detected in tcache 2`:glibc 检测到 **double free** 并终止当前 sshd 子进程,这正是本实验要观察的内存破坏/DoS 现象

> 注意:为了能够看到这一行,我们在构建 OpenSSH 时关闭了 seccomp sandbox(`--with-sandbox=no`),否则沙箱可能会在 double free 之前先拦截异常行为并直接终止子进程。

### 2. 效果性质

- 本实验环境中,PoC 能够稳定触发 **预认证子进程的崩溃(DoS)**,从而导致当前 SSH 连接失败。主 `sshd` 进程会继续为后续连接派生新的子进程。
- 由于预认证子进程运行在低权限 + chroot 环境中且默认存在多重安全机制,研究者普遍认为单独依赖该 double free 实现远程代码执行的难度极高。
File Snapshot

[4.0K] /data/pocs/b8b365bf701b43409ff2c47d07fb4b498fff8783 ├── [ 920] Dockerfile ├── [3.8K] poc.py └── [4.8K] README.md 1 directory, 3 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.