Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ps1 file to parse Shodan exports for HikVision 3.1.3.150324 Exploit | See https://github.com/tamim1089/HikvisionExploiter/
- # ----------------------------
- # 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
- # to targets.txt
- # ----------------------------
- # 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
- # from the targets.txt and put into duplicate_targets.txt with line numbers.
- #----------------------------
- # | Coded by ./ d0ts1ash ./ |
- #----------------------------
- Write-Host "CVE-2021-36260/150324 Parser 1.0 has run successfully! Created by ./ d0ts1ash ./" -ForegroundColor Green
- function Extract-Pairs {
- param ($obj)
- $results = @()
- if ($obj -is [pscustomobject]) {
- if ($obj.psobject.Properties.Name -contains "port" -and $obj.psobject.Properties.Name -contains "ip_str") {
- $results += "$($obj.ip_str):$($obj.port)"
- }
- foreach ($prop in $obj.psobject.Properties) {
- $results += Extract-Pairs $prop.Value
- }
- } elseif ($obj -is [array]) {
- foreach ($item in $obj) {
- $results += Extract-Pairs $item
- }
- }
- return $results
- }
- $jsonFiles = Get-ChildItem -Path . -Filter *.json
- $outputFile = "targets.txt"
- $existingPairs = @()
- if (Test-Path $outputFile) {
- $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]"
- if ($choice.ToUpper() -eq 'C') {
- Clear-Content $outputFile
- } else {
- $existingPairs = Get-Content $outputFile
- }
- }
- $newPairs = @()
- $fileCount = $jsonFiles.Count
- $currentFile = 0
- foreach ($file in $jsonFiles) {
- $currentFile++
- $percent = [math]::Round(($currentFile / $fileCount) * 100, 2)
- Write-Host "Processing file $currentFile of $fileCount ($percent%) - $($file.Name)"
- $content = Get-Content $file.FullName -Raw
- try {
- $data = ConvertFrom-Json -InputObject $content -ErrorAction Stop
- $pairs = Extract-Pairs $data
- } catch {
- $pairs = @()
- $lines = $content -split "\r?\n"
- $lineCount = $lines.Count
- $currentLine = 0
- foreach ($line in $lines) {
- $currentLine++
- if (($currentLine % 100) -eq 0 -or $currentLine -eq $lineCount) {
- $linePercent = [math]::Round(($currentLine / $lineCount) * 100, 2)
- Write-Host " Processing line $currentLine of $lineCount ($linePercent%) in $($file.Name)"
- }
- if ($line.Trim() -eq '') { continue }
- try {
- $item = ConvertFrom-Json -InputObject $line -ErrorAction Stop
- $pairs += Extract-Pairs $item
- } catch {
- $matches = [regex]::Matches($line, '"port":\s*(\d+).*?"ip_str":\s*"([\d.]+)"')
- foreach ($match in $matches) {
- $port = $match.Groups[1].Value
- $ip = $match.Groups[2].Value
- $pairs += "${ip}:${port}"
- }
- }
- }
- }
- $newPairs += $pairs
- }
- $allPairs = $existingPairs + $newPairs
- $occ = @{}
- $lines = @{}
- for ($i = 0; $i -lt $allPairs.Count; $i++) {
- $pair = $allPairs[$i]
- if (-not $occ.ContainsKey($pair)) {
- $occ[$pair] = 0
- $lines[$pair] = @()
- }
- $occ[$pair]++
- $lines[$pair] += ($i + 1)
- }
- $uniquePairs = @()
- $duplicateEntries = @()
- foreach ($pair in $allPairs) {
- if ($occ[$pair] -eq 1) {
- $uniquePairs += $pair
- }
- }
- foreach ($key in $occ.Keys) {
- if ($occ[$key] -gt 1) {
- $duplicateEntries += "${key} DUPLICATES FOUND ON LINE(S): $($lines[$key] -join ', ')"
- }
- }
- $uniquePairs | Set-Content -Path $outputFile
- if ($duplicateEntries.Count -gt 0) {
- $duplicateFile = "duplicate_targets.txt"
- $duplicateEntries | Set-Content -Path $duplicateFile
- Write-Host "WARNING: DUPLICATE IP'S WERE FOUND AND REMOVED FROM $outputFile !! Check duplicate_targets.txt for details." -ForegroundColor Yellow
- }
Advertisement
Add Comment
Please, Sign In to add comment