SHADOWOPS

Kaseya Endpoint Exploitation Detection.ps1

Jul 6th, 2021
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Clear-Host
  2. Write-Host "Checking For Suspicious Certificates..."
  3. $RegPath = Join-Path -Path $SoftwareKey -ChildPath 'Kaseya\Agent\*'
  4. Write-Host "==== Kaseya Endpoint Detection Tool v3 ===="
  5. $SoftwareKey = 'HKLM:\Software'
  6. if ([Environment]::Is64BitOperatingSystem)
  7. { $SoftwareKey = 'HKLM:\Software\WOW6432Node' }
  8. $var = 0
  9. [string[]]$FoundAgentPaths = Get-ItemProperty -Path $RegPath | Select-Object -ExpandProperty TempPath
  10.  
  11. foreach($Path in $FoundAgentPaths)
  12. {
  13.     $SuspiciousFile = Get-Childitem –Path $Path -Recurse -ErrorAction SilentlyContinue |  Where-Object { $_.Name -eq [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String("YWdlbnQuY3J0")) }
  14.     if ($null -ne $SuspiciousFile)
  15.     {
  16.         Write-Host "FAIL: Suspicious Certificate Found" -ForegroundColor Red
  17.         $var = 1
  18.     }
  19.     else
  20.     {
  21.         Write-Host "PASS: Suspicious Certificate Not Found" -ForegroundColor Green
  22.     }
  23. }
  24.  
  25. Write-Host "Checking For Suspicious Executables..."
  26. foreach($Path in $FoundAgentPaths)
  27. {
  28.     $SuspiciousFile = Get-Childitem –Path $Path -Recurse -ErrorAction SilentlyContinue |  Where-Object { $_.Name -eq [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String("YWdlbnQuZXhl")) }
  29.     if ($null -ne $SuspiciousFile)
  30.     {
  31.         #Avoid false-positive
  32.         if ((Get-FileHash -Path $($SuspiciousFile.FullName) -Algorithm MD5 | Select-Object -ExpandProperty Hash) -ine '10ec4c5b19b88a5e1b7bf1e3a9b43c12')
  33.         {
  34.             Write-Host "FAIL: Suspicious Executable Found" -ForegroundColor Red
  35.             $var = 1
  36.         } else {
  37.             Write-Host "PASS: Huntress Executable Not Found" -ForegroundColor Green
  38.         }
  39.     }
  40.     else
  41.     {
  42.         Write-Host "PASS: Suspicious Executable Not Found" -ForegroundColor Green
  43.     }
  44. }
  45.  
  46. Write-Host "Checking For Suspicious Executables..."
  47. foreach($Path in $FoundAgentPaths)
  48. {
  49.     $SuspiciousFile = Get-Childitem –Path $Path -Recurse -ErrorAction SilentlyContinue |  Where-Object { $_.Name -eq [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String("YWdlbnQuZXhl")) }
  50.     if ($null -ne $SuspiciousFile)
  51.     {
  52.         #Avoid false-positive
  53.         if ((Get-FileHash -Path $($SuspiciousFile.FullName) -Algorithm MD5 | Select-Object -ExpandProperty Hash) -ine '10ec4c5b19b88a5e1b7bf1e3a9b43c12')
  54.         {
  55.             Write-Host "FAIL: Suspicious Executable Found" -ForegroundColor Red
  56.             $var = 1
  57.         } else {
  58.             Write-Host "PASS: Huntress Executable Not Found" -ForegroundColor Green
  59.         }
  60.     }
  61.     else
  62.     {
  63.         Write-Host "PASS: Suspicious Executable Not Found" -ForegroundColor Green
  64.     }
  65. }
  66.  
  67. Write-Host "Searching For Evidence of Encryption..."
  68. $encryption = 0
  69.  
  70. [datetime]$StartFrom = "07/02/2021 00:01 AM"
  71. [string] $SearchString = "Your files are encrypted, and currently unavailable"
  72.  
  73. if($null -eq $FoundAgentPaths) {
  74.     $SearchPaths = Get-WmiObject –query "SELECT * from win32_logicaldisk where DriveType = '3'" | Select-Object -ExpandProperty DeviceID | ForEach-Object {Write-Output "$_\"}
  75. } else {$SearchPaths = $FoundAgentPaths}
  76. foreach($Path in $SearchPaths) {
  77.  
  78.     $Found = Get-ChildItem -Path $Path -Filter *readme.txt -File -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.LastWriteTime -ge $StartFrom} | Select-String $SearchString
  79.     if ($null -ne $Found)
  80.     {
  81.         $encryption = 1
  82.         $var = 3
  83.         break
  84.     }
  85. }
  86.  
  87.  
  88. if ($encryption -eq 1) {
  89.     Write-Host "FAIL: Evidence of Encryption Found" -ForegroundColor Red
  90. } else {
  91.     Write-Host "PASS: Evidence of Encryption Not Detected" -ForegroundColor Green
  92. }
  93.  
  94. Write-Host "Generating Results..."
  95. if ($var -gt 0 )
  96. {
  97.     if ($var -eq 3) {
  98.         Write-Host "RESULT: Scan Indicates Endpoint May Be Encrypted" -ForegroundColor Red
  99.     } else {
  100.         Write-Host "RESULT: Scan Indicates Endpoint May Be Vulnerable" -ForegroundColor Red
  101.     }
  102. }
  103. else
  104. {
  105.     Write-Host "RESULT: Scan Did Not Indicate Endpoint Is Vulnerable" -ForegroundColor Green
  106. }
  107.  
  108. Read-Host -Prompt "Press Enter to exit"
  109.  
Add Comment
Please, Sign In to add comment