-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathProgram.cs
More file actions
155 lines (139 loc) · 5.08 KB
/
Copy pathProgram.cs
File metadata and controls
155 lines (139 loc) · 5.08 KB
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
/*
* Author: @n0dec
* License: GNU General Public License v3.0
*
*/
using System;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace MalwLess
{
class Program
{
public static void Main(string[] args)
{
string file_name = null;
string json_file = null;
string sysmonpath = Utils.getSysmonPath();
string productVersion = null;
string productMajorVersion = null;
Utils.printHeader();
if(sysmonpath != null){
productVersion = Utils.getFileVersion(sysmonpath);
productMajorVersion = productVersion.Substring(0, productVersion.IndexOf('.'));
Console.WriteLine("Sysmon version: " + productVersion);
}else{
Console.WriteLine("[!] Error: Sysmon not found");
}
if(!Utils.isElevated()){
Console.WriteLine("[!] Run it as Administrator.");
Environment.Exit(-1);
}
try{
if (args.Length == 2 && args[0] == "-r")
{
file_name = args[1];
}
else if(args.Length == 0){
file_name = "rule_test.json";
}
else
{
Console.WriteLine("Usage: {0} [-r rule_test.json]", Path.GetFileName(Environment.GetCommandLineArgs()[0]));
return;
}
if(!File.Exists(file_name)){
Console.WriteLine("File {0} not found!", file_name);
Console.WriteLine("Check the MST default rule set on: https://github.com/n0dec/MalwLess/blob/master/rule_test.json");
Environment.Exit(-1);
}
Console.WriteLine("Using file '{0}'", file_name);
json_file = File.ReadAllText(file_name);
JObject rule_test = JObject.Parse(json_file);
JToken sysmon_config = getDefaultConfig("conf\\Sysmon.json");
JToken powershell_config = getDefaultConfig("conf\\PowerShell.json");
Console.WriteLine("");
Console.WriteLine("[Rule test file]: " + file_name);
Console.WriteLine("[Rule test name]: " + rule_test["name"]);
Console.WriteLine("[Rule test version]: " + rule_test["version"]);
Console.WriteLine("[Rule test author]: " + rule_test["author"]);
Console.WriteLine("[Rule test description]: " + rule_test["description"]);
Console.WriteLine("");
if(!rule_test["rules"].HasValues){
Console.WriteLine("No rules detected. Exiting...");
Environment.Exit(-1);
}
foreach(var rule in rule_test["rules"].Children()){
Console.WriteLine("[>] Detected rule: " + rule.Path);
foreach (var properties in rule.Children()){
if((bool)properties["enabled"] == true){
Console.WriteLine("... Source: " + properties["source"]);
Console.WriteLine("... Category: " + properties["category"]);
Console.WriteLine("... Description: " + properties["description"]);
switch (properties["source"].ToString())
{
case "Sysmon":
switch (productMajorVersion){
case "7":
SysmonClass_v7.WriteSysmonEvent(properties["category"].ToString(), properties["payload"], sysmon_config);
break;
case "8":
case "9":
SysmonClass_v8.WriteSysmonEvent(properties["category"].ToString(), properties["payload"], sysmon_config);
break;
case "10":
SysmonClass_v10.WriteSysmonEvent(properties["category"].ToString(), properties["payload"], sysmon_config);
break;
case "11":
// As of Sysmon 11.10, the FileCreateStreamHash event includes the 'Contents' field.
int productMinorVersion = int.Parse(productVersion.Split(new char[] { '.' })[1]);
if (productMinorVersion >= 10)
{
SysmonClass_v11_10.WriteSysmonEvent(properties["category"].ToString(), properties["payload"], sysmon_config);
}
else
{
SysmonClass_v11.WriteSysmonEvent(properties["category"].ToString(), properties["payload"], sysmon_config);
}
break;
case "12":
SysmonClass_v12.WriteSysmonEvent(properties["category"].ToString(), properties["payload"], sysmon_config);
break;
case "14":
SysmonClass_v14.WriteSysmonEvent(properties["category"].ToString(), properties["payload"], sysmon_config);
break;
default:
Console.WriteLine("[!] Error: Sysmon version not supported.");
break;
}
break;
case "PowerShell":
PowerShellClass.WritePowerShellEvent(properties["category"].ToString(), properties["payload"], powershell_config);
break;
default:
Console.WriteLine("... Source not supported");
break;
}
}else{
Console.WriteLine("... Rule disabled");
}
}
}
}
catch(JsonException jsonException){
Console.WriteLine("[!] Error with json file: " + jsonException.Message);
Environment.Exit(-1);
}catch(Exception e){
Console.WriteLine("[!] Error: " + e.StackTrace);
Environment.Exit(-1);
}
}
public static JToken getDefaultConfig(string filename){
if (!File.Exists(filename)){
Console.WriteLine("[!] Error: File {0} not found.", filename);
}
return JToken.Parse(File.ReadAllText(filename));
}
}
}