摘要
在長期運行的應用服務器上,近期的安全漏洞掃描揭示了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 thefiles 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博客