-
Notifications
You must be signed in to change notification settings - Fork 611
/
aslr-manager.ps1
23 lines (20 loc) · 1.01 KB
/
aslr-manager.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
param(
[Parameter(Mandatory = $true, HelpMessage="Enable or disable mandatory ASLR for the target executables.")][ValidateSet('Enable', 'Disable')][string]$Action,
[Parameter(mandatory=$true, ValueFromRemainingArguments=$true, HelpMessage="The paths of the target executables.")][string[]]$paths
)
# Define a string array that will hold the target executable paths.
$targets = @()
# Parse the target executable paths.
$paths | ForEach-Object {
if (Test-Path -Path "$_" -PathType Container) {
Get-ChildItem -Path "$_" -Filter *.exe -File | ForEach-Object { $targets += $_.FullName }
}
elseif (Test-Path -Path "$_" -PathType File -Filter *.exe) {
$targets += (Get-ChildItem -Path "$_" -File).FullName
}
else {
throw New-Object ArgumentException("The path `"$_`" provided is not valid!")
}
}
# Configure the security settings for each executable in the targets array.
$targets | ForEach-Object { Invoke-Expression "Set-ProcessMitigation -Name `"$_`" -$Action ForceRelocateImages" }