VividDawn24

CVE-2021-36260/150324 Parser 1.0

Sep 1st, 2025
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 4.10 KB | Cybersecurity | 0 0
  1. # ps1 file to parse Shodan exports for HikVision 3.1.3.150324 Exploit | See https://github.com/tamim1089/HikvisionExploiter/
  2. # ----------------------------
  3. # Make folder with your shodan json file export(s) for dork 3.1.3.150324 and this ps script. It'll parse the json and output
  4. # to targets.txt
  5. # ----------------------------
  6. # If the file doesn't exist it creates it, if it does exist it gives you the option to append or clear it. Duplicates are removed
  7. # from the targets.txt and put into duplicate_targets.txt with line numbers.
  8. #----------------------------
  9. # | Coded by ./ d0ts1ash ./ |
  10. #----------------------------
  11. Write-Host "CVE-2021-36260/150324 Parser 1.0 has run successfully! Created by ./ d0ts1ash ./" -ForegroundColor Green
  12. function Extract-Pairs {
  13.     param ($obj)
  14.     $results = @()
  15.     if ($obj -is [pscustomobject]) {
  16.         if ($obj.psobject.Properties.Name -contains "port" -and $obj.psobject.Properties.Name -contains "ip_str") {
  17.             $results += "$($obj.ip_str):$($obj.port)"
  18.         }
  19.         foreach ($prop in $obj.psobject.Properties) {
  20.             $results += Extract-Pairs $prop.Value
  21.         }
  22.     } elseif ($obj -is [array]) {
  23.         foreach ($item in $obj) {
  24.             $results += Extract-Pairs $item
  25.         }
  26.     }
  27.     return $results
  28. }
  29. $jsonFiles = Get-ChildItem -Path . -Filter *.json
  30. $outputFile = "targets.txt"
  31. $existingPairs = @()
  32. if (Test-Path $outputFile) {
  33.     $choice = Read-Host "A targets.txt file exists in this directory. Do you want to (A)ppend to that file or (C)lear it? [A/C]"
  34.     if ($choice.ToUpper() -eq 'C') {
  35.         Clear-Content $outputFile
  36.     } else {
  37.         $existingPairs = Get-Content $outputFile
  38.     }
  39. }
  40. $newPairs = @()
  41. $fileCount = $jsonFiles.Count
  42. $currentFile = 0
  43. foreach ($file in $jsonFiles) {
  44.     $currentFile++
  45.     $percent = [math]::Round(($currentFile / $fileCount) * 100, 2)
  46.     Write-Host "Processing file $currentFile of $fileCount ($percent%) - $($file.Name)"
  47.     $content = Get-Content $file.FullName -Raw
  48.     try {
  49.         $data = ConvertFrom-Json -InputObject $content -ErrorAction Stop
  50.         $pairs = Extract-Pairs $data
  51.     } catch {
  52.         $pairs = @()
  53.         $lines = $content -split "\r?\n"
  54.         $lineCount = $lines.Count
  55.         $currentLine = 0
  56.         foreach ($line in $lines) {
  57.             $currentLine++
  58.             if (($currentLine % 100) -eq 0 -or $currentLine -eq $lineCount) {
  59.                 $linePercent = [math]::Round(($currentLine / $lineCount) * 100, 2)
  60.                 Write-Host "  Processing line $currentLine of $lineCount ($linePercent%) in $($file.Name)"
  61.             }
  62.             if ($line.Trim() -eq '') { continue }
  63.             try {
  64.                 $item = ConvertFrom-Json -InputObject $line -ErrorAction Stop
  65.                 $pairs += Extract-Pairs $item
  66.             } catch {
  67.                 $matches = [regex]::Matches($line, '"port":\s*(\d+).*?"ip_str":\s*"([\d.]+)"')
  68.                 foreach ($match in $matches) {
  69.                     $port = $match.Groups[1].Value
  70.                     $ip = $match.Groups[2].Value
  71.                     $pairs += "${ip}:${port}"
  72.                 }
  73.             }
  74.         }
  75.     }
  76.     $newPairs += $pairs
  77. }
  78. $allPairs = $existingPairs + $newPairs
  79. $occ = @{}
  80. $lines = @{}
  81. for ($i = 0; $i -lt $allPairs.Count; $i++) {
  82.     $pair = $allPairs[$i]
  83.     if (-not $occ.ContainsKey($pair)) {
  84.         $occ[$pair] = 0
  85.         $lines[$pair] = @()
  86.     }
  87.     $occ[$pair]++
  88.     $lines[$pair] += ($i + 1)
  89. }
  90. $uniquePairs = @()
  91. $duplicateEntries = @()
  92. foreach ($pair in $allPairs) {
  93.     if ($occ[$pair] -eq 1) {
  94.         $uniquePairs += $pair
  95.     }
  96. }
  97. foreach ($key in $occ.Keys) {
  98.     if ($occ[$key] -gt 1) {
  99.         $duplicateEntries += "${key} DUPLICATES FOUND ON LINE(S): $($lines[$key] -join ', ')"
  100.     }
  101. }
  102. $uniquePairs | Set-Content -Path $outputFile
  103. if ($duplicateEntries.Count -gt 0) {
  104.     $duplicateFile = "duplicate_targets.txt"
  105.     $duplicateEntries | Set-Content -Path $duplicateFile
  106.     Write-Host "WARNING: DUPLICATE IP'S WERE FOUND AND REMOVED FROM $outputFile !! Check duplicate_targets.txt for details." -ForegroundColor Yellow
  107. }
Advertisement
Add Comment
Please, Sign In to add comment