|
| 1 | +## tallow.patterns |
| 2 | + |
| 3 | +Tallow pattern matching configuration files. |
| 4 | + |
| 5 | + |
| 6 | +## SYNOPSIS |
| 7 | + |
| 8 | +tallow(1) uses regular expressions to match journal entries and extract an IP |
| 9 | +address from them. JSON files are used to configure the patterns and banning |
| 10 | +thresholds used by tallow(1). |
| 11 | + |
| 12 | +`/etc/tallow/*.json` |
| 13 | +`/usr/share/tallow/*.json` |
| 14 | + |
| 15 | + |
| 16 | +## DESCRIPTION |
| 17 | + |
| 18 | +tallow(1) uses regular expressions to match journal entries and extract an IP |
| 19 | +address from them. JSON files are used to configure the patterns and banning |
| 20 | +thresholds used by tallow(1). This adds the ability to extend the patterns |
| 21 | +tallow(1) will recognize. Many JSON files can exist for logical grouping. The |
| 22 | +tallow(1) daemon will read all JSON files in the configuration directories at |
| 23 | +startup. |
| 24 | + |
| 25 | +tallow(1) operates with default pattern definitions |
| 26 | +in`/usr/share/tallow/*.json`. Users can add more patterns with their own JSON |
| 27 | +files under `/etc/tallow`. The default JSON files can be overridden by creating |
| 28 | +the same file under `/etc/tallow`. |
| 29 | + |
| 30 | + |
| 31 | +## FILE FORMAT |
| 32 | + |
| 33 | +Pattern configuration files use the JavaScript Object Notation (JSON) format. |
| 34 | + |
| 35 | +The JSON must be two levels deep and all properties are required. The root |
| 36 | +object is an array containing objects with a `filter` key and an `items` key. |
| 37 | + |
| 38 | +* `filter` is a string that defines a field for filtering the journal file. |
| 39 | + This helps make sure patterns are only matched to a subset of journal |
| 40 | + entries. See systemd.journal-fields(7) for valid journal fields. |
| 41 | + |
| 42 | +* `items` is an array of objects that contains three elements: `ban`, `score`, |
| 43 | + and `pattern`. |
| 44 | + |
| 45 | + * `ban` is an integer that defines the number of seconds to ban originating |
| 46 | + IP for. If this value is > 0, the IP address get banned immediately when a |
| 47 | + journal entry matches `pattern`. |
| 48 | + |
| 49 | + * `score` is a double that defines a value to add to the accumulated "score" |
| 50 | + of an originating IP address each time a journal entry matches |
| 51 | + the `pattern`. If the combined score is > 1.0, tallow bans the originating |
| 52 | + IP for the default time of 1 hour. The `ban` element value above is not |
| 53 | + used for bans made due to `score`. |
| 54 | + |
| 55 | + * `pattern` is a string that defines a Perl Compatible Regular Expressions |
| 56 | + (PCRE) to match against the filtered journal entries. The PCRE should |
| 57 | + extract exactly one substring: the originating IP address for tallow(1). |
| 58 | + See systemd.journal-fields(7) for valid journal fields. |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +## EXAMPLES |
| 63 | + |
| 64 | +1. The JSON below is a snippet from one of the default pattern configuration |
| 65 | + files for blocking certain failed `sshd` connections. |
| 66 | + |
| 67 | + The first pattern will ban an IP address after it fails to login 6 times |
| 68 | + causing it to reach a total score > 1.0. |
| 69 | + |
| 70 | + The second pattern will ban an IP address for 10 seconds every time a login is |
| 71 | + attempted with an invalid user. Additionally, it will ban the IP address for |
| 72 | + 1 hour if it attempts to login with an invalid user 6 times causing it to |
| 73 | + reach a total score > 1.0. |
| 74 | + |
| 75 | + See the `/usr/share/tallow/sshd.json` file for more `sshd` examples. |
| 76 | + |
| 77 | + ``` |
| 78 | + [ |
| 79 | + { |
| 80 | + "filter": "SYSLOG_IDENTIFIER=sshd", |
| 81 | + "items": [ |
| 82 | + { |
| 83 | + "ban": 0, |
| 84 | + "score": 0.2, |
| 85 | + "pattern": "MESSAGE=Failed .* for .* from ([0-9a-z:.]+) port \\d+ ssh2" |
| 86 | + }, |
| 87 | + { |
| 88 | + "ban": 10, |
| 89 | + "score": 0.2, |
| 90 | + "pattern": "MESSAGE=Invalid user .* from ([0-9a-z:.]+) port \\d+" |
| 91 | + } |
| 92 | + ] |
| 93 | + } |
| 94 | + ] |
| 95 | + ``` |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +2. The JSON below defines a pattern for blocking connections based on error logs |
| 100 | + from `nginx-mainline` if placed in a `/etc/tallow/nginx-mainline.json` file. |
| 101 | + |
| 102 | + The pattern will ban an IP address for 15 seconds every time it attempts to |
| 103 | + access a script that does not exist. Additionally, it will ban the IP |
| 104 | + address for 1 hour if it attempts to access invalid scripts 4 times causing |
| 105 | + it to reach a total score > 1.0. |
| 106 | + |
| 107 | + ``` |
| 108 | + [ |
| 109 | + { |
| 110 | + "filter": "SYSLOG_IDENTIFIER=nginx-mainline", |
| 111 | + "items": [ |
| 112 | + { |
| 113 | + "ban": 15, |
| 114 | + "score": 0.3, |
| 115 | + "pattern": ".Primary script unknown. while reading response header from upstream, client: ([0-9a-z:.]+)," |
| 116 | + } |
| 117 | + ] |
| 118 | + } |
| 119 | + ] |
| 120 | + ``` |
| 121 | + |
| 122 | +## SEE ALSO |
| 123 | + |
| 124 | +tallow(1), tallow.conf(5) |
| 125 | + |
| 126 | +## BUGS |
| 127 | + |
| 128 | +`tallow` is `NOT A SECURITY SOLUTION`, nor does it protect against random |
| 129 | +password logins. An attacker may still be able to logon to your systems if you |
| 130 | +allow password logins. |
| 131 | + |
| 132 | +## AUTHOR |
| 133 | + |
| 134 | +Auke Kok <auke-jan.h.kok@intel.com> |
0 commit comments