-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHivestormScript.ps1
More file actions
277 lines (243 loc) · 10.7 KB
/
HivestormScript.ps1
File metadata and controls
277 lines (243 loc) · 10.7 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
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
#2024 Hivestorm Competition Windows Script - Annotated
# Define the array at a global scope
$failedProcesses = New-Object -TypeName System.Collections.ArrayList
$successfulProcesses = New-Object -TypeName System.Collections.ArrayList
# Error handling wrapper function to ensure continued execution
function Try-Execute {
param (
[string]$ProcessName,
[scriptblock]$CodeBlock
)
try {
& $CodeBlock
Write-Host " "
Write-Host "Completed - ${ProcessName}" -ForegroundColor Green
$successfulProcesses.Add("$ProcessName")
}
catch {
$failedProcesses.Add("$ProcessName")
Write-Host "Failed - ${ProcessName}: $($_.Exception.Message)" -ForegroundColor Red
}
}
#Function to clear the processes lists
function Clear-Lists {
$failedProcesses.Clear()
$successfulProcesses.Clear()
}
# Function to report process status
function Report-Process-Status {
if ($failedProcesses -ne 0){
foreach($process in $failedProcesses){
Write-Host "Failed - $process" -ForegroundColor Red
}
}
foreach($process in $successfulProcesses){
Write-Host "Success - $process" -ForegroundColor Green
}
}
# Function to provide the Task Summary
function Task-Summary {
param (
$multipleProcesses
)
Write-Host "==============================="
Write-Host " Task Summary "
Write-Host "==============================="
if ($multipleProcesses -eq $true){
if ($failedProcesses.Count -eq 0){
Report-Process-Status
Write-Host "All processes completed successfully." -ForegroundColor Green
}
else{
$failedCount = $failedProcesses.Count
Report-Process-Status
Write-Host "${failedCount} processes failed." -ForegroundColor Red
}
}
else{
Report-Process-Status
}
Write-Host "==============================="
Clear-Lists
}
# Function to configure secure audit policies
function Set-AuditPolicies {
Write-Host "Configuring secure audit policies..."
# Set all audit policies for success and failure
$auditSettings = @(
"auditpol /set /category:'Account Logon' /success:enable /failure:enable",
"auditpol /set /category:'Account Management' /success:enable /failure:enable",
"auditpol /set /category:'DS Access' /success:enable /failure:enable",
"auditpol /set /category:'Logon/Logoff' /success:enable /failure:enable",
"auditpol /set /category:'System' /success:enable /failure:enable",
"auditpol /set /category:'Object Access' /success:enable /failure:enable",
"auditpol /set /category:'Policy Change' /success:enable /failure:enable",
"auditpol /set /category:'Privilege Use' /success:enable /failure:enable",
"auditpol /set /category:'Detailed Tracking' /success:enable /failure:enable"
)
foreach ($policy in $auditSettings) {
Invoke-Expression $policy
}
Write-Host "Audit policies configured successfully."
}
# Function to set Account security and password settings
function Set-AccountPolicies {
Write-Host "Configuring account policies..."
# Define the path to the security template
$templatePath = "C:\HivestormTemplate.inf"
# Check if the template file exists
if (Test-Path $templatePath) {
Write-Host "Applying security template..." -ForegroundColor Cyan
# Apply the security template using Secedit
secedit /configure /db secedit.sdb /cfg $templatePath /verbose
# Check if the security template was applied successfully
if ($?) {
Write-Host "Security template applied successfully." -ForegroundColor Green
} else {
Write-Host "Failed to apply the security template." -ForegroundColor Red
}
}
else {
Write-Host "Security template file not found. Please verify the path." -ForegroundColor Red
}
}
# Function to locate and confirm removal of media files
function Remove-MediaFiles {
Write-Host "Searching for media files in the C:\Users folder..."
# Define the path to the Users directory
$userFolder = "C:\Users"
# Define file extensions for media types to be removed
$mediaExtensions = @('*.mp3', '*.mp4', '*.wav', '*.jpg', '*.jpeg', '*.png', '*.gif', '*.bmp', '*.avi', '*.mov', '*.wmv', '*.mkv', '*.jfif', '*.txt', '*.csv')
# Initialize an array to store found media files
$mediaFiles = @()
# Search for media files in the Users folder and its subdirectories
foreach ($extension in $mediaExtensions) {
$mediaFiles += Get-ChildItem -Path $userFolder -Recurse -Filter $extension -ErrorAction SilentlyContinue
}
# Filter media files to ensure they are within the C:\Users path
$mediaFiles = $mediaFiles | Where-Object { $_.FullName -like "$userFolder\*" }
# Check if any media files were found
if ($mediaFiles.Count -eq 0) {
Write-Host "No media files found in the Users folder." -ForegroundColor Yellow
return
}
# List found media files and ask for confirmation before removal
Write-Host "Found the following media files in C:\Users:"
foreach ($file in $mediaFiles) {
Write-Host "$($file.FullName)"
}
# Confirm removal with the user
try {
foreach ($file in $mediaFiles) {
# Double-check that each file path still matches the intended Users directory
if ($file.FullName.StartsWith("$userFolder\", [System.StringComparison]::InvariantCultureIgnoreCase)) {
if($file.Name.StartsWith("Forensics", [System.StringComparison]::InvariantCultureIgnoreCase)){
Write-Host "Skipped: $($file.FullName)" -ForegroundColor Yellow
}
else{
Remove-Item -Path $file.FullName -Force -Confirm
Write-Host "Removed: $($file.FullName)" -ForegroundColor Green
}
}
}
}
catch {
Write-Host "Failed - An error occurred while removing media files: $($_.Exception.Message)" -ForegroundColor Red
}
}
# Function to disable insecure services
function Disable-InsecureServices {
Write-Host "Disabling insecure and unnecessary services..."
# List of services to disable, including new services requested
$servicesToDisable = @(
"RemoteRegistry", # Allows remote access to the registry, disable to prevent remote tampering.
"SSDPDiscovery", # SSDP discovery, unnecessary and can be used for information gathering.
"Telnet", # Insecure remote login protocol, replaced by SSH.
"UPnPHost", # UPnP protocol can be used in network attacks.
"Fax", # Typically unnecessary and can be a security risk.
"XblGameSave", # Xbox Live game save service, not required.
"XboxGipSvc", # Xbox accessory management, not needed for most environments.
"RemoteDesktopServices", # Remote desktop, insecure access protocol unless configured securely.
"FTPSVC", # FTP service, not secure and should be disabled unless necessary.
"W3SVC", # Web Services, often unused in competitions.
"IISADMIN" # IIS admin service, associated with web hosting.
)
foreach ($service in $servicesToDisable) {
try {
Stop-Service -Name"$service" -Force -ErrorAction SilentlyContinue
Set-Service -Name "$service" -Status Stopped -StartupType Disabled -ErrorAction Stop
Write-Host "Disabled - ${service}" -ForegroundColor Green
}
catch [System.InvalidOperationException] {
Write-Host "Unsuccessful - The service ${service} was not found" -ForegroundColor Yellow
}
catch {
Write-Host "Failed - Could not disable ${service}: $($_.Exception.Message)" -ForegroundColor Red
}
}
Write-Host "Insecure services configuration completed."
}
# Function to show the user menu
function Show-Menu {
Clear-Host
Write-Host "Welcome to my HiveStorm 2024 Windows Script. This script is currently under testing the following categories are still untested on an official practice image: 1-5. Please use caution when using these functions."
Write-Host " "
Write-Host "==============================="
Write-Host " Princeps' Security Menu "
Write-Host "==============================="
Write-Host "1. Configure Audit Policies"
Write-Host "2. Configure Account Policies"
Write-Host "3. Locate and Remove Media Files"
Write-Host "4. Disable Insecure Services"
Write-Host "5. Run All Security Functions"
Write-Host "0. Exit"
Write-Host "==============================="
}
# Function to run the menu with user selection
function Run-Menu {
do {
Show-Menu
$choice = Read-Host "Select an option (0-5)"
switch ($choice) {
"1" {
Try-Execute -ProcessName "Configure Audit Policies" -CodeBlock { Set-AuditPolicies }
Task-Summary -multipleProcesses $false
Read-Host "Press Enter to return to the menu"
}
"2" {
Try-Execute -ProcessName "Configure Account Policies" -CodeBlock { Set-AccountPolicies }
Task-Summary -multipleProcesses $false
Read-Host "Press Enter to return to the menu"
}
"3" {
Try-Execute -ProcessName "Locate and Remove Media Files" -CodeBlock { Remove-MediaFiles }
Task-Summary -multipleProcesses $false
Read-Host "Press Enter to return to the menu"
}
"4" {
Try-Execute -ProcessName "Disable Insecure Services" -CodeBlock { Disable-InsecureServices }
Task-Summary -multipleProcesses $false
Read-Host "Press Enter to return to the menu"
}
"5" {
Try-Execute -ProcessName "Configure Audit Policies" -CodeBlock { Set-AuditPolicies }
Try-Execute -ProcessName "Configure Account Policies" -CodeBlock { Set-AccountPolicies }
Try-Execute -ProcessName "Locate and Remove Media Files" -CodeBlock { Remove-MediaFiles }
Try-Execute -ProcessName "Disable Insecure Services" -CodeBlock { Disable-InsecureServices }
Task-Summary -multipleProcesses $true
Write-Host "All security functions have been executed."
Read-Host "Press Enter to return to the menu..."
}
"0" {
Write-Host "Exiting the script. Goodbye!"
}
default {
Write-Host "Invalid option. Please select a number between 0 and 5."
Read-Host "Press Enter to return to the menu"
}
}
}
while ($choice -ne "0")
}
# Execute the menu function to allow user selection
Run-Menu