-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain-sift.html
442 lines (381 loc) · 10.7 KB
/
domain-sift.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="/styles.1b8b925727a47aa0b397d2326344c60a14f98d348ccd63b9047f3a72456552ad.css"
type="text/css"
/>
<link
rel="icon"
href="/favicon.1d9d66e8e0f6f92db8c49e54f947c1f74da9a1a71ab0a0749fb43679df437515.svg"
type="image/svg+xml"
/>
<title>domain-sift: extract and format domains - anthesis</title>
<meta
name="description"
content="domain-sift is a Perl script that
extracts domains from text and formats them.
You can use it to block ads on your local
network."
/>
<meta name="color-scheme" content="light dark" />
<link rel="canonical" href="https://www.anthes.is/domain-sift.html" />
<link rel="alternate" type="application/atom+xml" href="/rss.xml" />
</head>
<body>
<header>
<nav class="navbar">
<ul>
<li><a href="/" hreflang="en">Home</a></li>
<li><a href="/contact.html" hreflang="en">Contact</a></li>
<li><a href="/src.html" hreflang="en">Source code</a></li>
</ul>
</nav>
</header>
<main>
<h1 id="domain-sift">domain-sift: extract and format domains</h1>
<p>
Last updated:
<time datetime="2023-09-04">September 4th, 2023</time>
</p>
<article>
<section>
<p>
<code>domain-sift</code> is a Perl script that extracts
unique domains from at least one provided file and
prints them to standard output in a given format. If no
file is provided, <code>domain-sift</code> reads from
standard input instead.
</p>
<p>
One use of this utility is to extract domains from
blocklists that contain known malicious or otherwise
undesirable domains, and then format them in such a way
that those domains can be blocked by a DNS resolver.
</p>
</section>
<nav>
<h2 id="table-of-contents">Table of Contents</h2>
<ol>
<li>
<a href="#project-structure">Project structure</a>
</li>
<li><a href="#installation">Installation</a></li>
<li><a href="#documentation">Documentation</a></li>
<li>
<a href="#domain-sift-and-unwind"
>domain-sift and unwind</a
>
</li>
<li>
<a href="#domain-sift-and-unbound"
>domain-sift and Unbound</a
>
</li>
<li>
<a href="#domain-sift-and-unbound-rpz"
>domain-sift and Unbound (RPZ)</a
>
</li>
<li>
<a href="#regarding-blocklist-sources"
>Regarding blocklist sources</a
>
</li>
<li><a href="#caveats">Caveats</a></li>
<li><a href="#license">License</a></li>
</ol>
</nav>
<section>
<h2 id="project-structure">Project structure</h2>
<pre><code>|-- Changes
|-- LICENSE
|-- MANIFEST
|-- Makefile.PL
|-- README.md
|-- bin
| `-- domain-sift
|-- lib
| `-- Domain
| |-- Sift
| | |-- Manipulate.pm
| | `-- Match.pm
| `-- Sift.pm
`-- t
|-- 00-load.t
|-- Domain-Sift-Manipulate.t
|-- Domain-Sift-Match.t
|-- manifest.t
|-- pod-coverage.t
`-- pod.t
</code></pre>
</section>
<section>
<h2 id="installation">Installation</h2>
<p>
To install <code>domain-sift</code>,
<a
href="https://github.com/maybebyte/domain-sift/releases"
>download the most recent release</a
>
and run the following commands inside the source
directory. Note that
<code>domain-sift</code> requires Perl 5.36 or later,
since subroutine signatures are no longer experimental
in that release.
</p>
<pre><code>$ perl Makefile.PL
$ make
$ make test
# make install
</code></pre>
</section>
<section>
<h2 id="documentation">Documentation</h2>
<p>
After installation, you can read the documentation with
<code>perldoc</code>. <code>man</code> often works as
well.
</p>
<pre><code>$ perldoc Domain::Sift
$ perldoc Domain::Sift::Match
$ perldoc Domain::Sift::Manipulate
$ perldoc domain-sift
</code></pre>
</section>
<section>
<h2 id="domain-sift-and-unwind">domain-sift and unwind</h2>
<p>
Here’s how to use <code>domain-sift</code> with
<a href="https://man.openbsd.org/unwind"
><code>unwind(8)</code></a
>
on OpenBSD.
</p>
<ol>
<li>Extract domains from your blocklist source:</li>
</ol>
<pre><code>$ domain-sift /path/to/blocklist_source > blocklist
</code></pre>
<ol start="2">
<li>
Move your blocklist to
<code>/etc/blocklist</code>:
</li>
</ol>
<pre><code># mv blocklist /etc/blocklist
</code></pre>
<ol start="3">
<li>
Modify your <code>unwind.conf</code> to include your
new blocklist:
</li>
</ol>
<pre><code>block list "/etc/blocklist"
</code></pre>
<ol start="4">
<li>Restart <code>unwind</code>:</li>
</ol>
<pre><code># rcctl restart unwind
</code></pre>
</section>
<section>
<h2 id="domain-sift-and-unbound">
domain-sift and Unbound
</h2>
<p>
Here’s how to use <code>domain-sift</code> with
<a href="https://man.openbsd.org/unbound"
><code>unbound(8)</code></a
>
on OpenBSD.
</p>
<ol>
<li>Extract domains from your blocklist source:</li>
</ol>
<pre><code>$ domain-sift -f unbound /path/to/blocklist_source > blocklist
</code></pre>
<ol start="2">
<li>
Move the blocklist to
<code>/var/unbound/etc</code>.
</li>
</ol>
<pre><code># mv blocklist /var/unbound/etc/blocklist
</code></pre>
<ol start="3">
<li>
Modify your <code>unbound.conf</code> to include
your new blocklist:
</li>
</ol>
<pre><code class="language-yaml">include: "/var/unbound/etc/blocklist"
</code></pre>
<ol start="4">
<li>Restart Unbound.</li>
</ol>
<pre><code># rcctl restart unbound
</code></pre>
</section>
<section>
<h2 id="domain-sift-and-unbound-rpz">
domain-sift and Unbound (RPZ)
</h2>
<p>
<code>domain-sift</code> also supports the Response
Policy Zone (RPZ) format.
<a
href="https://datatracker.ietf.org/doc/draft-vixie-dnsop-dns-rpz/"
>RPZ is defined in this Internet Draft</a
>.
</p>
<p>
By using RPZ, you can define DNS blocking policies in a
standardized way. A nice perk of using RPZ is the
ability to block wildcarded domains (<code
>*.example.com</code
>
will also block <code>subdomain.example.com</code>,
<code>subdomain.subdomain.example.com</code>, and so
on).
</p>
<p>
Here’s how to use <code>domain-sift</code> with
Unbound and RPZ on OpenBSD.
</p>
<ol>
<li>Extract domains from your blocklist source:</li>
</ol>
<pre><code>$ domain-sift -f rpz /path/to/blocklist_source > blocklist
</code></pre>
<ol start="2">
<li>Modify your <code>unbound.conf</code>:</li>
</ol>
<pre><code class="language-yaml">rpz:
name: rpz.home.arpa
zonefile: /var/unbound/etc/rpz-block.zone
#rpz-log: yes
rpz-signal-nxdomain-ra: yes
</code></pre>
<p>
NOTE: <code>rpz.home.arpa</code> is just an example. The
name entry may be different in your case. In a local
access network (LAN) where Unbound runs on the
gateway/router, ensure that a
<code>local-data</code> entry is present somewhere so
that the name you chose resolves. Something like this
should work:
</p>
<pre><code class="language-yaml">local-data: "rpz.home.arpa. IN A x.x.x.x"
</code></pre>
<p>
You’ll need to replace <code>x.x.x.x</code> with
the machine’s actual IP address.
</p>
<ol start="3">
<li>
Create
<code
>/var/unbound/etc/rpz-block.zone</code
>:
</li>
</ol>
<pre><code class="language-DNS">$ORIGIN rpz.home.arpa.
$INCLUDE /var/unbound/etc/blocklist
</code></pre>
<ol start="4">
<li>
Make sure that you move <code>blocklist</code> to
the correct location:
</li>
</ol>
<pre><code># mv /path/to/blocklist /var/unbound/etc/blocklist
</code></pre>
<ol start="5">
<li>Restart Unbound:</li>
</ol>
<pre><code># rcctl restart unbound
</code></pre>
</section>
<section>
<h2 id="regarding-blocklist-sources">
Regarding blocklist sources
</h2>
<p>
To keep things simple, <code>domain-sift</code> only
deals with extracting domains from text files and
formatting them. It doesn’t fetch blocklists or
provide them.
</p>
<p>
This is an explicit part of its design for a few
reasons.
</p>
<ol>
<li>
<p>
It follows the Unix philosophy: do one thing
well; read from a file or STDIN; print to
STDOUT.
</p>
</li>
<li>
<p>
It allows <code>domain-sift</code> to use a
minimum set of
<a href="https://man.openbsd.org/pledge"
><code>pledge(2)</code></a
>
promises through
<a
href="https://man.openbsd.org/OpenBSD%3A%3APledge"
><code>OpenBSD::Pledge(3p)</code></a
>.
</p>
</li>
<li>
<p>
The simple design makes it much more flexible
and portable.
</p>
</li>
</ol>
<p>Here is more or less what I use to fetch blocklists:</p>
<pre><code>$ grep -Ev '^#' blocklist_urls | xargs -- ftp -o - | domain-sift > blocklist
</code></pre>
<p>
You can find blocklist sources in many places, such as
<a href="https://firebog.net/">firebog.net</a>.
</p>
</section>
<section>
<h2 id="caveats">Caveats</h2>
<p>
If you’ve pulled in a lot of domains, Unbound may
fail to start on OpenBSD because it doesn’t have
enough time to process all of them. You can fix this by
increasing Unbound’s timeout value.
</p>
<pre><code>$ rcctl get unbound timeout
30
# rcctl set unbound timeout 120
$ rcctl get unbound timeout
120
</code></pre>
</section>
<section>
<h2 id="license">License</h2>
<p>This software is Copyright © 2023 by Ashlen.</p>
<p>
This is free software, licensed under the ISC License.
For more details, see the <code>LICENSE</code> file in
the project root.
</p>
</section>
</article>
</main>
</body>
</html>