Last active
January 8, 2023 01:40
-
-
Save curi0usJack/fedb4531820a565b6044df65f1a0fb2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $exepath = "c:\windows" | |
| $searchstrings = @("url", "uri") | |
| $skip = @("logoff.exe", "mcrmgr.exe", "audit.exe") | |
| Function Execute-Command ($commandPath, $commandArguments) | |
| { | |
| $pinfo = New-Object System.Diagnostics.ProcessStartInfo | |
| $pinfo.FileName = $commandPath | |
| $pinfo.RedirectStandardError = $true | |
| $pinfo.RedirectStandardOutput = $true | |
| $pinfo.UseShellExecute = $false | |
| $pinfo.Arguments = $commandArguments | |
| $p = New-Object System.Diagnostics.Process | |
| $p.StartInfo = $pinfo | |
| try { | |
| $p.Start() | Out-Null | |
| $p.WaitForExit(2000) | Out-Null | |
| if ($p.HasExited -eq $false) {$p.Kill()} | |
| } | |
| catch { | |
| $retstdout = "" | |
| } | |
| if ($p.StandardOutput) { | |
| $retstdout = $p.StandardOutput.ReadToEnd() | |
| } else {$retstdout = ""} | |
| $p.Dispose() | |
| [pscustomobject]@{ | |
| stdout = $retstdout | |
| #stderr = $p.StandardError.ReadToEnd() | |
| ExitCode = $p.ExitCode | |
| } | |
| } | |
| $exes = gci -recurse -path $exepath -filter "*.exe" -erroraction silentlycontinue | |
| Write-Output "Searching exes for $searchstrings" | |
| foreach ($exe in $exes) { | |
| $fullpath = $exe.DirectoryName + "\" + $exe.Name | |
| $output = "[-] Testing... $fullpath" | |
| Write-output $output | |
| Add-Content -Path "./exeout.log" -Value $output | |
| if ($skip -notcontains $exe.Name) { | |
| $exeout = Execute-Command $fullpath "/?" | |
| } | |
| if ($exeout.stdout | select-string -pattern $searchstrings -quiet) { | |
| $found = "[+] Found in $fullpath" | |
| Write-Host $found -foreground Green | |
| Add-Content -Path "./exeout.log" -Value $found | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment