Skip to content

Commit 2b698c7

Browse files
authored
DET-1326 - Update the custom rule article (#5444)
* Update layout * Update * Final updates * Update screenshot
1 parent 71e642d commit 2b698c7

File tree

2 files changed

+34
-38
lines changed

2 files changed

+34
-38
lines changed

docs/cse/rules/before-writing-custom-rule.md

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,56 +51,52 @@ Now that we understand the mapping in Cloud SIEM, we can see we will want to be
5151

5252
In this step, we’ll create the query that will serve as the rule expression when we create the rule.
5353

54-
Using the attributes we discovered from looking at the log mapping, we’ll run the following query, which returns the usernames that have successfully logged on over the last week, counted by `user_username`.
54+
1. Using the attributes we discovered from looking at the log mapping, we’ll run the following query, which returns the usernames that have successfully logged on over the last week, counted by `user_username`:
5555

56-
```sql
57-
_index=sec_record_*
58-
| where metadata_vendor = "Microsoft" and metadata_product = "Windows" and metadata_deviceEventId = "Security-4624"
59-
| count by user_username
60-
```
56+
```sql
57+
_index=sec_record_*
58+
| where metadata_vendor = "Microsoft" and metadata_product = "Windows" and metadata_deviceEventId = "Security-4624"
59+
| count by user_username
60+
```
6161

62-
<img src={useBaseUrl('img/cse/count-by-user.png')} alt="Count by user" width="800"/>
62+
<img src={useBaseUrl('img/cse/count-by-user.png')} alt="Count by user" width="800"/>
6363

64-
The results show two of our standard username patterns: 
64+
The results show two of our standard username patterns: 
6565

66-
* The username for regular user accounts are a plain string, with no special characters, like specops and jask.
67-
* Machine usernames are a string, followed by a dash character, followed by a string, followed by a dollar sign, like `win10-admin$` and `win10-client$`.
66+
* The username for regular user accounts are a plain string, with no special characters, like `specops` and `jask`.
67+
* Machine usernames are a string, followed by a dash character, followed by a string, followed by a dollar sign, like `win10-admin$` and `win10-client$`.
6868

69-
Now, we can refine our search to return usernames that do not comply with either of our standard patterns.
69+
1. Now, we can refine our search to return usernames that do not comply with either of our standard patterns:
7070

71-
```sql
72-
_index=sec_record_*
73-
| where metadata_vendor = "Microsoft" and metadata_product = "Windows" and metadata_deviceEventId = "Security-4624" and !(user_username matches /^[a-zA-Z]*$/ or user_username matches "*-*$")
74-
| count by user_username
75-
```
71+
```sql
72+
_index=sec_record_*
73+
| where metadata_vendor = "Microsoft" and metadata_product = "Windows" and metadata_deviceEventId = "Security-4624" and !(user_username matches /^[a-zA-Z]*$/ or user_username matches "*-*$")
74+
| count by user_username
75+
```
7676

77-
<img src={useBaseUrl('img/cse/non-matching-patterns.png')} alt="Non-matching patterns" width="800"/>
77+
<img src={useBaseUrl('img/cse/non-matching-patterns.png')} alt="Non-matching patterns" width="800"/>
7878

79-
Usernames returned include “anonymous logon”. A little [research](https://social.technet.microsoft.com/Forums/ie/en-US/dbcbb9f1-c6a7-43ea-94b8-ba72a89e2221/nt-authorityanonymous-logon?forum=winservergen) indicates that this is typically no cause for alarm, so we’ll refine our search again to exclude “anonymous logon”.
79+
1. Usernames returned include “anonymous logon”. A little [research](https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/understand-special-identities-groups) indicates that this is typically no cause for alarm, so we’ll refine our search again to exclude “anonymous logon”:
8080

81-
```sql
82-
_index=sec_record_*
83-
| where metadata_vendor = "Microsoft" and metadata_product = "Windows" and metadata_deviceEventId = "Security-4624" and !(user_username matches /^[a-zA-Z]*$/ or user_username matches "*-*$") and user_username != "anonymous logon"
84-
```
81+
```sql
82+
_index=sec_record_*
83+
| where metadata_vendor = "Microsoft" and metadata_product = "Windows" and metadata_deviceEventId = "Security-4624" and !(user_username matches /^[a-zA-Z]*$/ or user_username matches "*-*$") and user_username != "anonymous logon"
84+
```
8585

86-
Now that we’ve sorted out the usernames formats and values we want to exclude, we’ve removed \| count by `user_username` from the query.
86+
Now that we’ve sorted out the usernames formats and values we want to exclude, we’ve removed `| count by user_username` from the query.
8787

88-
Let’s say there is a field of interest in our raw messages—`EventData.ProcessName`—that isn’t mapped to a Cloud SIEM schema attribute. We want to parse that field out of the message so we can use it in our logic as well. We only want our rule to fire if a user with an anomalous logon ran an .exe process after successfully logging in. You can see all of the fields in the raw message in the **Messages** tab of your search results.
88+
1. Now we have a query we can use as the basis of an expression for our rule. Note that when you paste it into the rules editor, you should remove the first portion of the query (`_index=sec_record_*` and `| where`), which is only necessary when you are querying records in Sumo Logic. The expression is then as follows:
8989

90-
<img src={useBaseUrl('img/cse/messages-tab.png')} alt="Messages tab" width="800"/>
90+
```sql
91+
metadata_vendor = "Microsoft"
92+
and metadata_product = "Windows"
93+
and metadata_deviceEventId = "Security-4624"
94+
and !(user_username matches /^[a-zA-Z]*$/ or user_username matches "*-*$")
95+
and user_username != "anonymous logon"
96+
```
9197

92-
We update the query to parse out `EventData.ProcessName`, naming it `process_name`, and filtering to only fire on `.exe` files. 
98+
Also ensure that the syntax of the expression matches what is needed by the [Cloud SIEM rules syntax](/docs/cse/rules/cse-rules-syntax/). Once you are satisfied that the expression is ready, click **Test Rule Expression** to verify that the expression returns expected results.
9399

94-
```sql
95-
_index=sec_record_*
96-
| json field=_raw "$['EventData.ProcessName']" as process_name
97-
| where metadata_vendor = "Microsoft" and metadata_product = "Windows" and metadata_deviceEventId = "Security-4624" and !(user_username matches /^[a-zA-Z]*$/ or user_username matches "*-*$") and user_username != "anonymous logon" and process_name matches "*.exe"
98-
```
100+
You can use an expression like this example in any rule type. Here is an example Match rule with the expression, shown in the rules editor.
99101

100-
Now we have a query we can use as the rule expression for our rule. Note that when you paste it into the rules editor you should remove the first portion of the query, which is only necessary when you are querying records in Sumo Logic:
101-
102-
`_index=sec_record_*`
103-
104-
You can use an expression like this example in any rule type. Here is an example Match rule with the expression, shown in the rules editor.
105-
106-
<img src={useBaseUrl('img/cse/example-in-editor.png')} alt="Example in editor" width="700"/>
102+
<img src={useBaseUrl('img/cse/example-in-editor.png')} alt="Example in editor" width="700"/>
66.8 KB
Loading

0 commit comments

Comments
 (0)