-
Notifications
You must be signed in to change notification settings - Fork 29
/
Collect-MemoryDump.ps1
3442 lines (2971 loc) · 180 KB
/
Collect-MemoryDump.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
# Collect-MemoryDump v1.0
#
# @author: Martin Willing
# @copyright: Copyright (c) 2019-2024 Martin Willing. All rights reserved.
# @contact: Any feedback or suggestions are always welcome and much appreciated - [email protected]
# @url: https://lethal-forensics.com/
# @date: 2024-01-06
#
#
# ██╗ ███████╗████████╗██╗ ██╗ █████╗ ██╗ ███████╗ ██████╗ ██████╗ ███████╗███╗ ██╗███████╗██╗ ██████╗███████╗
# ██║ ██╔════╝╚══██╔══╝██║ ██║██╔══██╗██║ ██╔════╝██╔═══██╗██╔══██╗██╔════╝████╗ ██║██╔════╝██║██╔════╝██╔════╝
# ██║ █████╗ ██║ ███████║███████║██║█████╗█████╗ ██║ ██║██████╔╝█████╗ ██╔██╗ ██║███████╗██║██║ ███████╗
# ██║ ██╔══╝ ██║ ██╔══██║██╔══██║██║╚════╝██╔══╝ ██║ ██║██╔══██╗██╔══╝ ██║╚██╗██║╚════██║██║██║ ╚════██║
# ███████╗███████╗ ██║ ██║ ██║██║ ██║███████╗ ██║ ╚██████╔╝██║ ██║███████╗██║ ╚████║███████║██║╚██████╗███████║
# ╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═════╝╚══════╝
#
#
# Dependencies:
# 7-Zip 23.01 Standalone Console (2023-06-20)
# https://www.7-zip.org/download.html
#
# Belkasoft Live RAM Capturer (2018-10-22)
# https://belkasoft.com/ram-capturer
#
# MAGNET DumpIt for Windows (2023-01-17) --> Comae-Toolkit-v20230117
# https://www.magnetforensics.com/resources/magnet-dumpit-for-windows/
# https://support.magnetforensics.com/s/free-tools
#
# Magnet Encrypted Disk Detector v3.1.0 (2022-06-19)
# Requirements: .NET v4.0.30319
# https://www.magnetforensics.com/resources/encrypted-disk-detector/
# https://support.magnetforensics.com/s/free-tools
#
# Magnet RAM Capture v1.2.0 (2019-07-24)
# https://www.magnetforensics.com/resources/magnet-ram-capture/
# https://support.magnetforensics.com/s/free-tools
#
# Magnet RESPONSE v1.7.0 (2023-04-28)
# Requirements: .NET v4.0.30319
# https://www.magnetforensics.com/resources/magnet-response/
# https://support.magnetforensics.com/s/free-tools
#
# PsLoggedOn v1.35 (2016-06-29)
# https://docs.microsoft.com/de-de/sysinternals/downloads/psloggedon
#
# WinPMEM 4.0 RC2 (2020-10-13)
# https://github.com/Velocidex/WinPmem/releases
#
#
# Changelog:
# Version 0.1
# Release Date: 2019-10-25
# Initial Release
#
# Version 0.2
# Release Date: 2020-02-25
# Added: Creating Memory Snapshot w/ DumpIt (Raw Physical Memory Dump)
# Added: Creating Memory Snapshot w/ Magnet RAM Capture (Raw Physical Memory Dump)
# Added: Bitlocker-Protectors
# Added: DeviceGuard
# Added: NTFS “Last Access” Updates
# Added: Code Signing
# Added: Verify File Integrity of Memory Acquisition Tools
# Update: Magnet Forensics Encrypted Disk Detector v2.2.1 --> Magnet Forensics Encrypted Disk Detector v2.2.2
# Fixed: Other minor fixes and improvements
#
# Version 0.3
# Release Date: 2020-04-10
# Update: Comae-Toolkit-3.0.20200219.1 --> Comae-Toolkit-3.0.20200224.1
# Added: Usage of Get-FileHash (if available) instead of certutil.exe for better speed
# Added: Create Time and Last Modified Time of secure archive
# Added: Printing File Hash of secure archive
# Added: Check for active users via PsLoggedOn
# Added: Package script as EXE
# Fixed: Other minor fixes and improvements
#
# Version 0.4
# Release Date: 2020-10-26
# Added: FireEye Endpoint Security
# Added: McAfee Endpoint Security (ENS)
# Added: McAfee VirusScan Enterprise (VSE)
# Added: Get-SecurityProduct
# Added: Get-RoamingProfile
# Added: Get-FolderRedirection
# Update: Comae-Toolkit-3.0.20200224.1 --> Comae-Toolkit-3.0.20200902.2
# Update: Magnet Forensics Encrypted Disk Detector v2.2.2 --> Magnet Forensics Encrypted Disk Detector v3.0
#
# Version: 0.5
# Release Date: 2021-02-15
# Added: Trend Micro Apex One
# Added: PCSystemType
# Added: TRIM (SSD)
# Added: Domain/DomainRole
# Added: DnsClientCache
# Fixed: Other minor fixes and improvements
#
# Version 0.6
# Release Date: 2021-04-24
# Added: Microsoft Defender for Endpoint
# Added: Sophos Endpoint Security and Control (SESC)
# Update: Magnet Forensics Encrypted Disk Detector v3.0 --> Magnet Forensics Encrypted Disk Detector v3.0.1
# Fixed: Minor fixes and improvements
#
# Version 0.7
# Release Date: 2021-11-02
# Update: 7-Zip 9.20 Command Line Version --> 7-Zip 19.00 Standalone Console
# Added: Custom Windows Title
# Added: Error Log
# Added: Self-Signed Code Signature
# Fixed: Minor fixes and improvements
#
# Version: 0.8
# Release Date: 2022-07-19
# Added: Creating Memory Snapshot w/ DumpIt (Microsoft Crash Dump)
# Added: ARM64 Support (DumpIt)
# Added: Cybereason EDR
# Update: 7-Zip 19.00 Standalone Console --> 7-Zip 22.00 Standalone Console
# Update: Magnet Forensics Encrypted Disk Detector v3.0.1 --> Magnet Forensics Encrypted Disk Detector v3.0.2
# Fixed: Other minor fixes and improvements
#
# Version 0.9
# Release Date: 2022-09-26
# Added: Pagefile Collection
# Added: Belkasoft Live RAM Capturer
# Added: Check for enough disk space to save memory dump file (Physical Memory Size + 12.5%)
# Added: Active Connections
# Added: Network ARP Info
# Added: Prefetch Settings
# Added: Prefetch List
# Update: 7-Zip 22.00 Standalone Console --> 7-Zip 22.01 Standalone Console
# Update: DumpIt 3.0.20200902.2 --> DumpIt 3.5.0
# Update: Magnet Forensics Encrypted Disk Detector v3.0.2 --> Magnet Forensics Encrypted Disk Detector v3.1.0
# Fixed: Other minor fixes and improvements
#
# Version 0.9.1
# Release Date: 2022-10-05
# Fixed: ARM64 Support
#
# Version 0.9.2
# Release Date: 2022-11-26
# Update: DumpIt 3.5.0 --> DumpIt 3.6.20220824
#
# Version 0.9.3
# Release Date: 2023-01-30
# Added: Velociraptor
# Added: Cortex XDR (Palo Alto Networks)
# Update: DumpIt 3.6.20220824 --> DumpIt 3.6.20230117
# Fixed: Other minor fixes and improvements
#
# Version 1.0
# Release Date: 2024-01-09
# Added: Pagefile Collection w/ Magnet RESPONSE v1.7.0
# Added: Capturing Running Process/Module Information w/ Magnet RESPONSE v1.7.0
# Added: Error Notification (MessageBox)
# Added: Improved OS Fingerprinting
# Added: Improved LastBoot and Uptime (when Fast Startup is enabled)
# Update: 7-Zip 22.01 Standalone Console --> 7-Zip 23.01 Standalone Console (2023-06-20)
# Fixed: Other minor fixes and improvements
#
#
#############################################################################################################################################################################################
# Hash Values (Whitelisting)
# 7za.exe MD5: 8F57948E69C82BF98704F129C5460576 SHA1: 33E277AF0CEA397252C23D310961F803BE5CDF2B SHA256: F00836A63BE7EBF14E1B8C40100C59777FE3432506B330927EA1F1B7FD47EE44
# DumpIt.exe (ARM64) MD5: 4B39D63B86FFE39BBAE0415C400003C7 SHA1: E08DE257DB9EE0D2AEC8A34433883B025020227B SHA256: 13BCA00D0042748780B761FB93768754DFD96F48944E6CEC75618CAD93B3B5D5
# DumpIt.exe (x64) MD5: 0F10DA3A5EB49D17D73D8E195FE32F85 SHA1: 95F7B26CD15170A3043D6D1F049B2A88FB7A5C5F SHA256: 6A484C1DB7718949C7027ABDE97E164C7E7E4E4214E3E29FE48AC4364C0CD23C
# DumpIt.exe (x86) MD5: 586C57AD0EEA179FCAE4B8BA117F2AB9 SHA1: 31F4ECD04D5A94437A98D09435A2CEAC7DFD57DC SHA256: F4F353821178BDAF3E29B49DB6E6D80C543081AC7A4312E5FDB5583B96815839
# EDDv310.exe MD5: EE4E8097DA5DC038EC3C9B2CB9DB4700 SHA1: 94D250ECA8CD73FB62541E59EC9E6191F71F22A2 SHA256: DE3FC8F41D498D2108DFD52DE8E6200C6271BB45F3FBD6DA5E4C7C648A5BB5B8
# MagnetRESPONSE.exe MD5: 3E9E791F3645E79F55CB9B8930E0EFA2 SHA1: 2FFF9D36D021E3F39B75E41AD147EF191F8F82FC SHA256: 6105794279CEB9A2AD45705F1C6D31A60D0A94A2D16A5181B89ABAD871DAC0AA
# MRCv120.exe MD5: 51D286BDF58359417A28E3132ABA957F SHA1: 6FA7C189B736808C66C82CCF5F4AAA11F995C95A SHA256: 72DC1BA6DDC9D572D70A194EBDF6027039734ECEE23A02751B0B3B3C4EA430DE
# PsLoggedon.exe MD5: E3EA271E748CCDAD6A6D3E692D6F337E SHA1: F02E06BC439A28AAD6DD957DF8D0022F22798A09 SHA256: D689CB1DBD2E4C06CD15E51A6871C406C595790DDCDCD7DC8D0401C7183720EF
# PsLoggedon64.exe MD5: 07ED30D2343BF8914DAAED872B681118 SHA1: 1F5B5E40C420F64AA8E8DE471367E3DECC9763CD SHA256: FDADB6E15C52C41A31E3C22659DD490D5B616E017D1B1AA6070008CE09ED27EA
# RamCapture64.exe MD5: E331F960CDBA675DEA9218EFDED56A5F SHA1: 8BD76FB052A10A3EDA7F85993B4B6766C517C646 SHA256: 3F934019C46763B518C90E9D66088A301BD50FFC7F90D447FF1B54AF96AB9E4E
# RamCapture.exe MD5: FCA60980F235B4EFB3C3119EF4584FFF SHA1: 465F8F1BEFC212700EA1A71F5CE6F6899A707612 SHA256: 6E2C3E0CE3ABBD8D027E77D210891F2F835400856F36BB70AEA47598F1C5B131
# winpmem_mini_x64_rc2.exe MD5: 9DD3160679832165738BFABD7279ACEB SHA1: E460CA732204740674C27073E0FA478F334420FC SHA256: A4D516B6FCAF3B5B1D4EE709CE86F8EABF1D8028B3A83101479B7568B933D21B
# winpmem_mini_x86.exe MD5: C2BC7851F966BC39068345FB24BC8740 SHA1: F552A8C22D589471BE582BF884AA5624C967760B SHA256: DC6A82FC6CFDA792D3182E07DE10ADBFBA42BF336EF269DBC40732C4B2AE052C
#############################################################################################################################################################################################
#region Arguments
Function HelpMessage
{
Write-Output ""
Write-Output "Collect-MemoryDump v1.0 - Automated Creation of Windows Memory Snapshots for DFIR"
Write-Output "(c) 2019-2024 Martin Willing at Lethal-Forensics (https://lethal-forensics.com/)"
Write-Output ""
Write-Output "Usage: .\Collect-MemoryDump.ps1 [-Tool] [--Pagefile]"
Write-Output ""
Write-Output "Tools:"
Write-Output "-Comae Memory Snapshot will be collected w/ DumpIt (Microsoft Crash Dump)"
Write-Output "-DumpIt Memory Snapshot will be collected w/ DumpIt (Raw Physical Memory Dump)"
Write-Output "-RamCapture Memory Snapshot will be collected w/ Magnet Ram Capture (Raw Physical Memory Dump)"
Write-Output "-WinPMEM Memory Snapshot will be collected w/ WinPMEM (Raw Physical Memory Dump)"
Write-Output "-Belkasoft Memory Snapshot will be collected w/ Belkasoft Live Ram Capturer (Raw Physical Memory Dump)"
Write-Output ""
Write-Output "Optional:"
Write-Output "--Pagefile In addition, Pagefile(s) will be collected w/ Magnet RESPONSE"
Write-Output ""
Write-Output "Examples:"
Write-Output ".\Collect-MemoryDump.ps1 -Comae"
Write-Output ".\Collect-MemoryDump.ps1 -DumpIt"
Write-Output ".\Collect-MemoryDump.ps1 -WinPMEM"
Write-Output ".\Collect-MemoryDump.ps1 -RamCapture"
Write-Output ".\Collect-MemoryDump.ps1 -Belkasoft"
Write-Output ".\Collect-MemoryDump.ps1 -DumpIt --Pagefile"
Write-Output ".\Collect-MemoryDump.ps1 -WinPMEM --Pagefile"
Write-Output ""
Exit
}
# Arguments
# Check if an argument was provided
if($Args.Count -eq 0)
{
HelpMessage
}
# Check if more than 2 arguments were provided
if($Args.Count -gt 2)
{
HelpMessage
}
# Validate $Args[0]
if ($Args[0])
{
$Tool = ($Args[0] | Out-String).Trim()
if (($Tool -ne "-DumpIt") -and ($Tool -ne "-RamCapture") -and ($Tool -ne "-WinPMEM") -and ($Tool -ne "-Comae") -and ($Tool -ne "-Belkasoft"))
{
HelpMessage
}
}
# Validate $Args[1]
if ($Args[1])
{
$Pagefile = ($Args[1] | Out-String).Trim()
if (!($Pagefile -eq "--Pagefile"))
{
HelpMessage
}
}
#endregion Arguments
#############################################################################################################################################################################################
#region Declarations
# Declarations
# Script Root
if ($PSVersionTable.PSVersion.Major -gt 2)
{
# PowerShell 3+
$SCRIPT_DIR = $PSScriptRoot
}
else
{
# PowerShell 2
$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition
}
# Acquisition date (ISO 8601)
$Date = [datetime]::Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss") # YYYY-MM-DDThh:mm:ss
$Timestamp = $Date -replace ":", "" # YYYY-MM-DDThhmmss
# Output Directory
$OUTPUT_FOLDER = "$SCRIPT_DIR\$env:COMPUTERNAME\$Timestamp-Collect-MemoryDump"
# Logfile Directory
$LOG_DIR = "$SCRIPT_DIR\$env:COMPUTERNAME"
# Tools
# 7-Zip
$7za = "$SCRIPT_DIR\Tools\7-Zip\7za.exe"
# Belkasoft Live RAM Capturer
# x64
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64")
{
$Belkasoft = "$SCRIPT_DIR\Tools\RamCapturer\x64\RamCapture64.exe"
}
# x86
if ($env:PROCESSOR_ARCHITECTURE -eq "x86")
{
$Belkasoft = "$SCRIPT_DIR\Tools\RamCapturer\x86\RamCapture.exe"
}
# DumpIt
# ARM64
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64")
{
$DumpIt = "$SCRIPT_DIR\Tools\DumpIt\ARM64\DumpIt.exe"
}
# x64
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64")
{
$DumpIt = "$SCRIPT_DIR\Tools\DumpIt\x64\DumpIt.exe"
}
# x86
if ($env:PROCESSOR_ARCHITECTURE -eq "x86")
{
$DumpIt = "$SCRIPT_DIR\Tools\DumpIt\x86\DumpIt.exe"
}
# Magnet Forensics Encrypted Disk Detector (EDD)
$EDD = "$SCRIPT_DIR\Tools\EDD\EDDv310.exe"
# Magnet RAM Capture (MRC)
$MRC = "$SCRIPT_DIR\Tools\MRC\MRCv120.exe"
# Magnet RESPONSE
$MagnetRESPONSE = "$SCRIPT_DIR\Tools\MagnetRESPONSE\MagnetRESPONSE.exe"
# PsLoggedOn
# x64
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64")
{
$PsLoggedOn = "$SCRIPT_DIR\Tools\PsLoggedOn\PsLoggedon64.exe"
}
# x86
if ($env:PROCESSOR_ARCHITECTURE -eq "x86")
{
$PsLoggedOn = "$SCRIPT_DIR\Tools\PsLoggedOn\PsLoggedon.exe"
}
# WinPMEM
# x64
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64")
{
$WinPMEM = "$SCRIPT_DIR\Tools\WinPMEM\winpmem_mini_x64_rc2.exe"
}
# x86
if ($env:PROCESSOR_ARCHITECTURE -eq "x86")
{
$WinPMEM = "$SCRIPT_DIR\Tools\WinPMEM\winpmem_mini_x86.exe"
}
# Secure Archive Password
$PASSWORD = "IncidentResponse"
#endregion Declarations
#############################################################################################################################################################################################
#region Header
# Check if the PowerShell script is being run with admin rights
if (!([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
Write-Output "[Error] This PowerShell script must be run with admin rights."
Exit
}
# Check if the PowerShell script is being run in Windows PowerShell ISE
if ($psISE)
{
Write-Output "[Error] This PowerShell script must be run in Windows PowerShell."
Exit
}
# Windows Title
$script:DefaultWindowsTitle = $Host.UI.RawUI.WindowTitle
$Host.UI.RawUI.WindowTitle = "Collect-MemoryDump v1.0 - Automated Creation of Windows Memory Snapshots for DFIR"
# Add the required MessageBox class (Windows PowerShell)
Add-Type -AssemblyName System.Windows.Forms
# Function Get-FileSize
Function script:Get-FileSize() {
Param ([long]$Length)
if ($Length -gt 1TB) {[string]::Format("{0:0.00} TB", $Length / 1TB)}
elseIf ($Length -gt 1GB) {[string]::Format("{0:0.00} GB", $Length / 1GB)}
elseIf ($Length -gt 1MB) {[string]::Format("{0:0.00} MB", $Length / 1MB)}
elseIf ($Length -gt 1KB) {[string]::Format("{0:0.00} KB", $Length / 1KB)}
elseIf ($Length -gt 0) {[string]::Format("{0:0.00} Bytes", $Length)}
else {""}
}
# Function Test-RegistryValue
Function Test-RegistryValue
{
param([string]$Path,[string]$Value)
$ValueExist = $null -ne (Get-ItemProperty $Path).$Value
Return $ValueExist
}
# Get Start Time
$startTime = (Get-Date)
# Creating Output Directory
New-Item "$OUTPUT_FOLDER" -ItemType Directory -Force | Out-Null
# Logo
$Logo = @"
██╗ ███████╗████████╗██╗ ██╗ █████╗ ██╗ ███████╗ ██████╗ ██████╗ ███████╗███╗ ██╗███████╗██╗ ██████╗███████╗
██║ ██╔════╝╚══██╔══╝██║ ██║██╔══██╗██║ ██╔════╝██╔═══██╗██╔══██╗██╔════╝████╗ ██║██╔════╝██║██╔════╝██╔════╝
██║ █████╗ ██║ ███████║███████║██║█████╗█████╗ ██║ ██║██████╔╝█████╗ ██╔██╗ ██║███████╗██║██║ ███████╗
██║ ██╔══╝ ██║ ██╔══██║██╔══██║██║╚════╝██╔══╝ ██║ ██║██╔══██╗██╔══╝ ██║╚██╗██║╚════██║██║██║ ╚════██║
███████╗███████╗ ██║ ██║ ██║██║ ██║███████╗ ██║ ╚██████╔╝██║ ██║███████╗██║ ╚████║███████║██║╚██████╗███████║
╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═════╝╚══════╝
"@
Write-Output ""
Write-Output "$Logo"
Write-Output ""
Write-Output "" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
Write-Output "$Logo" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
Write-Output "" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
# Header
Write-Output "Collect-MemoryDump v1.0 - Automated Creation of Windows Memory Snapshots for DFIR"
Write-Output "(c) 2019-2024 Martin Willing at Lethal-Forensics (https://lethal-forensics.com/)"
Write-Output ""
Write-Output "Collect-MemoryDump v1.0 - Automated Creation of Windows Memory Snapshots for DFIR" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
Write-Output "(c) 2019-2024 Martin Willing at Lethal-Forensics (https://lethal-forensics.com/)" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
Write-Output "" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
# Acquisition date (ISO 8601)
$AcquisitionDate = $Date -replace “T”, " " # YYYY-MM-DD hh:mm:ss
Write-Output "Acquisition date: $AcquisitionDate UTC"
Write-Output ""
Write-Output "Acquisition date: $AcquisitionDate UTC" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
Write-Output "" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
# Hostname
Write-Output "[Info] Host Name: $env:COMPUTERNAME"
Write-Output "[Info] Host Name: $env:COMPUTERNAME" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
#endregion Header
#############################################################################################################################################################################################
#region Pagefile
# Note: Save the pagefile.sys file immediately after capturing RAM.
Function Get-Pagefile
{
# Magnet RESPONSE
if (Test-Path "$MagnetRESPONSE")
{
# Verify File Integrity
$certUtil = "$env:SystemDrive\Windows\System32\certutil.exe"
$MD5 = (((& $certUtil -hashfile "$MagnetRESPONSE" MD5) -replace '\s', '' | Select-String -Pattern "^[0-9a-f]{32}$" | Out-String).Trim()).ToUpper()
if ($MD5 -eq "3E9E791F3645E79F55CB9B8930E0EFA2")
{
# PageFileInfo
New-Item "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo" -ItemType Directory -Force | Out-Null
# AutomaticManagedPagefile
[string]$AutomaticManagedPagefile = (Get-WmiObject -Class Win32_ComputerSystem -Namespace 'root\cimv2' | Select-Object AutomaticManagedPagefile).AutomaticManagedPagefile
# Automatically manage paging file size for all drives
if ($AutomaticManagedPagefile -eq "True")
{
Write-Output "[Info] AutomaticManagedPagefile: True (Default: True)" | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\AutomaticManagedPagefile.txt"
Write-Output " Note: The automatic system page file management is enabled for all drives." | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\AutomaticManagedPagefile.txt" -Append
}
# Custom size, System managed size, No paging file
if ($AutomaticManagedPagefile -eq "False")
{
Write-Output "[Info] AutomaticManagedPagefile: False (Default: True)" | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\AutomaticManagedPagefile.txt"
Write-Output " Note: It seems that the automatic system page file management is disabled (for all drives)." | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\AutomaticManagedPagefile.txt" -Append
}
# DisablePagingExecutive - Specifies whether kernel-mode drivers and kernel-mode system code can be paged to disk when not in use (Default Value: 0).
$CurrentControlSet = (Get-ItemProperty "HKLM:\SYSTEM\Select" -Name Current).Current
$DisablePagingExecutive = (Get-ItemProperty "HKLM:\System\ControlSet00$CurrentControlSet\Control\Session Manager\Memory Management" -Name DisablePagingExecutive).DisablePagingExecutive
if ($DisablePagingExecutive -eq "0")
{
Write-Output "[Info] DisablePagingExecutive: 0 (Default Value: 0)" | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\DisablePagingExecutive.txt"
Write-Output " Note: Drivers and system code can be paged to disk as needed." | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\DisablePagingExecutive.txt" -Append
}
if ($DisablePagingExecutive -eq "1")
{
Write-Output "[Info] DisablePagingExecutive: 1 (Default Value: 0)" | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\DisablePagingExecutive.txt"
Write-Output " Note: Drivers and system code must remain in physical memory." | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\DisablePagingExecutive.txt" -Append
}
# NTFS Pagefile Encryption --> Encrypting File System (EFS)
$CurrentControlSet = (Get-ItemProperty "HKLM:\SYSTEM\Select" -Name Current).Current
$NtfsEncryptPagingFile = (Get-ItemProperty "HKLM:\SYSTEM\ControlSet00$CurrentControlSet\Control\FileSystem" -Name NtfsEncryptPagingFile).NtfsEncryptPagingFile
switch($NtfsEncryptPagingFile)
{
"0" { $PagefileEncryption = "Disabled" }
"1" { $PagefileEncryption = "Enabled" }
}
Write-Output "[Info] NTFS Pagefile Encryption: $PagefileEncryption" | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\NtfsEncryptPagingFile.txt"
# ExistingPageFiles (REG_MULTI_SZ)
$CurrentControlSet = (Get-ItemProperty "HKLM:\SYSTEM\Select" -Name Current).Current
(Get-ItemProperty "HKLM:\SYSTEM\ControlSet00$CurrentControlSet\Control\Session Manager\Memory Management" -Name ExistingPageFiles).ExistingPageFiles | ForEach-Object{($_ -replace "^\\\?\?\\","")} | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\ExistingPageFiles.txt"
# PagingFiles (REG_MULTI_SZ)
$CurrentControlSet = (Get-ItemProperty "HKLM:\SYSTEM\Select" -Name Current).Current
(Get-ItemProperty "HKLM:\SYSTEM\ControlSet00$CurrentControlSet\Control\Session Manager\Memory Management" -Name PagingFiles).PagingFiles | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\PagingFiles.txt"
# PagefileOnOsVolume
$CurrentControlSet = (Get-ItemProperty "HKLM:\SYSTEM\Select" -Name Current).Current
if (Test-RegistryValue -Path "HKLM:\SYSTEM\ControlSet00$CurrentControlSet\Control\Session Manager\Memory Management" -Value "PagefileOnOsVolume")
{
$PagefileOnOsVolume = (Get-ItemProperty "HKLM:\SYSTEM\ControlSet00$CurrentControlSet\Control\Session Manager\Memory Management" -Name PagefileOnOsVolume).PagefileOnOsVolume
Write-Output "$PagefileOnOsVolume" | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\PagefileOnOsVolume.txt"
}
# ClearPageFileAtShutdown - Specifies whether inactive pages in the paging file are filled with zeros when the system stops (Default Value: 0).
$CurrentControlSet = (Get-ItemProperty "HKLM:\SYSTEM\Select" -Name Current).Current
$ClearPageFileAtShutdown = (Get-ItemProperty "HKLM:\System\ControlSet00$CurrentControlSet\Control\Session Manager\Memory Management" -Name ClearPageFileAtShutdown).ClearPageFileAtShutdown
if ($ClearPageFileAtShutdown -eq "0")
{
Write-Output "[Info] ClearPageFileAtShutdown: 0 (Default Value: 0)" | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\ClearPageFileAtShutdown.txt"
Write-Output " Note: Inactive pages are not filled with zeros." | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\ClearPageFileAtShutdown.txt" -Append
}
if ($ClearPageFileAtShutdown -eq "1")
{
Write-Output "[Info] ClearPageFileAtShutdown: 1 (Default Value: 0)" | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\ClearPageFileAtShutdown.txt"
Write-Output " Note: Inactive pages are filled with zeros." | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\ClearPageFileAtShutdown.txt" -Append
}
# Check if it is an Array --> Multiple Pagefiles
$PageFileList = Get-WmiObject -Class Win32_PageFile
if ($PageFileList -is [array])
{
# Count Pagefiles
# Note: Windows supports up to 16 paging files; however, normally only one is used.
$Count = $PageFileList.Length
if ($Count -gt 0)
{
Write-Output "[Info] $Count Page File(s) found"
Write-Output "[Info] $Count Page File(s) found" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
}
else
{
Write-Output "[Info] No Page File found"
}
$i = 1
foreach ($PageFile in $PageFileList)
{
# Name
$Name = ($PageFile | Select-Object -Property Name).Name
# File Size
$Bytes = ($PageFile | Select-Object -Property FileSize).FileSize
$FileSize = Get-FileSize($Bytes)
Write-Output "[Info] Pagefile #$i`: $Name [$FileSize]"
Write-Output "[Info] Pagefile #$i`: $Name [$FileSize]" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
$i += 1
}
}
else
{
# Name
$Name = (Get-WmiObject -Class Win32_PageFileUsage | Select-Object -Property Name).Name
Write-Output "[Info] Pagefile Name: $Name"
Write-Output "[Info] PageFile Name: $Name" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
# File Size
$AllocatedBaseSize = (Get-WmiObject -Class Win32_PageFileUsage | Select-Object -Property AllocatedBaseSize).AllocatedBaseSize
$Length = ($AllocatedBaseSize*1024*1024)
$FileSize = Get-FileSize($Length)
Write-Output "[Info] Pagefile Size: $FileSize"
Write-Output "[Info] Pagefile Size: $FileSize" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
}
# Collecting Pagefile(s)
# .NET 4.0 Framework
if (Test-Path "HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full")
{
Write-Output "[Info] Collecting Pagefile(s) [approx. 1-20 min] ... "
Write-Output "[Info] Collecting Pagefile(s) [approx. 1-20 min] ... " | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
$StartTime_MagnetRESPONSE = (Get-Date)
& $MagnetRESPONSE /accepteula /nodiagnosticdata /unattended /caseref:"Collect-MemoryDump-v1.0" /output:"$OUTPUT_FOLDER\Memory\Pagefile" /capturepagefile /capturevolatile /captureextendedprocessinfo /saveprocfiles
Wait-Process -Name "MagnetRESPONSE"
Start-Sleep -Seconds 1
$EndTime_MagnetRESPONSE = (Get-Date)
$Time_MagnetRESPONSE = ($EndTime_MagnetRESPONSE-$StartTime_MagnetRESPONSE)
('Pagefile Collection duration: {0} h {1} min {2} sec' -f $Time_MagnetRESPONSE.Hours, $Time_MagnetRESPONSE.Minutes, $Time_MagnetRESPONSE.Seconds) >> "$OUTPUT_FOLDER\Memory\Pagefile\Stats.txt"
# Rename Archive
if (Test-Path "$OUTPUT_FOLDER\Memory\Pagefile\*\*.zip")
{
Get-ChildItem -Path "$OUTPUT_FOLDER\Memory\Pagefile\*\*.zip" | Rename-Item -NewName {"$env:COMPUTERNAME.zip"}
}
# Rename Directory
if (Test-Path "$OUTPUT_FOLDER\Memory\Pagefile\*\*.zip")
{
Get-ChildItem "$OUTPUT_FOLDER\Memory\Pagefile" | Where-Object {($_.FullName -match "MagnetRESPONSE")} | Rename-Item -NewName {"Pagefile"}
}
# MD5 Calculation
if (Test-Path "$OUTPUT_FOLDER\Memory\Pagefile\Pagefile\$env:COMPUTERNAME.zip")
{
if (Get-Command Get-FileHash -ErrorAction SilentlyContinue)
{
Write-Output "[Info] Calculating MD5 checksum of $env:COMPUTERNAME.zip [approx. 1-2 min] ... "
Write-Output "[Info] Calculating MD5 checksum of $env:COMPUTERNAME.zip [approx. 1-2 min] ... " | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
$StartTime_MD5 = (Get-Date)
$MD5 = (Get-FileHash -LiteralPath "$OUTPUT_FOLDER\Memory\Pagefile\Pagefile\$env:COMPUTERNAME.zip" -Algorithm MD5).Hash
Write-Output "[Info] MD5 Hash: $MD5"
Write-Output "[Info] MD5 Hash: $MD5" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
$MD5 > "$OUTPUT_FOLDER\Memory\Pagefile\Pagefile\MD5.txt"
$EndTime_MD5 = (Get-Date)
$Time_MD5 = ($EndTime_MD5-$StartTime_MD5)
('MD5 Calculation duration: {0} h {1} min {2} sec' -f $Time_MD5.Hours, $Time_MD5.Minutes, $Time_MD5.Seconds) >> "$OUTPUT_FOLDER\Memory\Pagefile\Stats.txt"
}
}
# Get File Size of "$env:COMPUTERNAME.zip"
if (Test-Path "$OUTPUT_FOLDER\Memory\Pagefile\Pagefile\$env:COMPUTERNAME.zip")
{
$Length = $Length = (Get-Item -Path "$OUTPUT_FOLDER\Memory\Pagefile\Pagefile\$env:COMPUTERNAME.zip").Length
$Size = Get-FileSize($Length)
Write-Output "[Info] Archive Size: $Size"
Write-Output "[Info] Archive Size: $Size" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
}
# Create Time (ISO 8601)
if (Test-Path "$OUTPUT_FOLDER\Memory\Pagefile\Pagefile\$env:COMPUTERNAME.zip")
{
$CreationTime = ((Get-Item -LiteralPath "$OUTPUT_FOLDER\Memory\Pagefile\Pagefile\$env:COMPUTERNAME.zip").CreationTimeUtc).ToString("yyyy-MM-dd HH:mm:ss UTC")
Write-Output "[Info] Create Time: $CreationTime"
Write-Output "[Info] Create Time: $CreationTime" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
}
# Last Modified Time (ISO 8601)
if (Test-Path "$OUTPUT_FOLDER\Memory\Pagefile\Pagefile\$env:COMPUTERNAME.zip")
{
$LastWriteTime = ((Get-Item -LiteralPath "$OUTPUT_FOLDER\Memory\Pagefile\Pagefile\$env:COMPUTERNAME.zip").LastWriteTimeUtc).ToString("yyyy-MM-dd HH:mm:ss UTC")
Write-Output "[Info] Last Modified Time: $LastWriteTime"
Write-Output "[Info] Last Modified Time: $LastWriteTime" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
}
}
else
{
Write-Output "[Error] NET Framework v4 NOT found. Pagefile Collection will be skipped ..."
Write-Output "[Error] NET Framework v4 NOT found. Pagefile Collection will be skipped ..." | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
}
# WMI Classes
# Win32_PageFileUsage
$PageFileList = Get-WmiObject -Class Win32_PageFile
if ($PageFileList -is [array])
{
$PageFileList = Get-WmiObject -Class Win32_PageFileUsage
$i = 1
foreach ($PageFile in $PageFileList)
{
$Name = ($PageFile | Select-Object -Property Name).Name
$InstallDateString = ($PageFile | Select-Object InstallDate).InstallDate
$InstallDate = ([Management.ManagementDateTimeConverter]::ToDateTime("$InstallDateString")).ToUniversalTime()
$AllocatedBaseSize = ($PageFile | Select-Object -Property AllocatedBaseSize).AllocatedBaseSize
$CurrentUsage = ($PageFile | Select-Object -Property CurrentUsage).CurrentUsage
$PeakUsage = ($PageFile | Select-Object -Property PeakUsage).PeakUsage
$TempPageFile = ($PageFile | Select-Object -Property TempPageFile).TempPageFile
$Win32_PageFileUsage = [PSCustomObject]@{
"Pagefile #$i" = $Name
"Install Date" = ($InstallDate).ToString("yyyy-MM-dd HH:mm:ss UTC")
"Allocated Base Size" = "$AllocatedBaseSize MB"
"Current Usage" = "$CurrentUsage MB"
"Peak Usage" = "$PeakUsage MB"
"Temp Page File" = $TempPageFile
}
($Win32_PageFileUsage | Out-String).Trim() | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\Win32_PageFileUsage_Pagefile-$i.txt"
$i += 1
}
}
else
{
$PageFile = Get-WmiObject -Class Win32_PageFileUsage
$Name = ($PageFile | Select-Object -Property Name).Name
$InstallDateString = ($PageFile | Select-Object InstallDate).InstallDate
$InstallDate = ([Management.ManagementDateTimeConverter]::ToDateTime("$InstallDateString")).ToUniversalTime()
$AllocatedBaseSize = ($PageFile | Select-Object -Property AllocatedBaseSize).AllocatedBaseSize
$CurrentUsage = ($PageFile | Select-Object -Property CurrentUsage).CurrentUsage
$PeakUsage = ($PageFile | Select-Object -Property PeakUsage).PeakUsage
$TempPageFile = ($PageFile | Select-Object -Property TempPageFile).TempPageFile
$Win32_PageFileUsage = [PSCustomObject]@{
"Pagefile " = $Name
"Install Date" = ($InstallDate).ToString("yyyy-MM-dd HH:mm:ss UTC")
"Allocated Base Size" = "$AllocatedBaseSize MB"
"Current Usage" = "$CurrentUsage MB"
"Peak Usage" = "$PeakUsage MB"
"Temp Page File" = $TempPageFile
}
($Win32_PageFileUsage | Out-String).Trim() | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\Win32_PageFileUsage.txt"
}
# Win32_PageFileSetting
[string]$AutoManaged = $null -eq (Get-WmiObject -Class Win32_PageFile)
if ($AutoManaged -eq "False")
{
$PageFileList = Get-WmiObject -Class Win32_PageFileSetting
if ($PageFileList -is [array])
{
$i = 1
foreach ($PageFile in $PageFileList)
{
$Name = $PageFile.Name
$InitialSize = $PageFile.InitialSize
$MaximumSize = $PageFile.MaximumSize
$Win32_PageFileSetting = [PSCustomObject]@{
"Pagefile #$i" = $Name
"Initial Size" = "$InitialSize MB"
"Maximum Size" = "$MaximumSize MB"
}
($Win32_PageFileSetting | Out-String).Trim() | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\Win32_PageFileSetting_Pagefile-$i.txt"
$i += 1
}
}
else
{
$PageFile = Get-WmiObject -Class Win32_PageFileSetting
$Name = $PageFile.Name
$InitialSize = $PageFile.InitialSize
$MaximumSize = $PageFile.MaximumSize
$Win32_PageFileSetting = [PSCustomObject]@{
"Pagefile" = $Name
"Initial Size" = "$InitialSize MB"
"Maximum Size" = "$MaximumSize MB"
}
($Win32_PageFileSetting | Out-String).Trim() | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\Win32_PageFileSetting.txt"
}
}
# Win32_PageFile
[string]$AutoManaged = $null -eq (Get-WmiObject -Class Win32_PageFile)
if ($AutoManaged -eq "False")
{
$PageFileList = Get-WmiObject -Class Win32_PageFile
if ($PageFileList -is [array])
{
$i = 1
foreach ($PageFile in $PageFileList)
{
$Name = $PageFile.Name
$Compressed = $PageFile.Compressed
$CompressionMethod = $PageFile.CompressionMethod
$CreationDateString = ($PageFile | Select-Object CreationDate).CreationDate
$CreationDate = ([Management.ManagementDateTimeConverter]::ToDateTime("$CreationDateString")).ToUniversalTime()
$Encrypted = $PageFile.Encrypted
$EncryptionMethod = $PageFile.EncryptionMethod
$FileSize = $PageFile.FileSize
$InitialSize = $PageFile.InitialSize
$InstallDateString = $PageFile.InstallDate
$InstallDate = ([Management.ManagementDateTimeConverter]::ToDateTime("$InstallDateString")).ToUniversalTime()
$LastAccessedString = $PageFile.LastAccessed
$LastAccessed = ([Management.ManagementDateTimeConverter]::ToDateTime("$LastAccessedString")).ToUniversalTime()
$LastModifiedString = $PageFile.LastModified
$LastModified = ([Management.ManagementDateTimeConverter]::ToDateTime("$LastModifiedString")).ToUniversalTime()
$MaximumSize = $PageFile.MaximumSize
$Win32_PageFile = [PSCustomObject]@{
"Pagefile" = $Name
"Compressed" = $Compressed
"CompressionMethod" = $CompressionMethod
"CreationDate" = ($CreationDate).ToString("yyyy-MM-dd HH:mm:ss UTC")
"Encrypted" = $Encrypted
"EncryptionMethod" = $EncryptionMethod
"FileSize" = $FileSize
"Initial Size" = "$InitialSize MB"
"InstallDate" = ($InstallDate).ToString("yyyy-MM-dd HH:mm:ss UTC")
"LastAccessed" = ($LastAccessed).ToString("yyyy-MM-dd HH:mm:ss UTC")
"LastModified" = ($LastModified).ToString("yyyy-MM-dd HH:mm:ss UTC")
"MaximumSize" = "$MaximumSize MB"
}
($Win32_PageFile | Out-String).Trim() | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\Win32_PageFile_Pagefile-$i.txt"
$i += 1
}
}
else
{
$PageFile = Get-WmiObject -Class Win32_Pagefile
$Name = $PageFile.Name
$Compressed = $PageFile.Compressed
$CompressionMethod = $PageFile.CompressionMethod
$CreationDateString = ($PageFile | Select-Object CreationDate).CreationDate
$CreationDate = ([Management.ManagementDateTimeConverter]::ToDateTime("$CreationDateString")).ToUniversalTime()
$Encrypted = $PageFile.Encrypted
$EncryptionMethod = $PageFile.EncryptionMethod
$FileSize = $PageFile.FileSize
$InitialSize = $PageFile.InitialSize
$InstallDateString = $PageFile.InstallDate
$InstallDate = ([Management.ManagementDateTimeConverter]::ToDateTime("$InstallDateString")).ToUniversalTime()
$LastAccessedString = $PageFile.LastAccessed
$LastAccessed = ([Management.ManagementDateTimeConverter]::ToDateTime("$LastAccessedString")).ToUniversalTime()
$LastModifiedString = $PageFile.LastModified
$LastModified = ([Management.ManagementDateTimeConverter]::ToDateTime("$LastModifiedString")).ToUniversalTime()
$MaximumSize = $PageFile.MaximumSize
$Win32_PageFile = [PSCustomObject]@{
"Pagefile" = $Name
"Compressed" = $Compressed
"CompressionMethod" = $CompressionMethod
"CreationDate" = ($CreationDate).ToString("yyyy-MM-dd HH:mm:ss UTC")
"Encrypted" = $Encrypted
"EncryptionMethod" = $EncryptionMethod
"FileSize" = $FileSize
"Initial Size" = "$InitialSize MB"
"InstallDate" = ($InstallDate).ToString("yyyy-MM-dd HH:mm:ss UTC")
"LastAccessed" = ($LastAccessed).ToString("yyyy-MM-dd HH:mm:ss UTC")
"LastModified" = ($LastModified).ToString("yyyy-MM-dd HH:mm:ss UTC")
"MaximumSize" = "$MaximumSize MB"
}
($Win32_PageFile | Out-String).Trim() | Out-File "$OUTPUT_FOLDER\Memory\Pagefile\PageFileInfo\Win32_PageFile.txt"
}
}
}
else
{
Write-Output "[Error] File Hash does NOT match."
Write-Output "[Error] File Hash does NOT match." | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
$Host.UI.RawUI.WindowTitle = "$DefaultWindowsTitle"
Exit
}
}
else
{
Write-Output "[Error] MagnetRESPONSE.exe NOT found."
Write-Output "[Error] MagnetRESPONSE.exe NOT found." | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
$Host.UI.RawUI.WindowTitle = "$DefaultWindowsTitle"
Exit
}
}
#endregion Pagefile
#############################################################################################################################################################################################
#region Comae
Function New-ComaeSnapshot
{
# DumpIt
if (Test-Path "$DumpIt")
{
# Verify File Integrity
$certUtil = "$env:SystemDrive\Windows\System32\certutil.exe"
$MD5 = (((& $certUtil -hashfile "$DumpIt" MD5) -replace '\s', '' | Select-String -Pattern "^[0-9a-f]{32}$" | Out-String).Trim()).ToUpper()
# ARM64 or x64 or x86
if (($MD5 -eq "4B39D63B86FFE39BBAE0415C400003C7") -Or ($MD5 -eq "0F10DA3A5EB49D17D73D8E195FE32F85") -OR ($MD5 -eq "586C57AD0EEA179FCAE4B8BA117F2AB9"))
{
# Get Physical Memory Size
if ($PSVersionTable.PSVersion.Major -ge 3)
{
$TotalMemory = Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum | ForEach-Object {"{0}" -f ([math]::round(($_.Sum / 1GB)))}
Write-Output "[Info] Total Physical Memory Size: $TotalMemory GB"
Write-Output "[Info] Total Physical Memory Size: $TotalMemory GB" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
}
else
{
$TotalMemory = Get-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum | ForEach-Object {"{0}" -f ([math]::round(($_.Sum / 1GB)))}
Write-Output "[Info] Total Physical Memory Size: $TotalMemory GB"
Write-Output "[Info] Total Physical Memory Size: $TotalMemory GB" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
}
# Check Available Space (GB)
$DriveLetter = "$SCRIPT_DIR".Substring(0,2)
$AvailableSpace = (Get-WmiObject -Class Win32_LogicalDisk -Filter "deviceid='$DriveLetter'" | Select-Object FreeSpace).FreeSpace | ForEach-Object {"{0}" -f ([math]::round(($_ / 1GB)))}
[int]$TotalMemoryInt32 = [convert]::ToInt32($TotalMemory, 10)
[int]$AvailableSpaceInt32 = [convert]::ToInt32($AvailableSpace, 10)
[int]$AdditionalSpaceInt32 = ($TotalMemoryInt32/100*12.5) # +12,5%
[int]$RequiredSpaceInt32 = ([int]$TotalMemoryInt32)+([int]$AdditionalSpaceInt32)
if ($RequiredSpaceInt32 -gt $AvailableSpaceInt32)
{
Write-Output "[Error] Not enough disk space to save memory dump file."
Write-Output "[Error] Not enough disk space to save memory dump file." | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
Write-Output ""
$Host.UI.RawUI.WindowTitle = "$DefaultWindowsTitle"
Exit
}
# Check if output directory exists
if (Test-Path $OUTPUT_FOLDER\Memory\DumpIt)
{
# Check for output directory content
if (Test-Path $OUTPUT_FOLDER\Memory\DumpIt\*)
{
# Delete output directory content after confirmation
Get-ChildItem -Path "$OUTPUT_FOLDER\Memory\DumpIt" -Force -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -Confirm
}
}
else
{
# Creating Output Directory
New-Item "$OUTPUT_FOLDER\Memory\DumpIt" -ItemType Directory -Force | Out-Null
}
# Microsoft Crash Dump
$StartTime_MemoryAcquisition = (Get-Date)
Write-Output "[Info] Creating Memory Snapshot w/ DumpIt (Microsoft Crash Dump) [approx. 1-5 min] ... "
Write-Output "[Info] Creating Memory Snapshot w/ DumpIt (Microsoft Crash Dump) [approx. 1-5 min] ... " | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
& $DumpIt /T DMP /N /Q /NOCOMPRESS /O "$OUTPUT_FOLDER\Memory\DumpIt\$env:COMPUTERNAME.dmp" 2>&1 | Out-File "$OUTPUT_FOLDER\Memory\DumpIt\DumpIt.log"
$EndTime_MemoryAcquisition = (Get-Date)
$Time_MemoryAcquisition = ($EndTime_MemoryAcquisition-$StartTime_MemoryAcquisition)
('Memory Acquisition duration: {0} h {1} min {2} sec' -f $Time_MemoryAcquisition.Hours, $Time_MemoryAcquisition.Minutes, $Time_MemoryAcquisition.Seconds) >> "$OUTPUT_FOLDER\Memory\DumpIt\Stats.txt"
# Error: Can't install the driver
if (Test-Path "$OUTPUT_FOLDER\Memory\DumpIt\DumpIt.log")
{
if (Get-Content "$OUTPUT_FOLDER\Memory\DumpIt\DumpIt.log" | Select-String -Pattern "Error: Can't install the driver." -Quiet)
{
Write-Output "[Error] Installing the DumpIt.sys driver failed. Please try WinPMEM."
Write-Output "[Error] Installing the DumpIt.sys driver failed. Please try WinPMEM." | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
}
}
# SHA256
if (Test-Path "$OUTPUT_FOLDER\Memory\DumpIt\DumpIt.log")
{
$SHA256 = Get-Content "$OUTPUT_FOLDER\Memory\DumpIt\DumpIt.log" | Select-String -Pattern "[A-Fa-f0-9]{64}" | ForEach-Object { $PSItem.Matches[0].Value } | Select-Object -First 1
if ($SHA256)
{
Write-Output "[Info] SHA256 Hash: $SHA256"
Write-Output "[Info] SHA256 Hash: $SHA256" | Out-File "$LOG_DIR\$Timestamp-Logfile.txt" -Append
}
}
# Processing... Failed.
if (Test-Path "$OUTPUT_FOLDER\Memory\DumpIt\DumpIt.log")
{
# Error: The request could not be performed because of an I/O device error.
if (Get-Content "$OUTPUT_FOLDER\Memory\DumpIt\DumpIt.log" | Select-String -Pattern "Error: The request could not be performed because of an I/O device error." -Quiet)
{
Write-Output "[Error] The request could not be performed because of an I/O device error."
}
}
# Collecting PageFile
if ($PageFile -eq "--PageFile")
{
Get-Pagefile
}
# Creating Secure Archive File