Skip to content

Commit a70fa70

Browse files
authored
SMTPBatchOutput bot (#2253)
SMTPBatchOutput bot Hi, we use this bot in CSIRT.cz since 2015 to inform our constituents about all recent incidents twice a week. Events are aggregated in a redis cache by the abuse e-mail and sent at once. Since we are reaching the external organisations, we've put together some experience to tune up the format of the CSV so that people of various IT skills were able to open it in their spreadsheet software, we use GPG signing and pack the events into ZIP files as we sometimes hit the ceiling of an SMTP server. We've recently upgraded the syntax to honour the IntelMQ 3, cleaned up the code, put some tips (like CRON setup) to bots.rst and be glad if the community would accept the bot.
1 parent 99a632f commit a70fa70

File tree

10 files changed

+548
-0
lines changed

10 files changed

+548
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ D
1717
Dalila Lima <dcrypt3d@gmail.com>
1818
Dognaedis <github@dognaedis.com>
1919
Dustin Demuth <dustin.demuth@intevation.de>
20+
Edvard Rejthar, CSIRT.cz <edvard.rejthar+intelmq@nic.cz>
2021
Franz Nemeth <franz.nemeth@fnemeth.net>
2122
Fyodor Y <fygrave@gmail.com>
2223
Gernot Schulz <gernot@intevation.de>

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ CHANGELOG
4848
#### Outputs
4949
- `intelmq.bots.outputs.cif3.output`: Added (PR#2244 by Michael Davis).
5050
- `intelmq.bots.outputs.sql.output`: New parameter `fail_on_errors` (PR#2362 by Sebastian Wagner).
51+
- `intelmq.bots.outputs.smtp_batch.output`: Added a bot to gathering the events and sending them by e-mails at a stroke as CSV files (PR#2253 by Edvard Rejthar)
5152

5253
### Documentation
5354

docs/user/bots.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,6 +4050,73 @@ The prime motivation for creating this feature was to protect users from badness
40504050
More information: https://dnsrpz.info
40514051
40524052
4053+
.. _intelmq.bots.outputs.smtp_batch.output:
4054+
4055+
SMTP Batch Output Bot
4056+
4057+
Aggregate events by e-mail addresses in the `source.abuse_contact` field and batch send them at once as a zipped CSV file attachment in a GPG signed message.
4058+
4059+
**Information**
4060+
4061+
* `name:` intelmq.bots.outputs.smtp_batch.output
4062+
* `lookup:` no
4063+
* `public:` yes
4064+
* `cache (redis db):` none
4065+
* `description:` Sends events collected over a period of time via SMTP in a GPG signed messages
4066+
4067+
**Configuration Parameters**
4068+
4069+
* `alternative_mails`: string or null. Path to CSV in the form `original@email.com,alternative@email.com`.
4070+
- Needed when some of the recipients ask you to forward their e-mails to another address.
4071+
* `attachment_name`: string. Attachment file name for the outgoing messages. May contain date formatting like this `%Y-%m-%d`. Example: "events_%Y-%m-%d" will appear as "events_2022-12-01.zip".
4072+
* `bcc`: list or null. A list of e-mails to be put in the `Bcc` field for every mail.
4073+
* `email_from`: string. Sender's e-mail of the outgoing messages.
4074+
* `gpg_key`: string or null. The Key or the fingerprint of a GPG key stored in ~/.gnupg keyring folder.
4075+
* `gpg_pass`: string or null. Password for the GPG key if needed.
4076+
* `mail_template`: string. Path to the file containing the body of the mail for the outgoing messages.
4077+
* `ignore_older_than_days`: int or null, default 0. If 1..n skip all events with time.observation older than 1..n day; 0 disabled (allow all).
4078+
- If your queue gets stuck for a reason, you do not want to send old (and probably already solved) events.
4079+
* `limit_results`: int or null. Intended as a debugging option, allows loading just first N e-mails from the queue.
4080+
* `redis_cache_db`: int. Redis database used for event aggregation. As the databases < 10 are reserved for the IntelMQ core, recommended is a bigger number.
4081+
* `redis_cache_host`: string
4082+
* `redis_cache_port`: int
4083+
* `redis_cache_ttl`: int. Recommended 1728000 for 20 days.
4084+
* `smtp_server`: mixed. SMTP server information and credentials.
4085+
- See SMTP parameter of https://github.com/CZ-NIC/envelope#sending
4086+
- Examples: "mailer", `{"host": "mailer", "port": 587, "user": "john", "password": "123"}`, `["mailer", 587, "john", "password"]`
4087+
* `subject`: string. Subject for the outgoing messages. May contain date formatting like this `%Y-%m-%d`. Example: "IntelMQ weekly warning (%d.%m.%Y)".
4088+
* `testing_to`: string or null. Tester's e-mail.
4089+
4090+
When the bot is run normally by IntelMQ, it just aggregates the events for later use into a custom Redis database.
4091+
If run through CLI (by a cron or manually), it shows e-mail messages that are ready to be sent and let you send them to the tester's e-mail OR to abuse contact e-mails.
4092+
E-mails are sent in a zipped CSV file, delimited by a comma, while keeping strings in double quotes.
4093+
Note: The field "raw" gets base64 decoded if possible. Bytes `\n` and `\r` are replaced with "\n" and "\r" strings in order to guarantee best CSV files readability both in Microsoft Office and LibreOffice. (A multiline string may be stored in "raw" which completely confused Microsoft Excel.)
4094+
4095+
Launch it like that:
4096+
`</usr/local/bin executable> <bot-id> cli [--tester tester's email]`
4097+
Ex:
4098+
`intelmq.bots.outputs.smtp_batch.output smtp_batch-output-cz --cli --tester your-email@example.com`
4099+
4100+
CLI flags:
4101+
```
4102+
-h, --help show this help message and exit
4103+
--cli initiate CLI interface
4104+
--tester TESTING_TO tester's e-mail
4105+
--ignore-older-than-days IGNORE_OLDER_THAN_DAYS
4106+
1..n skip all events with time.observation older than 1..n day; 0 disabled (allow all)
4107+
--gpg-key GPG_KEY fingerprint of gpg key to be used
4108+
--limit-results LIMIT_RESULTS
4109+
Just send first N mails.
4110+
--send Sends now, without dialog.
4111+
```
4112+
4113+
You can schedule the batch sending easily with a cron script, I.E. put this into `crontab -e` of the `intelmq` user:
4114+
4115+
```
4116+
# Send the e-mails every day at 6 AM
4117+
0 6 * * * /usr/local/bin/intelmq.bots.outputs.smtp_batch.output smtp_batch-output-cz cli --ignore-older-than-days 4 --send > /tmp/intelmq-send.log
4118+
```
4119+
40534120
.. _intelmq.bots.outputs.smtp.output:
40544121
40554122
SMTP Output Bot
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-FileCopyrightText: 2022 CSIRT.cz <https://csirt.cz>
2+
# SPDX-License-Identifier: AGPL-3.0-or-later
3+
envelope

intelmq/bots/outputs/smtp_batch/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)