-
Notifications
You must be signed in to change notification settings - Fork 7
/
XPROT.ps1
279 lines (276 loc) · 13.3 KB
/
XPROT.ps1
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<#PSScriptInfo
.VERSION 1.1
.GUID b56395b0-2bbb-4a46-b9b5-aa2862312a9b
.AUTHOR neohiro
.COMPANYNAME FrenzyPenguin Media
.COPYRIGHT (c) 2023 FrenzyPenguin Media. All rights reserved under AGPL-3.0 license.
.TAGS ExploitProtection XPROT Security
.LICENSEURI https://github.com/neohiro/ExploitProtection/blob/M3T4P0D.3XPL01T/LICENSE
.PROJECTURI https://github.com/neohiro/ExploitProtection
.ICONURI https://github.com/neohiro/ExploitProtection/blob/M3T4P0D.3XPL01T/media/icons8-windows-defender-70.ico
.EXTERNALMODULEDEPENDENCIES VisualBasic,Forms
.RELEASENOTES
.DESCRIPTION Windows Exploit Protection Manager
#>
# © 2023 FrenzyPenguin Media
# Update, backup, remove all, import or reboot device for Exploit Protection Settings (best ran with PowerShell ISE)
Requires -RunAsAdministrator
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
clear
Write-Host ""
Write-Host " XProtGUI 1.0"
Write-Host ""
Write-Host " Keep this terminal open & use grey popup window to continue."
Write-Host ""
$date = Get-Date -Format "MMddyyyy"
$dlfolder = "$env:Programfiles"
$dllink = "$dlfolder\XPROTlogo.png"
if (-not(Test-Path -Path $dllink -PathType Leaf)) {
try {
$imglink = "https://raw.githubusercontent.com/neohiro/ExploitProtection/M3T4P0D.3XPL01T/media/Exploitprotectionlogo3.png"
Invoke-WebRequest $imglink -OutFile $dllink;
} Catch {
[System.Windows.Forms.MessageBox]::Show("ERROR: $_.Exception.Message - System","Error");
}
}
# Warn for untested version
# [System.Windows.Forms.MessageBox]::Show("XProt is not yet fully tested. Apologies for any inconvenience at the moment, fellow nerd. Feedback & contributions are welcome!" , "Bèta testing")
# Drawing Main Menu Form
do {
$Form_MainMenu = New-Object System.Windows.Forms.Form -ErrorAction SilentlyContinue
$Form_MainMenu.Text = "WEPS Manager 1.0"
$Form_MainMenu.Size = New-Object System.Drawing.Size (330,635)
$Form_MainMenu.FormBorderStyle = "FixedDialog"
$Form_MainMenu.TopMost = $true
$Form_MainMenu.MaximizeBox = $false
$Form_MainMenu.MinimizeBox = $true
$Form_MainMenu.ControlBox = $true
$Form_MainMenu.StartPosition = "CenterScreen"
$Form_MainMenu.Font = "Segoe UI"
# ADD LOGO
$img = [System.Drawing.Image]::Fromfile($dllink)
$pictureBox = New-Object Windows.Forms.PictureBox -ErrorAction SilentlyContinue
$pictureBox.Location = New-Object System.Drawing.Size (55,0)
$pictureBox.Size = New-Object System.Drawing.Size(250,140)
$pictureBox.Image = $img
$Form_MainMenu.Controls.Add($pictureBox)
# LABEL WITH INFO TEXT on Main Menu Form
$label_MainMenu = New-Object System.Windows.Forms.Label
$label_MainMenu.Location = New-Object System.Drawing.Size (35,147)
$label_MainMenu.Size = New-Object System.Drawing.Size (250,20)
$label_MainMenu.TextAlign = "MiddleCenter"
$label_MainMenu.Text = "Welcome to XPROT"
$Form_MainMenu.Controls.Add($label_MainMenu)
# BOTTOM LABEL WITH INFO TEXT on Form
$label_MainMenu2 = New-Object System.Windows.Forms.Label
$label_MainMenu2.Location = New-Object System.Drawing.Size (32,480)
$label_MainMenu2.Size = New-Object System.Drawing.Size (260,125)
$label_MainMenu2.TextAlign = "MiddleCenter"
$label_MainMenu2.Text = "XploitProtection is an online community held database of protection settings for many popular Windows programs. Update again soon! FrenzyPenguin Media © 2023"
$Form_MainMenu.Controls.Add($label_MainMenu2)
# BUTTONS GROUP
$MyGroupBox1 = New-Object System.Windows.Forms.GroupBox
$MyGroupBox1.Location = '15,168'
$MyGroupBox1.size = '295,255'
# BUTTON 1
$RadioButton1 = New-Object System.Windows.Forms.RadioButton
$RadioButton1.Location = '20,10'
$RadioButton1.size = '240,40'
$RadioButton1.Checked = $false
$RadioButton1.Text = "UPDATE + IMPORT online .XML"
# BUTTON 2
$RadioButton2 = New-Object System.Windows.Forms.RadioButton
$RadioButton2.Location = '20,50'
$RadioButton2.size = '240,40'
$RadioButton2.Checked = $false
$RadioButton2.Text = "BACKUP current settings"
# BUTTON 3
$RadioButton3 = New-Object System.Windows.Forms.RadioButton
$RadioButton3.Location = '20,90'
$RadioButton3.size = '240,40'
$RadioButton3.Checked = $false
$RadioButton3.Text = "REMOVE ALL protection settings"
# BUTTON 4
$RadioButton4 = New-Object System.Windows.Forms.RadioButton
$RadioButton4.Location = '20,130'
$RadioButton4.size = '240,40'
$RadioButton4.Checked = $false
$RadioButton4.Text = "IMPORT local .XML settings file"
# BUTTON 5
$RadioButton5 = New-Object System.Windows.Forms.RadioButton
$RadioButton5.Location = '20,170'
$RadioButton5.size = '240,40'
$RadioButton5.Checked = $false
$RadioButton5.Text = "REBOOT to activate changes"
# BUTTON 6
$RadioButton6 = New-Object System.Windows.Forms.RadioButton
$RadioButton6.Location = '20,210'
$RadioButton6.size = '240,40'
$RadioButton6.Checked = $false
$RadioButton6.Text = "SUPPORT + software list (Github)"
# OK button
$OKButton = new-object System.Windows.Forms.Button
$OKButton.Location = '28,440'
$OKButton.Size = '100,40'
$OKButton.Text = 'OK'
$OKButton.DialogResult=[System.Windows.Forms.DialogResult]::OK
# EXIT button
$CancelButton = new-object System.Windows.Forms.Button
$CancelButton.Location = '198,440'
$CancelButton.Size = '100,40'
$CancelButton.Text = "Exit"
$CancelButton.DialogResult=[System.Windows.Forms.DialogResult]::Cancel
# Add all the GroupBox controls on one line
$MyGroupBox1.Controls.AddRange(@($Radiobutton1,$RadioButton2,$RadioButton3,$RadioButton4,$RadioButton5,$RadioButton6))
# Add all the Form controls on one line
$Form_MainMenu.Controls.AddRange(@($MyGroupBox1,$OKButton,$CancelButton))
# Assign the Accept and Cancel options in the form to the corresponding buttons
$Form_MainMenu.AcceptButton = $OKButton
$Form_MainMenu.CancelButton = $CancelButton
# Get the results from the button click
$dialogResult = $Form_MainMenu.ShowDialog()
# If the OK/Cancel button is selected, also verify button clicked and perform actions accordingly
if ($dialogResult -eq "OK"){
# Check current state of each radio button and act accordingly
if ($RadioButton1.Checked){
# updating from online .XML
$file_url = "https://raw.githubusercontent.com/neohiro/ExploitProtection/M3T4P0D.3XPL01T/XploitProtection.xml"
$file_path = "$dlfolder\XploitProtection-UPDATE-$date.xml"
Write-Host "Downloading new settings XML & importing." -NoNewline
Invoke-WebRequest -Uri $file_url -OutFile $file_path
if (Test-Path $file_path) {
if ((Set-ProcessMitigation -PolicyFilePath $file_path -IsValid) -eq "Is Valid XML: True") {
Set-ProcessMitigation -PolicyFilePath $file_path
[System.Windows.Forms.MessageBox]::Show("Reboot to finalize protection","Update completed");
} else {
[System.Windows.Forms.MessageBox]::Show("$file_path is not valid","Error");
}
} else {
[System.Windows.Forms.MessageBox]::Show("Could not find downloaded XML","Error");
}
}
elseif ($RadioButton2.Checked){
# POPUP to request filename & location
$title = 'BACKUP EXPLOIT PROTECTION SETTINGS'
$msg = 'Choose filename for backup:'
$name = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
$dialog = New-Object System.Windows.Forms.FolderBrowserDialog
if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
$directoryName = $dialog.SelectedPath
Write-Host "Directory selected is $directoryName"
}
Get-ProcessMitigation -RegistryConfigFilePath "$directoryName\$name.xml"
[System.Windows.Forms.MessageBox]::Show("Backup saved at $directoryName","Success")
}
elseif ($RadioButton3.Checked){
# Backup current settings
Get-ProcessMitigation -RegistryConfigFilePath "$dlfolder\XPROT-BACKUP-$date.xml"
# Delete ExploitGuard ProcessMitigations for a given key in the registry. If no other settings exist under the specified key,
# the key is deleted as well
function Remove-ProcessMitigations([Object] $Key, [string] $Name) {
Try {
if ($Key.GetValue("MitigationOptions")) {
Write-Host "Removing MitigationOptions for: " $Name
Remove-ItemProperty -Path $Key.PSPath -Name "MitigationOptions" -ErrorAction Stop;
}
if ($Key.GetValue("MitigationAuditOptions")) {
Write-Host "Removing MitigationAuditOptions for: " $Name
Remove-ItemProperty -Path $Key.PSPath -Name "MitigationAuditOptions" -ErrorAction Stop;
}
if ($Key.GetValue("EAFModules")) {
Write-Host "Removing EAFModules for: " $Name
Remove-ItemProperty -Path $Key.PSPath -Name "EAFModules" -ErrorAction Stop;
}
# Remove the FilterFullPath value if there is nothing else
if (($Key.SubKeyCount -eq 0) -and ($Key.ValueCount -eq 1) -and ($Key.GetValue("FilterFullPath"))) {
Remove-ItemProperty -Path $Key.PSPath -Name "FilterFullPath" -ErrorAction Stop;
}
# If the key is empty now, delete it
if (($Key.SubKeyCount -eq 0) -and ($Key.ValueCount -eq 0)) {
Write-Host "Removing empty Entry: " $Name
Remove-Item -Path $Key.PSPath -ErrorAction Stop
}
}
Catch {
[System.Windows.Forms.MessageBox]::Show("ERROR: $-.Exception.Message - at $MitigationItemName","Error");
}
}
# Delete all ExploitGuard ProcessMitigations
function Remove-All-ProcessMitigations {
Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options" | ForEach-Object {
$MitigationItem = $_;
$MitigationItemName = $MitigationItem.PSChildName
Try {
Remove-ProcessMitigations $MitigationItem $MitigationItemName
# "UseFilter" indicate full path filters may be present
if ($MitigationItem.GetValue("UseFilter")) {
Get-ChildItem -Path $MitigationItem.PSPath | ForEach-Object {
$FullPathItem = $_
if ($FullPathItem.GetValue("FilterFullPath")) {
$Name = $MitigationItemName + "-" + $FullPathItem.GetValue("FilterFullPath")
Write-Host "Removing FullPathEntry: " $Name
Remove-ProcessMitigations $FullPathItem $Name
}
# If there are no subkeys now, we can delete the "UseFilter" value
if ($MitigationItem.SubKeyCount -eq 0) {
Remove-ItemProperty -Path $MitigationItem.PSPath -Name "UseFilter" -ErrorAction Stop
}
}
}
if (($MitigationItem.SubKeyCount -eq 0) -and ($MitigationItem.ValueCount -eq 0)) {
Write-Host "Removing empty Entry: " $MitigationItemName
Remove-Item -Path $MitigationItem.PSPath -ErrorAction Stop
}
}
Catch {
[System.Windows.Forms.MessageBox]::Show("ERROR: $-.Exception.Message - at $MitigationItemName","Error");
}}}
# Delete all ExploitGuard System-wide Mitigations
function Remove-All-SystemMitigations {
$Kernel = Get-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\kernel"
Try {
if ($Kernel.GetValue("MitigationOptions"))
{ Write-Host "Removing System MitigationOptions"
Remove-ItemProperty -Path $Kernel.PSPath -Name "MitigationOptions" -ErrorAction Stop;
}
if ($Kernel.GetValue("MitigationAuditOptions"))
{ Write-Host "Removing System MitigationAuditOptions"
Remove-ItemProperty -Path $Kernel.PSPath -Name "MitigationAuditOptions" -ErrorAction Stop;
}
} Catch {
[System.Windows.Forms.MessageBox]::Show("ERROR: $_.Exception.Message - System","Error");
}
}
Remove-All-ProcessMitigations
Remove-All-SystemMitigations
[System.Windows.Forms.MessageBox]::Show("Recovery backup in Program Files folder.","Reboot to remove protection.");
}
elseif ($RadioButton4.Checked){
# IMPORT LOCAL XML
Add-Type -AssemblyName 'System.Windows.Forms'
$fileDialog = New-Object System.Windows.Forms.OpenFileDialog
$fileDialog.CheckPathExists = $true
if ($fileDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
$directoryName = Split-Path $fileDialog.FileName
$fileName = $fileDialog.FileName
}
Set-ProcessMitigation -PolicyFilePath $fileDialog.Filename
[System.Windows.Forms.MessageBox]::Show("Import completed from $fileName","Reboot to update.");
}
elseif ($RadioButton5.Checked){
$result = [System.Windows.Forms.MessageBox]::Show("Restart computer now?","Reboot",[System.Windows.Forms.MessageBoxButtons]::YesNo,[System.Windows.Forms.MessageBoxIcon]::Question);
If ($result -eq "Yes") {
Restart-Computer
}
}
elseif ($RadioButton6.Checked){
Start-Process "https://github.com/neohiro/ExploitProtection"
}
else {
[System.Windows.Forms.MessageBox]::Show("Please choose first." , "Error");
}
}
} while ($dialogResult -ne "Cancel")
exit