Skip to content

Instantly share code, notes, and snippets.

@andreafortuna
Created June 28, 2017 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreafortuna/058011001874c9c19df6fda26a3ccf1f to your computer and use it in GitHub Desktop.
Save andreafortuna/058011001874c9c19df6fda26a3ccf1f to your computer and use it in GitHub Desktop.
Local vaccine for #Petya / #NotPetya
$extensions = "", ".dat", ".dll"
$baseFileName = "C:\windows\perfc"
foreach ($extension in $extensions)
{
$outFile = "{0}{1}" -f $baseFileName, $extension
Write-Host ("Creating file: {0}" -f $baseFileName)
New-Item $outFile -ItemType file -Value "Road block for Petya." -Force
$ACL = Get-ACL $outFile
$ACL.SetAccessRuleProtection($True, $False) # Remove inheritance.
$ACL.Access | % { $acl.RemoveAccessRule($_) } # Remove explicit ACL's.
$roRule = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Administrators", "Read", "Allow") # Administrators read-only.
$ACL.AddAccessRule($roRule)
Write-Host "Applying read-only ACL..."
Set-ACL $outFile $ACL | Out-Null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment