Skip to content

Commit 5e6575f

Browse files
enhance: add juniper and update mikrotik format bl-mirror
1 parent 98dd524 commit 5e6575f

File tree

1 file changed

+105
-17
lines changed

1 file changed

+105
-17
lines changed

crowdsec-docs/unversioned/bouncers/blocklist-mirror.mdx

Lines changed: 105 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ List of blocklists to serve. Each blocklist has the following configuration.
204204
Format of the blocklist, the following are supported:
205205

206206
- `plain_text` : One IP per line
207-
- `mikrotik` : Lines for mikrotik, format is `/ip|/ipv6 firewall address-list add list={list_name} address={ip} comment="{scenario} for {duration}"`
208-
- `F5` : Lines for f5 appliances, format is `{ip|range},{netmask},bl,{scenario}`
207+
- `mikrotik` : Generates a mikrotik script
208+
- `F5` : Lines for f5 appliances
209+
- `juniper`: One entry per line using CIDR notation
209210

210211
#### `endpoint`
211212
> string
@@ -311,27 +312,43 @@ Example:
311312

312313
### mikrotik
313314

314-
If your mikrotik router does not support ipv6, then you can use the global query parameters to only return ipv4 addresses.
315+
Generates a MikroTik Script that the device can execute to populate the specified firewall address list.
315316

316-
Example:
317+
#### MikroTik query parameters
317318

318-
```text
319-
/ip firewall address-list remove [find list=CrowdSec]
320-
/ipv6 firewall address-list remove [find list=CrowdSec]
321-
/ip firewall address-list add list=CrowdSec address=192.168.1.1 comment="crowdsecurity/ssh-bf for 152h40m24.308868973s"
322-
/ip firewall address-list add list=CrowdSec address=192.168.1.2 comment="crowdsecurity/postfix-spam for 166h40m25.280338424s"/ipv6 firewall address-list add list=CrowdSec address=2001:470:1:c84::17 comment="crowdsecurity/ssh-bf for 165h13m42.405449876s"
319+
| Parameter | Description |
320+
|----------------|--------------------------------------------------------------------------|
321+
| `listname=foo` | Set the list name to `foo`. By default, `listname` is set to `CrowdSec`. |
322+
323+
Example output:
324+
```bash
325+
/ip/firewall/address-list/remove [ find where list="foo" ];
326+
:global CrowdSecAddIP;
327+
:set CrowdSecAddIP do={
328+
:do { /ip/firewall/address-list/add list=foo address=$1 comment="$2" timeout=$3; } on-error={ }
329+
}
330+
$CrowdSecAddIP 1.2.3.4 "ssh-bf" 152h40m24s
331+
$CrowdSecAddIP 4.3.2.1 "postfix-spam" 166h40m25s
332+
$CrowdSecAddIP 2001:470:1:c84::17 "ssh-bf" 165h13m42s
323333
```
324334

325-
#### mikrotik query parameters
335+
#### Example: MikroTik import script
326336

327-
`?listname=foo` - Set the list name to `foo`, by default `listname` is set to `CrowdSec`
337+
Using on device [MikroTik scripting](https://help.mikrotik.com/docs/display/ROS/Scripting) following is a starting point to download and import the blocklist. Ensure to adjust the [global query parameters](#global-runtime-query-parameters) according to your needs!
328338

329-
example output:
330-
```text
331-
/ip firewall address-list remove [find list=foo]
332-
/ipv6 firewall address-list remove [find list=foo]
333-
/ip firewall address-list add list=foo address=192.168.1.1 comment="crowdsecurity/ssh-bf for 152h40m24.308868973s"
334-
/ip firewall address-list add list=foo address=192.168.1.2 comment="crowdsecurity/postfix-spam for 166h40m25.280338424s"/ipv6 firewall address-list add list=foo address=2001:470:1:c84::17 comment="crowdsecurity/ssh-bf for 165h13m42.405449876s"
339+
```bash
340+
:local name "[crowdsec]"
341+
:local url "http://<IP>:41412/security/blocklist?ipv4only&nosort"
342+
:local fileName "blocklist.rsc"
343+
:log info "$name fetch blocklist from $url"
344+
/tool fetch url="$url" mode=http dst-path=$fileName
345+
:if ([:len [/file find name=$fileName]] > 0) do={
346+
:log info "$name import;start"
347+
/import file-name=$fileName
348+
:log info "$name import:done"
349+
} else={
350+
:log error "$name failed to fetch the blocklist"
351+
}
335352
```
336353
337354
### F5
@@ -342,3 +359,74 @@ Example:
342359
192.168.1.1,32,bl,ssh-slow-bf
343360
192.168.1.2,32,bl,ssh-slow-bf
344361
```
362+
363+
### Juniper
364+
365+
Generates a .txt file with all IP addresses (single host and subnets) in the CIDR notation format supported by the Juniper Networks SRX firewall platform.
366+
367+
Example:
368+
```text
369+
1.2.3.4/32
370+
4.3.2.1/32
371+
```
372+
373+
#### SRX Dynamic Address configuration sample
374+
375+
Using the blocklist on a Juniper SRX requires that the published url ends in .txt. This can be acieved by altering the endpoint config in `cfg.yaml` as follows:
376+
377+
Sample `cfg.yaml`
378+
```yaml
379+
####
380+
blocklists:
381+
- format: juniper # Supported formats are either of "plain_text", "mikrotik", "juniper"
382+
endpoint: /security/blocklist.txt #Must have .txt for juniper formatter.
383+
authentication:
384+
type: none # Supported types are either of "none", "ip_based", "basic"
385+
user:
386+
password:
387+
trusted_ips: # IP ranges, or IPs which don't require auth to access this blocklist
388+
- 127.0.0.1
389+
- ::1
390+
####
391+
```
392+
393+
This can then be configured on the SRX firewall as follows:
394+
395+
Sample SRX config:
396+
```test
397+
user@srx> show configuration security dynamic-address | display set
398+
399+
set security dynamic-address feed-server crowdsec url http://192.168.1.2:41412
400+
set security dynamic-address feed-server crowdsec update-interval 30
401+
set security dynamic-address feed-server crowdsec feed-name crowdsec path /security/blocklist.txt
402+
set security dynamic-address address-name crowdsec-blocklist profile feed-name crowdsec
403+
```
404+
405+
[Further information here](https://www.juniper.net/documentation/us/en/software/junos/cli-reference/topics/ref/statement/dynamic-address.html)
406+
407+
A successful configuration should return a similar result when queried:
408+
409+
```text
410+
user@srx> show security dynamic-address summary
411+
412+
413+
Dynamic-address session scan status : Disable
414+
Hold-interval for dynamic-address session scan : 10 seconds
415+
416+
417+
Server Name : crowdsec
418+
Hostname/IP : http://192.168.1.2:41412
419+
Update interval : 30
420+
Hold interval : 86400
421+
TLS Profile Name : ---
422+
User Name : ---
423+
424+
425+
Feed Name : crowdsec
426+
Mapped dynamic address name : crowdsec-blocklist
427+
URL : http://192.168.1.2:41412/security/blocklist.txt
428+
Feed update interval : 30 Feed hold interval :86400
429+
Total update : 16310
430+
Total IPv4 entries : 16240
431+
Total IPv6 entries : 0
432+
```

0 commit comments

Comments
 (0)