-
Notifications
You must be signed in to change notification settings - Fork 194
/
HostEnum.ps1
4569 lines (3600 loc) · 194 KB
/
HostEnum.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
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
Invoke-HostEnum
@andrewchiles
https://github.com/threatexpress/red-team-scripts
Future Additions
------------------
Re-work registry checking functions similar to Get-HostProfile
LLMNR and NetBIOS over TCP/IP Settings
RDP Settings HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server
StickyNotes
Win10 - %UserProfile%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite
Win7 - C:\Users\Username\AppData\Roaming\Microsoft\StickyNotes\StickyNotes.snt
Tanium https://docs.tanium.com/client/client/troubleshooting.html
64-bit C:\Program Files (x86)\Tanium\Tanium Client\TaniumClient.exe
32-bit C:\Program Files\Tanium\Tanium Client\TaniumClient.exe
32-bit HKEY_LOCAL_MACHINE\Software\Tanium\Tanium Client
64-bit HKEY_LOCAL_MACHINE\Software\Wow6432Node\Tanium\Tanium Client
Windows Event Forwarding registry::HKLM\Software\Policies\Microsoft\Windows\EventLog\EventForwarding\SubscriptionManager"
Add https://github.com/sekirkity/BrowserGather.git
User IdleTime https://stackoverflow.com/questions/15845508/get-idle-time-of-machine
Get all ConsoleHost history files
#>
#requires -version 2
function Invoke-HostEnum {
<#
.SYNOPSIS
Performs local host and/or domain enumeration for situational awareness
Author: Andrew Chiles (@andrewchiles) leveraging functions by @mattifestation, @harmj0y, @tifkin_, Joe Bialek, rvrsh3ll, Beau Bullock, and Tim Medin
License: BSD 3-Clause
Depenencies: None
Requirements: None
https://github.com/threatexpress/red-team-scripts
.DESCRIPTION
A compilation of multiple system enumeration / situational awareness techniques collected over time.
If system is a member of a domain, it can perform additional enumeration. However, the included domain enumeration is limited with the intention that PowerView, BoodHound, etc will be also be used.
Report HTML file is written in the format of YYYYMMDD_HHMMSS_HOSTNAME.html in the current working directory.
Invoke-HostEnum is Powershell 2.0 compatible to ensure it functions on the widest variety of Windows targets
Enumerated Information:
- OS Details, Hostname, Uptime, Installdate
- Installed Applications and Patches
- Network Adapter Configuration, Network Shares, Listening Ports, Connections, Routing Table, DNS Cache, Firewall Status
- Running Processes and Installed Services
- Interesting Registry Entries
- Local Users, Groups, Administrators
- Personal Security Product Status, AV Processes
- Interesting file locations and keyword searches via file indexing
- Interesting Windows Logs (User logins)
- Basic Domain enumeration (users, groups, trusts, domain controllers, account policy, SPNs)
.PARAMETER All
Executes Local, Domain, and Privesc functions
.PARAMETER Local
Executes the local enumeration functions
.PARAMETER Domain
Executes the domain enumeration functions
.PARAMETER Privesc
Executes modified version of PowerUp privilege escalation enumeration (Invoke-AllChecks)
.PARAMETER Quick
Executes a brief initial survey that may be useful when initially accessing a host
Only enumerates basic system info, processes, av, network adapters, firewall state, network connections, users, and groups
Note: Not usable with -HTMLReport
.PARAMETER HTMLReport
Creates an HTML Report of enumeration results
.PARAMETER Verbose
Enables verbosity (Leverages Write-Verbose and output may differ depending on the console/agent you're using)
.EXAMPLE
PS C:\> Invoke-HostEnum -Local -HTMLReport -Verbose
Performs local system enumeration with verbosity and writes output to a HTML report
.EXAMPLE
PS C:\> Invoke-HostEnum -Domain -HTMLReport
Performs domain enumeration using net commands and saves the output to the current directory
.EXAMPLE
PS C:\> Invoke-HostEnum -Local -Domain
Performs local and domain enumeration functions and outputs the results to the console
.LINK
https://github.com/threatexpress/red-team-scripts
#>
[CmdletBinding()]
Param(
[Switch]$All,
[Switch]$Local,
[Switch]$Domain,
[Switch]$Quick,
[Switch]$Privesc,
[Switch]$HTMLReport
)
# Ignore Errors and don't print to screen unless specified otherwise when calling Functions
$ErrorActionPreference = "SilentlyContinue"
# $All switch runs Local, Domain, and Privesc checks
If ($All) {$Local = $True; $Domain = $True; $Privesc = $True}
### Begin Main Execution
$Time = (Get-Date).ToUniversalTime()
[string]$StartTime = $Time|Get-Date -uformat %Y%m%d_%H%M%S
# Create filename for HTMLReport
If ($HTMLReport) {
[string]$Hostname = $ENV:COMPUTERNAME
[string]$FileName = $StartTime + '_' + $Hostname + '.html'
$HTMLReportFile = (Join-Path $PWD $FileName)
# Header for HTML table formatting
$HTMLReportHeader = @"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;font-family:courier;}
TR:Nth-Child(Even) {Background-Color: #dddddd;}
.odd { background-color:#ffffff; }
.even { background-color:#dddddd; }
</style>
<style>
.aLine {
border-top:1px solid #6495ED};
height:1px;
margin:16px 0;
}
</style>
<title>System Report</title>
"@
# Attempt to write out HTML report header and exit if there isn't sufficient permission
Try {
ConvertTo-HTML -Title "System Report" -Head $HTMLReportHeader `
-Body "<H1>System Enumeration Report for $($Env:ComputerName) - $($Env:UserName)</H1>`n<div class='aLine'></div>" `
| Out-File $HTMLReportFile -ErrorAction Stop
}
Catch {
"`n[-] Error writing enumeration output to disk! Check your permissions on $PWD.`n$($Error[0])`n"; Return
}
}
# Print initial execution status
"[+] Invoke-HostEnum"
"[+] STARTTIME:`t$StartTime"
"[+] PID:`t$PID`n"
# Check user context of Powershell.exe process and alert if running as SYSTEM
$IsSystem = [Security.Principal.WindowsIdentity]::GetCurrent().IsSystem
If ($IsSystem) {
"`n[*] Warning: Enumeration is running as SYSTEM and some enumeration techniques (Domain and User-context specific) may fail to yield desired results!`n"
If ($HTMLReport) {
ConvertTo-HTML -Fragment -PreContent "<H2>Note: Enumeration performed as 'SYSTEM' and report may contain incomplete results!</H2>" -as list | Out-File -Append $HTMLReportFile
}
}
# Execute a quick system survey
If ($Quick) {
Write-Verbose "Performing quick enumeration..."
"`n[+] Host Summary`n"
$Results = Get-Sysinfo
$Results | Format-List
"`n[+] Running Processes`n"
$Results = Get-ProcessInfo
$Results | Format-Table ID, Name, Owner, Path -auto -wrap
"`n[+] Installed AV Product`n"
$Results = Get-AVInfo
$Results | Format-List
"`n[+] Potential AV Processes`n"
$Results = Get-AVProcesses
$Results | Format-Table -Auto
"`n[+] Installed Software:`n"
$Results = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, InstallDate, DisplayVersion, Publisher, InstallLocation
if ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq "64-bit")
{
$Results += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, InstallDate, DisplayVersion, Publisher, InstallLocation
}
$Results = $Results | Where-Object {$_.DisplayName} | Sort-Object DisplayName
$Results | Format-Table -Auto -Wrap
"`n[+] System Drives:`n"
$Results = Get-PSDrive -psprovider filesystem | Select-Object Name, Root, Used, Free, Description, CurrentLocation
$Results | Format-Table -auto
"`n[+] Active TCP Connections:`n"
$Results = Get-ActiveTCPConnections | Select-Object LocalAddress, LocalPort, RemoteAddress, RemotePort, State, IPVersion
$Results | Format-Table -auto
"`n[+] Firewall Status:`n"
$Results = Get-FirewallStatus
$Results | Format-Table -auto
"`n[+] Local Users:`n"
$Results = Get-LocalUsers | Sort-Object SID -Descending | Select-Object Name, SID, AccountType, PasswordExpires, Disabled, Lockout, Status, PasswordLastSet, LastLogin, Description
$Results | Format-Table -auto -wrap
"`n[+] Local Administrators:`n"
$Results = Get-WmiObject -Class Win32_groupuser -Filter "GroupComponent=""Win32_Group.Domain='$env:COMPUTERNAME',Name='Administrators'""" |
% {[wmi]$_.PartComponent} | Select-Object Name, Domain, SID, AccountType, PasswordExpires, Disabled, Lockout, Status, Description
"`n[+] Local Groups:`n"
$Results = Get-WmiObject -Class Win32_Group -Filter "Domain='$($env:ComputerName)'" | Select-Object Name,SID,Description
$Results | Format-Table -auto -wrap
"`n[+] Group Membership for ($($env:username))`n"
$Results = Get-UserGroupMembership | Sort-Object SID
$Results | Format-Table -Auto
}
# Execute local system enumeration functions
If ($Local) {
# Execute local enumeration functions and format for report
"`n[+] Host Summary`n"
$Results = Get-Sysinfo
$Results | Format-List
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Host Summary</H2>" -as list | Out-File -Append $HTMLReportFile
}
# Get Installed software, check for 64-bit applications
"`n[+] Installed Software:`n"
$Results = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, InstallDate, DisplayVersion, Publisher, InstallLocation
if ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq "64-bit")
{
$Results += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, InstallDate, DisplayVersion, Publisher, InstallLocation
}
$Results = $Results | Where-Object {$_.DisplayName} | Sort-Object DisplayName
$Results | Format-Table -Auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Installed Software</H2>" | Out-File -Append $HTMLReportFile
}
# Get installed patches
"`n[+] Installed Patches:`n"
$Results = Get-WmiObject -class Win32_quickfixengineering | Select-Object HotFixID,Description,InstalledBy,InstalledOn | Sort-Object InstalledOn -Descending
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Installed Patches</H2>" | Out-File -Append $HTMLReportFile
}
# Process Information
"`n[+] Running Processes`n"
$Results = Get-ProcessInfo
$Results | Format-Table ID, Name, Owner, Path, CommandLine -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -Property ID, Name, Owner, MainWindowTitle, Path, CommandLine -PreContent "<H2>Process Information</H2>" | Out-File -Append $HTMLReportFile
}
# Services
"`n[+] Installed Services:`n"
$Results = Get-WmiObject win32_service | Select-Object Name, DisplayName, State, PathName
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Installed Services</H2>" | Out-File -Append $HTMLReportFile
}
# Environment variables
"`n[+] Environment Variables:`n"
$Results = Get-Childitem -path env:* | Select-Object Name, Value | Sort-Object name
$Results |Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Environment Variables</H2>"| Out-File -Append $HTMLReportFile
}
# BIOS information
"`n[+] BIOS Information:`n"
$Results = Get-WmiObject -Class win32_bios |Select-Object SMBIOSBIOSVersion, Manufacturer, Name, SerialNumber, Version
$Results | Format-List
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>BIOS Information</H2>" -as List| Out-File -Append $HTMLReportFile
}
# Physical Computer Information
"`n[+] Computer Information:`n"
$Results = Get-WmiObject -class Win32_ComputerSystem | Select-Object Domain, Manufacturer, Model, Name, PrimaryOwnerName, TotalPhysicalMemory, @{Label="Role";Expression={($_.Roles) -join ","}}
$Results | Format-List
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Physical Computer Information</H2>" -as List | Out-File -Append $HTMLReportFile
}
# System Drives (Returns mapped drives too, but not their associated network path)
"`n[+] System Drives:`n"
$Results = Get-PSDrive -psprovider filesystem | Select-Object Name, Root, Used, Free, Description, CurrentLocation
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>System Drives</H2>" | Out-File -Append $HTMLReportFile
}
# Mapped Network Drives
"`n[+] Mapped Network Drives:`n"
$Results = Get-WmiObject -Class Win32_MappedLogicalDisk | Select-Object Name, Caption, VolumeName, FreeSpace, ProviderName, FileSystem
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Mapped Network Drives</H2>" | Out-File -Append $HTMLReportFile
}
## Local Network Configuration
# Network Adapters
"`n[+] Network Adapters:`n"
$Results = Get-WmiObject -class Win32_NetworkAdapterConfiguration |
Select-Object Description,@{Label="IPAddress";Expression={($_.IPAddress) -join ", "}},@{Label="IPSubnet";Expression={($_.IPSubnet) -join ", "}},@{Label="DefaultGateway";Expression={($_.DefaultIPGateway) -join ", "}},MACaddress,DHCPServer,DNSHostname | Sort-Object IPAddress -descending
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Network Adapters</H2>" | Out-File -Append $HTMLReportFile
}
# DNS Cache
"`n[+] DNS Cache:`n"
$Results = Get-WmiObject -query "Select * from MSFT_DNSClientCache" -Namespace "root\standardcimv2" | Select-Object Entry, Name, Data
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>DNS Cache</H2>" | Out-File -Append $HTMLReportFile
}
# Network Shares
"`n[+] Network Shares:`n"
$Results = Get-WmiObject -class Win32_Share | Select-Object Name, Path, Description, Caption, Status
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Network Shares</H2>" | Out-File -Append $HTMLReportFile
}
# TCP Network Connections
"`n[+] Active TCP Connections:`n"
$Results = Get-ActiveTCPConnections | Select-Object LocalAddress, LocalPort, RemoteAddress, RemotePort, State, IPVersion
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Active TCP Connections</H2>" | Out-File -Append $HTMLReportFile
}
# IP Listeners
"`n[+] TCP/UDP Listeners:`n"
$Results = Get-ActiveListeners |Where-Object {$_.ListeningPort -LT 50000}| Select-Object Protocol, LocalAddress, ListeningPort, IPVersion
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>TCP/UDP Listeners</H2>" | Out-File -Append $HTMLReportFile
}
# Firewall Status
"`n[+] Firewall Status:`n"
$Results = Get-FirewallStatus
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Firewall Status</H2>" | Out-File -Append $HTMLReportFile
}
# WMI Routing Table
"`n[+] Routing Table:`n"
$Results = Get-WmiObject -class "Win32_IP4RouteTable" -namespace "root\CIMV2" |Select-Object Destination, Mask, Nexthop, InterfaceIndex, Metric1, Protocol, Type
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Routing Table</H2>" | Out-File -Append $HTMLReportFile
}
# WMI Net Sessions
"`n[+] Net Sessions:`n"
$Results = Get-WmiObject win32_networkconnection | Select-Object LocalName, RemoteName, RemotePath, Name, Status, ConnectionState, Persistent, UserName, Description
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Network Sessions</H2>" | Out-File -Append $HTMLReportFile
}
# Proxy Information
"`n[+] Proxy Configuration:`n"
$regkey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$Results = New-Object -TypeName PSObject -Property @{
Enabled = If ((Get-ItemProperty -Path $regkey).proxyEnable -eq 1) {"True"} else {"False"}
ProxyServer = (Get-ItemProperty -Path $regkey).proxyServer
AutoConfigURL = (Get-ItemProperty -Path $regkey).AutoConfigUrl
}
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Proxy Configuration</H2>" | Out-File -Append $HTMLReportFile
}
## Local User and Group Enumeration
#######################
# Local User Accounts
"`n[+] Local users:`n"
$Results = Get-LocalUsers | Sort-Object SID -Descending | Select-Object Name, SID, AccountType, PasswordExpires, Disabled, Lockout, Status, PasswordLastSet, LastLogin, Description
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Local Users</H2>" | Out-File -Append $HTMLReportFile
}
# Local Administrators
"`n[+] Local Administrators:`n"
$Results = Get-WmiObject -Class Win32_groupuser -Filter "GroupComponent=""Win32_Group.Domain='$env:COMPUTERNAME',Name='Administrators'""" |
% {[wmi]$_.PartComponent} | Select-Object Name, Domain, SID, AccountType, PasswordExpires, Disabled, Lockout, Status, Description
$Results | Format-Table -auto -wrap
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Local Administrators</H2>" | Out-File -Append $HTMLReportFile
}
# Local Groups
"`n[+] Local Groups:`n"
$Results = Get-WmiObject -Class Win32_Group -Filter "Domain='$($env:ComputerName)'" | Select-Object Name,SID,Description
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Local Groups</H2>" | Out-File -Append $HTMLReportFile
}
# Local Group Membership
"`n[+] Local Group Membership:`n"
$Groups = Get-WmiObject -Class Win32_Group -Filter "Domain='$($env:ComputerName)'" | Select-Object -expand Name
Foreach ($Group in $Groups) {
$results = $Null
$Results = Get-WmiObject -Class Win32_groupuser -Filter "GroupComponent=""Win32_Group.Domain='$env:COMPUTERNAME',Name='$Group'""" | % {[wmi]$_.PartComponent} | Select-Object Name, Domain, SID, AccountType, PasswordExpires, Disabled, Lockout, Status, Description
"[+] $Group - Members"
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Local Group Membership - $Group</H2>" | Out-File -Append $HTMLReportFile
}
}
# Explicit Logon Events (Requires admin)
"`n[+] Explicit Logon Events (4648) - Last 10 Days:`n"
$Results = Get-ExplicitLogonEvents -Days 10 | Select TimeCreated,TargetUserName,TargetDomainName,ProcessName,SubjectUserName,SubjectDomainName | Sort-Object TimeCreated
$Results | Format-Table -auto -wrap
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Explicit Logon Events (4648) - Last 10 Days</H2>" | Out-File -Append $HTMLReportFile
}
# Logon Events (Requires admin)
"`n[+] Logon Events (4624) - Last 200 Events:`n"
# Filter out NT Authority and Machine logons
$Results = Get-LogonEvents -MaxEvents 200 | Where-Object {$_.Target -NotLike "NT AUTHORITY*" -and $_.Target -NotLike "*$"} |Sort-Object TimeCreated
$Results | Format-Table -auto -wrap
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Logon Events (4624) - Last 200 Events</H2>" | Out-File -Append $HTMLReportFile
}
## AV Products
#########################
"`n[+] Installed AV Product`n"
$Results = Get-AVInfo
$Results | Format-List
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Installed AV Product</H2>" -as list | Out-File -Append $HTMLReportFile
}
# Potential Running AV Processes
"`n[+] Potential AV Processes`n"
$Results = Get-AVProcesses
$Results | Format-Table -Auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Potential AV Processes</H2>" | Out-File -Append $HTMLReportFile
}
# If McAfee is installed then pull some recent logs
If ($Results.displayName -Match "mcafee") {
$Results = Get-McafeeLogs
$Results |Format-List
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Recent McAfee AV Logs</H2>" -as list | Out-File -Append $HTMLReportFile
}
}
## Interesting Locations
#############################
"`n[+] Registry Keys`n"
$Results = Get-InterestingRegistryKeys
$Results
If ($HTMLReport) {
ConvertTo-HTML -Fragment -PreContent "<H2>Interesting Registry Keys</H2>`n<table><tr><td><PRE>$Results</PRE></td></tr></table>" -as list | Out-File -Append $HTMLReportFile
}
# Interesting File Search (String formatted due to odd formatting issues with file listings)
"`n[+] Interesting Files:`n"
$Results = Get-InterestingFiles
$Results
If ($HTMLReport) {
ConvertTo-HTML -Fragment -PreContent "<H2>Interesting Files</H2>`n<table><tr><td><PRE>$Results</PRE></td></tr></table>" | Out-File -Append $HTMLReportFile
}
## Current User Enumeration
############################
# Group Membership for Current User
"`n[+] Group Membership - $($Env:UserName)`n"
$Results = Get-UserGroupMembership | Sort-Object SID
$Results | Format-Table -Auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Group Membership - $($env:username)</H2>"| Out-File -Append $HTMLReportFile
}
# Browser History (IE, Firefox, Chrome)
"`n[+] Browser History`n"
$Results = Get-BrowserInformation | Where-Object{$_.Data -NotMatch "google" -And $_.Data -NotMatch "microsoft" -And $_.Data -NotMatch "chrome" -And $_.Data -NotMatch "youtube" }
$Results | Format-Table Browser, DataType, User, Data -Auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -Property Browser, DataType, User, Data, Name -PreContent "<H2>Browser History</H2>" | Out-File -Append $HTMLReportFile
}
# Open IE Tabs
"`n[+] Active Internet Explorer URLs - $($Env:UserName)`n"
$Results = Get-ActiveIEURLS
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Active Internet Explorer URLs - $($Env:UserName)</H2>" | Out-File -Append $HTMLReportFile
}
# Recycle Bin Files
"`n`n[+] Recycle Bin Contents - $($Env:UserName)`n"
$Results = Get-RecycleBin
$Results | Format-Table -Auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Recycle Bin Contents - $($Env:UserName)</H2>" | Out-File -Append $HTMLReportFile
}
# Clipboard Contents
Add-Type -Assembly PresentationCore
"`n[+] Clipboard Contents - $($Env:UserName):`n"
$Results = ''
$Results = ([Windows.Clipboard]::GetText()) -join "`r`n" | Out-String
$Results
If ($HTMLReport) {
ConvertTo-HTML -Fragment -PreContent "<H2>Clipboard Contents - $($Env:UserName)</H2><table><tr><td><PRE>$Results</PRE></td></tr></table>"| Out-File -Append $HTMLReportFile
}
}
# Simple Domain Enumeration
If ($Domain) {
If ($HTMLReport) {
ConvertTo-HTML -Fragment -PreContent "<H1>Domain Report - $($env:USERDOMAIN)</H1><div class='aLine'></div>" | Out-File -Append $HTMLReportFile
}
# Check if host is part of a domain before executing domain enumeration functions
If ((gwmi win32_computersystem).partofdomain){
Write-Verbose "Enumerating Windows Domain..."
"`n[+] Domain Mode`n"
$Results = ([System.Directoryservices.Activedirectory.Domain]::GetCurrentDomain()).DomainMode
$Results
If ($HTMLReport) {
ConvertTo-HTML -Fragment -PreContent "<H2>Domain Mode: $Results</H2>" | Out-File -Append $HTMLReportFile
}
# DA Level Accounts
"`n[+] Domain Administrators`n"
$Results = Get-DomainAdmins
$Results
If ($HTMLReport) {
ConvertTo-HTML -Fragment -PreContent "<H2>Domain Administrators</H2><table><tr><td><PRE>$Results</PRE></td></tr></table>" | Out-File -Append $HTMLReportFile
}
# Domain account password policy
"`n[+] Domain Account Policy`n"
$Results = Get-DomainAccountPolicy
$Results | Format-List
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Domain Account Policy</H2>" -as List | Out-File -Append $HTMLReportFile
}
# Domain Controllers
"`n[+] Domain Controllers:`n"
$Results = ([System.Directoryservices.Activedirectory.Domain]::GetCurrentDomain()).DomainControllers | Select-Object Name,OSVersion,Domain,Forest,SiteName,IpAddress
$Results | Format-Table -Auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Domain Controllers</H2>" | Out-File -Append $HTMLReportFile
}
# Domain Trusts
"`n[+] Domain Trusts:`n"
$Results = ([System.Directoryservices.Activedirectory.Domain]::GetCurrentDomain()).GetAllTrustRelationships()
$Results | Format-List
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Domain Trusts</H2>" -as List | Out-File -Append $HTMLReportFile
}
# Domain Users
"`n[+] Domain Users:`n"
$Results = Get-WmiObject -Class Win32_UserAccount | Select-Object Name,Caption,SID,Fullname,Disabled,Lockout,Description |Sort-Object SID
$Results | Format-Table -Auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Domain Users</H2>" | Out-File -Append $HTMLReportFile
}
# Domain Groups
"`n[+] Domain Groups:`n"
$Results = Get-WmiObject -Class Win32_Group | Select-Object Name,SID,Description | Sort-Object SID
$Results | Format-Table -Auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>Domain Groups</H2>" | Out-File -Append $HTMLReportFile
}
# Domain Admins, Enterprise Admins, Server Admins, Backup Operators
# Get User SPNS
"`n[+] User Account SPNs`n"
$Results = $null
$Results = Get-UserSPNS -UniqueAccounts | Sort-Object PasswordLastSet -Unique
$Results | Format-Table -auto
If ($HTMLReport) {
$Results | ConvertTo-HTML -Fragment -PreContent "<H2>User Account SPNs</H2>" | Out-File -Append $HTMLReportFile
}
}
Else {
"`n[-] Host is not a member of a domain. Skipping domain checks...`n"
If ($HTMLReport) {
ConvertTo-HTML -Fragment -PreContent "<H2>Host is not a member of a domain. Domain checks skipped.</H2>" | Out-File -Append $HTMLReportFile
}
}
}
# Privilege Escalation Enumeration
If ($Privesc) {
If ($HTMLReport) {
Invoke-AllChecks -HTMLReport
}
Else {
Invoke-AllChecks
}
}
# Determine the execution duration
$Duration = New-Timespan -start $Time -end ((Get-Date).ToUniversalTime())
# Print report location and finish execution
"`n"
If ($HTMLReport) {
"[+] FILE:`t$HTMLReportFile"
"[+] FILESIZE:`t$((Get-Item $HTMLReportFile).length) Bytes"
}
"[+] DURATION:`t$Duration"
"[+] Invoke-HostEnum complete!"
}
function Get-SysInfo {
<#
.SYNOPSIS
Gets basic system information from the host
#>
$os_info = gwmi Win32_OperatingSystem
$uptime = [datetime]::ParseExact($os_info.LastBootUpTime.SubString(0,14), "yyyyMMddHHmmss", $null)
$uptime = (Get-Date).Subtract($uptime)
$uptime = ("{0} Days, {1} Hours, {2} Minutes, {3} Seconds" -f ($uptime.Days, $uptime.Hours, $uptime.Minutes, $uptime.Seconds))
$date = Get-Date
$IsHighIntegrity = [bool]([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
$SysInfoHash = @{
HOSTNAME = $ENV:COMPUTERNAME
IPADDRESSES = (@([System.Net.Dns]::GetHostAddresses($ENV:HOSTNAME)) | %{$_.IPAddressToString}) -join ", "
OS = $os_info.caption + ' ' + $os_info.CSDVersion
ARCHITECTURE = $os_info.OSArchitecture
"DATE(UTC)" = $date.ToUniversalTime()| Get-Date -uformat "%Y%m%d%H%M%S"
"DATE(LOCAL)" = $date | Get-Date -uformat "%Y%m%d%H%M%S%Z"
INSTALLDATE = $os_info.InstallDate
UPTIME = $uptime
USERNAME = $ENV:USERNAME
DOMAIN = (GWMI Win32_ComputerSystem).domain
LOGONSERVER = $ENV:LOGONSERVER
PSVERSION = $PSVersionTable.PSVersion.ToString()
PSCOMPATIBLEVERSIONS = ($PSVersionTable.PSCompatibleVersions) -join ', '
PSSCRIPTBLOCKLOGGING = If((Get-ItemProperty HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -EA 0).EnableScriptBlockLogging -eq 1){"Enabled"} Else {"Disabled"}
PSTRANSCRIPTION = If((Get-ItemProperty HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -EA 0).EnableTranscripting -eq 1){"Enabled"} Else {"Disabled"}
PSTRANSCRIPTIONDIR = (Get-ItemProperty HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -EA 0).OutputDirectory
PSMODULELOGGING = If((Get-ItemProperty HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -EA 0).EnableModuleLogging -eq 1){"Enabled"} Else {"Disabled"}
LSASSPROTECTION = If((Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Lsa -EA 0).RunAsPPL -eq 1){"Enabled"} Else {"Disabled"}
LAPS = If((Get-ItemProperty "HKLM:\SOFTWARE\Policies\Microsoft Services\AdmPwd" -EA 0).AdmPwdEnabled -eq 1){"Enabled"} Else {"Disabled"}
UAC = If((Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System -EA 0).EnableLUA -eq 1){"Enabled"} Else {"Disabled (UAC is Disabled)"}
# LocalAccountTokenFilterPolicy = 1 disables local account token filtering for all non-rid500 accounts
UACLOCALACCOUNTTOKENFILTERPOLICY = If((Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System -EA 0).LocalAccountTokenFilterPolicy -eq 1){"Disabled (PTH likely w/ non-RID500 Local Admins)"} Else {"Enabled (Remote Administration restricted for non-RID500 Local Admins)"}
UACFILTERADMINISTRATORTOKEN = If((Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System -EA 0).FilterAdministratorToken -eq 1){"Enabled (RID500 protected)"} Else {"Disabled (PTH likely with RID500 Account)"}
HIGHINTEGRITY = $IsHighIntegrity
DENYRDPCONNECTIONS = [bool](Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server" -EA 0).FDenyTSConnections
}
# PS feels the need to randomly re-order everything when converted to an object so let's presort
New-Object -TypeName PSobject -Property $SysInfoHash | Select-Object Hostname, OS, Architecture, "Date(UTC)", "Date(Local)", InstallDate, UpTime, IPAddresses, Domain, Username, LogonServer, PSVersion, PSCompatibleVersions, PSScriptBlockLogging, PSTranscription, PSTranscriptionDir, PSModuleLogging, LSASSProtection, LAPS, UAC, UACLocalAccountTokenFilterPolicy, UACFilterAdministratorToken, HighIntegrity
}
function Get-ProcessInfo() {
<#
.SYNOPSIS
Gets detailed process information via WMI
#>
# Extra work here to include process owner and commandline using WMI
Write-Verbose "Enumerating running processes..."
$owners = @{}
$commandline = @{}
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}
gwmi win32_process |% {$commandline[$_.handle] = $_.commandline}
$procs = Get-Process | Sort-Object -property ID
$procs | ForEach-Object {$_|Add-Member -MemberType NoteProperty -Name "Owner" -Value $owners[$_.id.tostring()] -force}
$procs | ForEach-Object {$_|Add-Member -MemberType NoteProperty -Name "CommandLine" -Value $commandline[$_.id.tostring()] -force}
Return $procs
}
function Get-LocalUsers {
<#
.SYNOPSIS
Pulls local users and some of their properties.
.DESCRIPTION
Uses the [ADSI] object type to query user objects for group membership, password expiration, etc
.LINK
This function borrows the ADSI code from the following link:
http://www.bryanvine.com/2015/08/powershell-script-get-localusers.html
#>
$LocalUsers = Get-WmiObject -Class Win32_UserAccount -Filter "Domain='$($env:ComputerName)'"
# Pull some additional properties that we don't get through Win32_UserAccount
$LocalUserProps = ([ADSI]"WinNT://$env:computerName").Children | ?{$_.SchemaClassName -eq 'user'} | %{
$_ | Select @{n='UserName';e={$_.Name}},
@{n='Disabled';e={if(($_.userflags.value -band 2) -eq 2){$true} else{$false}}},
@{n='PasswordExpired';e={if($_.PasswordExpired){$true} else{$false}}},
@{n='PasswordNeverExpires';e={if(($_.userflags.value -band 65536) -eq 65536){$true} else{$false}}},
@{n='PasswordAge';e={if($_.PasswordAge[0] -gt 0){[DateTime]::Now.AddSeconds(-$_.PasswordAge[0])} else {$null}}},
@{n='LastLogin';e={$_.LastLogin}},
@{n='Description';e={$_.Description}},
@{n='UserFlags';e={$_.userflags}}
}
# Add PasswordAge and LastLogin properties to our users enumerated via WMI
$passwordage = @{}
$lastlogin = @{}
$LocalUserProps |%{$passwordage[$_.UserName] = $_.PasswordAge}
$LocalUserProps |%{$lastlogin[$_.UserName] = $_.LastLogin}
$LocalUsers | ForEach-Object {$_|Add-Member -MemberType NoteProperty -Name "PasswordLastSet" -Value $passwordage[$_.Name] -force}
$Localusers | ForEach-Object {$_|Add-Member -MemberType NoteProperty -Name "LastLogin" -Value $lastlogin[$_.Name] -force}
$LocalUsers
}
function Get-UserGroupMembership {
<#
.SYNOPSIS
Pulls local group membership for the current user
#>
Write-Verbose "Enumerating current user local group membership..."
$UserIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$CurrentUserSids = $UserIdentity.Groups | Select-Object -expand value
$Groups = ForEach ($sid in $CurrentUserSids) {
$SIDObj = New-Object System.Security.Principal.SecurityIdentifier("$sid")
$GroupObj = New-Object -TypeName PSObject -Property @{
SID = $sid
GroupName = $SIDObj.Translate([System.Security.Principal.NTAccount])
}
$GroupObj
}
$Groups
}
function Get-ActiveTCPConnections {
<#
.SYNOPSIS
Enumerates active TCP connections for IPv4 and IPv6
Adapted from Beau Bullock's TCP code
https://raw.githubusercontent.com/dafthack/HostRecon/master/HostRecon.ps1
#>
Write-Verbose "Enumerating active network connections..."
$IPProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
$Connections = $IPProperties.GetActiveTcpConnections()
foreach($Connection in $Connections) {
if($Connection.LocalEndPoint.AddressFamily -eq "InterNetwork" ) { $IPType = "IPv4" } else { $IPType = "IPv6" }
New-Object -TypeName PSobject -Property @{
"LocalAddress" = $Connection.LocalEndPoint.Address
"LocalPort" = $Connection.LocalEndPoint.Port
"RemoteAddress" = $Connection.RemoteEndPoint.Address
"RemotePort" = $Connection.RemoteEndPoint.Port
"State" = $Connection.State
"IPVersion" = $IPType
}
}
}
function Get-ActiveListeners {
<#
.SYNOPSIS
Enumerates active TCP/UDP listeners.
#>
Write-Verbose "Enumerating active TCP/UDP listeners..."
$IPProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
$TcpListeners = $IPProperties.GetActiveTCPListeners()
$UdpListeners = $IPProperties.GetActiveUDPListeners()
ForEach($Connection in $TcpListeners) {
if($Connection.address.AddressFamily -eq "InterNetwork" ) { $IPType = "IPv4" } else { $IPType = "IPv6" }
New-Object -TypeName PSobject -Property @{
"Protocol" = "TCP"
"LocalAddress" = $Connection.Address
"ListeningPort" = $Connection.Port
"IPVersion" = $IPType
}
}
ForEach($Connection in $UdpListeners) {
if($Connection.address.AddressFamily -eq "InterNetwork" ) { $IPType = "IPv4" } else { $IPType = "IPv6" }
New-Object -TypeName PSobject -Property @{
"Protocol" = "UDP"
"LocalAddress" = $Connection.Address
"ListeningPort" = $Connection.Port
"IPVersion" = $IPType
}
}
}
function Get-FirewallStatus {
<#
.SYNOPSIS
Enumerates local firewall status from registry
#>
$regkey = "HKLM:\System\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy"
New-Object -TypeName PSobject -Property @{
Standard = If ((Get-ItemProperty $regkey\StandardProfile).EnableFirewall -eq 1){"Enabled"}Else {"Disabled"}
Domain = If ((Get-ItemProperty $regkey\DomainProfile).EnableFirewall -eq 1){"Enabled"}Else {"Disabled"}
Public = If ((Get-ItemProperty $regkey\PublicProfile).EnableFirewall -eq 1){"Enabled"}Else {"Disabled"}
}
}
function Get-InterestingRegistryKeys {
<#
.SYNOPSIS
Pulls potentially interesting registry keys
#>
Write-Verbose "Enumerating registry keys..."
# Recently typed "run" commands
"`n[+] Recent RUN Commands:`n"
Get-Itemproperty "HKCU:\software\microsoft\windows\currentversion\explorer\runmru" | Out-String
# HKLM SNMP Keys
"`n[+] SNMP community strings:`n"
Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\services\snmp\parameters\validcommunities" | Format-List | Out-String
# HKCU SNMP Keys
"`n[+] SNMP community strings for current user:`n"
Get-ItemProperty "HKCU:\SYSTEM\CurrentControlSet\services\snmp\parameters\validcommunities"| Format-List |Out-String
# Putty Saved Session Keys
"`n[+] Putty saved sessions:`n"
Get-ItemProperty "HKCU:\Software\SimonTatham\PuTTY\Sessions\*" |Format-List | Out-String
"`n[+] Windows Update Settings:`n"
Get-ItemProperty "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" |Format-List | Out-String
"`n[+] Kerberos Settings:`n"
Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\Kerberos\Parameters" |Format-List | Out-String
"`n[+] Wdigest Settings:`n"
Get-ItemProperty "HKLM:\System\CurrentControlSet\Control\SecurityProviders\WDigest" |Format-List | Out-String
"`n[+] Windows Installer Settings:`n"
Get-ItemProperty "HKLM:\Software\Policies\Microsoft\Windows\Installer" |Format-List | Out-String
Get-ItemProperty "HKCU:\Software\Policies\Microsoft\Windows\Installer" |Format-List | Out-String
"`n[+] Windows Policy Settings:`n"
Get-ChildItem registry::HKEY_LOCAL_MACHINE\Software\Policies -recurse | Out-String
Get-ChildItem registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies -recurse | Out-String
Get-ChildItem registry::HKEY_CURRENT_USER\Software\Policies -recurse | Out-String
Get-ChildItem registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies -recurse | Out-String
}
function Get-IndexedFiles {
<#
.SYNOPSIS
Uses the Windows indexing service to search for interesting files and often includes Outlook e-mails.
Code originally adapted from a Microsoft post, but can no longer locate the exact source. Doesn't work on all systems.
#>
param (
[Parameter(Mandatory=$true)][string]$Pattern)
if($Path -eq ""){$Path = $PWD;}
$pattern = $pattern -replace "\*", "%"
$path = $path + "\%"
$con = New-Object -ComObject ADODB.Connection
$rs = New-Object -ComObject ADODB.Recordset
# This directory indexing search doesn't work on some systems tested (i.e.Server 2K8r2)
# Using Try/Catch to break the search in case the provider isn't available
Try {
$con.Open("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';")}
Catch {
"[-] Indexed file search provider not available";Break
}
$rs.Open("SELECT System.ItemPathDisplay FROM SYSTEMINDEX WHERE System.FileName LIKE '" + $pattern + "' " , $con)
While(-Not $rs.EOF){
$rs.Fields.Item("System.ItemPathDisplay").Value
$rs.MoveNext()
}
}
function Get-InterestingFiles {
<#
.SYNOPSIS
Local filesystem enumeration
#>
Write-Verbose "Enumerating interesting files..."
# Get Indexed files containg $searchStrings (Experimental), edit this to desired list of "dirty words"
$SearchStrings = "*secret*","*creds*","*credential*","*.vmdk","*confidential*","*proprietary*","*pass*","*credentials*","web.config","KeePass.config*","*.kdbx","*.key","tnsnames.ora","ntds.dit","*.dll.config","*.exe.config"
$IndexedFiles = Foreach ($String in $SearchStrings) {Get-IndexedFiles $string}
"`n[+] Indexed File Search:`n"
"`n[+] Search Terms ($SearchStrings)`n`n"
$IndexedFiles |Format-List |Out-String -width 300
# Get Top Level file listing of all drives
"`n[+] All 'FileSystem' Drives - Top Level Listing:`n"
Get-PSdrive -psprovider filesystem |ForEach-Object {gci $_.Root} |Select-Object Fullname,LastWriteTimeUTC,LastAccessTimeUTC,Length | Format-Table -auto | Out-String -width 300
# Get Program Files
"`n[+] System Drive - Program Files:`n"
GCI "$ENV:ProgramFiles\" | Select-Object Fullname,LastWriteTimeUTC,LastAccessTimeUTC,Length | Format-Table -auto | Out-String -width 300
# Get Program Files (x86)
"`n[+] System Drive - Program Files (x86):`n"
GCI "$ENV:ProgramFiles (x86)\" | Select-Object Fullname,LastWriteTimeUTC,LastAccessTimeUTC,Length | Format-Table -auto | Out-String -width 300
# Get %USERPROFILE%\Desktop top level file listing
"`n[+] Current User Desktop:`n"
GCI $ENV:USERPROFILE\Desktop | Select-Object Fullname,LastWriteTimeUTC,LastAccessTimeUTC,Length | Format-Table -auto | Out-String -width 300
# Get %USERPROFILE%\Documents top level file listing
"`n[+] Current User Documents:`n"
GCI $ENV:USERPROFILE\Documents | Select-Object Fullname,LastWriteTimeUTC,LastAccessTimeUTC,Length | Format-Table -auto | Out-String -width 300
# Get Files in the %USERPROFILE% directory with certain extensions or phrases
"`n[+] Current User Profile (*pass*,*diagram*,*.pdf,*.vsd,*.doc,*docx,*.xls,*.xlsx,*.kdbx,*.key,KeePass.config):`n"
GCI $ENV:USERPROFILE\ -recurse -include *pass*,*diagram*,*.pdf,*.vsd,*.doc,*docx,*.xls,*.xlsx,*.kdbx,*.key,KeePass.config | Select-Object Fullname,LastWriteTimeUTC,LastAccessTimeUTC,Length | Format-Table -auto | Out-String -width 300
# Get Powershell History
"`n[+] Current User Powershell Console History:`n`n"
Try {
$PowershellHistory = (Get-PSReadlineOption).HistorySavePath
(Get-Content $PowershellHistory -EA 0 |select -last 50) -join "`r`n"
} Catch [System.Management.Automation.CommandNotFoundException]{