
CVE-2022-22965 (Spring4Shell) भेद्यता के लिए पहचान स्क्रिप्ट और मार्गदर्शन, जिसमें Spring Framework में PowerShell और Bash स्कैनर शामिल हैं जो असुरक्षित JAR/WAR फ़ाइलों और JDK संस्करण जाँच के लिए हैं।
https://github.com/NCSC-NL/spring4shell/blob/main/software/README.md
CVE-2022-22965 के लिए कमज़ोर होने की शर्तें:
नीचे दिए गए Powershell और bash स्क्रिप्ट देखें।
Hilko Bengen ने एक स्कैनर प्रकाशित किया है जो यहाँ दिए गए संस्करणों के आधार पर CachedIntrospectionResults.class के कमज़ोर संस्करणों की खोज करता है: https://github.com/hillu/local-spring-vuln-scanner
यह जानने के लिए निम्नलिखित चलाएँ:
java -version
संबंधित सिस्टम पर। ध्यान दें कि java एप्लिकेशन कई अलग-अलग तरीकों से चल सकते हैं, और एक साथ कई अलग-अलग संस्करण स्थापित हो सकते हैं। यह सुनिश्चित करने के लिए कि कौन सा java संस्करण चल रहा है, पहले पहचानें कि java बाइनरी फ़ाइल कहाँ से चल रही है, और फिर उस java बाइनरी फ़ाइल का संस्करण देखें।
Linux में यह निम्नलिखित चलाकर किया जा सकता है:
ps aux | grep java
जहाँ आप उदाहरण के लिए /usr/lib/jvm/java-11-openjdk-amd64/bin/java पाते हैं, और फिर पूर्ण फ़ाइल पथ का उपयोग करके निम्नलिखित कमांड चला सकते हैं:
$ /usr/lib/jvm/java-11-openjdk-amd64/bin/java -version
openjdk version "11.0.14.1" 2022-02-08
OpenJDK Runtime Environment (build 11.0.14.1+1-Ubuntu-0ubuntu1.18.04)
OpenJDK 64-Bit Server VM (build 11.0.14.1+1-Ubuntu-0ubuntu1.18.04, mixed mode, sharing)
इसी प्रकार Windows में, चल रही java प्रक्रियाओं के लिए पूर्ण फ़ाइल पथ या तो WMI या Powershell का उपयोग करके पाया जा सकता है:
WMI: C:\> wmic process where "name='java.exe'" get ExecutablePath
PowerShell: PS C:\> Get-Process java | Select-Object Path
JFrog ने Python कोड प्रकाशित किया है जो इसके उपयोग की पहचान करता है, और इसे सीधे संकलित Java प्रोग्रामों पर उपयोग किया जा सकता है ताकि .jar/.war फ़ाइलों को निकालने की आवश्यकता न हो: https://github.com/jfrog/jfrog-spring-tools
जहाँ तक सिस्टम पर Spring Framework की पहचान का सवाल है, यह इस बात पर निर्भर करता है कि कौन सा ऑपरेटिंग सिस्टम चल रहा है:
संभावित रूप से कमज़ोर एप्लिकेशन खोजने के लिए निम्नलिखित Powershell स्क्रिप्ट, यानी वे एप्लिकेशन जो Spring Framework का उपयोग करते हैं या उस पर आधारित हैं। ध्यान दें कि ये स्क्रिप्ट अद्यतन संस्करणों और गैर-अद्यतन संस्करणों के बीच अंतर नहीं करेंगी, लेकिन वे उन सिस्टमों की पहचान करेंगी जिनमें वर्तमान में कमज़ोरी होने की संभावना है (ऊपर बिंदु 1 देखें)।
सिस्टम पर *.war फ़ाइलों में spring-beans*.jar और cachedintrospectionresults.class खोजें:
$SearchName = "*.war"
$Drives = Get-WmiObject Win32_LogicalDisk -Filter 'DriveType=3' | Select -ExpandProperty DeviceID
#$Drives = Get-CimInstance Win32_LogicalDisk -Filter 'DriveType=3' | Select-Object -ExpandProperty DeviceID
#powershell version 6
$Vulnerable = $false
$entries = @()
$hits = @()
$search1 = "spring-beans*.jar"
$search2 = "cachedintrospectionresults.class"
Foreach ($drive in $drives) {
$SearchDir = "$drive\"
$wars= (&cmd /c pushd $searchDir `& robocopy /l "$searchDir" null "$searchName" /ns /njh /njs /np /nc /ndl /xjd /mt /s) -replace '^\s+|\s+$'
Foreach ($war in $wars){
If($war) {
#$war
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem
$entries = ([System.IO.Compression.ZipArchive](https://github.com/helsecert/cve-2022-22965/blob/main/%5BSystem.IO.Compression.ZipFile%5D%3A%3AOpenRead%28%24war))).Entries
foreach ($entry in $entries){
if ($entry.Name -like $search1) {
"$($war)\$($entry.FullName)"
$hits = $hits +1
}
if ($entry.Name -like $search2) {
"$($war)\$($entry.FullName)"
$hits = $hits +1
}
}
}
}
}
If ($hits){ "Vulnerable" }
Else { "Compliant" }
इसके अलावा, सभी .jar फ़ाइलों में cachedintrospectionresults.class की खोज करना उपयोगी है, और हम जानते हैं कि यह क्लास हमेशा spring-beans*.jar में नहीं होती है।
$SearchName = "*.jar"
$Drives = Get-WmiObject Win32_LogicalDisk -Filter 'DriveType=3' | Select -ExpandProperty DeviceID
#$Drives = Get-CimInstance Win32_LogicalDisk -Filter 'DriveType=3' | Select-Object -ExpandProperty DeviceID
#powershell version 6
$Vulnerable = $false
$entries = @()
$hits = @()
$search1 = "cachedintrospectionresults.class"
Foreach ($drive in $drives) {
$SearchDir = "$drive\"
$wars= (&cmd /c pushd $searchDir `& robocopy /l "$searchDir" null "$searchName" /ns /njh /njs /np /nc /ndl /xjd /mt /s) -replace '^\s+|\s+$'
Foreach ($war in $wars){
If($war) {
#$war
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem
$entries = ([System.IO.Compression.ZipArchive](https://github.com/helsecert/cve-2022-22965/blob/main/%5BSystem.IO.Compression.ZipFile%5D%3A%3AOpenRead%28%24war))).Entries
foreach ($entry in $entries){
if ($entry.Name -like $search1) {
"$($war)\$($entry.FullName)"
$hits = $hits +1
}
}
}
}
}
If ($hits){ "Vulnerable" }
Else { "Compliant" }
Linux पर खोजने के लिए, डिस्क पर सभी .jar और .war फ़ाइलों में cachedintrospectionresults.class क्लास को देखें, साथ ही *.war फ़ाइलों में spring-beans*.jar को देखें:
find / -name '*.jar' -exec grep -Fi 'cachedintrospectionresults.class' {} \;
find / -name '*.war' -exec grep -Ei 'cachedintrospectionresults\.class|spring-beans.*\.jar' {} \;
और .war फ़ाइलों के अंदर स्थित .jar फ़ाइलों में भी उसी क्लास नाम की खोज करें:
#!/bin/bash
find / -name '*.war' -print0 2>/dev/null -print0 | while read -d $'\0' spring; do
echo -en "${spring}: "$(unzip -p "${spring}" '*.jar' | strings | grep -Fi 'cachedintrospectionresults.class' | awk '{ print $NF }')"\n"
done
exit 0