如何在 Windows 10 PC 上找到易受攻擊的 log4j 程式 (CVE-2021-44228) 以及當我無法更新到固定的 log4j 版本時如何提供急救?
uj5u.com熱心網友回復:
可以從log4j-core jar 檔案中洗掉 JndiLookup 類,以便在 log4j 安全災難( CVE-2021-44228 )的背景關系中提供急救。 洗掉 JndiLookup 類,如果您無法將 Java 應用程式更新到具有固定 log4j 版本的版本,因為它是log4j 自己建議的。
所以這只是一個急救快速修復,直到您獲得應用程式更新!以下 PowerShell 腳本將在所有驅動器中搜索 log4j-core*.jar 檔案。在找到的任何一個中,我們將使用“zip -q -d”命令從中洗掉 JndiLookup 類。
在 Windows 10 PC 上,有用于撰寫腳本的 PowerShell。因此,創建一個包含以下內容的anyname.ps1檔案:
# Ensure we can run everything
Set-ExecutionPolicy Bypass -Scope Process -Force
# Escape characters in PowerShell: https://ss64.com/ps/syntax-esc.html
Write-Host "Start iterating drives..."
$volumes = Get-WmiObject win32_volume -filter "drivetype=3"
foreach ($volume in $volumes)
{
$driveletter = $volume.driveletter # e.g. C:
if ($driveletter -ne $null)
{
$drivename = $volume.name # e.g. C:\
Write-Host "`n== Checking $driveletter... =="
# Find log4j-core*.jar files, directly
# and remove org/apache/logging/log4j/core/lookup/JndiLookup.class
# with zip.exe -q -d command.
# Use unzip -l | findstr JndiLookup as paranoia check.
Write-Host "== Find log4j-core*.jar files... =="
Get-ChildItem -Path $drivename -Filter log4j-core*.jar -Recurse -ErrorAction SilentlyContinue | % {
Write-Host "== $($_.FullName) =="
Write-Host "> zip.exe -q -d `"$($_.FullName)`" `"org/apache/logging/log4j/core/lookup/JndiLookup.class`""
zip.exe -q -d "$($_.FullName)" "org/apache/logging/log4j/core/lookup/JndiLookup.class"
Write-Host "> unzip.exe -l `"$($_.FullName)`" | findstr JndiLookup"
unzip.exe -l "$($_.FullName)" | findstr JndiLookup
Write-Host "== END =="
}
# Find JndiLookup.class in uncompressed directories on the file-system (aka *.class)
Write-Host "== Find uncompressed JndiLookup.class files... =="
Get-ChildItem -Path $drivename -Filter JndiLookup.class -Recurse -ErrorAction SilentlyContinue | % {
Write-Host "== $($_.FullName) =="
Write-Host "> Remove-Item -Path `"$($_.FullName)`" -Force"
Remove-Item -Path $_.FullName -Force
Write-Host "== END =="
}
}
}
# Find embedded log4j-core*.jar files ("Java über JARs" or shaded JARs, i.e., JARs in other JAR/WAR/etc.)
Write-Host "== Find log4j-core*.jar files that are embedded into other archives... =="
Write-Host "TODO: Not supported!"
Write-Host "INSTEAD APPLY: https://github.com/mergebase/log4j-detector"
# Find log4j in docker containers
Write-Host "== Find log4j in docker containers... =="
Write-Host "TODO: Not supported!"
Write-Host "READ: https://www.docker.com/blog/apache-log4j-2-cve-2021-44228/"
Write-Host "THUS, APPLY: docker scan"
Write-Host "Press ENTER to continue..."
cmd /c Pause | Out-Null
現在你可以執行這個 ps1 檔案了。
執行ps1檔案的簡單方法:除了同名的ps1檔案外,創建一個anyname.cmd檔案,內容如下:
powershell.exe -ExecutionPolicy ByPass -noprofile -command "&{start-process powershell -ArgumentList '-ExecutionPolicy ByPass -noprofile -NoExit -file \"%~dpn0.ps1\"' -verb RunAs}"
您可以雙擊cmd。它將以提升的權限執行 ps1 腳本。
親切的問候!
更新: log4j(版本 2.15、2.16 和現在的 2.17)現在已經嘗試了幾次修復。可能,“急救”洗掉 JndiLookup 類(從任何 log4j JAR,可能是嵌入的,即“Java über JAR”或陰影 JAR,或在檔案系統上的未壓縮目錄中,又名 *.class)實際上應該是您現在和未來的首選選擇。
uj5u.com熱心網友回復:
更新:2021-12-18...
請記住始終從下面列出的資源中檢查最新資訊
CVE-2021-45105 ... 2.16.0 和 2.12.2 不再是有效的補救措施!當前的修復版本是 2.17.0 (Java 8) 和 2.12.3 (Java 7)。所有其他 Java 版本都必須采用停止間隙方法(從 log4j-core JAR 中洗掉/洗掉 JndiLookup.class 檔案。
我已相應地更新了下面的訊息。
直接回答問題:
我知道你專門問了如果不能升級怎么辦……我會在底部回答這個問題。但是,我也包括其他資訊,供其他任何偶然發現的人使用。
對于檢測:請參閱Cyber??PetaNeuron 的其他答案
補救措施:繼續閱讀
- 更多資源
- https://www.reddit.com/r/blueteamsec/comments/rd38z9/log4j_0day_being_exploited/
- 這個有很多有用的資訊,包括檢測器、更多的資源鏈接、非常容易理解的修復步驟等等
- https://www.cisa.gov/uscert/apache-log4j-vulnerability-guidance
- https://github.com/cisagov/log4j-affected-db
- https://logging.apache.org/log4j/2.x/security.html
- https://www.reddit.com/r/blueteamsec/comments/rd38z9/log4j_0day_being_exploited/
補救措施:
CVE-2021-45046 ... CVE-2021-44228 ... CVE-2021-45105
雖然大多數需要了解的人可能已經足夠了解他們需要做的事情,但我想我仍然會把它放在以防萬一...
- 遵循這些資源中的指導......它可能會改變,但是
截至 2021-12-18
基本上是
- 如果可能,洗掉 log4j-core JAR 檔案
- 從兩臺跑步機立即修復和
- 在您的源代碼/源代碼管理檔案中,以防止未來的構建/發布/部署覆寫更改
- 如果這是不可能的(由于依賴性),請升級它們
- 如果您運行的是 Java 8,那么您可以升級到 log4j 2.17.0
- 如果您運行的是 Java 7,那么您可以升級到 log4j 2.12.3
- 如果您運行的是舊版本的 Java,那么您需要升級到最新版本的 Java,然后使用最新版本的 Log4J
- 同樣,這些更改必須同時發生在運行機器和代碼中
- 如果由于某種原因這些都不可能......那么從 log4j 核心 JAR 中洗掉 JndiLookup.class 檔案是非修復的止損。
zip默認情況下,使用大多數 Linux 發行版打包的命令在 Linux 上有一個單行停止間隙選項。zip -q -d "$LOG4J_JAR_PATH" org/apache/logging/log4j/core/lookup/JndiLookup.class
- 在撰寫本文時,大多數 Windows 上停止間隙選項的在線指南都說要執行以下操作(再次...假設您無法執行上述洗掉 JAR 或升級選項之一):
- 安裝類似 7-zip 的東西
- 找到所有 log4j-core JAR 檔案,并對每個檔案執行以下操作...
- 重命名 JAR 以將擴展名更改為
.zip - 使用 7-zip 解壓縮 JAR(現在有
.zip擴展名) - 在解壓后的檔案夾中找到并洗掉 JndiLookup.class 檔案
- 路徑是
\\path\\to\\unzippedFolder\\org\\apache\\logging\\log4j\\core\\lookup\\JndiLookup.class
- 路徑是
- 洗掉舊的 JAR 檔案(現在擴展名為 .zip)
- 使用 7-zip 重新壓縮檔案夾
- 重命名新的 .zip 檔案夾以將擴展名更改為
.jar
- 還有一些選項可以使用 Power Shell
- Reddit 執行緒:log4j_0day_being_exploited
- ctrl f代表“PowerShell”
如果您只有 1 或 2 個 JAR 檔案需要處理并且您不介意安裝 7-zip 或您有可用的 PowerShell 來執行此操作,那么這很好。但是,如果您有大量 JAR 檔案,或者您不想安裝 7-zip 并且無法訪問 Power Shell,我創建了一個開源 VBS 腳本,無需安裝即可為您完成任何附加軟體。https://github.com/CrazyKidJack/Windowslog4jClassRemover
閱讀自述檔案和發行說明https://github.com/CrazyKidJack/Windowslog4jClassRemover/releases/latest
uj5u.com熱心網友回復:
我在另一個答案中提供了急救 PowerShell 腳本,但是,同時有幾個高級工具允許在 CVE-2021-44228 的背景關系中檢測和修補基于 log4j 的應用程式,以防您無法升級應用程式和它捆綁的 log4j,但是。
log4j-detector是一個基于 Java 的工具,用于搜索易受攻擊的 log4j 實體。它在“Java über JAR”以及其他 JAR/WAR、檔案系統(又名 *.class)上的未壓縮目錄和陰影 jar 中檢測 log4j。它提供有關找到的 log4j 版本的資訊。(它不提供修補程式來修復發現的問題。)但這似乎是最徹底的檢測。
log4j-vuln-scanner是一個基于 Go 的工具,具有適用于 x86_64 Windows、Linux、MacOSX 的二進制版本,用于搜索易受攻擊的 log4j 實體。它也在其他 JAR 和 WAR 檔案中找到 log4j,并提供有關找到的 log4j 版本的資訊。(它似乎不像上面的 log4j-detector 那樣徹底。)但這提供了一個修補程式來修復發現。
log4j2-scan適用于 Windows、Linux 和 MacOS。搜索的深度不像其他的那樣明確。但是,它還提供了修復其發現的方法。
log4shell-detector是一個基于 python 的工具,用于搜索日志檔案,并從日志字串中嘗試檢測任何利用嘗試。
相關問題:如何在 Docker 容器中查找 log4j 實體?使用碼頭掃描!但請閱讀https://www.docker.com/blog/apache-log4j-2-cve-2021-44228/以獲取進一步說明。
更新: log4j(版本 2.15、2.16 和現在的 2.17)現在已經嘗試了幾次修復。可能,“急救”洗掉 JndiLookup 類(從任何 log4j JAR,可能是嵌入的,即“Java über JAR”或陰影 JAR,或在檔案系統上的未壓縮目錄中,又名 *.class)實際上應該是您現在和未來的首選選擇。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/387735.html
標籤:安全 日志4j cve-2021-44228
上一篇:WP網站不斷因加密劫持而遭到黑客攻擊-如何找到漏洞?
下一篇:Mavenpom.xml中將log4j2的所有用法升級到2.15.0的最簡單方法是什么,包括使用log4j2的依賴項?參見CVE-2021-44228
