1
1
# Command Line Interface (CLI)
2
2
3
- This covers more advanced CLI use cases and workflows. To [ get started] ( README.md#getting-started ) with the CLI, reference
4
- the [ README] ( README.md ) . Basic use of the CLI such as [ creating a rule] ( CONTRIBUTING.md#creating-a-rule-with-the-cli ) or
3
+ This covers more advanced CLI use cases and workflows. To [ get started] ( README.md#getting-started ) with the CLI, reference
4
+ the [ README] ( README.md ) . Basic use of the CLI such as [ creating a rule] ( CONTRIBUTING.md#creating-a-rule-with-the-cli ) or
5
5
[ testing] ( CONTRIBUTING.md#testing-a-rule-with-the-cli ) are referenced in the [ contribution guide] ( CONTRIBUTING.md ) .
6
6
7
7
8
8
## Using a config file or environment variables
9
9
10
- CLI commands which are tied to Kibana and Elasticsearch are capable of parsing auth-related keyword args from a config
11
- file or environment variables.
10
+ CLI commands which are tied to Kibana and Elasticsearch are capable of parsing auth-related keyword args from a config
11
+ file or environment variables.
12
12
13
- If a value is set in multiple places, such as config file and environment variable, the order of precedence will be as
13
+ If a value is set in multiple places, such as config file and environment variable, the order of precedence will be as
14
14
follows:
15
15
* explicitly passed args (such as ` --user joe ` )
16
16
* environment variables
@@ -35,10 +35,10 @@ EX: `DR_USER=joe`
35
35
36
36
## Importing rules into the repo
37
37
38
- You can import rules into the repo using the ` create-rule ` or ` import-rules ` commands. Both of these commands will
39
- require that the rules are schema-compliant and able to pass full validation. The biggest benefit to using these
40
- commands is that they will strip[ * ] ( #note ) additional fields[ ** ] ( #note-2 ) and prompt for missing required
41
- fields.
38
+ You can import rules into the repo using the ` create-rule ` or ` import-rules ` commands. Both of these commands will
39
+ require that the rules are schema-compliant and able to pass full validation. The biggest benefit to using these
40
+ commands is that they will strip[ * ] ( #note ) additional fields[ ** ] ( #note-2 ) and prompt for missing required
41
+ fields.
42
42
43
43
Alternatively, you can manually place rule files in the directory and run tests to validate as well.
44
44
@@ -81,10 +81,10 @@ Options:
81
81
```
82
82
83
83
The primary advantage of using this command is the ability to import multiple rules at once. Multiple rule paths can be
84
- specified explicitly with unlimited arguments, recursively within a directory using ` -d/--directory ` [ * ] ( #note-3 ) , or
84
+ specified explicitly with unlimited arguments, recursively within a directory using ` -d/--directory ` [ * ] ( #note-3 ) , or
85
85
a combination of both.
86
86
87
- In addition to the formats mentioned using ` create-rule ` , this will also accept an ` .ndjson ` /` jsonl ` file
87
+ In addition to the formats mentioned using ` create-rule ` , this will also accept an ` .ndjson ` /` jsonl ` file
88
88
containing multiple rules (as would be the case with a bulk export).
89
89
90
90
This will also strip additional fields and prompt for missing required fields.
@@ -103,6 +103,7 @@ defined, otherwise arguments should be passed to the sub-command as:
103
103
104
104
` python -m detection-rules kibana -u <username> -p <password> upload-rule <...> `
105
105
106
+
106
107
``` console
107
108
python -m detection_rules es -h
108
109
@@ -122,30 +123,111 @@ Commands:
122
123
collect-events Collect events from Elasticsearch.
123
124
```
124
125
126
+ Providers are the name that Elastic Cloud uses to configure authentication in Kibana. When we create deployment, Elastic Cloud configures two providers by default: basic/cloud-basic and saml/cloud-saml (for SSO).
127
+
125
128
``` console
126
129
python -m detection_rules kibana -h
127
130
131
+ █▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
132
+ █ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
133
+ █▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
134
+
128
135
Usage: detection_rules kibana [OPTIONS] COMMAND [ARGS]...
129
136
130
137
Commands for integrating with Kibana.
131
138
132
139
Options:
140
+ --ignore-ssl-errors TEXT
133
141
--space TEXT Kibana space
134
- -kp, --kibana-password TEXT
142
+ --provider-name TEXT For cloud deployments, Elastic Cloud configures
143
+ two providers by default: cloud-basic and
144
+ cloud-saml (for SSO)
145
+ --provider-type TEXT For cloud deployments, Elastic Cloud configures
146
+ two providers by default: basic and saml (for
147
+ SSO)
135
148
-ku, --kibana-user TEXT
136
- --cloud-id TEXT
137
- -k, --kibana-url TEXT
149
+ --kibana-url TEXT
150
+ -kp, --kibana-password TEXT
151
+ -kc, --kibana-cookie TEXT Cookie from an authed session
152
+ --cloud-id TEXT ID of the cloud instance. Defaults the cloud
153
+ provider to cloud-basic if this option is
154
+ supplied
138
155
-h, --help Show this message and exit.
139
156
140
157
Commands:
141
- upload-rule Upload a list of rule .toml files to Kibana.
158
+ search-alerts Search detection engine alerts with KQL.
159
+ upload-rule Upload a list of rule .toml files to Kibana.
160
+ ```
161
+
162
+ ## Searching Kibana for Alerts
163
+
164
+ Alerts stored in Kibana can be quickly be identified by searching with the ` search-alerts ` command.
165
+
166
+
167
+ ``` console
168
+ python -m detection_rules kibana search-alerts -h
169
+
170
+ Kibana client:
171
+ Options:
172
+ --ignore-ssl-errors TEXT
173
+ --space TEXT Kibana space
174
+ --provider-name TEXT For cloud deployments, Elastic Cloud configures
175
+ two providers by default: cloud-basic and
176
+ cloud-saml (for SSO)
177
+ --provider-type TEXT For cloud deployments, Elastic Cloud configures
178
+ two providers by default: basic and saml (for
179
+ SSO)
180
+ -ku, --kibana-user TEXT
181
+ --kibana-url TEXT
182
+ -kp, --kibana-password TEXT
183
+ -kc, --kibana-cookie TEXT Cookie from an authed session
184
+ --cloud-id TEXT ID of the cloud instance. Defaults the cloud
185
+ provider to cloud-basic if this option is
186
+ supplied
187
+
188
+ Usage: detection_rules kibana search-alerts [OPTIONS] [QUERY]
189
+
190
+ Search detection engine alerts with KQL.
191
+
192
+ Options:
193
+ -d, --date-range <TEXT TEXT>...
194
+ Date range to scope search
195
+ -c, --columns TEXT Columns to display in table
196
+ -e, --extend If columns are specified, extend the
197
+ original columns
198
+ -h, --help Show this message and exit.
142
199
```
143
200
201
+ Running the following command will print out a table showing any alerts that have been generated recently.
202
+ ` python3 -m detection_rules kibana --provider-name cloud-basic --kibana-url <url> --kibana-user <username> --kibana-password <password> search-alerts `
144
203
204
+ ``` console
205
+
206
+ █▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄ █▀▀▄ ▄ ▄ ▄ ▄▄▄ ▄▄▄
207
+ █ █ █▄▄ █ █▄▄ █ █ █ █ █ █▀▄ █ █▄▄▀ █ █ █ █▄▄ █▄▄
208
+ █▄▄▀ █▄▄ █ █▄▄ █▄▄ █ ▄█▄ █▄█ █ ▀▄█ █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█
209
+
210
+ ===================================================================================================================================
211
+ host rule
212
+ hostname name @timestamp
213
+ ===================================================================================================================================
214
+ stryker-malwares-MacBook-Pro.local Sudo Heap-Based Buffer Overflow Attempt 2022-06-21T14:08:34.288Z
215
+ stryker-malwares-MacBook-Pro.local Suspicious Automator Workflows Execution 2022-06-21T13:58:30.857Z
216
+ stryker-malwares-MacBook-Pro.local Privilege Escalation Enumeration via LinPEAS 2022-06-21T13:33:18.218Z
217
+ stryker-malwares-MacBook-Pro.local Privilege Escalation Enumeration via LinPEAS 2022-06-21T13:28:14.685Z
218
+ stryker-malwares-MacBook-Pro.local Potential Reverse Shell Activity via Terminal 2022-06-21T12:53:00.234Z
219
+ stryker-malwares-MacBook-Pro.local Potential Reverse Shell Activity via Terminal 2022-06-21T12:53:00.237Z
220
+ stryker-malwares-MacBook-Pro.local Potential Kerberos Attack via Bifrost 2022-06-20T20:33:53.810Z
221
+ stryker-malwares-MacBook-Pro.local Potential Kerberos Attack via Bifrost 2022-06-20T20:33:53.813Z
222
+ stryker-malwares-MacBook-Pro.local Potential Privilege Escalation via Root Crontab File Modification 2022-06-20T20:23:50.557Z
223
+ stryker-malwares-MacBook-Pro.local Download and Execution of JavaScript Payload 2022-06-20T20:18:46.211Z
224
+ ===================================================================================================================================
225
+
226
+ ```
145
227
## Uploading rules to Kibana
146
228
147
- Toml formatted rule files can be uploaded as custom rules using the ` kibana upload-rule ` command. To upload more than one
148
- file, specify multiple files at a time as individual args. This command is meant to support uploading and testing of
229
+ Toml formatted rule files can be uploaded as custom rules using the ` kibana upload-rule ` command. To upload more than one
230
+ file, specify multiple files at a time as individual args. This command is meant to support uploading and testing of
149
231
rules and is not intended for production use in its current state.
150
232
151
233
``` console
@@ -172,7 +254,7 @@ Options:
172
254
(detection-rules-build) (base) ➜ detection-rules git:(rule-loader) ✗
173
255
```
174
256
175
- Alternatively, rules can be exported into a consolidated ndjson file which can be imported in the Kibana security app
257
+ Alternatively, rules can be exported into a consolidated ndjson file which can be imported in the Kibana security app
176
258
directly.
177
259
178
260
``` console
@@ -195,13 +277,13 @@ Options:
195
277
-h, --help Show this message and exit.
196
278
```
197
279
198
- _ * To load a custom rule, the proper index must be setup first. The simplest way to do this is to click
280
+ _ * To load a custom rule, the proper index must be setup first. The simplest way to do this is to click
199
281
the ` Load prebuilt detection rules and timeline templates ` button on the ` detections ` page in the Kibana security app._
200
282
201
283
202
284
## Converting between JSON and TOML
203
285
204
- [ Importing rules] ( #importing-rules-into-the-repo ) will convert from any supported format to toml. Additionally, the
286
+ [ Importing rules] ( #importing-rules-into-the-repo ) will convert from any supported format to toml. Additionally, the
205
287
command ` view-rule ` will also allow you to view a converted rule without importing it by specifying the ` --rule-format ` flag.
206
288
207
289
To view a rule in JSON format, you can also use the ` view-rule ` command with the ` --api-format ` flag, which is the default.
@@ -215,7 +297,7 @@ white space stripped, normalized, sorted, and indented, prior to their json conv
215
297
table is also stripped out, as this is meant to be used only in the context of this repository and not in Kibana..
216
298
217
299
Additionally, the ` version ` of the rule is added to the file prior to exporting it. This is done to restrict version bumps
218
- to occur intentionally right before we create a release. Versions are auto-incremented based on detected changes in
300
+ to occur intentionally right before we create a release. Versions are auto-incremented based on detected changes in
219
301
rules. This is based on the hash of the rule in the following format:
220
302
* sorted json
221
303
* serialized
@@ -229,5 +311,5 @@ As a result, all cases where rules are shown or converted to JSON are not just s
229
311
Most of the CLI errors will print a concise, user friendly error. To enable debug mode and see full error stacktraces,
230
312
you can define ` "debug": true ` in your config file, or run ` python -m detection-rules -d <commands...> ` .
231
313
232
- Precedence goes to the flag over the config file, so if debug is enabled in your config and you run
314
+ Precedence goes to the flag over the config file, so if debug is enabled in your config and you run
233
315
` python -m detection-rules --no-debug ` , debugging will be disabled.
0 commit comments