Skip to content

Commit 1e9d5d8

Browse files
eirsepengechas
authored andcommitted
fix null query filter conversion from sigma to query string query (opensearch-project#722)
* fix null query filter conversion from sigma to query string query Signed-off-by: Surya Sashank Nistala <[email protected]> * fix rule to query conversion tests for null filter Signed-off-by: Surya Sashank Nistala <[email protected]> * enhance test to verify non null doc doesnt match null query Signed-off-by: Surya Sashank Nistala <[email protected]> --------- Signed-off-by: Surya Sashank Nistala <[email protected]>
1 parent 7357bb4 commit 1e9d5d8

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

src/main/java/org/opensearch/securityanalytics/rules/backend/OSQueryBackend.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public OSQueryBackend(String ruleCategory, boolean collectErrors, boolean enable
131131
this.reEscapeChar = "\\";
132132
this.reExpression = "%s: /%s/";
133133
this.cidrExpression = "%s: \"%s\"";
134-
this.fieldNullExpression = "%s: null";
134+
this.fieldNullExpression = "%s: (NOT [* TO *])";
135135
this.unboundValueStrExpression = "\"%s\"";
136136
this.unboundValueNumExpression = "\"%s\"";
137137
this.unboundWildcardExpression = "%s";

src/test/java/org/opensearch/securityanalytics/TestHelpers.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,37 @@ public static String randomRule() {
168168
"level: high";
169169
}
170170

171+
172+
public static String randomNullRule() {
173+
return "title: null field\n" +
174+
"id: 5f92fff9-82e2-48eb-8fc1-8b133556a551\n" +
175+
"description: Detects remote RPC calls to possibly abuse remote encryption service via MS-EFSR\n" +
176+
"references:\n" +
177+
" - https://attack.mitre.org/tactics/TA0008/\n" +
178+
" - https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-36942\n" +
179+
" - https://github.com/jsecurity101/MSRPC-to-ATTACK/blob/main/documents/MS-EFSR.md\n" +
180+
" - https://github.com/zeronetworks/rpcfirewall\n" +
181+
" - https://zeronetworks.com/blog/stopping_lateral_movement_via_the_rpc_firewall/\n" +
182+
"tags:\n" +
183+
" - attack.defense_evasion\n" +
184+
"status: experimental\n" +
185+
"author: Sagie Dulce, Dekel Paz\n" +
186+
"date: 2022/01/01\n" +
187+
"modified: 2022/01/01\n" +
188+
"logsource:\n" +
189+
" product: rpc_firewall\n" +
190+
" category: application\n" +
191+
" definition: 'Requirements: install and apply the RPC Firew all to all processes with \"audit:true action:block uuid:df1941c5-fe89-4e79-bf10-463657acf44d or c681d488-d850-11d0-8c52-00c04fd90f7e'\n" +
192+
"detection:\n" +
193+
" selection:\n" +
194+
" EventID: 22\n" +
195+
" RecordNumber: null\n" +
196+
" condition: selection\n" +
197+
"falsepositives:\n" +
198+
" - Legitimate usage of remote file encryption\n" +
199+
"level: high";
200+
}
201+
171202
public static String randomRuleWithKeywords() {
172203
return "title: Remote Encrypting File System Abuse\n" +
173204
"id: 5f92fff9-82e2-48eb-8fc1-8b133556a551\n" +
@@ -1353,6 +1384,44 @@ public static String randomDocOnlyNumericAndText(int severity, int version, Stri
13531384
return String.format(Locale.ROOT, doc, severity, version, opCode);
13541385
}
13551386

1387+
public static String randomDocWithNullField() {
1388+
return "{\n" +
1389+
"\"@timestamp\":\"2020-02-04T14:59:39.343541+00:00\",\n" +
1390+
"\"EventTime\":\"2020-02-04T14:59:39.343541+00:00\",\n" +
1391+
"\"HostName\":\"EC2AMAZ-EPO7HKA\",\n" +
1392+
"\"Keywords\":\"9223372036854775808\",\n" +
1393+
"\"SeverityValue\":2,\n" +
1394+
"\"Severity\":\"INFO\",\n" +
1395+
"\"EventID\":22,\n" +
1396+
"\"SourceName\":\"Microsoft-Windows-Sysmon\",\n" +
1397+
"\"ProviderGuid\":\"{5770385F-C22A-43E0-BF4C-06F5698FFBD9}\",\n" +
1398+
"\"Version\":5,\n" +
1399+
"\"TaskValue\":22,\n" +
1400+
"\"OpcodeValue\":0,\n" +
1401+
"\"RecordNumber\":null,\n" +
1402+
"\"ExecutionProcessID\":1996,\n" +
1403+
"\"ExecutionThreadID\":2616,\n" +
1404+
"\"Channel\":\"Microsoft-Windows-Sysmon/Operational\",\n" +
1405+
"\"Domain\":\"NTAUTHORITY\",\n" +
1406+
"\"AccountName\":\"SYSTEM\",\n" +
1407+
"\"UserID\":\"S-1-5-18\",\n" +
1408+
"\"AccountType\":\"User\",\n" +
1409+
"\"Message\":\"Dns query:\\r\\nRuleName: \\r\\nUtcTime: 2020-02-04 14:59:38.349\\r\\nProcessGuid: {b3c285a4-3cda-5dc0-0000-001077270b00}\\r\\nProcessId: 1904\\r\\nQueryName: EC2AMAZ-EPO7HKA\\r\\nQueryStatus: 0\\r\\nQueryResults: 172.31.46.38;\\r\\nImage: C:\\\\Program Files\\\\nxlog\\\\nxlog.exe\",\n" +
1410+
"\"Category\":\"Dns query (rule: DnsQuery)\",\n" +
1411+
"\"Opcode\":\"Info\",\n" +
1412+
"\"UtcTime\":\"2020-02-04 14:59:38.349\",\n" +
1413+
"\"ProcessGuid\":\"{b3c285a4-3cda-5dc0-0000-001077270b00}\",\n" +
1414+
"\"ProcessId\":\"1904\",\"QueryName\":\"EC2AMAZ-EPO7HKA\",\"QueryStatus\":\"0\",\n" +
1415+
"\"QueryResults\":\"172.31.46.38;\",\n" +
1416+
"\"Image\":\"C:\\\\Program Files\\\\nxlog\\\\regsvr32.exe\",\n" +
1417+
"\"EventReceivedTime\":\"2020-02-04T14:59:40.780905+00:00\",\n" +
1418+
"\"SourceModuleName\":\"in\",\n" +
1419+
"\"SourceModuleType\":\"im_msvistalog\",\n" +
1420+
"\"CommandLine\": \"eachtest\",\n" +
1421+
"\"Initiated\": \"true\"\n" +
1422+
"}";
1423+
}
1424+
13561425
public static String randomDoc() {
13571426
return "{\n" +
13581427
"\"EventTime\":\"2020-02-04T14:59:39.343541+00:00\",\n" +

src/test/java/org/opensearch/securityanalytics/rules/backend/QueryBackendTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public void testConvertValueNull() throws IOException, SigmaError {
282282
" sel:\n" +
283283
" fieldA1: null\n" +
284284
" condition: sel", false));
285-
Assert.assertEquals("mappedA: null", queries.get(0).toString());
285+
Assert.assertEquals("mappedA: (NOT [* TO *])", queries.get(0).toString());
286286
}
287287

288288
public void testConvertValueRegex() throws IOException, SigmaError {
@@ -525,7 +525,7 @@ public void testConvertOrInUnallowedValueType() throws IOException, SigmaError {
525525
" - value2\n" +
526526
" - null\n" +
527527
" condition: sel", false));
528-
Assert.assertEquals("(mappedA: \"value1\") OR (mappedA: \"value2\") OR (mappedA: null)", queries.get(0).toString());
528+
Assert.assertEquals("(mappedA: \"value1\") OR (mappedA: \"value2\") OR (mappedA: (NOT [* TO *]))", queries.get(0).toString());
529529
}
530530

531531
public void testConvertOrInListNumbers() throws IOException, SigmaError {

0 commit comments

Comments
 (0)