-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSokol.ps1
811 lines (662 loc) · 31 KB
/
Sokol.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
Param (
[Parameter(Mandatory = $false)]
[string] $module,
[Parameter(Mandatory = $false)]
[string] $folder = "C:\Windows\Temp\IR"
)
[string] $date = Get-Date -Format yyyyMMddHHmmss
[string] $ComputerName = $Env:COMPUTERNAME
function usage {
Write-Output "
PARAMETERS
-module all : run all modules
-module <name> : run specific module
-folder <path> : output folder [Default: C:\Windows\Temp\IR]
-module help : display usage
MODULES
{Malware - Persistence}
AutoRuns : Gather files in common startup locations
Services : Gather Windows Services
InstalledSoftware : Gather Installed Software from Uninstall Key
DNSCache : Get clients local DNS cache
RunningProcesses : Get all running processes and hashes
{Forensics - Evidence of Execution}
Prefetch : Get list of files in prefetch
PEFiles : Get list of PE files and hashes in user writeable locations
JumpLists : Get a copy of JumpLists (AutomaticDestinations & CustomDestinations)
SRUM : Get a copy of SRUDB.DAT
{Forensics - Deleted Items & File Existence}
RecycleBin : Get a copy of the contents of $Recycle.Bin
Thumbcache : Get a copy of the Thumbcache from user's %AppData% folder
WordWheelQuery : Get a copy of WordWheelQuery key from NTUSER.DAT hive
UserTypedPaths : Get a copy of TypedPaths from NTUSER.DAT hive
{Forensics - Files & Folders Opened}
LNKFiles : Get LNK files on desktop and recent files list
OpenSaveMRU : Get a copy of OpenSavePidlMRU from NTUSER.DAT hive
OfficeRecentfiles : Get Office file MRU lists from NTUSER.DAT hive
{Malware - Miscellaneous}
OfficeFiles : Get list of office docs and hashes in user writeable locations
ScriptFiles : Get list of scripts and hashes in user writeable locations
{Forensics - Miscellaneous}
EventLogs : Gather Event Logs
HiddenFilesDirs : Get hidden files and directories
WindowsUpdates : Get installed windows updates
BrowserExtensions : Get list of extensions for Chrome and Firefox
KrbSessions : Get list of kerberos sessions
Recall : Gathers screenshots and other data from Microsoft's Recall feature"
}
# Ensure the output directory exists
if (-Not (Test-Path $folder)) {
New-Item -Path $folder -Type Directory -Force | Out-Null
}
$Global:irPath = $folder
# [START] Malware - Persistence
function Get-AutoRuns {
Write-Output "[+] Gathering Windows AutoRuns ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_AutoRuns.csv"
$results = Get-CimInstance -Class Win32_StartupCommand | Select-Object Name, Caption, Description, Command, Location, User
$results | Export-Csv -NoTypeInformation -Path $outputFile
Write-Output "[ done ]"
}
function Get-Services {
Write-Output "[+] Gathering Windows Services ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_Services.csv"
$results = Get-CimInstance -Class Win32_Service -Filter "Caption LIKE '%'" | Select-Object Caption, Description, DisplayName, Name, PathName, ProcessId, StartMode, State, Status
$results | Export-Csv -NoTypeInformation -Path $outputFile
Write-Output "[ done ]"
}
function Get-InstalledSoftware {
Write-Output "[+] Gathering Installed Software ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_InstalledSoftware.csv"
$regPaths = @("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\*")
$results = @()
foreach ($path in $regPaths) {
$results = $results + (Get-ItemProperty -Path "Registry::$path" | Where-Object DisplayName -ne $null | Select-Object Publisher, DisplayName, DisplayVersion, InstallDate, InstallSource, InstallLocation)
}
$results | Export-Csv -NoTypeInformation -Path $outputFile
Write-Output "[ done ]"
}
function Get-DNSCache {
Write-Output "[+] Gathering DNS Client Cache ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_DNSClientCache.csv"
Get-DnsClientCache | Select-Object TTL, Data, DataLength, Entry, Name, TimeToLive, Type | Export-Csv -NoTypeInformation -Path $outputFile
Write-Output "[ done ]"
}
function Get-RunningProcesses {
Write-Output "[+] Gathering Running Processes ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_Processes.csv"
$procs = Get-Process -IncludeUserName
foreach ($proc in $procs) {
$procInfo = Get-CimInstance Win32_Process | Where-Object ProcessID -eq $proc.Id | Select-Object -Property Path, CommandLine
$proc | Add-Member -MemberType NoteProperty -Name "CommandLine" -Value $procInfo.CommandLine
$proc | Add-Member -MemberType NoteProperty -Name "Hash" -Value $procInfo.Path
}
$results = Get-Process | Select-Object Id, Name, ProcessName, Path, Hash, FileVersion, CommandLine, Company, Product, Description, StartTime
$results | Export-CSV -NoTypeInformation -Path $outputFile
Write-Output "[ done ]"
}
# [END] Malware - Persistence
# [START] Forensics - Evidence of Execution
function Get-Prefetch {
Write-Output "[+] Gathering Prefetch Cache ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_Prefetch.csv"
$results = Get-ChildItem -Path "C:\Windows\Prefetch\" -Filter *.pf -ErrorAction SilentlyContinue | Select-Object Name, FullName, CreationTimeUtc, LastAccessTimeUtc, LastWriteTimeUtc
$results | Export-Csv -NoTypeInformation -Path $outputFile
Write-Output "[ done ]"
}
function Get-PEFiles {
Write-Output "[+] Gathering list of PE files in TEMP locations ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_PEFiles.csv"
$PEExtPattern = ".exe|.dll|.sys"
$filePaths = @(
"${env:TEMP}\*",
"${env:USERPROFILE}\Downloads\*",
"${env:USERPROFILE}\Documents\*",
"${env:LOCALAPPDATA}\Microsoft\Windows\INetCache\Content.Outlook\*",
"${env:windir}\Temp\*"
)
$peFiles = @()
try {
Foreach ($path in $filePaths) {
Get-ChildItem -Force -Recurse -Path $path -Attributes !System, !ReparsePoint -ErrorAction SilentlyContinue |
Where-Object { $_.Extension -match $PEExtPattern } |
ForEach-Object {
$filePath = $_.FullName
$hash = (Get-FileHash -Path $filePath -Algorithm SHA256).Hash
$peFiles += New-Object PSObject -Property @{
Hash = $hash
FilePath = $filePath
}
}
}
}
catch { }
$peFiles | Export-Csv -NoTypeInformation -Path $outputFile
Write-Output "[ done ]"
}
function Get-JumpLists {
Write-Output "[+] Gathering JumpLists ..."
$ir_jumplists_path = Join-Path $Global:irPath "${ComputerName}_JumpLists"
New-Item -Path $ir_jumplists_path -Type Directory -Force | Out-Null
$jumplist_paths = @("${env:APPDATA}\Microsoft\Windows\Recent\AutomaticDestinations", "${env:APPDATA}\Microsoft\Windows\Recent\CustomDestinations")
foreach ($path in $jumplist_paths) {
$jumplists = Get-ChildItem -Path $path -Recurse -ErrorAction SilentlyContinue
foreach ($file in $jumplists) {
Copy-Item -Path $file.FullName -Destination $ir_jumplists_path -ErrorAction SilentlyContinue
}
}
Write-Output "[ done ]"
}
function Get-SRUM {
Write-Output "[+] Gathering SRUM data ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_SRUDB.DAT"
$srum_path = "C:\Windows\System32\sru\SRUDB.dat"
if (Test-Path $srum_path) {
Copy-Item -Path $srum_path -Destination $outputFile
}
Write-Output "[ done ]"
}
# [END] Forensics - Evidence of Execution
# [START] Forensics - Deleted Items & File Existence
function Get-RecycleBin {
Write-Output "[+] Gathering Recycle Bin contents ..."
$ir_recyclebin_path = Join-Path $Global:irPath "${ComputerName}_RecycleBin"
New-Item -Path $ir_recyclebin_path -Type Directory -Force | Out-Null
$recycleBinPath = "C:\$Recycle.Bin\*"
$recycleBinItems = Get-ChildItem -Path $recycleBinPath -Recurse -ErrorAction SilentlyContinue
foreach ($item in $recycleBinItems) {
Copy-Item -Path $item.FullName -Destination $ir_recyclebin_path -ErrorAction SilentlyContinue
}
Write-Output "[ done ]"
}
function Get-Thumbcache {
Write-Output "[+] Gathering Thumbcache ..."
$ir_thumbcache_path = Join-Path $Global:irPath "${ComputerName}_Thumbcache"
New-Item -Path $ir_thumbcache_path -Type Directory -Force | Out-Null
$thumbcachePath = "C:\Users\*\AppData\Local\Microsoft\Windows\Explorer\thumbcache_*"
$thumbcacheItems = Get-ChildItem -Path $thumbcachePath -Recurse -ErrorAction SilentlyContinue
foreach ($item in $thumbcacheItems) {
Copy-Item -Path $item.FullName -Destination $ir_thumbcache_path -ErrorAction SilentlyContinue
}
Write-Output "[ done ]"
}
function Get-WordWheelQuery {
Write-Output "[+] Gathering WordWheelQuery from NTUSER.DAT ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_WordWheelQuery.txt"
$ntuserPath = "C:\Users\*\NTUSER.DAT"
$users = Get-ChildItem "C:\Users" | Where-Object { Test-Path "$($_.FullName)\NTUSER.DAT" }
foreach ($user in $users) {
$username = $user.Name
$ntuser = "$($user.FullName)\NTUSER.DAT"
if (Test-Path $ntuser) {
reg.exe load HKU\TempHive $ntuser | Out-Null
$wordWheelQuery = Get-ItemProperty -Path "HKU\TempHive\Software\Microsoft\Windows\CurrentVersion\Explorer\WordWheelQuery"
reg.exe unload HKU\TempHive | Out-Null
Add-Content -Path $outputFile -Value "[$username]"
Add-Content -Path $outputFile -Value $wordWheelQuery
Add-Content -Path $outputFile -Value ""
}
}
Write-Output "[ done ]"
}
function Get-OfficeRecentFiles {
Write-Output "[+] Gathering Office Recent Files from NTUSER.DAT ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_OfficeRecentFiles.csv"
$results = @()
$ntuserPath = "C:\Users\*\NTUSER.DAT"
$users = Get-ChildItem "C:\Users" | Where-Object { Test-Path "$($_.FullName)\NTUSER.DAT" }
foreach ($user in $users) {
$username = $user.Name
$ntuser = "$($user.FullName)\NTUSER.DAT"
if (Test-Path $ntuser) {
reg.exe load HKU\TempHive $ntuser | Out-Null
$officeVersions = Get-ChildItem -Path "HKU\TempHive\Software\Microsoft\Office\" | Select-Object -ExpandProperty Name
foreach ($version in $officeVersions) {
$apps = Get-ChildItem -Path "HKU\TempHive\Software\Microsoft\Office\$version\" | Select-Object -ExpandProperty Name
foreach ($app in $apps) {
$mruPath = "HKU\TempHive\Software\Microsoft\Office\$version\$app\File MRU"
$liveIdMruPath = "HKU\TempHive\Software\Microsoft\Office\$version\$app\LiveId_*\File MRU"
$adMruPath = "HKU\TempHive\Software\Microsoft\Office\$version\$app\AD_*\File MRU"
# Collect MRU entries
foreach ($path in @($mruPath, $liveIdMruPath, $adMruPath)) {
try {
$mruEntries = Get-ItemProperty -Path $path -ErrorAction Stop
foreach ($property in $mruEntries.PSObject.Properties) {
if ($property.Name -match "Item") {
$results += [PSCustomObject]@{
Username = $username
OfficeApp = $app
Version = $version
MRUPath = $path
MRUEntry = $property.Value
}
}
}
} catch {
# Handle the error if the path does not exist
}
}
}
}
reg.exe unload HKU\TempHive | Out-Null
}
}
$results | Export-Csv -Path $outputFile -NoTypeInformation
Write-Output "[ done ]"
}
function Get-UserTypedPaths {
Write-Output "[+] Gathering UserTypedPaths from NTUSER.DAT ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_UserTypedPaths.txt"
$ntuserPath = "C:\Users\*\NTUSER.DAT"
$users = Get-ChildItem "C:\Users" | Where-Object { Test-Path "$($_.FullName)\NTUSER.DAT" }
foreach ($user in $users) {
$username = $user.Name
$ntuser = "$($user.FullName)\NTUSER.DAT"
if (Test-Path $ntuser) {
reg.exe load HKU\TempHive $ntuser | Out-Null
$userTypedPaths = Get-ItemProperty -Path "HKU\TempHive\Software\Microsoft\Windows\CurrentVersion\Explorer\TypedPaths"
reg.exe unload HKU\TempHive | Out-Null
Add-Content -Path $outputFile -Value "[$username]"
Add-Content -Path $outputFile -Value $userTypedPaths
Add-Content -Path $outputFile -Value ""
}
}
Write-Output "[ done ]"
}
# [END] Forensics - Deleted Items & File Existence
# [START] Forensics - Files & Folders Opened
function Get-LnkFiles {
Write-Output "[+] Gathering LNK files ..."
$ir_lnkfiles_path = Join-Path $Global:irPath "${ComputerName}_LnkFiles"
New-Item -Path $ir_lnkfiles_path -Type Directory | Out-Null
$lnkfiles_path = @("${env:LOCALAPPDATA}\Microsoft\Windows\Recent\", "${env:LOCALAPPDATA}\Microsoft\Office\Recent\", "C:\Users\*\Desktop\")
foreach ($path in $lnkfiles_path) {
$lnk_files = Get-ChildItem -Path $path -Filter *.lnk -Recurse -ErrorAction SilentlyContinue
foreach ($file in $lnk_files) {
Copy-Item -Path $file.FullName -Destination $ir_lnkfiles_path -ErrorAction SilentlyContinue
}
}
}
# [END] Forensics - Files & Folders Opened
# [START] Malware - Miscellaneous
function Get-OfficeFiles {
Write-Output "[+] Gathering list of Office files in TEMP locations ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_OfficeFiles.csv"
$PEExtPattern = ".docx|.docm|.xlsx|.xlsm|.pptx|.pptm"
$filePaths = @(
"${env:TEMP}\*",
"${env:USERPROFILE}\Downloads\*",
"${env:USERPROFILE}\Documents\*",
"${env:LOCALAPPDATA}\Microsoft\Windows\INetCache\Content.Outlook\*",
"${env:windir}\Temp\*"
)
$peFiles = @()
try {
Foreach ($path in $filePaths) {
Get-ChildItem -Force -Recurse -Path $path -Attributes !System, !ReparsePoint -ErrorAction SilentlyContinue |
Where-Object { $_.Extension -match $PEExtPattern } |
ForEach-Object {
$filePath = $_.FullName
$hash = (Get-FileHash -Path $filePath -Algorithm SHA256).Hash
$peFiles += New-Object PSObject -Property @{
Hash = $hash
FilePath = $filePath
}
}
}
}
catch { }
$peFiles | Export-Csv -NoTypeInformation -Path $outputFile
Write-Output "[ done ]"
}
function Get-ScriptFiles {
Write-Output "[+] Gathering list of Script files in TEMP locations ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_ScriptFiles.csv"
$PEExtPattern = ".bat|.vbs|.cmd|.js|.com|.ps1|.psm|.psm1|.psd"
$filePaths = @(
"${env:TEMP}\*",
"${env:USERPROFILE}\Downloads\*",
"${env:USERPROFILE}\Documents\*",
"${env:LOCALAPPDATA}\Microsoft\Windows\INetCache\Content.Outlook\*",
"${env:windir}\Temp\*"
)
$peFiles = @()
try {
Foreach ($path in $filePaths) {
Get-ChildItem -Force -Recurse -Path $path -Attributes !System, !ReparsePoint -ErrorAction SilentlyContinue |
Where-Object { $_.Extension -match $PEExtPattern } |
ForEach-Object {
$filePath = $_.FullName
$hash = (Get-FileHash -Path $filePath -Algorithm SHA256).Hash
$peFiles += New-Object PSObject -Property @{
Hash = $hash
FilePath = $filePath
}
}
}
}
catch { }
$peFiles | Export-Csv -NoTypeInformation -Path $outputFile
Write-Output "[ done ]"
}
# [END] Malware - Miscellaneous
# [START] Forensics - Miscellaneous
function Get-EventLogs {
Write-Output "[+] Gathering Event Logs ..."
$ir_evtx_path = Join-Path $Global:irPath "${ComputerName}_evtx"
New-Item -Path $ir_evtx_path -Type Directory | Out-Null
$evtx_files = Get-ChildItem -Path "C:\Windows\system32\winevt\logs\" -Filter *.evtx -ErrorAction SilentlyContinue
foreach ($file in $evtx_files) {
Copy-Item -Path $file.FullName -Destination $ir_evtx_path -ErrorAction SilentlyContinue
}
Write-Output "[ done ]"
}
function Get-Hidden {
Write-Output "[+] Gathering hidden files and directories ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_HiddenFilesDirs.csv"
Get-ChildItem C:\ -Recurse -Hidden -ErrorAction SilentlyContinue | Export-Csv -Path $outputFile -NoTypeInformation
Write-Output "[ done ]"
}
function Get-InstalledWindowsUpdates {
Write-Output "[+] Gathering installed Windows Updates and Hotfixes ..."
$outputFileHotFixes = Join-Path $Global:irPath "${ComputerName}_WinHotfixes.csv"
$outputFileWinUpdates = Join-Path $Global:irPath "${ComputerName}_WinUpdates.csv"
Get-HotFix | Select-Object InstalledOn, InstalledBy, HotFixID, Description | Export-Csv -NoTypeInformation -Path $outputFileHotFixes
$session = New-Object -ComObject Microsoft.Update.Session
$searcher = $session.CreateUpdateSearcher()
$searcher.Search("IsInstalled=1").Updates | Select-Object Title | Export-Csv -NoTypeInformation -Path $outputFileWinUpdates
}
function Get-BrowserExtensions {
Write-Output "[+] Gathering browser extensions for all users and major browsers ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_BrowserExtensions.csv"
$chromePath = "C:\Users\*\AppData\Local\Google\Chrome\User Data\Default\Extensions"
$firefoxPath = "C:\Users\*\AppData\Roaming\Mozilla\Firefox\Profiles"
$extArray = @()
# Chrome
$chromeManifests = Get-ChildItem -Path $chromePath -Include manifest.json -Recurse -ErrorAction SilentlyContinue
foreach ($manifest in $chromeManifests) {
$info = Get-Content -Path $manifest.FullName -Raw | ConvertFrom-Json
$manifest.FullName -match 'users\\(.*?)\\appdata' | Out-Null
if ($matches) {
$username = $matches[1]
}
else {
$username = "N/A"
}
$extObject = New-Object -TypeName psobject
Add-Member -InputObject $extObject -MemberType NoteProperty -Name Application -Value "Google Chrome"
Add-Member -InputObject $extObject -MemberType NoteProperty -Name Username -Value $username
Add-Member -InputObject $extObject -MemberType NoteProperty -Name ExtensionName -Value $info.name
Add-Member -InputObject $extObject -MemberType NoteProperty -Name Description -Value ($info.description -replace "`n", " ")
Add-Member -InputObject $extObject -MemberType NoteProperty -Name Version -Value $info.version
Add-Member -InputObject $extObject -MemberType NoteProperty -Name Path -Value $manifest.FullName
$extArray += $extObject
}
# Firefox
$firefoxProfiles = Get-ChildItem -Path $firefoxPath -Include addons.json -Recurse -ErrorAction SilentlyContinue
foreach ($profile in $firefoxProfiles) {
$info = Get-Content -Path $profile.FullName -Raw | ConvertFrom-Json
$profile.FullName -match 'users\\(.*?)\\appdata' | Out-Null
if ($matches) {
$username = $matches[1]
}
else {
$username = "N/A"
}
foreach ($addon in $info.addons) {
$extObject = New-Object -TypeName psobject
Add-Member -InputObject $extObject -MemberType NoteProperty -Name Application -Value "Firefox"
Add-Member -InputObject $extObject -MemberType NoteProperty -Name Username -Value $username
Add-Member -InputObject $extObject -MemberType NoteProperty -Name ExtensionName -Value $addon.name
Add-Member -InputObject $extObject -MemberType NoteProperty -Name Description -Value ($addon.description -replace "`n", " ")
Add-Member -InputObject $extObject -MemberType NoteProperty -Name Version -Value $addon.version
Add-Member -InputObject $extObject -MemberType NoteProperty -Name Path -Value $profile.FullName
$extArray += $extObject
}
}
$extArray | Export-Csv -Path $outputFile -NoTypeInformation
Write-Output "[ done ]"
}
function Get-KrbSessions {
Write-Output "[+] Gathering klist sessions ..."
$outputFile = Join-Path $Global:irPath "${ComputerName}_klistsessions.csv"
$sessions = klist sessions
$klistArray = @()
foreach ($session in $sessions) {
$listNumber = ($session.split(' ')[0] -replace "`n", "")
$sessionNumber = ($session.split(' ')[2] -replace "`n", "")
$logonId = ($session.split(' ')[3] -replace "0:", "" -replace "`n", "")
$identity = ($session.split(' ')[4] -replace "`n", "")
$authType = ($session.split(' ')[5] -replace "`n", "")
$klistObject = New-Object -TypeName psobject
Add-Member -InputObject $klistObject -MemberType NoteProperty -Name ListNumber -Value $listNumber
Add-Member -InputObject $klistObject -MemberType NoteProperty -Name SessionNumber -Value $sessionNumber
Add-Member -InputObject $klistObject -MemberType NoteProperty -Name LogonId -Value $logonId
Add-Member -InputObject $klistObject -MemberType NoteProperty -Name Identity -Value $identity
Add-Member -InputObject $klistObject -MemberType NoteProperty -Name AuthType -Value $authType
$klistArray += $klistObject
}
$klistArray | Export-Csv -Path $outputFile -NoTypeInformation
Write-Output "[ done ]"
Write-Output "[*] Session List"
$sessions
Write-Output ""
Write-Output "Kerberos sessions successfully obtained. To view further details run: klist -li [logon_id]"
}
function Get-Recall {
param (
[string]$FromDate = $null,
[string]$ToDate = $null,
[string]$SearchTerm = $null
)
Write-Output "[+] Gathering contents from Microsoft Recall ..."
function Modify-Permissions {
param (
[string]$Path
)
try {
icacls $Path /grant "$($env:USERNAME):(OI)(CI)F" /T /C /Q | Out-Null
Write-Host "Permissions modified for $Path and all its subdirectories and files" -ForegroundColor Green
} catch {
Write-Host "Failed to modify permissions for $Path: $($_)" -ForegroundColor Red
}
}
$username = $env:USERNAME
$basePath = "C:\Users\$username\AppData\Local\CoreAIPlatform.00\UKP"
if (-Not (Test-Path $basePath)) {
Write-Host "[!] Base path does not exist."
return
}
Modify-Permissions -Path $basePath
$guidFolder = Get-ChildItem -Path $basePath -Directory | Select-Object -First 1
if (-Not $guidFolder) {
Write-Host "[!] Could not find the GUID folder."
return
}
$guidFolderPath = $guidFolder.FullName
Write-Host "[+] Recall folder found: $guidFolderPath"
$dbPath = Join-Path -Path $guidFolderPath -ChildPath "ukg.db"
$imageStorePath = Join-Path -Path $guidFolderPath -ChildPath "ImageStore"
if (-Not (Test-Path $dbPath) -or -Not (Test-Path $imageStorePath)) {
Write-Host "[!] Windows Recall feature not found. Nothing to extract."
return
}
$timestamp = (Get-Date).ToString("yyyy-MM-dd-HH-mm")
$extractionFolder = Join-Path -Path $Global:irPath -ChildPath "${timestamp}_Recall_Extraction"
New-Item -ItemType Directory -Path $extractionFolder -Force | Out-Null
Write-Host "`nCreating extraction folder: $extractionFolder`n"
Copy-Item -Path $dbPath -Destination $extractionFolder
Copy-Item -Path $imageStorePath -Destination (Join-Path -Path $extractionFolder -ChildPath "ImageStore") -Recurse -Force
Get-ChildItem -Path (Join-Path -Path $extractionFolder -ChildPath "ImageStore") | ForEach-Object {
$imagePath = $_.FullName
if (-Not ($imagePath -match "\.jpg$")) {
Rename-Item -Path $imagePath -NewName ($imagePath + ".jpg")
}
}
$dbExtractionPath = Join-Path -Path $extractionFolder -ChildPath "ukg.db"
try {
$conn = [System.Data.SQLite.SQLiteConnection]::new("Data Source=$dbExtractionPath")
$conn.Open()
} catch {
Write-Host "[!] Failed to open SQLite database: $($_)" -ForegroundColor Red
return
}
$cmd = $conn.CreateCommand()
$fromDateTimestamp = if ($FromDate) { [int](([DateTime]::ParseExact($FromDate, "yyyy-MM-dd", $null).ToUniversalTime() - [datetime]'1970-01-01').TotalSeconds * 1000) } else { $null }
$toDateTimestamp = if ($ToDate) { [int](([DateTime]::ParseExact($ToDate, "yyyy-MM-dd", $null).AddDays(1).ToUniversalTime() - [datetime]'1970-01-01').TotalSeconds * 1000) } else { $null }
$query = "SELECT WindowTitle, TimeStamp, ImageToken FROM WindowCapture WHERE (WindowTitle IS NOT NULL OR ImageToken IS NOT NULL)"
$cmd.CommandText = $query
$reader = $cmd.ExecuteReader()
$capturedWindows = @()
$imagesTaken = @()
while ($reader.Read()) {
$windowTitle = $reader["WindowTitle"]
$timestamp = [int]$reader["TimeStamp"]
$imageToken = $reader["ImageToken"]
$readableTimestamp = [datetime]'1970-01-01'.AddMilliseconds($timestamp).ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")
if (($null -eq $fromDateTimestamp -or $fromDateTimestamp -le $timestamp) -and ($null -eq $toDateTimestamp -or $timestamp -lt $toDateTimestamp)) {
if ($windowTitle) {
$capturedWindows += "[$readableTimestamp] $windowTitle"
}
if ($imageToken) {
$imagesTaken += "[$readableTimestamp] $imageToken"
}
}
}
$reader.Close()
$conn.Close()
$capturedWindowsCount = $capturedWindows.Count
$imagesTakenCount = $imagesTaken.Count
$output = @(
"Captured Windows: $capturedWindowsCount",
"Images Taken: $imagesTakenCount"
)
if ($SearchTerm) {
try {
$conn.Open()
$searchQuery = "SELECT c1, c2 FROM WindowCaptureTextIndex_content WHERE c1 LIKE '%$SearchTerm%' OR c2 LIKE '%$SearchTerm%'"
$cmd.CommandText = $searchQuery
$searchReader = $cmd.ExecuteReader()
$searchResults = @()
while ($searchReader.Read()) {
$searchResults += "c1: $($searchReader["c1"]), c2: $($searchReader["c2"])"
}
$searchResultsCount = $searchResults.Count
$output += "Search results for '$SearchTerm': $searchResultsCount"
$searchReader.Close()
} catch {
Write-Host "[!] Failed to execute search query: $($_)" -ForegroundColor Red
} finally {
$conn.Close()
}
}
$recallpath = Join-Path -Path $extractionFolder -ChildPath "Recall.txt"
Set-Content -Path $recallpath -Value "Captured Windows:`n$($capturedWindows -join "`n")`n`nImages Taken:`n$($imagesTaken -join "`n")`n"
if ($SearchTerm) {
Add-Content -Path $recallpath -Value "`nSearch Results:`n$($searchResults -join "`n")"
}
$output | ForEach-Object { Write-Host $_ }
Write-Host "`nSummary of the extraction is available in the file:"
Write-Host "$($recallpath)" -ForegroundColor Yellow
Write-Host "`nFull extraction folder path:"
Write-Host "$($extractionFolder)" -ForegroundColor Yellow
Write-Output "[ done ]"
}
# [END] Forensics - Miscellaneous
$outputLog = "C:\Windows\Temp\IR\0 - Sokol_Output.txt"
Start-Transcript -Path $outputLog -Force
# Function to invoke all modules at once
function Invoke-AllIRModules {
Write-Output "[+] Running all IR modules ..."
# [Malware - Persistence]
Get-AutoRuns
Get-Services
Get-InstalledSoftware
Get-DNSCache
Get-RunningProcesses
# [Forensics - Evidence of Execution]
Get-Prefetch
Get-PEFiles
Get-JumpLists
Get-SRUM
# [Forensics - Deleted Items & File Existence]
Get-RecycleBin
Get-Thumbcache
Get-WordWheelQuery
Get-OfficeRecentFiles
# [Forensics - Files & Folders Opened]
Get-LnkFiles
Get-OfficeRecentFiles
# [Malware - Miscellaneous]
Get-OfficeFiles
Get-ScriptFiles
# [Forensics - Miscellaneous]
Get-EventLogs
Get-Hidden
Get-InstalledWindowsUpdates
Get-BrowserExtensions
Get-KrbSessions
Get-Recall
}
if ($module) {
if (-Not (Test-Path $folder)) {
New-Item -Path $folder -Type Directory -Force | Out-Null
}
$Global:irPath = $folder
switch ($module.ToLower()) {
all { Invoke-AllIRModules }
# [Malware - Persistence]
autoruns { Get-AutoRuns }
services { Get-Services }
installedsoftware { Get-InstalledSoftware }
dnscache { Get-DNSCache }
runningprocesses { Get-RunningProcesses }
# [Forensics - Evidence of Execution]
prefetch { Get-Prefetch }
pefiles { Get-PEFiles }
recyclebin { Get-RecycleBin }
jumplists { Get-JumpLists }
srum { Get-SRUM }
# [Forensics - Deleted Items & File Existence]
thumbcache { Get-Thumbcache }
wordwheelquery { Get-WordWheelQuery }
usertypedpaths { Get-UserTypedPaths }
# [Forensics - Files & Folders Opened]
lnkfiles { Get-LnkFiles }
officerecentfiles { Get-OfficeRecentFiles }
# [Malware - Miscellaneous]
officefiles { Get-OfficeFiles }
scriptfiles { Get-ScriptFiles }
# [Forensics - Miscellaneous]
eventlogs { Get-EventLogs }
hiddenfilesdirs { Get-Hidden }
windowsupdates { Get-InstalledWindowsUpdates }
browserextensions { Get-BrowserExtensions }
krbsessions { Get-KrbSessions }
recall { Get-Recall }
# Usage instructions
help { usage }
default { usage }
}
} else {
usage
exit
}
# Stop the transcript and inform the user
Stop-Transcript
Write-Host "IR artifacts saved in $Global:irPath" -ForegroundColor Yellow -BackgroundColor Black
Write-Host "See the console output in $outputLog" -ForegroundColor Yellow -BackgroundColor Black
# Compress the IR folder into a ZIP file
Write-Output "[+] Compressing the IR folder into IR.zip ..."
$zipFilePath = Join-Path $Global:irPath "IR.zip"
if (Test-Path $zipFilePath) {
Remove-Item -Path $zipFilePath -Force
}
try {
Compress-Archive -Path $Global:irPath\* -DestinationPath $zipFilePath
Write-Output "[ done ]"
Write-Host "IR folder compressed to $zipFilePath" -ForegroundColor Yellow -BackgroundColor Black
} catch {
Write-Output "[!] Failed to compress IR folder: $($_)"
}