
CVE-2023-50164 के लिए Apache Struts2 में पहचान स्क्रिप्ट, जो PowerShell और Bash टूल प्रदान करती है ताकि फ़ाइल सिस्टम और आर्काइव में कमज़ोर संस्करणों को स्कैन किया जा सके।
Powershell 5.1 और उससे नए के लिए। Kjetil Sigvartsen द्वारा लिखित, Norsk helsenett SF में।
[String[]]$Extensions = @('*.jar', '*.war', '*.ear')
[string]$searchString = 'struts2-core'
foreach ($Disk in (Get-CimInstance Win32_LogicalDisk)) {
[string]$DriveLetter = $Disk.DeviceID
[string]$Path = "$($driveLetter)\"
foreach ($ChildItem in (Get-ChildItem -Path $Path -Recurse -Include $Extensions -File -ErrorAction SilentlyContinue)) {
[String]$FilePath = $ChildItem.FullName
$Content = Get-Content -Path $filePath -Raw
if ($Content -like "*$searchString*") {
Write-Output $filePath
} #if
} #foreach
} #foreach
Powershell 5.1 और उससे नए के लिए। Kjetil Sigvartsen द्वारा लिखित, Norsk helsenett SF में।
यह अधिक CPU-गहन हो सकता है, लेकिन ऊपर वाले संस्करण की तुलना में काफी तेज़ होगा। ध्यान दें कि C:\Windows को गति के लिए फ़िल्टर किया गया है।
यदि अधिक विस्तृत आउटपुट चाहिए, तो स्क्रिप्ट के शीर्ष पर निम्नलिखित जोड़ें:
$VerbosePreference = 'Continue'
कोड इस प्रकार है:
[String[]]$Extensions = @('*.jar', '*.war', '*.ear')
[string]$searchString = 'struts2-core'
[string[]]$Exceptions = @('C:\Windows')
foreach ($Disk in (Get-CimInstance Win32_LogicalDisk)) {
[string]$DriveLetter = $Disk.DeviceID
[string]$Path = "$($driveLetter)\"
Write-Verbose -Message "Working on $Path"
try {
[System.IO.DirectoryInfo[]]$Folders = Get-ChildItem -Path $Path -Directory -ErrorAction Stop
} #try
catch {
Write-Verbose -Message "Unable to get child folders in disk $Path"
continue
} #catch
[System.Management.Automation.Job[]]$Jobs = $Null
[System.Management.Automation.Job[]]$Jobs = foreach ($Folder in $Folders) {
[string]$JobName = $Path + $Folder.Name
if ($Exceptions -contains $JobName) {
Write-Verbose -Message "Skipping $JobName, in exception list"
continue
} #if
Write-Verbose -Message "Starting jobs for $JobName"
Start-Job -Name $JobName -ScriptBlock {
Return (Get-ChildItem -Path $Using:JobName -Recurse -Include $Using:Extensions -File -ErrorAction SilentlyContinue)
} #Start-Job
} #Foreach
[System.Object[]]$JobResults = $Null
[System.Object[]]$JobResults = Receive-Job -Job $Jobs -AutoRemoveJob -Wait -ErrorAction Stop
[System.Management.Automation.Job[]]$RemainingJobs = $Null
[System.Management.Automation.Job[]]$RemainingJobs = get-Job -Name "$Path*" -ErrorAction Stop
if ($RemainingJobs) {
Write-Verbose -Message "$($RemainingJobs.count) jobs remaining"
} #if
foreach ($ChildItem in $JobResults) {
[String]$FilePath = $ChildItem.FullName
[string]$Content = Get-Content -Path $filePath -Raw
if ($Content -like "*$searchString*" -or $FilePath -like "*$searchString*") {
Write-Output $filePath
} #if
} #foreach
} #foreach
sudo find / -type f \( -iname "*.jar" -o -iname "*.war" -o -iname "*.ear" \) -exec grep -Fl "struts2-core" {} 2>/dev/null \;
स्क्रिप्ट उन फ़ाइलों को सूचीबद्ध करेंगी जो struts2 कोर लाइब्रेरी हैं या उसमें शामिल हैं। इसके कुछ उदाहरण:
/sti/til/mappe/struts2-core-6.3.0.2.jar - यहां struts2 कोर लाइब्रेरी सीधे फाइलसिस्टम पर स्थित है, और संस्करण 6.3.0.2 है, जहां कमजोरी बंद की गई है।
/sti/til/mappe/apps/struts2-showcase-6.3.0.2.war - यहां struts2 कोर लाइब्रेरी .war फ़ाइल के अंदर स्थित है, जहां यह देखने के लिए सामग्री को सूचीबद्ध किया जाना चाहिए कि Struts2 का कौन सा संस्करण शामिल है:
$ unzip -l /sti/til/mappe/apps/struts2-showcase-6.3.0.2.war | fgrep struts2-core
1519992 2023-12-05 05:58 WEB-INF/lib/struts2-core-6.3.0.2.jar
Powershell 5.1 और उससे नए के लिए। Kjetil Sigvartsen द्वारा लिखित, Norsk helsenett SF में।
[string[]]$ZipFiles = @(
'C:\sti\til\mappe\apps\struts2-showcase-6.3.0.2.war'
)
Add-Type -AssemblyName System.IO.Compression.FileSystem
foreach ($ZipFile in $ZipFiles) {
foreach ($Entry in ([System.IO.Compression.ZipFile]::OpenRead($zipFile).Entries)) {
if ($Entry.FullName -like "*struts2-core*") {
Write-Output $Entry.FullName
} #if
} #foreach
} #foreach