-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecurityScanner.ps1
More file actions
391 lines (253 loc) · 16 KB
/
SecurityScanner.ps1
File metadata and controls
391 lines (253 loc) · 16 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
#run this powershell as ADMIN account
#install DSinternals from manually from https://github.com/MichaelGrafnetter/DSInternals
Install-Module DSInternals -Force
write -----------------------------------------------------------------------------------------------
write -------------!!!Creating Folders!!!---------------------
write -----------------------------------------------------------------------------------------------
#Create folder for download
$FolderName = "C:\DAS_Tools"
if (Test-Path $FolderName) {
Write-Host "Folder Already Exists"
# Perform Delete file from folder operation
}
else
{
#PowerShell Create directory if not exists
New-Item $FolderName -ItemType Directory
Write-Host "Folder Created successfully"
}
$FolderName = "C:\DAS_Tools\SecurityRisks\"
if (Test-Path $FolderName) {
Write-Host "Folder Already Exists"
# Perform Delete file from folder operation
}
else
{
#PowerShell Create directory if not exists
New-Item $FolderName -ItemType Directory
Write-Host "Folder Created successfully"
}
#Create folder for download
$FolderName = "C:\DAS_Tools\NMAP-Download\"
if (Test-Path $FolderName) {
Write-Host "Folder Already Exists"
# Perform Delete file from folder operation
}
else
{
#PowerShell Create directory if not exists
New-Item $FolderName -ItemType Directory
Write-Host "Folder Created successfully"
}
write -----------------------------------------------------------------------------------------------
write -------------!!!Downloading NMAP!!!---------------------
write -----------------------------------------------------------------------------------------------
#download NMAP
# Source file location
$source = 'https://nmap.org/dist/nmap-7.80-setup.exe'
# Destination to save the file
$destination = 'C:\DAS_Tools\NMAP-Download\nmap-7.80-setup.exe'
#Download the file
Invoke-WebRequest -Uri $source -OutFile $destination
write -----------------------------------------------------------------------------------------------
write -------------!!!Installing NMAP-CLICK YES!!!---------------------
write -----------------------------------------------------------------------------------------------
#Install NMAP
$CurrentLocation = "C:\DAS_Tools\NMAP-Download\"
$exe = "nmap-7.80-setup.exe"
Start-Process -FilePath $CurrentLocation\$exe -ArgumentList "/S" -wait
write -----------------------------------------------------------------------------------------------
write -------------!!! Downloading custom NSEs !!!---------------------
write -----------------------------------------------------------------------------------------------
#Download Custom NSEs
# Source file location
$source = 'https://pastebin.com/raw/YBewdfj0'
# Destination to save the file
$destination = 'C:\DAS_Tools\NMAP-Download\smtp-vuln-cve2020-28017-through-28026-21nails.nse'
Invoke-WebRequest -Uri $source -OutFile $destination
# Source file location
#$source = 'https://pastebin.com/raw/eFgkVEDx'
# Destination to save the file
#$destination = 'C:\DAS_Tools\NMAP-Download\mysql-auth-bypass.nse'
#Invoke-WebRequest -Uri $source -OutFile $destination
write -----------------------------------------------------------------------------------------------
write -------------!!! UPDATE NMAP Database !!!---------------------
write -----------------------------------------------------------------------------------------------
Nmap --script-updatedb
write -----------------------------------------------------------------------------------------------
write -------------!!! Download Custom Powershell scripts!!!---------------------
write -----------------------------------------------------------------------------------------------
#download custom powershell files
# Source file location
$source = 'https://pastebin.com/raw/a1CyDqic'
# Destination to save the file
$destination = 'C:\DAS_Tools\NMAP-Download\Get-UnlinkedGPO.ps1'
Invoke-WebRequest -Uri $source -OutFile $destination
# Source file location
$source = 'https://pastebin.com/raw/KtVdnasd'
# Destination to save the file
$destination = 'C:\DAS_Tools\NMAP-Download\get-machinecount.ps1'
Invoke-WebRequest -Uri $source -OutFile $destination
# Source file location
$source = 'https://pastebin.com/raw/SdVbmAp5'
# Destination to save the file
$destination = 'C:\DAS_Tools\NMAP-Download\Get-GPOsLinkedToEmptyOUs.ps1'
Invoke-WebRequest -Uri $source -OutFile $destination
# Source file location
$source = 'https://pastebin.com/raw/7TKfRVm2'
# Destination to save the file
$destination = 'C:\DAS_Tools\NMAP-Download\Get-GPOExtraRegistry.ps1'
Invoke-WebRequest -Uri $source -OutFile $destination
# Source file location
$source = 'https://pastebin.com/raw/hdeTMBLM'
# Destination to save the file
$destination = 'C:\DAS_Tools\NMAP-Download\Get-EmptyGPO.ps1'
Invoke-WebRequest -Uri $source -OutFile $destination
# Source file location
$source = 'https://pastebin.com/raw/HgxfvA1F'
# Destination to save the file
$destination = 'C:\DAS_Tools\NMAP-Download\Get-DomainAdmins.ps1'
Invoke-WebRequest -Uri $source -OutFile $destination
write -----------------------------------------------------------------------------------------------
write -------------!!! Creating Folder for results!!!---------------------
write -----------------------------------------------------------------------------------------------
#Create folder for for results
$FolderName = "C:\DAS_Tools\SecurityRisks"
if (Test-Path $FolderName) {
Write-Host "Folder Already Exists"
# Perform Delete file from folder operation
}
else
{
#PowerShell Create directory if not exists
New-Item $FolderName -ItemType Directory
Write-Host "Folder Created successfully"
}
# NMAP SCANS TO COMPLETE
write -----------------------------------------------------------------------------------------------
write ----------------------- Gather information for NMAP scans -------------------------------------
write -----------------------------------------------------------------------------------------------
$hosts=Read-Host "Please enter network to scan"
$sub=Read-Host "Please enter subnet example: 24"
cmd.exe /c dir c:\|Tee-Object C:\DAS_Tools\SecurityRisks\log4jscan$hosts.txt
write --------------------------------------------------------------
write -------------------- Scanning for Log4J --------------------
write --------------------------------------------------------------
C:'\Program Files (x86)'\Nmap\nmap.exe -p 80,443,631,7080,8080,8443,8088,5800,3872,8180,8000 --script http-vuln-cve2017-5638 $hosts/$sub |Tee-Object C:\DAS_Tools\SecurityRisks\log4jscan$hosts.txt
cmd.exe /c dir c:\|Tee-Object C:\DAS_Tools\SecurityRisks\EternalBluescan$hosts.txt
write --------------------------------------------------------------------------
write -------------------- Scanning for EternalBlue --------------------------
write --------------------------------------------------------------------------
C:'\Program Files (x86)'\Nmap\nmap.exe -p 445 --script smb-vuln-ms17-010 $hosts/$sub |Tee-Object C:\DAS_Tools\SecurityRisks\EternalBluescan$hosts.txt
cmd.exe /c dir c:\|Tee-Object C:\DAS_Tools\SecurityRisks\BlueKeepscan$hosts.txt
write ------------------------------------------------------------------
write --------------------- Scanning for BlueKeep ---------------------
write ------------------------------------------------------------------
C:'\Program Files (x86)'\Nmap\nmap.exe -sV --script=rdp-vuln-ms12-020 -p 3389 $hosts/$sub |Tee-Object C:\DAS_Tools\SecurityRisks\BlueKeepscan$hosts.txt
cmd.exe /c dir c:\|Tee-Object C:\DAS_Tools\SecurityRisks\HeartBleed$hosts.txt
write ---------------------------------------------------------------------
write -------------------- Scanning for HeartBleed -----------------------
write ---------------------------------------------------------------------
C:'\Program Files (x86)'\Nmap\nmap.exe -p 443 --script ssl-heartbleed $hosts/$sub |Tee-Object C:\DAS_Tools\SecurityRisks\HeartBleed$hosts.txt
cmd.exe /c dir c:\|Tee-Object C:\DAS_Tools\SecurityRisks\cve2020-28017-through-28026-21-$hosts.txt
write -------------------------------------------------------------------------------------
write -------------------- Scanning for cve2020-28017-through-28026-21 --------------------
write -------------------------------------------------------------------------------------
C:'\Program Files (x86)'\Nmap\nmap.exe --script C:\DAS_Tools\NMAP-Download\smtp-vuln-cve2020-28017-through-28026-21nails.nse $hosts/$sub |Tee-Object C:\DAS_Tools\SecurityRisks\cve2020-28017-through-28026-21-$hosts.txt
cmd.exe /c dir c:\|Tee-Object C:\DAS_Tools\SecurityRisks\Vulners-$hosts.txt
write --------------------------------------------------------------------
write --------------------- Scanning for vulners.nse ---------------------
write --------------------- https://github.com/scipag ---------------------
write ---------------------------------------------------------------------
C:'\Program Files (x86)'\Nmap\nmap.exe -sV --version-light --script vulners.nse [--script-args mincvss=<arg_val>] $hosts/$sub |Tee-Object C:\DAS_Tools\SecurityRisks\Vulners-$hosts.txt
write -----------------------------------------------------------------------------------------------
write -------------!!! This is the of NMAP Scans moving to AD Security Risks !!!---------------------
write -----------------------------------------------------------------------------------------------
# downloading top passwords - you can change the amoount you want to download
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
#curl "https://gitlab.com/kalilinux/packages/seclists/-/raw/kali/master/Passwords/Common-Credentials/10-million-password-list-top-500.txt" -O "C:\DAS_Tools\NMAP-Download\weakpasswords.txt"
#curl "https://gitlab.com/kalilinux/packages/seclists/-/raw/kali/master/Passwords/Common-Credentials/10-million-password-list-top-1000.txt" -O "C:\DAS_Tools\NMAP-Download\weakpasswords.txt"
curl "https://gitlab.com/kalilinux/packages/seclists/-/raw/kali/master/Passwords/Common-Credentials/10-million-password-list-top-10000.txt" -O "C:\DAS_Tools\NMAP-Download\weakpasswords.txt"
#clean up password file and create clean version
Get-Content -Path "C:\DAS_Tools\NMAP-Download\weakpasswords.txt" > "C:\DAS_Tools\NMAP-Download\cleanpassword.txt"
Remove-Item "C:\DAS_Tools\NMAP-Download\weakpasswords.txt"
Rename-Item "C:\DAS_Tools\NMAP-Download\cleanpassword.txt" "C:\DAS_Tools\NMAP-Download\weakpasswords.txt"
write -----------------------------------------------------------------------------------------------
write -------------!!! Getting Server and workstation counts!!!---------------------
write -----------------------------------------------------------------------------------------------
#Get Computer and Server counts
powershell C:\DAS_Tools\NMAP-Download\get-machinecount.ps1 > C:\DAS_Tools\SecurityRisks\servers_Workstation_counts.txt
write -----------------------------------------------------------------------------------------------
write -------------!!! Getting Computer Accounts no Passwords !!!---------------------
write -----------------------------------------------------------------------------------------------
#Getting Computer Accounts no Passwords
Get-ADComputer -Filter {((Enabled -eq $true) -and (PasswordNotRequired -eq $true))} -Properties PasswordLastSet | Export-Csv -Path C:\DAS_Tools\SecurityRisks\computer_noPass.csv
write -----------------------------------------------------------------------------------------------
write -------------!!! Getting Empty GPOs !!!---------------------
write -----------------------------------------------------------------------------------------------
#Empty GPOs
powershell C:\DAS_Tools\NMAP-Download\Get-EmptyGPO.ps1 > C:\DAS_Tools\SecurityRisks\EmptyGPO.txt
write -----------------------------------------------------------------------------------------------
write -------------!!! Getting GPOs with extra Reg Keys !!!---------------------
write -----------------------------------------------------------------------------------------------
#GPO with Extra Registry
powershell C:\DAS_Tools\NMAP-Download\Get-GPOExtraRegistry.ps1 > C:\DAS_Tools\SecurityRisks\GPOExtraRegistry.txt
write -----------------------------------------------------------------------------------------------
write -------------!!! Getting GPOS Linked to empty OUs !!!---------------------
write -----------------------------------------------------------------------------------------------
#GPOs Linked To Empty OUs
powershell C:\DAS_Tools\NMAP-Download\Get-GPOsLinkedToEmptyOUs.ps1 > C:\DAS_Tools\SecurityRisks\GPOsLinkedToEmptyOUs.txt
write -----------------------------------------------------------------------------------------------
write -------------!!! Getting Unlinked GPOs !!!---------------------
write -----------------------------------------------------------------------------------------------
#Unlinked GPOs
powershell C:\DAS_Tools\NMAP-Download\Get-UnlinkedGPO.ps1 > C:\DAS_Tools\SecurityRisks\UnlinkedGPO.txt
write -----------------------------------------------------------------------------------------------
write -------------!!! Getting DOMAIN ADMIN users information !!!---------------------
write -----------------------------------------------------------------------------------------------
#Gather Domain Admins
Get-ADGroupMember -Identity "Domain Admins" | Get-ADUser -Properties PasswordLastSet | Select-Object -Property Name, PasswordLastSet > C:\DAS_Tools\SecurityRisks\DomainAdminInfo.txt
#check for weak passwords
write -----------------------------------------------------------------------------------------------
write ----------------------- WE ARE CHECKING WEAK AND PASSWORD SECURITY ---------------------------
write -----------------------------------------------------------------------------------------------
$DictFile = "C:\DAS_Tools\NMAP-Download\weakpasswords.txt"
$DC=Read-Host "Please enter AD Server"
$Domain=Read-Host "Enter OU | example: DC=ROOT,DC=DOMAIN,DC=ORG"
Get-ADReplAccount -All -Server $DC -NamingContext $Domain | Test-PasswordQuality -WeakPasswordsFile $DictFile > C:\DAS_Tools\SecurityRisks\weakpasswords_Report_Found.txt
#making sure ware running DSinternals
Import-Module DSInternals
#Run As Admin Account to get hashes
$cred = Get-Credential
# Getting Hashes from AD
write -----------------------------------------------------------------------------------------------
write --------------------------- WE ARE GETING PASSWORD HASHES -------------------------------------
write -----------------------------------------------------------------------------------------------
$server=Read-Host " What AD server to want to use?"
$OU=Read-Host "What OU do you want to get Hashes from? example: DC=ROOT,DC=DOMAIN,DC=ORG"
$file = "C:\DAS_Tools\SecurityRisks\HASHoutfile.csv"
Function GetLine ($sam){
$s = $sam
$account=Get-ADReplAccount -SamAccountName $sam -Server $server -Credential $cred
for ($i=1;$i -le $account.nthashhistory.count;$i++){
$h = ConvertTo-Hex -input $account.nthashhistory[$i-1]
$s += ","+$h
}
return $s
}
#### MAIN SCRIPT FOR HASH
# Set filter to desired population (1 or more accounts are acceptable)
$accounts = Get-ADUser -Filter "Enabled -eq 'true' " -SearchBase $OU
# Loop and write to a file
foreach ($a in $accounts){
GetLine ($a.SamAccountname) >> $file
}
write -----------------------------------------------------------------------------------------------
write ---------------------Getting Domain Password Policy-----------------------------------------
write -----------------------------------------------------------------------------------------------
Get-ADDefaultDomainPasswordPolicy > C:\DAS_Tools\SecurityRisks\ADPasswordPolicy.txt
write -----------------------------------------------------------------------------------------------
write ---------------------Opening security results folder-----------------------------------------
write -----------------------------------------------------------------------------------------------
#Opening security results folder
explorer.exe C:\DAS_Tools\SecurityRisks