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
Copy file name to clipboardExpand all lines: docs/user/bots.md
+61-50Lines changed: 61 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,84 @@ 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
+
To escape a character in the regular expression, JSON requires you to double-escape, for example, in `"extra.version": "^10\\.0"` the `.` is matched as literal character.
3269
+
* All **other types**: boolean, integer, float, etc: Direct equality comparison
3270
+
3271
+
To check for the existence of a field, you can therefore always use the condition `"."`.
3272
+
3273
+
#### Action
3274
+
3275
+
You can set the value of the field to a string literal or number.
3276
+
3277
+
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).
3278
+
3279
+
Setting a field to an empty string deletes the field, for example:
3280
+
```json
3281
+
[
3251
3282
{
3283
+
"rulename": "Delete NAICS",
3284
+
"if": {
3285
+
"extra.naics": "."
3286
+
},
3287
+
"then": {
3288
+
"extra.naics": ""
3289
+
}
3290
+
}
3291
+
]
3292
+
```
3293
+
The same effect can be achieved with the [Field Reducer Expert](#intelmq.bots.experts.field_reducer.expert).
3294
+
3295
+
#### Examples
3296
+
3297
+
```json
3298
+
[
3299
+
{
3252
3300
"rulename": "Spamhaus Cert conficker",
3253
3301
"if": {
3302
+
"feed.name": "^Spamhaus Cert$",
3254
3303
"malware.name": "^conficker(ab)?$"
3255
3304
},
3256
3305
"then": {
3257
3306
"classification.identifier": "conficker"
3258
3307
}
3259
3308
},
3260
3309
{
3261
-
"rulename": "bitdefender",
3310
+
"rulename": "Spamhaus Cert bitdefender",
3262
3311
"if": {
3312
+
"feed.name": "^Spamhaus Cert$",
3263
3313
"malware.name": "bitdefender-(.*)$"
3264
3314
},
3265
3315
"then": {
3266
3316
"malware.name": "{matches[malware.name][1]}"
3267
3317
}
3268
3318
},
3269
3319
{
3270
-
"rulename": "urlzone",
3271
-
"if": {
3272
-
"malware.name": "^urlzone2?$"
3273
-
},
3274
-
"then": {
3275
-
"classification.identifier": "urlzone"
3276
-
}
3277
-
},
3278
-
{
3279
-
"rulename": "default",
3320
+
"rulename": "Spamhaus Cert default",
3280
3321
"if": {
3281
3322
"feed.name": "^Spamhaus Cert$"
3282
3323
},
@@ -3287,44 +3328,14 @@ The configuration is called `modify.conf` and looks like this:
3287
3328
]
3288
3329
```
3289
3330
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]}`.
3331
+
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
3335
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.
3336
+
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
3337
3327
-
For boolean values, the comparison value needs to be `true` or `false` as in JSON they are written all-lowercase.
3338
+
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