本文仅限于技术讨论与分享,严禁用于非法途径。若读者因此作出任何危害网络安全等违法行为后果自负,与本号及作者无关。
大家好我是小迪徒弟,已经学习7个月了,在学习过程中在小迪老师这里学习到了很多技术与知识,特此开了一个公众号,记录学习的内容。
Swagger是什么
swagger 是一个规范且完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。通俗的讲,swagger 就是将项目中所有接口展现在页面上,并且可以进行接口调用和测试的服务。
一般要用到swagger的大多数学都是使用的spring框架
同时使用了webapck打包的网站,一般用到接口大多数都是swagger的那么它也有就可能有swagger接口文档,那么你就可能获得了无数个接口未授权
如果他隐藏了接口文档,如果那个网站是使用webpack进行打包那也是可以在js中发掘接口路由的。
关于webpack的网站怎么测试可以参考我发的这一篇文章:
https://mp.weixin.qq.com/s/ThO7wZmv4iI9qZRGya72cQ s7eyd7,公众号:云梦安全webpack-API安全测试
如何发现swagger接口文档
有时候一般都是通过接口扫描得出来的接口文档地址,但是js的站大多数都是就一个登录框,这个时候我们可以通过对功能点的抓包,通常spring框架用到了swagger的网站它的功能点都是使用接口去进行调用的,那么就去查看那个功能点的请求地址然后再去进行扫描。
举个例子:
比如这个网站是在登录框输入密码的时候进行抓包的。
结合上面所说的去掉后面的login,我们去访问一下看看
可以看到是一个明显的spring报错页面。
这个时候可以尝使用目录扫描工具进行扫描,或者使用spring敏感目录
http://127.0.0.1/manager/
这样去扫描,如果是直接加host的话大概率是扫描不到
结合burp爆破模块进行遍历或者使用python写一个脚本,目录如下:
json/swagger.json
doc.html
v2/api-docs
swagger-resources
swagger-ui.html
swagger
api-docs
api.html
swagger-ui
swagger/codes
api/index.html
api/v2/api-docs
v2/swagger.json
swagger-ui/html
distv2/index.html
swagger/index.html
sw/swagger-ui.html
api/swagger-ui.html
static/swagger.json
user/swagger-ui.html
swagger-ui/index.html
swagger-dubbo/api-docs
template/swagger-ui.html
swagger/static/index.html
dubbo-provider/distv2/index.html
spring-security-rest/api/swagger-ui.html
spring-security-oauth-resource/swagger-ui.html
mappings
metrics
beans
configprops
actuator/metrics
actuator/mappings
actuator/beans
actuator/configprops
actuator
auditevents
autoconfig
caches
conditions
docs
dump
env
flyway
health
heapdump
httptrace
info
intergrationgraph
jolokia
logfile
loggers
liquibase
prometheus
refresh
scheduledtasks
sessions
shutdown
trace
threaddump
actuator/auditevents
actuator/health
actuator/conditions
actuator/env
actuator/info
actuator/loggers
actuator/heapdump
actuator/threaddump
actuator/scheduledtasks
actuator/httptrace
actuator/jolokia
actuator/hystrix.stream
actuator/refresh
jolokia/list
api/swagger
Swagger/ui/index
api/swaggerui
swagger/ui
api/swagger/ui
libs/swaggerui
swagger-resources/configuration/ui
swagger-resources/configuration/security
druid/index.html
swagger/v1/swagger.json
swagger/v2/swagger.json
api/doc
docs/
v1/api-docs
v3/api-docs
脚本代码如下
import requests
from concurrent.futures import ThreadPoolExecutor
from optparse import OptionParser
def burst_domain(list):
sub_domain = host + '/' + list.strip()
url = 'http://' + sub_domain
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0'
}
try:
response = requests.get(url=url, headers=headers)
if response.status_code == 200:
print('%s 接口地址存在n' % url.strip())
except:
pass
# print('%s 域名不存在'% sub_domain)
if __name__ == '__main__':
parse = OptionParser()
parse.add_option('-d','--host',dest='host',type='string',help="请输需要爆破的域名",default='127.0.0.1:8080')
parse.add_option('-t','--threads',dest='threads',type='int',help='请输入你要爆破的线程数',default='50')
options,args = parse.parse_args()
host = options.host
threads= options.threads
print('正在爆破........')
with open('list.txt','r') as f :
with ThreadPoolExecutor(max_workers=threads) as pool:
list = f.readline()
while list:
pool.submit(burst_domain,list)
list = f.readline()
TRAFFIC SAFETY 有时候会扫描不到swagger-ui.html和v2/api-docs,
其实是开发改了v2/api-docs地址把swagger-ui.html文档删除了
TRAFFIC SAFETY 这个时候我们访问/swagger-resources目录可以查看到地址,如图上。
但是v2/api-docs的都是json格式的不像swagger-ui.html是图形化表示的比较难看有一些东西还要自己输入。
使用到如下工具可以将json格式的swagger输出成html图形化的。
https://github.com/lijiejie/swagger-exp
首先感谢这个师父造的轮子
TRAFFIC SAFETY TRAFFIC SAFETY 然后打开就可以了
TRAFFIC SAFETY 或者直接把v2/api-docs里面的json内容复制到
https://editor.swagger.io/
中
TRAFFIC SAFETY 然后就可以开始冲了呀,兄弟们
模糊测试方法
测试工具:
https://github.com/jayus0821/swagger-hack
再次感谢这个师父造的轮子,
TRAFFIC SAFETY 建议:这个工具还是要谨慎使用,因为文档中不乏有删除接口
测试之前确保没有删除接口再进行测试!避免误删数据。
手动测试方法
主要是根据接口功能点去测试,测试方法与web测试一样,如未授权,越权,SQL注入,文件上传,XSS
在swagger.html中会显示接口提交的数据类型是int还是char
TRAFFIC SAFETY 像int类型的可以使用burp进行遍历,其他点和web一样,这里不多说。
测试实例:
这边这个网站没有发现swagger的接口文档,当时也不妨碍测试,主要是通过js中找到接口地址的没什么区别。
开局一个登录框。
TRAFFIC SAFETY F12查看js文件
TRAFFIC SAFETY TRAFFIC SAFETY 在js中看到了一个html地址,直接访问
TRAFFIC SAFETY 芜湖,直接进入爽歪歪,不过不重要这不是重点,继续查看js文件
然后找啊找找到js中有一个这个东西
TRAFFIC SAFETY 可以看到第一个url是已POST方式进行提交的,然后data下面写一个
Id:id这个就很明显了,直接构造数据包提交
TRAFFIC SAFETY TRAFFIC SAFETY 直接fuzz一波,然后解密登录
TRAFFIC SAFETY Js中还有很多接口地址,就不一一测试了,方法都是一样的。
学安全找小迪,小迪安全yyds,只有干货没有水货
原文始发于微信公众号(云梦安全实验室):swagger接口漏洞测试
- 左青龙
- 微信扫一扫
- 右白虎
- 微信扫一扫
评论