-
-
Save jbarcia/f5a4c8b1776a48d6d1a7193cab3a449d to your computer and use it in GitHub Desktop.
Get the hashes of all exe / dll files downloaded from the internet. Checks for the Zone.Identifier ADS and ensures the value is 3.
This file contains 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
function Get-DownloadedPEHashes | |
{ | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$true, Position=0)] | |
[String]$Path, | |
[Switch]$Recursive = $true | |
) | |
if (!$Path.EndsWith('\')) | |
{ | |
$Path += '\*' | |
} else { | |
$Path += '*' | |
} | |
if ($Recursive) | |
{ | |
Get-ChildItem -path $Path -Recurse -Include *.exe, *.dll ` | |
| Where-Object { Get-Item $_.FullName -Stream Zone.Identifier -ErrorAction SilentlyContinue } ` | |
| Where-Object { (Get-Content "$($_.FullName):Zone.Identifier") -like "ZoneId=3" } ` | |
| % { ` | |
if (![String]::IsNullOrEmpty($_.FullName)) ` | |
{ ` | |
Get-FileHash -Path $_.FullName -Algorithm MD5 ` | |
} ` | |
} | |
} else { | |
Get-ChildItem -path $Path -Include *.exe, *.dll ` | |
| Where-Object { Get-Item $_.FullName -Stream Zone.Identifier -ErrorAction SilentlyContinue } ` | |
| Where-Object { (Get-Content "$($_.FullName):Zone.Identifier") -like "ZoneId=3" } ` | |
| % { ` | |
if (![String]::IsNullOrEmpty($_.FullName)) ` | |
{ ` | |
Get-FileHash -Path $_.FullName -Algorithm MD5 ` | |
} ` | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment