【Linux】升级FastJSON版本-jar

摘要

在长期运行的应用服务器上,近期的安全漏洞扫描揭示了fastjson组件存在潜在的安全隐患(FastJSON是一个Java 语言实现的 JSON 解析器和生成器。FastJSON存在远程代码执行漏洞,恶意攻击者可以通过此漏洞远程执行恶意代码来入侵服务器)。为解决这一漏洞,解决方案是对fastjson版本的升级,以增强系统的安全性。为了避免因重新打包整个应用带来的不便与效率损失,我们采取了一种更为灵活的更新策略——直接在生产环境中升级fastjson至最新稳定版本。

FastJson下载

官方链接:https://mvnrepository.com/artifact/com.alibaba/fastjson

按照如下步骤进行下载FastJson的jar包

 下滑找到你要的fastjson包版本,我选择1.2.83。

 跳转到具体1.2.83版本页。

 跳转到GitHub,点击如下图所示:

 点击下载FastJson的jar包

 升级Fastjson

1.找到服务器上正在运行的Java的jar包

# 根据命令能看见正在跑的Java的jar包
ps -ef|grep java
# 根据命令找到Java包的位置
find / -name xx.jar

2.备份jar包

# 切换到jar包目录
cd /xxx/xxx
# 复制一份jar包
cp xx.jar xx.jar_日期.bak

 举例如下:

3.创建临时文件夹,并将jar移入

注:先备份要进行升级fastjson的jar包

mkdir temp
mv xxx.jar temp/
# 切换到临时目录
cd temp/

4.解压jar包

jar xvf xxx.jar
# 一般解压有三个目录:BOOT-INF/ META-INF/ org/

通过jar --help 命令查看 jar 的相关命令

Illegal option: -
Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
Options:
    -c  create new archive
    -t  list table of contents for archive
    -x  extract named (or all) files from archive
    -u  update existing archive
    -v  generate verbose output on standard output
    -f  specify archive file name
    -m  include manifest information from specified manifest file
    -n  perform Pack200 normalization after creating a new archive
    -e  specify application entry point for stand-alone application 
        bundled into an executable jar file
    -0  store only; use no ZIP compression
    -P  preserve leading '/' (absolute path) and ".." (parent directory) components from file names
    -M  do not create a manifest file for the entries
    -i  generate index information for the specified jar files
    -C  change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.

Example 1: to archive two class files into an archive called classes.jar: 
       jar cvf classes.jar Foo.class Bar.class 
Example 2: use an existing manifest file 'mymanifest' and archive all the
           files in the foo/ directory into 'classes.jar': 
       jar cvfm classes.jar mymanifest -C foo/ .

用法:jar {ctxui} [vfmn0PMe] [jar文件] [清单文件] [入口点] [-C目录]文件...
选项:
    -c创建新档案
    -t列出要归档的目录
    -x从存档中提取命名(或所有)文件
    -u更新现有档案
    -v在标准输出上生成详细输出
    -f指定归档文件名
    -m包含来自指定清单文件的清单信息
    -n在创建新存档后执行Pack200规范化
    -e指定独立应用程序的应用程序入口点
        捆绑到可执行的jar文件中
    -0只存储;不使用ZIP压缩 (数字0)
    -P从文件名保留前导的“ /”(绝对路径)和“ ..”(父目录)组件
    -M不为条目创建清单文件
    -i为指定的jar文件生成索引信息
    -C更改为指定目录并包含以下文件
如果任何文件是目录,则将对其进行递归处理。
清单文件名称,归档文件名称和入口点名称为
以与“ m”,“ f”和“ e”标志相同的顺序指定。

5.更新fastjson的jar包

# 切换到BOOT-INF/lib
cd BOOT-INF/lib
# 找到fastjson.jar并替换,可采用文件传输工具或者命令

6.重新打成jar包

#打包时先删除当前目录的xxx.jar包
rm -rf xxx.jar
#将所有文件重新压缩成xxx.jar包
jar -cvfM0 xxx.jar BOOT-INF/ META-INF/ org/
#将重新打包的xxx.jar放回原来目录,并运行新的jar包。

到此,在Linux环境下fastjson升级完成。

参考:jar包的解压和重新打包_jar解压后重新打包-CSDN博客

  • 19
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值