-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfairy_law.ps1
More file actions
173 lines (138 loc) · 5.66 KB
/
Copy pathfairy_law.ps1
File metadata and controls
173 lines (138 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
Write-Host "`n=== MicrosoftSignedOnly Check + Auto IFEO Handling + Setting Global Mitigation ===`n"
# ============================================
# Auto-Elevation: Relaunch as Administrator
# ============================================
$IsAdmin = ([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (-not $IsAdmin) {
Write-Host "[!] Script is not running as Administrator. Elevating..."
# Restart PowerShell as Administrator
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = "powershell.exe"
$psi.Arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
$psi.Verb = "runas"
try {
[System.Diagnostics.Process]::Start($psi) | Out-Null
exit
}
catch {
Write-Host "[-] Elevation cancelled or failed."
exit 1
}
}
Write-Host "[+] Running with Administrator privileges."
# ============================================================
# 1) LISTS
# ============================================================
# A) NEVER APPLY IFEO (SKIPPED)
$Exclusions = @(
"specificNames",
"placeholder"
)
# B) ALWAYS APPLY IFEO (FORCED)
$AutoProtect = @(
"chrome",
"otherExecutableNames"
)
Write-Host "ExclusionList: $($Exclusions -join ', ')" -ForegroundColor DarkGray
Write-Host "AutoProtectList: $($AutoProtect -join ', ')" -ForegroundColor DarkGray
# ============================================================
# 2) SIGNATURE CHECK
# ============================================================
function Is-MicrosoftSigned {
param([string]$File)
if (-not (Test-Path $File)) { return $true }
$sig = Get-AuthenticodeSignature -FilePath $File
if ($sig.Status -ne "Valid") { return $false }
$issuer = $sig.SignerCertificate.Issuer
return ($issuer -like "*Microsoft*" -or $issuer -like "*Windows*")
}
# ============================================================
# 3) REGISTRY LOOKUP TABLE
# ============================================================
$uninstall = Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*,
HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* `
-ErrorAction SilentlyContinue
$unsafe = @()
# ============================================================
# 4) MAIN OFFLINE CHECK + IFEO ACTION
# ============================================================
Get-Package | ForEach-Object {
$name = $_.Name
if (-not $name) { return }
# A) Skip items in ExclusionList
if ($Exclusions | Where-Object { $name -like "*$_*" }) {
Write-Host "Skipping excluded program: $name" -ForegroundColor Yellow
return
}
# B) Get install location
$entry = $uninstall |
Where-Object { $_.DisplayName -eq $name -and $_.InstallLocation -and (Test-Path $_.InstallLocation) } |
Select-Object -First 1
if (-not $entry) { return }
$path = $entry.InstallLocation
# C) Select main EXE
$exe = Get-ChildItem -Path $path -Filter *.exe -File -ErrorAction SilentlyContinue |
Select-Object -First 1
if (-not $exe) { return }
# D) Forced IFEO (AutoProtectList)
if ($AutoProtect | Where-Object { $name -like "*$_*" }) {
Write-Host "AutoProtect IFEO enabled for: $name ($($exe.Name))" -ForegroundColor Cyan
Set-ProcessMitigation -Name $exe.Name -Disable MicrosoftSignedOnly 2>$null
return
}
# E) Fast top-level DLL scan (offline)
$dlls = Get-ChildItem -Path $path -Filter *.dll -File -ErrorAction SilentlyContinue
foreach ($dll in $dlls) {
if (-not (Is-MicrosoftSigned $dll.FullName)) {
Write-Host "Adding IFEO exclusion for: $($exe.Name)" -ForegroundColor Cyan
try {
Set-ProcessMitigation -Name $exe.Name -Disable MicrosoftSignedOnly -ErrorAction Stop
} catch {
Write-Warning "Failed to set IFEO for $($exe.Name): $_"
}
$unsafe += [PSCustomObject]@{
Program = $name
MainExe = $exe.Name
InstallPath = $path
FailingDLL = $dll.Name
MicrosoftOnly = "IFEO Disabled"
Status = "Would fail without IFEO"
}
break
}
}
}
# ============================================================
# 5) SHOW RESULTS
# ============================================================
if ($unsafe.Count -eq 0) {
Write-Host "`nAll scanned programs appear compatible with MicrosoftSignedOnly." -ForegroundColor Green
} else {
Write-Host "`nPrograms that WOULD FAIL but have been auto-excluded (IFEO):`n" -ForegroundColor Yellow
$unsafe | Sort-Object Program | Format-Table -AutoSize
}
# ============================================================
# 6) ENABLE SYSTEM-WIDE MITIGATION
# ============================================================
Write-Host "`nEnabling system-wide MicrosoftSignedOnly...`n"
try {
Set-ProcessMitigation -System -Enable MicrosoftSignedOnly
Write-Host "System-wide MicrosoftSignedOnly ENABLED" -ForegroundColor Green
} catch {
Write-Host "SYSTEM mitigation FAILED: $_" -ForegroundColor Red
}
# ============================================================
# 7) REBOOT THE SYSTEM
# ============================================================
for ($i = 10; $i -ge 1; $i--) {
Write-Host "Continuing in $i..."
Start-Sleep -Seconds 1
}
try {
Restart-Computer -Force -Confirm:$false -ErrorAction Stop
}
catch {
Write-Host "[-] Failed to reboot: $($_.Exception.Message)" -ForegroundColor Red
}