Java安全之挖掘回显链

Java安全之挖掘回显链0x00前言前文中叙述反序列化回显只是为了拿到Request和Response对象。在这里说的的回显链其实就是通过一连串反射代码获取到该Request对象。在此之前想吹

大家好,又见面了,我是全栈君,祝每个程序员都可以多学几门语言。

Java安全之挖掘回显链

0x00 前言

前文中叙述反序列化回显只是为了拿到RequestResponse对象。在这里说的的回显链其实就是通过一连串反射代码获取到该Request对象。

在此之前想吹爆一个项目,Java Object Searcher项目地址

0x01 回显链挖掘

借助Java Object Searche工具根据工具说明文档,在tomcat中下断点,然后在IDEA的Evaluate中执行索引语句。

Java安全之挖掘回显链

Java安全之挖掘回显链

TargetObject = {org.apache.tomcat.util.threads.TaskThread} 
  ---> group = {java.lang.ThreadGroup} 
   ---> threads = {class [Ljava.lang.Thread;} 
    ---> [14] = {java.lang.Thread} 
     ---> target = {org.apache.tomcat.util.net.NioEndpoint$Poller} 
      ---> this$0 = {org.apache.tomcat.util.net.NioEndpoint} 
         ---> handler = {org.apache.coyote.AbstractProtocol$ConnectionHandler} 
          ---> global = {org.apache.coyote.RequestGroupInfo}

根据得出结果在Evaluate中进行查看

Java安全之挖掘回显链

获取group

编写代码获取该对象

Field group = Class.forName("org.apache.tomcat.util.threads.TaskThread").getDeclaredField("group");
            group.setAccessible(true);
            ThreadGroup threadGroup = (ThreadGroup) group.get(thread);

获取测试错误了,其原因是因为org.apache.tomcat.util.threads.TaskThread中并没有group变量,该类继承了Thread类, 该变量在Thread类中。

Java安全之挖掘回显链

 Field group = Class.forName("java.lang.Thread").getDeclaredField("group");
            group.setAccessible(true);
            ThreadGroup threadGroup = (ThreadGroup) group.get(thread);

获取成功。

Java安全之挖掘回显链

获取thread

ThreadGroup threadGroup = (ThreadGroup) group.get(thread);
Field threads = Class.forName("java.lang.ThreadGroup").getDeclaredField("threads");
threads.setAccessible(true);
Thread[] thread1 = (Thread[])threads.get(threadGroup);

Java安全之挖掘回显链

获取target

发现thread并不是每一次都是14,需要这里采用获取线程名称进行定位对于的thread。

Java安全之挖掘回显链

Java安全之挖掘回显链

if (thread2.getName().contains("http-nio")&&thread2.getName().contains("ClientPoller-1"))

最终代码

package com;

import org.apache.coyote.RequestGroupInfo;
import org.apache.coyote.RequestInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Field;
//TargetObject = {org.apache.tomcat.util.threads.TaskThread}
//  ---> group = {java.lang.ThreadGroup}
//   ---> threads = {class [Ljava.lang.Thread;}
//    ---> [14] = {java.lang.Thread}
//     ---> target = {org.apache.tomcat.util.net.NioEndpoint$Poller}
//      ---> this$0 = {org.apache.tomcat.util.net.NioEndpoint}
//         ---> handler = {org.apache.coyote.AbstractProtocol$ConnectionHandler}
//          ---> global = {org.apache.coyote.RequestGroupInfo}
@WebServlet("/test2Servlet")
public class test2Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Thread thread = Thread.currentThread();
        try {
            Class<?> aClass = Class.forName("java.lang.Thread");
            Field group = aClass.getDeclaredField("group");
            group.setAccessible(true);
            ThreadGroup threadGroup = (ThreadGroup) group.get(thread);
            Field threads = Class.forName("java.lang.ThreadGroup").getDeclaredField("threads");
            threads.setAccessible(true);
            Thread[] thread1 = (Thread[])threads.get(threadGroup);
            for (Thread thread2 : thread1) {
                if (thread2.getName().contains("http-nio")&&thread2.getName().contains("ClientPoller-1")){
                    Field target = Class.forName("java.lang.Thread").getDeclaredField("target");
                    target.setAccessible(true);
                    Object o = target.get(thread2);
                    Field this$0 = o.getClass().getDeclaredField("this$0");
                    this$0.setAccessible(true);
                    Object o1 = this$0.get(o);
                    Field handler = Class.forName("org.apache.tomcat.util.net.AbstractEndpoint").getDeclaredField("handler");
                    handler.setAccessible(true);
                    Object handler1 = handler.get(o1);

                    Field global = handler1.getClass().getDeclaredField("global");
                    global.setAccessible(true);
                    RequestGroupInfo requestGroupInfo = (RequestGroupInfo)global.get(handler1);

                    Field processors = Class.forName("org.apache.coyote.RequestGroupInfo").getDeclaredField("processors");
                    processors.setAccessible(true);
                    java.util.List<RequestInfo> RequestInfo_list = (java.util.List<RequestInfo>) processors.get(requestGroupInfo);
                    Field req = Class.forName("org.apache.coyote.RequestInfo").getDeclaredField("req");
                    req.setAccessible(true);
                    for (RequestInfo requestInfo : RequestInfo_list) {
                        org.apache.coyote.Request request1 = (org.apache.coyote.Request) req.get(requestInfo);
                        org.apache.catalina.connector.Request request2 = ( org.apache.catalina.connector.Request)request1.getNote(1);
                        org.apache.catalina.connector.Response response2 = request2.getResponse();
                        response2.getWriter().write("Success!!!");
                    }



                }
            }
//            for (Thread thread2 : thread1) {
//                System.out.println(thread2.getName());
//            }

//            if ()
//            thread1[14]
//            Field target = Class.forName("java.lang.Thread").getDeclaredField("target");
//            target.setAccessible(true);
//            Runnable runnable = (Runnable)target.get(thread1[13]);


        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

Java安全之挖掘回显链

Reference

半自动化挖掘request实现多种中间件回显

0x02 结尾

其他中间件也是同理,设置筛选条件。然后定位request进行一步步的反射获取即可。再次吹爆该项目。目前只会简单使用,其他用法待研究。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/119867.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Android Studio中Intel HAXM的那些坑「建议收藏」

    Android Studio中Intel HAXM的那些坑「建议收藏」最近用过两台电脑折腾AndroidStudio,都是windows的系统,不知道为什么连着踩了两个坑。第一台我结束了qemu-system-i386.exe这个倒霉的进程导致我开启模拟器的时候一直提示我没有安装IntelHAXM,没办法咯,只好再安装一遍,然后奇葩的事情就发生了,出现了以下问题。Excuseme?我CPU虚拟化是开启的呀。这是什么鬼?安装了一次,不…

    2022年6月28日
    46
  • executescalar mysql_ExecuteScalar

    executescalar mysql_ExecuteScalar这两个答案和一点点思考使我想到了一个接近答案的东西。首先再澄清一下:该应用程序是用C#(2.0+)编写的,并使用ADO.NET与SQLServer2005进行通信。镜像设置是托管主体和镜像的两个W2k3服务器以及托管作为监视器的快速实例的第三个服务器。这样做的好处是,故障转移对于使用数据库的应用程序几乎是透明的,它将对某些连接引发错误,但从根本上讲一切都会很好地进行。是的,我们得到了奇怪的误报…

    2022年6月30日
    18
  • sstream头文件

    sstream头文件之前的sscanf和sprintfsscanf函数原型为intsscanf(constchar*str,constchar*format,…),将参数str的字符串根据参数format字符串来转换并格式化数据,转换后的结果存于对应的参数内;#include<iostream>#include<cstdio>usingnamespacestd;i…

    2022年6月4日
    52
  • 听我讲完redo log、binlog原理,面试官老脸一红

    听我讲完redo log、binlog原理,面试官老脸一红MySQL 问题答得很好 收到入职通知后 却发现被 HR 坑了 有毒

    2025年7月21日
    5
  • c语言中的位移位操作

    c语言中的位移位操作

    2021年12月2日
    41
  • c++深拷贝和浅拷贝[通俗易懂]

    c++深拷贝和浅拷贝[通俗易懂]C++中类的拷贝有两种:深拷贝,浅拷贝当出现类的等号赋值时,会调用拷贝函数在未定义显示拷贝构造函数的情况下,系统会调用默认的拷贝函数——即浅拷贝,它能够完成成员的一一复制。当数据成员中没有指针时,浅拷贝是可行的。但当数据成员中有指针时,如果采用简单的浅拷贝,则两类中的两个指针将指向同一个地址,当对象快结束时,会调用两次析构函数,而导致指针悬挂现象。所以,这时,必须采用深拷贝。深拷贝与浅拷贝

    2022年10月1日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号