crowdsecurity/blocklist-mirror

By crowdsecurity

Updated 6 months ago

Image
0

100K+

crowdsecurity/blocklist-mirror repository overview

blocklist-mirror

Installation

  1. Create a config file, cfg.yaml with the contents below:
config_version: v1.0
crowdsec_config:
  lapi_key: ${API_KEY}
  lapi_url: http://127.0.0.1:8080/
  update_frequency: 10s
  include_scenarios_containing: []
  exclude_scenarios_containing: []
  only_include_decisions_from: []
  insecure_skip_verify: false

blocklists:
  - format: plain_text # Supported formats are either of "plain_text", "mikrotik", "juniper"
    endpoint: /security/blocklist
    authentication:
      type: none # Supported types are either of "none", "ip_based", "basic"
      user:
      password:
      trusted_ips: # IP ranges, or IPs which don't require auth to access this blocklist
        - 127.0.0.1
        - ::1

listen_uri: 0.0.0.0:41412
tls:
  cert_file:
  key_file:

metrics:
  enabled: true
  endpoint: /metrics

log_media: stdout
log_level: info

Please find the full config reference below.

  1. Set the lapi_key and lapi_url. The LAPI must be accessible from the docker container.

lapi_key can be obtained by running the following on the machine running LAPI:

sudo cscli -oraw bouncers add blocklistMirror
  1. Modify the blocklists section as required.

Run the image with the config file mounted and port mapped as desired:

docker run \
-v $PWD/cfg.yaml:/etc/crowdsec/bouncers/crowdsec-blocklist-mirror.yaml \
-p 41412:41412 \
crowdsecurity/blocklist-mirror
  1. If you want to enable TLS, then set cert_file and key_file config. While running the container mount these from host to the provided path.

Configuration Reference

crowdsec_config
ParameterDescription
lapi_urlThe URL of CrowdSec LAPI. It should be accessible from whichever network the bouncer has access.
lapi_keyIt can be obtained by running the following on the machine CrowdSec LAPI is deployed on.
update_frequencyThe bouncer will poll the CrowdSec every update_frequency interval.
include_scenarios_containingIgnore IPs banned for triggering scenarios not containing either of the provided words.
exclude_scenarios_containingIgnore IPs banned for triggering scenarios containing either of the provided words.
only_include_decisions_fromOnly include IPs banned due to decisions originating from provided sources. e.g., value ["cscli", "crowdsec"]
insecure_skip_verifySet to true to skip verifying the certificate.
listen_uriLocation where the mirror will start the server.
tls_config
ParameterDescription
cert_filePath to the certificate to use if TLS is to be enabled.
key_filePath to the certificate key file.
metrics
ParameterDescription
enabledBoolean (true/false). Set to true to enable serving and collecting metrics.
endpointEndpoint to serve the metrics on.
blocklists

Each blocklist has the following configuration:

ParameterDescription
formatFormat of the blocklist. Currently, only plain_text and mikrotik are supported.
endpointEndpoint to serve the blocklist on.
authenticationAuthentication related config. See the table below for authentication parameters.
authentication
ParameterDescription
typeAuthentication type. Currently "basic" and "ip_based" authentication are supported. You can disable authentication completely by setting this to 'none'.
userValid username if using basic authentication.
passwordPassword for the provided user when using basic authentication.
trusted_ipsList of valid IPv4 and IPv6 IPs and ranges which have access to blocklist. Only applicable when authentication type is ip_based.

Global RunTime Query Parameters

ParameterDescriptionRequires ValueExample Usage
ipv4onlyOnly return IPv4 addressesNohttp://localhost:41412/security/blocklist?ipv4only
ipv6onlyOnly return IPv6 addressesNohttp://localhost:41412/security/blocklist?ipv6only
nosortDo not sort IPs. Only use if you do not care about the sorting of the list; can result in average 1ms improvementNohttp://localhost:41412/security/blocklist?nosort
originOnly return IPs by originYeshttp://localhost:41412/security/blocklist?origin=cscli

Formats

The bouncer can expose the blocklist in the following formats. You can configure the format of the blocklist by setting its format parameter to any of the supported formats described below.

plain_text

Example:

1.2.3.4
4.3.2.1
mikrotik

Generates a MikroTik Script that the device can execute to populate the specified firewall address list.

MikroTik query parameters
ParameterDescription
listname=fooSet the list name to foo. By default, listname is set to CrowdSec.

Example output:

/ip/firewall/address-list/remove [ find where list="foo" ];
:global CrowdSecAddIP;
:set CrowdSecAddIP do={
    :do { /ip/firewall/address-list/add list=foo address=$1 comment="$2" timeout=$3; } on-error={ }
}
$CrowdSecAddIP 1.2.3.4 "ssh-bf" 152h40m24s
$CrowdSecAddIP 4.3.2.1 "postfix-spam" 166h40m25s
$CrowdSecAddIP 2001:470:1:c84::17 "ssh-bf" 165h13m42s
Example: MikroTik import script

Using on device MikroTik scripting following is a starting point to download and import the blocklist. Ensure to adjust the global query parameters according to your needs!

:local name "[crowdsec]"
:local url "http://<IP>:41412/security/blocklist?ipv4only&nosort"
:local fileName "blocklist.rsc"
:log info "$name fetch blocklist from $url"
/tool fetch url="$url" mode=http dst-path=$fileName
:if ([:len [/file find name=$fileName]] > 0) do={
    :log info "$name import;start"
    /import file-name=$fileName
    :log info "$name import:done"
} else={
    :log error "$name failed to fetch the blocklist"
}
Juniper SRX

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.

Example:

1.2.3.4/32
4.3.2.1/32
SRX Dynamic Address configuration sample

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:

Sample cfg.yaml

####
blocklists:
  - format: plain_text # Supported formats are either of "plain_text", "mikrotik", "juniper
    endpoint: /security/blocklist.txt #Modify to .txt for juniper formatter.
    authentication:
      type: none # Supported types are either of "none", "ip_based", "basic"
      user:
      password:
      trusted_ips: # IP ranges, or IPs which don't require auth to access this blocklist
        - 127.0.0.1
        - ::1
####

This can then be configured on the SRX firewall as follows:

Sample SRX config:

user@srx> show configuration security dynamic-address | display set

set security dynamic-address feed-server crowdsec url http://192.168.1.2:41412
set security dynamic-address feed-server crowdsec update-interval 30
set security dynamic-address feed-server crowdsec feed-name crowdsec path /security/blocklist.txt
set security dynamic-address address-name crowdsec-blocklist profile feed-name crowdsec

Further information here: https://www.juniper.net/documentation/us/en/software/junos/cli-reference/topics/ref/statement/dynamic-address.html

A successful configuration should return a similar result when queried:

user@srx> show security dynamic-address summary


Dynamic-address session scan status            : Disable
Hold-interval for dynamic-address session scan : 10 seconds


  Server Name                 : crowdsec
    Hostname/IP               : http://192.168.1.2:41412
    Update interval           : 30
    Hold   interval           : 86400
    TLS Profile Name          : ---
    User        Name          : ---


    Feed Name                             : crowdsec
        Mapped dynamic address name       : crowdsec-blocklist
        URL                               : http://192.168.1.2:41412/security/blocklist.txt
        Feed update interval              : 30       Feed hold interval :86400
        Total update                      : 16310
        Total IPv4 entries                : 16240
        Total IPv6 entries                : 0

Tag summary

Content type

Image

Digest

sha256:41ded9bfb

Size

8.7 MB

Last updated

6 months ago

docker pull crowdsecurity/blocklist-mirror