• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

Changelog.mdH A D30-Apr-2020187 106

LICENSEH A D30-Apr-202011.1 KiB203169

NOTICEH A D30-Apr-2020294 96

README.mdH A D30-Apr-202013.9 KiB315212

SH.pmH A D30-Apr-202031.1 KiB831674

hbltest.shH A D30-Apr-2020700 1913

sh.cfH A D30-Apr-20209.9 KiB169129

sh.preH A D03-May-2022333 84

sh_hbl.cfH A D30-Apr-20202.1 KiB3622

sh_hbl_scores.cfH A D30-Apr-2020480 1812

sh_scores.cfH A D30-Apr-20201.5 KiB6152

README.md

1
2# Using DQS with SpamAssassin
3
4This repository contains the configuration files and a plugin written for SpamAssassin, (https://spamassassin.apache.org/) for use with Spamhaus Technology Data Query Service (DQS) product.
5
6***
7
8### Table of contents
9- [What is DQS](#what-is-dqs)?
10- [What zones are available with DQS](#what-zones-are-available-with-dqs)?
11- [What are the advantages of DQS](#what-are-the-advantages-of-dqs)?
12- [How does DQS Perform](#how-does-dqs-perform)?
13	- [HBL performance boost](#hbl-performance-boost)
14- [What is the licensing for DQS](#what-is-the-licensing-for-dqs)?
15- [What is the difference between paid-for and free DQS](#what-is-the-difference-between-paid-for-and-free-dqs)?
16- [How do I register a DQS key](#how-do-i-register-a-dqs-key)?
17- [Prerequisites](#prerequisites)
18- [Conventions](#conventions)
19- Installation instructions
20	- [Install from Github](#install-from-github)
21	- [Install from FreeBSD ports](#install-from-freebsd-ports)
22- [Plugin internals](#plugin-internals)
23- [Final recommendations](#final-recommendations)
24- [Support and feedback](#support-and-feedback)
25- [Acnowledgements](#acnowledgements)
26
27***
28
29#### What is DQS?
30
31Data Query Service (DQS) is a set of DNSBLs, updated in real-time, operated by Spamhaus Technology ([https://www.spamhaustech.com](https://www.spamhaustech.com))
32
33***
34
35#### What zones are available with DQS?
36
37All zones, their definitions, and all possible return codes are documented [here](https://docs.spamhaustech.com/10-data-type-documentation/datasets/030-datasets.html)
38
39***
40
41#### What are the advantages of DQS?
42
43With DQS, Spamhaus provides real time updates instead of the one-minute-delayed updates that are used by the public mirrors and the RSYNC feed.
44Sixty seconds doesn't seem like much, but when dealing with hailstormers they are *crucial*: the increase in catch rate between the public mirrors and DQS is mostly due to the real time updates.
45
46Along with the above advantage, free DQS users will also get two new zones to query, Zero Reputation Domains (ZRD) and AuthBL. Paid-for DQS users will also get access to the Hash BlockList (HBL).
47
48ZRD automatically adds newly-registered as well as previously-dormant domains to a block list for 24 hours. It also gives return codes that indicate the age of the domain (in hours) since first detection.
49
50AuthBL is primarily designed for use by anyone operating a submission SMTP server. It is a list of IPs that are known to host bots that use stolen credentials to spam. If one of your customers gets their credentials stolen, AuthBL greatly mitigates the ability of botnets to abuse the account, and keeps your MTAs safe from collateral damage.
51
52HBL is a zone dedicated to deal with sextortions/scam cryptowallets, dropbox emails and malicious files.
53
54***
55
56#### How does DQS perform?
57
58You can [see it yourself](https://www.virusbulletin.com/testing/results/latest/vbspam-email-security). We are independently tested by Virus Bulletin, a company that tests both DQS and public mirror performances. The difference between them is that DQS catches up to 42% more spam than our public mirrors.
59NOTE: Results on VBSpam are achieved by using *only* the DQS dataset, meaning that if you just add an antivirus to your email filtering setup you can potentially reach the same performance as other commercial antispam products.
60
61#### HBL performance boost
62
63While we know that every scenario is different, our in the field observations made using the Virus Bulletin spam feed shows that including HBL in your antispam setup could roughly boost spam detection from 0,3% up to slightly more than 1%
64
65***
66
67#### What is the licensing for DQS?
68
69The usage terms are [the same](https://www.spamhaus.org/organization/dnsblusage/) as the terms for our public mirrors, meaning that if you already use our public mirrors you are entitled to a free DQS key.
70
71***
72
73#### What is the difference between paid-for and free DQS?
74
75With free DQS you have access to ZRD and AuthBL, and you must abide by the [free usage policy limits](https://www.spamhaus.org/organization/dnsblusage/)
76
77With a paid subscription there is no query limit, and access to HBL (the new zone that deals with cryptovalues, emails and malware) is included.
78
79All the technical information about HBL is available [here](https://docs.spamhaustech.com/10-data-type-documentation/datasets/030-datasets.html#hbl)
80
81If you have a free DQS subscription and would like to trial HBL, please send an email to [sales@spamteq.com](mailto:sales@spamteq.com) including your customer ID, and you will be contacted by one of our representative to activate a 30 day trial.
82
83***
84
85#### How do I register a DQS key?
86
87Just go [here](https://www.spamhaustech.com/dqs/) and complete the registration procedure. After you register an account, go to [this](https://portal.spamhaustech.com/manuals/dqs/) page and you'll find the DQS key under section "1.0 Datafeed Query Service".
88
89***
90
91#### Prerequisites
92
93You need a DQS key along with an existing SpamAssassin 3.4.1+ installation on your system. These instructions do not cover the initial SpamAssassin installation. To correctly install SpamAssassin, please refer to instructions applicable to your SpamAssassin distribution.
94
95The scores in this configuration file are weighted for a `required_score` of 4 instead of the default 6. If you use a different `required_score`, remember to adjust the values accordingly.
96
97***
98
99#### Conventions
100
101We are going to use some abbreviations and placeholders:
102
103 * SA: SpamAssassin
104 * SH: Spamhaus
105 * *configuration directory*: whenever you find these italic words, we are referring to SA's configuration directory. Depending on your distribution it may be `/etc/spamassassin` or `/etc/mail/spamassassin` or something else.
106 * Whenever you see the box below, it means that you need to enter the command on your shell:
107```
108	$ command
109```
110 * Whenever you see the box below, it means that you need to enter the command on a shell with *root privileges*:
111```
112	# command
113```
114
115## Installation instructions
116
117#### Install from Github
118
119Start by downloading the latest package:
120
121```
122	$ git clone https://github.com/spamhaus/spamassassin-dqs
123	Cloning into 'spamassassin-dqs'...
124	remote: Enumerating objects: 11, done.
125	remote: Counting objects: 100% (11/11), done.
126	remote: Compressing objects: 100% (9/9), done.
127	remote: Total 11 (delta 0), reused 11 (delta 0), pack-reused 0
128	Unpacking objects: 100% (11/11), done.
129```
130
131A subdirectory called `spamassassin-dqs` will be created. Within it you will find the following files:
132
133- `README.md`. This is just a pointer to this document.
134- `Changelog.md`. The changes log file
135- `hbltest.sh`. A script that helps you know if your DQS key is HBL enabled
136- `sh.pre`. This file is the loader for the plugin
137- `SH.pm`. This is a dedicated SA plugin written by SH that overcomes some of SA's limitations
138- `sh.cf`. This file contains lookup redefinitions and will need to be edited (see below)
139- `sh_scores.cf`. In this file we override some of SA's default rule scoring
140- `sh_hbl.cf`. Definitions for HBL lookups
141- `sh_hbl_scores.cf`. Definitions for HBL lookups scores
142- `LICENSE`. The Apache software license
143- `NOTICE`. A file containing copyright notices
144
145Next, configure your DQS key. Assuming your key is `aip7yig6sahg6ehsohn5shco3z`, execute the following commands:
146
147```
148	$ cd spamassassin-dqs
149	$ sed -i -e 's/your_DQS_key/aip7yig6sahg6ehsohn5shco3z/g' sh.cf
150	$ sed -i -e 's/your_DQS_key/aip7yig6sahg6ehsohn5shco3z/g' sh_hbl.cf
151```
152
153If you are using FreeBSD, the commands change slightly:
154
155```
156	$ cd spamassassin-dqs
157	$ sed -i "" -e 's/your_DQS_key/aip7yig6sahg6ehsohn5shco3z/g' sh.cf
158	$ sed -i "" -e 's/your_DQS_key/aip7yig6sahg6ehsohn5shco3z/g' sh_hbl.cf
159```
160
161There will be no output, but the key will be inserted into `sh.cf` and `sh_hbl.cf` in all the needed places.
162
163Edit `sh.pre` with your editor of choice, and look at the first line:
164
165```
166	loadplugin       Mail::SpamAssassin::Plugin::SH <config_directory>/SH.pm
167```
168
169You will need to replace `<config_directory>` with your actual *configuration directory*. So, for example, if your *configuration directory* is `/etc/mail/spamassassin`, the line will become:
170
171```
172	loadplugin       Mail::SpamAssassin::Plugin::SH /etc/mail/spamassassin/SH.pm
173```
174
175We provide a simple script to help you verify whether your DQS key is HBL enabled or not. Use this script to understand what files to copy in your Rspamd config directory. You only need to run the script and input your DQS key.
176
177Assuming the example key ```aip7yig6sahg6ehsohn5shco3z``` *is* DQS enabled, run the script and the output will confirm whether your key is HBL enabled:
178
179```
180	$ sh hbltest.sh
181	Please input your DQS key: aip7yig6sahg6ehsohn5shco3z
182	Looking up test record for HBL... done
183	Your DQS key aip7yig6sahg6ehsohn5shco3z is enabled for HBL
184	You can copy sh_hbl.cf and sh_hbl_scores.cf if you want HBL enabled
185```
186
187If your key is not HBL enabled (meaning that you registered a FREE DQS key and did not use a paid subscription) the output will be the following:
188
189```
190	$ sh hbltest.sh
191	Please input your DQS key: aip7yig6sahg6ehsohn5shco3z
192	Looking up test record for HBL... done
193	Your DQS key aip7yig6sahg6ehsohn5shco3z is -=NOT=- enabled for HBL
194	Please *do not* copy sh_hbl.cf and sh_hbl_scores.cf
195```
196
197Based on the output of the above script, copy the relevant .cf files in SA *configuration directory*.
198
199If you have an HBL enabled key, and assuming the *configuration directory* is `/etc/mail/spamassassin` do the following:
200
201```
202	# cp SH.pm /etc/mail/spamassassin
203	# cp sh.cf /etc/mail/spamassassin
204	# cp sh_scores.cf /etc/mail/spamassassin
205	# cp sh_hbl.cf /etc/mail/spamassassin
206	# cp sh_hbl_scores.cf /etc/mail/spamassassin
207	# cp sh.pre /etc/mail/spamassassin
208```
209
210If your key is *not* HBL enabled, this is what needs to be done:
211
212```
213	# cp SH.pm /etc/mail/spamassassin
214	# cp sh.cf /etc/mail/spamassassin
215	# cp sh_scores.cf /etc/mail/spamassassin
216	# cp sh.pre /etc/mail/spamassassin
217```
218
219We strongly suggest to not copy the HBL files if your key is not HBL enabled, as the lookups timout will very likely slow SA email processing.
220
221Next, test the setup by running:
222
223```
224	# spamassassin --lint
225```
226
227This command checks the whole SA installation; if you don't see any output then congratulations! You successfully installed SH's SA setup. You only need to restart SpamAssassin to have the plugin loaded.
228
229***
230
231#### Install from FreeBSD ports
232
233[lrosenman](https://github.com/lrosenman) maintains a FreeBSD port of our plugin. We don't give support for this port, but if you want to use it, the instructions are as follows:
234
235```
236	# pkg install spamassassin-dqs
237```
238and then follow the instructions.
239
240Or, if using ports:
241
242```
243	$ cd /usr/ports/mail/spamassassin-dqs
244	$ sudo make install
245```
246
247***
248
249## Plugin internals
250
251While we acknowledge SpamAssassin's abilities at stopping spam with only minor tweaking of the default config, there are some key uses of our datasets that can only be fully taken advantage of by writing some special SA functions. That is why we decided to develop this special plugin that includes these functions:
252
253 * `check_sh_helo`.
254This function checks the domain used in the HELO/EHLO string against DBL and ZRD.
255
256 * `check_sh_headers`.
257This function takes the domain out of the *From* , *Reply-to* , *Envelope From*, *Return-Path* header lines and then checks the domain against DBL and ZRD.
258
259 * `check_sh_bodyemail`.
260This function scans the email body looking for email addresses. For all email addresses found, it extracts the domain and check it against DBL and ZRD. This approach has been proven useful, for example, in some dating-scam campaigns.
261
262 * `check_sh_bodyemail_ns`.
263This function scans the email body looking for email addresses. For all email addresses found, it extracts the domain and then checks its authoritative nameservers IPs in SBL (beta, not used, but you are encouraged to try it).
264
265 * `check_sh_reverse`
266This function checks the reverse DNS (rDNS) of the last untrusted relay in both DBL and ZRD
267
268 * `check_sh_bodyuri_a`
269 This function scans the email body and looks for URLs; when one is found the hostname is then resolved, and the resulting IP address is checked in SBL and CSS.
270
271 * `check_sh_bodyuri_ns`
272 This function scans the email body and looks for URLs; when one is found it takes the domain's authoritative nameservers IPs and checks them in SBL (beta, not used, but you are encouraged to try it).
273
274 * `check_sh_crypto`
275 This functions looks for cryptowallets in the email body and checks them in HBL. As of today, we support the following cryptos:
276 	 - BTC
277	 - BCH
278	 - XMR
279	 - LTC
280	 - XRP
281	 - ETH
282
283* `check_sh_attachment`
284This functions computes the hash of all the attachments and checks them in HBL, looking for confirmed or suspect malware.
285
286* `check_sh_emails`
287This functions collects all email addresses from headers and body and checks their hashes in HBL.
288
289
290 ***
291
292## Final recommendations
293
294The configuration in the VBSpam survey makes exclusive use of our data, since our goal was to certify their quality, and to keep an eye on how we perform in the field.
295
296While the results are reasonably good, the malware/phishing scoring can certainly be improved by employing some additional actions that we recommend.
297
298- Install an antivirus software on your mailserver;
299- The modern rule of thumb for receiving email should be to "stay defensive", which is why we recommend doing basic attachment filtering by dropping all emails that contains potentially hazardous attachments, at *minimum* all file extensions that match this regex:
300
301```
302(exe|vbs|pif|scr|bat|cmd|com|cpl|dll|cpgz|chm|js|jar|wsf)
303```
304
305- You should also drop, by default, all Office documents with macros.
306
307## Support and feedback
308
309We would be happy to receive your feedback! If you notice any problems with this installation, please open a Github issue and we'll do our best to help you.
310
311Remember that we are only going to support the latest version, so before opening an issue, please be sure to be running the up-to-date code from this Github repository.
312
313## Acknowledgements
314
315We'd like to thank everyone for their suggestions and contributions!