-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
986 lines (898 loc) · 46.8 KB
/
Program.cs
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
using System;
using System.Linq;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Security.Principal;
using Microsoft.Win32;
using TaskScheduler;
using System.Security.Cryptography;
using System.ServiceProcess;
namespace StormlightDinosaur
{
class Program
{
public static void Header()
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(@" _____ __ ___ __ __ ");
Console.WriteLine(@" / ___// /_____ _________ ___ / (_)___ _/ /_ / /_");
Console.WriteLine(@" \__ \/ __/ __ \/ ___/ __ `__ \/ / / __ `/ __ \/ __/ ");
Console.WriteLine(@" ___/ / /_/ /_/ / / / / / / / / / / /_/ / / / / /_");
Console.WriteLine(@" /____/\__/\____/_/ /_/ /_/ /_/_/_/\__, /_/ /_/\__/ ");
Console.WriteLine(@" /____/ ");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(@"( ~ ( \ ' \ )_ -' / __ _ / (_--__'_ )__");
Console.WriteLine(@" _\ _\ ` _ ___-) / ) '- (( __( _ ) -__'___)");
Console.WriteLine(@" `(__\ \ `/ (-_'-_______)-----'");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(@" `\ \ _..--+~/@-~--. / _/ ");
Console.WriteLine(@" _\_\ _-=~ ( . ''} _/ / ");
Console.WriteLine(@" `\\ _-~ _.--=.\ \"""""""" / __/");
Console.WriteLine(@" \\ _ ~ _- \ \_\ _/ /");
Console.WriteLine(@" \ = _= '--' /__/");
Console.WriteLine(@" ' = // .");
Console.WriteLine(@"_ : : ____ /' '=_. ___");
Console.WriteLine(@" ___ | ; ____ '~--.~.");
Console.WriteLine(@"____ ; ; _____ } |");
Console.WriteLine(@" ___= \ ___ __ __..-...__ ___/__/__");
Console.WriteLine(@" creosote : =_ _.-~~ ~~--.__");
Console.WriteLine(@" _____ \ ~-+-~ ___~=_______");
Console.WriteLine(@"__ ~'#~~ == ...______ __ ___ _--~~--_ ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(@" ____ _");
Console.WriteLine(@" / __ \(_)___ ____ _________ ___ _______");
Console.WriteLine(@" / / / / / __ \/ __ \/ ___/ __ `/ / / / ___/");
Console.WriteLine(@" / /_/ / / / / / /_/ (__ ) /_/ / /_/ / / ");
Console.WriteLine(@" /_____/_/_/ /_/\____/____/\__,_/\__,_/_/ v1.1 ");
Console.WriteLine(" ");
Console.ResetColor();
}
/// //////////////////////////////////////////////////
/// //////////////////////////////////////////////////
/// //// Run Keys ////////////////////////////////
/// //////////////////////////////////////////////////
/// //////////////////////////////////////////////////
public static void RunKeys()
{
string[] runKeys = new string[] {
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunService",
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnceService",
};
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(" [+] Checking HKey Local Machine " + "\n");
foreach (string LMrkey in runKeys)
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(LMrkey);
if (key == null)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] HKLM\\" + LMrkey + " does not exist");
}
else
{
try
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Checking HKLM\\" + LMrkey);
foreach (var xkey in key.GetValueNames())
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" --------------------------------------------------------------------");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" Registry Key: " + xkey);
using (RegistryKey keyValue = Registry.LocalMachine.OpenSubKey(xkey))
{
if (xkey != null)
{
Object o = key.GetValue(xkey);
if (o != null)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" Value: " + o);
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" --------------------------------------------------------------------");
}
}
else { Console.WriteLine(" Value: Empty" + "\n"); }
}
}
}
catch (Exception ex) { }
}
}
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(" [+] Checking HKey Current User " + "\n");
foreach (string CUrkey in runKeys)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(CUrkey);
if (key == null)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] HKCU\\" + CUrkey + " does not exist");
}
else
{
try
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Checking HKCU\\" + CUrkey);
foreach (var xkey in key.GetValueNames())
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" --------------------------------------------------------------------");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" Registry Key: " + xkey);
using (RegistryKey keyValue = Registry.LocalMachine.OpenSubKey(xkey))
{
if (xkey != null)
{
Object o = key.GetValue(xkey);
if (o != null)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" Value: " + o);
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" --------------------------------------------------------------------");
}
}
else { Console.WriteLine(" Value: Empty" + "\n"); }
}
}
}
catch (Exception ex) { }
}
}
}
/// //////////////////////////////////////////////////
/// //////////////////////////////////////////////////
/// //// Scheduled Tasks /////////////////////////
/// //////////////////////////////////////////////////
/// //////////////////////////////////////////////////
public static void ProcessTaskFoler(ITaskFolder taskFolder)
{
int idx;
string name, path;
string ePs, schXm, msTaskPath;
_TASK_STATE state;
IRegisteredTaskCollection taskCol = taskFolder.GetTasks((int)_TASK_ENUM_FLAGS.TASK_ENUM_HIDDEN);
for (idx = 1; idx <= taskCol.Count; idx++)
{
IRegisteredTask runTask = taskCol[idx];
// Some lolbins..remove common ones if a lot of noise is created
string[] interestingTasks = new string[] {
"certutil.exe","cmstp.exe","control.exe","csc.exe","cscript.exe","bitsadmin","installutil.exe","jsc.exe","makecab.exe","msbuild.exe",
"dfsvc.exe","diskshadow.exe","dnscmd.exe","esentutl.exe","eventvwr.exe","expand.exe","extexport.exe","extrac32.exe",
"findstr.exe","forfiles.exe","ftp.exe","ie4uinit.exe","ieexec.exe","infdefaultinstall.exe",
"msconfig.exe","msdt.exe","mshta.exe","msiexec.exe","odbcconf.exe","pcalua.exe","pcwrun.exe","presentationhost.exe",
"print.exe","regasm.exe","regedit.exe","reg.exe","runonce.exe","runscripthelper.exe","schtasks.exe","scriptrunner.exe",
"syncappvpublishingserver.exe","verclsid.exe","wab.exe","wmic.exe","wscript.exe"
};
name = runTask.Name;
path = runTask.Path;
state = runTask.State;
schXm = runTask.Xml;
string schXml = schXm.ToLower();
msTaskPath = "\\Microsoft\\";
ePs = "powershell.exe";
string sched_out = " Name: " + name + "\n" + " Path: " + path + "\n" + " State: " + state + "\n";
bool mspath = path.Contains(msTaskPath);
bool bPs = schXml.Contains(ePs);
/////////////////////
// Based off array //
/////////////////////
foreach (string itasks in interestingTasks)
{
bool chkItasks = schXml.Contains(itasks);
if (chkItasks == true)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] Detected interesting String in task: ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(sched_out);
}
}
////////////////
// Powershell //
////////////////
if (bPs == true)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] PowerShell Detected - task info: ");
Console.WriteLine(sched_out);
//Console.WriteLine(schXm);
}
////////////////////////////
// Outside Microsoft folder
////////////////////////////
if (mspath == false)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] Detected Task outside of Microsoft folder - task info: ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(sched_out);
}
}
ITaskFolderCollection taskFolderCol = taskFolder.GetFolders(0);
for (idx = 1; idx <= taskFolderCol.Count; idx++)
ProcessTaskFoler(taskFolderCol[idx]);
}
public static void ParseScheduleTasks()
{
ITaskService taskService = new TaskScheduler.TaskScheduler();
taskService.Connect();
ProcessTaskFoler(taskService.GetFolder("\\"));
}
/// ////////////////////////////////////////////
/// //// Hash Calc /////////////////////////
/// ////////////////////////////////////////////
public static string CalculateMD5(string filename)
{
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}
}
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
/// //// Netsh Helpers /////////////////////
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
public static void NethshHelpers()
{
string[] netshKeys = new string[] {
"SOFTWARE\\Microsoft\\NetSh"
};
// Default x64 Netsh dll's v14393
string[] realNetshNames = new string[] {
"ifmon.dll","rasmontr.dll","authfwcfg.dll","dhcpcmonitor.dll","dot3cfg.dll",
"fwcfg.dll","hnetmon.dll","netiohlp.dll","nettrace.dll","nshhttp.dll","nshipsec.dll",
"nshwfp.dll","p2pnetsh.dll","rpcnsh.dll","WcnNetsh.dll","whhelper.dll","wlancfg.dll",
"wshelper.dll","wwancfg.dll","peerdistsh.dll",
};
// Valid Win Enterprise DLL 64-bit hashes v14393
// NOTE: These hashes change often! Not reliable as intrusion detection method
/*string[] realNetshHashes = new string[] {
"6516b277fddf621ca229bc83e42d37b1","60ced926123c2302151672f9da7d7af2","ea7d47bd2d258a559b252cad9443cedd",
"668a386775b2aa36cc7f1e7db96deff4","ff4c066dcba425aa9079f8f5031657c2","4c0eadc150facd63625a1cfc70ef63a5",
"4a0ad58e4f8b963b05b466cf903347a4","ee26dd15d15b17f6fb172f1b3b9ef69f","edb17de73c6b77e6621eb1c931d2fc6e",
"90ce7e9f0ec74e31e2a1527c784e71ed","0c83a44dcd312485e1abe30caeca0588","980d774495aa11fc776970f8c81ce867",
"0899fc19072fa27de8edcfec4575c4a3","9680bccd0e8e98c94b782fbf7d7190f5","1807b9121dad338e1fb45fb9f43549ae",
"93ecae56f56cac45efe1e7d1b60a3658","e63dd2879f98a7f28b954235e31b42c5","8eb4f3b56439370088a32f6e064fa162",
"a41806e419220b18b90fbdc391317438","90dc77e5d7fa9e80434e95bcb9a6861a","801dcb0a415284c4655a6591028e9a8b",
};*/
// Starting Netsh key check
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(" [+] Validating Default DLL Names" + "\n");
foreach (string LMrkey in netshKeys)
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(LMrkey);
try
{
foreach (var v in key.GetValueNames())
{
using (RegistryKey keyValue = Registry.LocalMachine.OpenSubKey(v))
{
if (key != null)
{
Object o = key.GetValue(v);
var val = o.ToString();
//Validate DLL names
if (realNetshNames.Any(val.Contains))
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Sucess: " + val);
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] Non-Default DLL Found!: " + val);
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" Investigate HKLM\\SOFTWARE\\Microsoft\\NetSh\\" + v + " and DLL in System32");
}
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] Empty Entry Found: " + v);
}
}
}
}
catch (Exception ex) { }
}
}
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
/// //// BITS Jobs /////////////////////////
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
public static void BitsJobs()
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("------------------------------------------------------------------------------");
Console.ForegroundColor = ConsoleColor.Gray;
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "bitsadmin",
Arguments = "/list /allusers /verbose",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
string line = proc.StandardOutput.ReadLine();
Console.WriteLine(line);
}
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("------------------------------------------------------------------------------");
Console.ForegroundColor = ConsoleColor.DarkCyan;
}
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
/// //// WMI Subscriptions /////////////////
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
public static void WmiSubs()
{
// WMI EventFilter
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Querying Non-Default WMI Event Filters");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("------------------------------------------------------------------------------");
Console.ForegroundColor = ConsoleColor.DarkCyan;
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "powershell",
Arguments = "-c Get-WMIObject -Namespace root\\Subscription -Class __EventFilter | Select-String -Pattern '\\bSCM Event Log Filter\\b' -NotMatch -CaseSensitive",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
Console.ForegroundColor = ConsoleColor.White;
string line = proc.StandardOutput.ReadLine();
Console.WriteLine(line);
}
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("------------------------------------------------------------------------------");
Console.ForegroundColor = ConsoleColor.DarkCyan;
// WMI EventConsumer
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Querying Non-Default WMI Event Consumers");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("------------------------------------------------------------------------------");
Console.ForegroundColor = ConsoleColor.DarkCyan;
var procCons = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "powershell",
Arguments = "-c Get-WMIObject -Namespace root\\Subscription -Class __EventConsumer | Select-String -Pattern '\\bSCM Event Log Consumer\\b' -NotMatch -CaseSensitive",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
procCons.Start();
while (!procCons.StandardOutput.EndOfStream)
{
Console.ForegroundColor = ConsoleColor.White;
string line = procCons.StandardOutput.ReadLine();
Console.WriteLine(line);
}
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("------------------------------------------------------------------------------");
Console.ForegroundColor = ConsoleColor.DarkCyan;
}
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
/// //// Startup Folder /////////////////
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
public static void StartFolder()
{
// Get %APPDATA% env. var
string mlem = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string fullFolP = mlem + "\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
string[] stFolder = Directory.GetFiles(fullFolP);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Looking in " + fullFolP + "\\");
if (stFolder == null)
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(" [+] Looks like your Users Startup Folder is Empty");
}
else
{
foreach (string thingy in stFolder)
{
// List all files in the Startup folder
string stName = thingy.Substring(thingy.LastIndexOf('\\') + 1);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" [+] Found: " + stName);
}
}
}
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
/// //// Services /////////////////
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
public static void EvilServices()
{
string[] safeSvc = new string[] {
"system32","SYSTEM32","System32",
};
string[] safeSvcPro = new string[] {
"C:\\Program Files\\", "C:\\Program Files (x86)\\", "C:\\Windows\\", "C:\\WINDOWS\\", "c:\\Program Files\\"
};
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [-] Checking if Service Descriptions are Empty");
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController service in services)
{
var xsvc = new ManagementObject(new ManagementPath(string.Format("Win32_Service.Name='{0}'", service.ServiceName)));
var zsvc = xsvc["Description"];
if (zsvc != null)
{ }
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] Empty Description Found! Verify it's a legitimate Service");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" Service: " + service.DisplayName);
}
}
String registryKey = @"SYSTEM\CurrentControlSet\Services";
using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey))
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Checking Services Image Paths outside of Protected Directories");
foreach (String subkeyName in key.GetSubKeyNames())
{
var imgPath = key.OpenSubKey(subkeyName).GetValue("ImagePath");
var keyD = key.OpenSubKey(subkeyName).GetValue("Description");
// Search for service exe's outside of protected folders
if (imgPath != null)
{
var ipa = imgPath.ToString();
//if (safeSvc.Any(ipa.Contains))
if(safeSvc.Any(ipa.Contains))
{ /*Console.WriteLine(" [+] Sucess: " + subkeyName);*/
}
else
{
if (safeSvcPro.Any(ipa.Contains))
{ }
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] Found Image Path outside of a Protected Directory: ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" Service: " + subkeyName);
Console.WriteLine(" Path: " + ipa);
}
}
}
}
}
}
/// ////////////////////////////////////////////
/// //// Admin Check /////////////////
/// ////////////////////////////////////////////
public static bool IsAdministrator()
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
/// //// svchost.exe Check /////////////////
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
public static void EnumSvchost()
{
Process[] localByName = Process.GetProcessesByName("svchost");
foreach (Process svch in localByName)
{
var myId = svch.Id;
///////////////////////////////////////////////
/// Get ppids of each svchost instance
/// TODO: make this a separate method to call
var query = string.Format("SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {0}", myId);
var search = new ManagementObjectSearcher("root\\CIMV2", query);
var results = search.Get().GetEnumerator();
results.MoveNext();
var queryObj = results.Current;
var parentId = (uint)queryObj["ParentProcessId"];
var parent = Process.GetProcessById((int)parentId);
var parentName = parent.ProcessName;
///////////////////////////////////////////////
if (parentName != "services")
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] svchost.exe Process NOT start by services.exe!");
Console.WriteLine(" PID : " + myId);
Console.WriteLine(" PPID : " + parent);
Console.WriteLine(" Parent Name : " + parentName);
}
else
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Sucess - svchost PID of: " + myId);
}
}
}
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
/// //// lsass.exe Check /////////////////
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
public static void EnumLsass()
{
Process[] localByName = Process.GetProcessesByName("lsass");
int i = 0;
foreach (Process lsas in localByName)
{
var myId = lsas.Id;
i++;
// Look for lsass parent
var query = string.Format("SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {0}", myId);
var search = new ManagementObjectSearcher("root\\CIMV2", query);
var results = search.Get().GetEnumerator();
results.MoveNext();
var queryObj = results.Current;
var parentId = (uint)queryObj["ParentProcessId"];
var parent = Process.GetProcessById((int)parentId);
var parentName = parent.ProcessName;
if (parentName != "wininit")
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] lsass.exe Process NOT start by blah!");
Console.WriteLine(" PID : " + myId);
Console.WriteLine(" PPID : " + parent);
Console.WriteLine(" Parent Name : " + parentName);
}
else
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Sucess - Parent of lsass.exe is wininit.exe");
}
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"SELECT * " +
"FROM Win32_Process " +
"WHERE ParentProcessId=" + myId);
ManagementObjectCollection collection = searcher.Get();
if (collection.Count > 0)
{
foreach (var item in collection)
{
UInt32 childProcessId = (UInt32)item["ProcessId"];
if ((int)childProcessId != Process.GetCurrentProcess().Id)
{
Process childProcess = Process.GetProcessById((int)childProcessId);
}
}
}
else
{
Console.Write(" [+] Sucess - lsass.exe has " + collection.Count + " child processes \n");
}
}
if (i != 1)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] Found: " + i + " lsass.exe processes running!");
}
else
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Sucess - Only 1 lsass.exe found running");
}
}
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
/// //// IFEO Check /////////////////
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
public static void IFEO()
{
String registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Image File Execution Options";
using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey))
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Checking IFEO SubKeys");
var dnum = 0;
var gnum = 0;
// Store each IFEO subkey NAME in subkeyName
foreach (String subkeyName in key.GetSubKeyNames())
{
String ikey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\" + subkeyName;
//Get the values of each subkey and store in vkey
using (Microsoft.Win32.RegistryKey vkey = Registry.LocalMachine.OpenSubKey(ikey))
{
Console.ForegroundColor = ConsoleColor.Cyan;
//Look in each subkey value for 'debugger' and 'globalflag'
foreach (var subVals in vkey.GetValueNames())
{
if (subVals == "Debugger")
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] 'Debugger' Value found in:");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" " + vkey);
dnum = dnum + 1;
}
if (subVals == "GlobalFlag")
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] 'GlobalFlag' Value found in:");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" " + vkey);
gnum = gnum + 1;
}
}
}
}
if (dnum == 0)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Success - 'Debugger' Value not found");
}
if (gnum == 0)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Success - 'GlobalFlag' Value not found");
}
}
String registryKeyWOW = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options";
using (Microsoft.Win32.RegistryKey keyWOW = Registry.LocalMachine.OpenSubKey(registryKeyWOW))
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Checking Wow6432Node IFEO SubKeys");
var dnumWOW = 0;
var gnumWOW = 0;
// Store each IFEO subkey NAME in subkeyName
foreach (String subkeyNameWOW in keyWOW.GetSubKeyNames())
{
String ikeyWOW = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\" + subkeyNameWOW;
//Get the values of each subkey and store in vkey
using (Microsoft.Win32.RegistryKey vkeyWOW = Registry.LocalMachine.OpenSubKey(ikeyWOW))
{
Console.ForegroundColor = ConsoleColor.Cyan;
//Look in each subkey value for 'debugger' and 'globalflag'
foreach (var subValsWOW in vkeyWOW.GetValueNames())
{
if (subValsWOW == "Debugger")
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] 'Debugger' Value found in:");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" " + vkeyWOW);
dnumWOW = dnumWOW + 1;
}
if (subValsWOW == "GlobalFlag")
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] 'GlobalFlag' Value found in:");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" " + vkeyWOW);
gnumWOW = gnumWOW + 1;
}
}
}
}
if (dnumWOW == 0)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Success - Wow6432Node 'Debugger' Value not found");
}
if (gnumWOW == 0)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Success - Wow6432Node 'GlobalFlag' Value not found");
}
}
String silentKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\SilentProcessExit";
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Checking for SilentProcessExit Key");
using (Microsoft.Win32.RegistryKey skey = Registry.LocalMachine.OpenSubKey(silentKey))
{
if (skey == null)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Success - SilentProcessExit SubKey does not exist");
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] SilentProcessExit SubKey Found!");
foreach (String skeyName in skey.GetSubKeyNames())
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" " + skey);
}
}
}
String silentKeyWOW = @"SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\SilentProcessExit";
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Checking for Wow6432Node SilentProcessExit Key");
using (Microsoft.Win32.RegistryKey skeyWOW = Registry.LocalMachine.OpenSubKey(silentKeyWOW))
{
if (skeyWOW == null)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Success - Wow6432Node SilentProcessExit SubKey does not exist");
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] Wow6432Node SilentProcessExit SubKey Found!");
foreach (String skeyNameWOW in skeyWOW.GetSubKeyNames())
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" " + skeyWOW);
}
}
}
}
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
/// //// App Shimming /////////////////
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
public static void AppShims()
{
String appKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Custom";
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Checking 'Custom' SubKey entries");
using (Microsoft.Win32.RegistryKey skey = Registry.LocalMachine.OpenSubKey(appKey))
{
if (skey == null)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Success - 'Custom' SubKey does not exist");
}
else
{
var aSubKey = 0;
foreach (String skeyName in skey.GetSubKeyNames())
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] Custom SubKey Found! ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" " + skey + "\\" + skeyName);
aSubKey = aSubKey + 1;
}
if (aSubKey == 0)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Sucess - No SubKeys detected");
}
}
}
String sdbKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\InstalledSDB";
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Checking 'InstalledSDB' SubKey entries");
using (Microsoft.Win32.RegistryKey ukey = Registry.LocalMachine.OpenSubKey(sdbKey))
{
if (ukey == null)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Success - 'InstalledSDB' SubKey does not exist");
}
else
{
var uSubKey = 0;
foreach (String ukeyName in ukey.GetSubKeyNames())
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [-] InstalledSDB SubKey Found! ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" " + ukey + "\\" + ukeyName);
uSubKey = uSubKey + 1;
}
if (uSubKey == 0)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" [+] Sucess - No SubKeys detected");
}
}
}
}
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
/// //// Codename: StormlightDinosaur ////
/// ////////////////////////////////////////////
/// ////////////////////////////////////////////
static void Main(string[] args)
{
Header();
Console.ForegroundColor = ConsoleColor.Magenta;
if (IsAdministrator() != true)
{ Console.Write("[!] NOT Running as Administrator! Results will be skewed!" + "\n"); }
// LSASS
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] Verifying basic lsass.exe integrity - T1177" + "\n");
EnumLsass();
Console.Write("\n");
// Run Keys
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] Checking RunKeys - T1060" + "\n");
RunKeys();
Console.Write("\n");
// Startup Folder
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] Checking Startup Folder - T1060" + "\n");
StartFolder();
Console.Write("\n");
// Services
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] Checking Services - T1050" + "\n");
EvilServices();
Console.Write("\n");
// Scheduled Tasks
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] Checking Scheduled Tasks - T1053" + "\n");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(" [+] Searching Tasks that are utilizing unusual Binaries or Locations ");
ParseScheduleTasks();
Console.Write("\n");
// SVCHOST
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] Verifying Parent Process of running svchost.exe's is services.exe" + "\n");
EnumSvchost();
Console.Write("\n");
// BITS
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] Checking BITS Jobs - T1197" + "\n");
BitsJobs();
Console.Write("\n");
// WMI Event Subscriptions
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] Checking WMI Event Subscriptions - T1084" + "\n");
WmiSubs();
Console.Write("\n");
// IFEO
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] Checking Accessibility Abuse (IFEO) - T1183" + "\n");
IFEO();
Console.Write("\n");
// Application Shimming
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] Checking Application Shims - T1138" + "\n");
AppShims();
Console.Write("\n");
// NetSh DLL Helpers
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] Checking Netsh DLL Helpers - T1128" + "\n");
NethshHelpers();
Console.Write("\n");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("------------------------------------------------------------------------------");
Console.WriteLine("---------------------- COMPLETE ----------------------------");
Console.WriteLine("------------------------------------------------------------------------------");
Console.ResetColor();
//Console.ReadLine();
}
}
}