You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Shorten the example configuration to the essential rules and move it
to the examples.
- Remove any mention of a `default` rule behaviour that does not exist
- Better describe the conditions and what it does with different types,
regular expressions
- Add how to delete fields
- Add an abstract rule to explain the format
- Describe the rule name
- Describe how to check for an existence of a field
Copy file name to clipboardExpand all lines: docs/user/bots.md
+60-50Lines changed: 60 additions & 50 deletions
Original file line number
Diff line number
Diff line change
@@ -3229,7 +3229,7 @@ This bots allows you to change arbitrary field values of events using a configur
3229
3229
3230
3230
(optional, boolean) Overwrite any existing fields by matching rules. Defaults to false.
3231
3231
3232
-
**Configuration File**
3232
+
#### Configuration File Format
3233
3233
3234
3234
The modify expert bot allows you to change arbitrary field values of events just using a configuration file. Thus it is
3235
3235
possible to adapt certain values or adding new ones only by changing JSON-files without touching the code of many other
@@ -3240,43 +3240,83 @@ The configuration is called `modify.conf` and looks like this:
3240
3240
```json
3241
3241
[
3242
3242
{
3243
-
"rulename": "Standard Protocols http",
3243
+
"rulename": "Name of Rule 1",
3244
3244
"if": {
3245
-
"source.port": "^(80|443)$"
3245
+
"fieldname": "comparison_value"
3246
3246
},
3247
3247
"then": {
3248
-
"protocol.application": "http"
3248
+
"fieldname": "newvalue"
3249
3249
}
3250
3250
},
3251
+
[...]
3252
+
]
3253
+
```
3254
+
3255
+
Each rule consists of a *rule name*, *conditions* and *actions*:
3256
+
The rule name is for your own documentation and only used in debugging output.
3257
+
Conditions and actions are dictionaries holding the field names of
3258
+
events and regular expressions to match values (selection) or set values (action). All matching rules will be applied in
3259
+
the given order. The actions of a rule are only performed if all conditions of the rule apply.
3260
+
3261
+
One configuration file can contain an arbitrary number of rules.
3262
+
3263
+
#### Condition
3264
+
3265
+
* **Empty string**: If the value for a condition is an empty string, the bot checks if the field does not exist. This is useful to apply default values for empty fields.
3266
+
* A non-empty **string**: The matching uses [regular expressions](https://docs.python.org/3/library/re.html#re.search) to match the field. Use explicit beginning and end markers to match the full string instead of a substring: `^regex$`.
3267
+
If the field is not a string, it will be converted to a string first. This allows for matching numeric values with regular expressions.
3268
+
* All **other types**: boolean, integer, float, etc: Direct equality comparison
3269
+
3270
+
To check for the existence of a field, you can therefore always use the condition `"."`.
3271
+
3272
+
#### Action
3273
+
3274
+
You can set the value of the field to a string literal or number.
3275
+
3276
+
In addition you can use the [standard Python string format syntax](https://docs.python.org/3/library/string.html#format-string-syntax) to access the values from the processed event as `msg` and the match groups of the conditions as `matches`, see the bitdefender example above. Group 0 ([`0`]) contains the full matching string. See also the documentation on [re.Match.group](https://docs.python.org/3/library/re.html?highlight=re%20search#re.Match.group).
3277
+
3278
+
Setting a field to an empty string deletes the field, for example:
3279
+
```json
3280
+
[
3251
3281
{
3282
+
"rulename": "Delete NAICS",
3283
+
"if": {
3284
+
"extra.naics": "."
3285
+
},
3286
+
"then": {
3287
+
"extra.naics": ""
3288
+
}
3289
+
}
3290
+
]
3291
+
```
3292
+
The same effect can be achieved with the [Field Reducer Expert](#intelmq.bots.experts.field_reducer.expert).
3293
+
3294
+
#### Examples
3295
+
3296
+
```json
3297
+
[
3298
+
{
3252
3299
"rulename": "Spamhaus Cert conficker",
3253
3300
"if": {
3301
+
"feed.name": "^Spamhaus Cert$",
3254
3302
"malware.name": "^conficker(ab)?$"
3255
3303
},
3256
3304
"then": {
3257
3305
"classification.identifier": "conficker"
3258
3306
}
3259
3307
},
3260
3308
{
3261
-
"rulename": "bitdefender",
3309
+
"rulename": "Spamhaus Cert bitdefender",
3262
3310
"if": {
3311
+
"feed.name": "^Spamhaus Cert$",
3263
3312
"malware.name": "bitdefender-(.*)$"
3264
3313
},
3265
3314
"then": {
3266
3315
"malware.name": "{matches[malware.name][1]}"
3267
3316
}
3268
3317
},
3269
3318
{
3270
-
"rulename": "urlzone",
3271
-
"if": {
3272
-
"malware.name": "^urlzone2?$"
3273
-
},
3274
-
"then": {
3275
-
"classification.identifier": "urlzone"
3276
-
}
3277
-
},
3278
-
{
3279
-
"rulename": "default",
3319
+
"rulename": "Spamhaus Cert default",
3280
3320
"if": {
3281
3321
"feed.name": "^Spamhaus Cert$"
3282
3322
},
@@ -3287,44 +3327,14 @@ The configuration is called `modify.conf` and looks like this:
3287
3327
]
3288
3328
```
3289
3329
3290
-
In our example above we have five groups labeled `Standard Protocols http`, `Spamhaus Cert conficker`,
3291
-
`bitdefender`, `urlzone` and `default`. All sections will be considered, in the given order (from top to bottom).
3292
-
3293
-
Each rule consists of *conditions* and *actions*. Conditions and actions are dictionaries holding the field names of
3294
-
events and regular expressions to match values (selection) or set values (action). All matching rules will be applied in
3295
-
the given order. The actions are only performed if all selections apply.
3296
-
3297
-
If the value for a condition is an empty string, the bot checks if the field does not exist. This is useful to apply
3298
-
default values for empty fields.
3299
-
3300
-
**Actions**
3301
-
3302
-
You can set the value of the field to a string literal or number.
3303
-
3304
-
In addition you can use the [standard Python string format syntax](https://docs.python.org/3/library/string.html#format-string-syntax) to access the values from the processed event as `msg` and the match groups of the conditions as `matches`, see the bitdefender example above. Group 0 ([`0`]) contains the full matching string. See also the documentation on [re.Match.group](https://docs.python.org/3/library/re.html?highlight=re%20search#re.Match.group).
3305
-
3306
-
Note that `matches` will also contain the match groups from the default conditions if there were any.
3307
-
3308
-
**Examples**
3309
-
3310
-
We have an event with `feed.name = Spamhaus Cert` and `malware.name = confickerab`. The expert loops over all sections
3311
-
in the file and eventually enters section `Spamhaus Cert`. First, the default condition is checked, it matches!
3312
-
OK, going on. Otherwise the expert would have selected a different section that has not yet been considered. Now, go
3313
-
through the rules, until we hit the rule `conficker`. We combine the conditions of this rule with the default
3314
-
conditions, and both rules match! So we can apply the action: `classification.identifier`is set to `conficker`, the
3315
-
trivial name.
3316
-
3317
-
Assume we have an event with `feed.name = Spamhaus Cert` and `malware.name = feodo`. The default condition matches, but
3318
-
no others. So the default action is applied. The value for `classification.identifier` will be set to `feodo`
3319
-
by `{msg[malware.name]}`.
3330
+
In our example above we have three rules named `Spamhaus Cert conficker`,
Assume we have an event with `feed.name = Spamhaus Cert` and `malware.name = confickerab`, and `maximum_matches` is set to 1.
3322
3334
3323
-
If the rule is a string, a regular expression search is performed, also for numeric values (`str()` is called on them).
3324
-
If the rule is numeric for numeric values, a simple comparison is done. If other types are mixed, a warning will be
3325
-
thrown.
3335
+
The expert loops over all sections in the file, and the first matching one is `Spamhaus Cert conficker`. It applies the action, setting the new `classification.identifier` and then stops, as the maximum matches has been reached.
3326
3336
3327
-
For boolean values, the comparison value needs to be `true` or `false` as in JSON they are written all-lowercase.
3337
+
Assume we have an event with `feed.name = Spamhaus Cert` and `malware.name = feodo`. The first and only matching rule is the `default`. So the default action is applied. The value for `classification.identifier` will be set to `feodo` by `{msg[malware.name]}`.
0 commit comments