tree: 08d5f73692fa672eaa7c254f5f3e0dc028859824 [path history] [tgz]
  1. banip.blacklist
  2. banip.conf
  3. banip.countries
  4. banip.dns
  5. banip.hotplug
  6. banip.init
  7. banip.maclist
  8. banip.mail
  9. banip.service
  10. banip.sh
  11. banip.sources
  12. banip.whitelist
  13. README.md
external/subpack/net/banip/files/README.md

banIP - ban incoming and/or outgoing ip adresses via ipsets

Description

IP address blocking is commonly used to protect against brute force attacks, prevent disruptive or unauthorized address(es) from access or it can be used to restrict access to or from a particular geographic area — for example.

Main Features

  • Support of the following fully pre-configured domain blocklist sources (free for private usage, for commercial use please check their individual licenses)
SourceFocusInformation
asnASN blockLink
bogonBogon prefixesLink
countryCountry blocksLink
darklistblocks suspicious attacker IPsLink
deblFail2ban IP blacklistLink
dohPublic DoH-ProviderLink
dropSpamhaus drop compilationLink
dshieldDshield IP blocklistLink
edropSpamhaus edrop compilationLink
feodoFeodo TrackerLink
firehol1Firehol Level 1 compilationLink
firehol2Firehol Level 2 compilationLink
firehol3Firehol Level 3 compilationLink
firehol4Firehol Level 4 compilationLink
greensnowblocks suspicious server IPsLink
iblockadsAdvertising blocklistLink
iblockspyMalicious spyware blocklistLink
myipMyip Live IP blacklistLink
nixspamiX spam protectionLink
proxyFirehol list of open proxiesLink
ssblSSL botnet IP blacklistLink
talosCisco Talos IP BlacklistLink
threatEmerging ThreatsLink
torTor exit nodesLink
uceprotect1Spam protection level 1Link
uceprotect2Spam protection level 2Link
voipVoIP fraud blocklistLink
yoyoAd protection blacklistLink
  • zero-conf like automatic installation & setup, usually no manual changes needed
  • automatically selects one of the following supported download utilities: aria2c, curl, uclient-fetch, wget
  • fast downloads & list processing as they are handled in parallel as background jobs in a configurable 'Download Queue'
  • full IPv4 and IPv6 support
  • ipsets (one per source) are used to ban a large number of IP addresses
  • supports blocking by ASN numbers
  • supports blocking by iso country codes
  • supports local black- & whitelist (IPv4, IPv6, CIDR notation or domain names)
  • auto-add unsuccessful LuCI, nginx or ssh login attempts via 'dropbear'/'sshd' to local blacklist
  • auto-add the uplink subnet to local whitelist
  • black- and whitelist also accept domain names as input to allow IP filtering based on these names
  • supports a 'whitelist only' mode, this option allows to restrict Internet access from/to a small number of secure websites/IPs
  • provides a small background log monitor to ban unsuccessful login attempts in real-time
  • per source configuration of SRC (incoming) and DST (outgoing)
  • integrated IPSet-Lookup
  • integrated bgpview-Lookup
  • blocklist source parsing by fast & flexible regex rulesets
  • minimal status & error logging to syslog, enable debug logging to receive more output
  • procd based init system support (start/stop/restart/reload/refresh/status)
  • procd network interface trigger support
  • automatic blocklist backup & restore, they will be used in case of download errors or during startup
  • provides comprehensive runtime information
  • provides a detailed IPSet Report
  • provides a powerful query function to quickly find blocked IPs/CIDR in banIP related IPSets
  • provides an easily configurable blocklist update scheduler called 'Refresh Timer'
  • strong LuCI support
  • optional: add new banIP sources on your own

Prerequisites

  • OpenWrt, tested with the stable release series (21.02.x) and with the latest rolling snapshot releases. On turris devices it has been successfully tested with TurrisOS 5.2.x
    Please note: Ancient OpenWrt releases like 18.06.x or 17.01.x are not supported!
    Please note: Devices with less than 128 MByte RAM are not supported!
    Please note: If you're updating from former banIP 0.3x please manually remove your config (/etc/config/banip) before you start!
  • A download utility with SSL support: 'wget', 'uclient-fetch' with one of the 'libustream-*' ssl libraries, 'aria2c' or 'curl' is required
  • A certificate store like 'ca-bundle', as banIP checks the validity of the SSL certificates of all download sites by default
  • Optional E-Mail notification support: for E-Mail notifications you need to install and setup the additional 'msmtp' package

Installation & Usage

  • Update your local opkg repository (opkg update)
  • Install 'banip' (opkg install banip). The banIP service is disabled by default
  • Install the LuCI companion package 'luci-app-banip' (opkg install luci-app-banip)
  • It's strongly recommended to use the LuCI frontend to easily configure all aspects of banIP, the application is located in LuCI under the 'Services' menu

banIP CLI

  • All important banIP functions are accessible via CLI as well.

banIP config options

  • Usually the auto pre-configured banIP setup works quite well and no manual overrides are needed
OptionTypeDefaultDescription
ban_enabledoption0enable the banIP service
ban_autodetectoption1auto-detect wan interfaces, devices and subnets
ban_debugoption0enable banIP related debug logging
ban_mail_enabledoption0enable the mail service
ban_monitor_enabledoption0enable the log monitor, e.g. to catch failed ssh/luci logins
ban_logsrc_enabledoption0enable the src-related logchain
ban_logdst_enabledoption0enable the dst-related logchain
ban_autoblacklistoption1add suspicious IPs automatically to the local blacklist
ban_autowhitelistoption1add wan IPs/subnets automatically to the local whitelist
ban_whitelistonlyoption0allow to restrict Internet access from/to a small number of secure websites/IPs
ban_maxqueueoption4size of the download queue to handle downloads and processing in parallel
ban_reportdiroption/tmp/banIP-Reportdirectory where banIP stores the report files
ban_backupdiroption/tmp/banIP-Backupdirectory where banIP stores the compressed backup files
ban_ifaceslist-list option to add logical wan interfaces manually
ban_sourceslist-list option to add banIP sources
ban_countrieslist-list option to add certain countries as an alpha-2 ISO code, e.g. 'de' for germany
ban_asnslist-list option to add certain ASNs (autonomous system number), e.g. '32934' for facebook
ban_chainoptionbanIPname of the root chain used by banIP
ban_global_settypeoptionsrc+dstglobal settype as default for all sources
ban_settype_srclist-special SRC settype for a certain sources
ban_settype_dstlist-special DST settype for a certain sources
ban_settype_alllist-special SRC+DST settype for a certain sources
ban_target_srcoptionDROPdefault src action (used by log chains as well)
ban_target_dstoptionREJECTdefault dst action (used by log chains as well)
ban_lan_inputchains_4listinput_lan_rulelist option to add IPv4 lan input chains
ban_lan_inputchains_6listinput_lan_rulelist option to add IPv6 lan input chains
ban_lan_forwardchains_4listforwarding_lan_rulelist option to add IPv4 lan forward chains
ban_lan_forwardchains_6listforwarding_lan_rulelist option to add IPv6 lan forward chains
ban_wan_inputchains_4listinput_wan_rulelist option to add IPv4 wan input chains
ban_wan_inputchains_6listinput_wan_rulelist option to add IPv6 wan input chains
ban_wan_forwardchains_4listforwarding_wan_rulelist option to add IPv4 wan forward chains
ban_wan_forwardchains_6listforwarding_wan_rulelist option to add IPv6 wan forward chains
ban_fetchutiloption-, auto-detected'uclient-fetch', 'wget', 'curl' or 'aria2c'
ban_fetchparmoption-, auto-detectedmanually override the config options for the selected download utility
ban_fetchinsecureoption0, disableddon't check SSL server certificates during download
ban_mailreceiveroption-receiver address for banIP related notification E-Mails
ban_mailsenderoptionno-reply@banIPsender address for banIP related notification E-Mails
ban_mailtopicoptionbanIP notificationtopic for banIP related notification E-Mails
ban_mailprofileoptionban_notifymail profile used in 'msmtp' for banIP related notification E-Mails
ban_srcarcoption/etc/banip/banip.sources.gzfull path to the compressed source archive file used by banIP
ban_localsourceslistmaclist, whitelist, blacklistlimit the selection to certain local sources
ban_extrasourceslist-add additional, non-banIP related IPSets e.g. for reporting or queries
ban_maclist_timeoutoption-individual maclist IPSet timeout
ban_whitelist_timeoutoption-individual whitelist IPSet timeout
ban_blacklist_timeoutoption-individual blacklist IPSet timeout
ban_logtermslistdropbear, sshd, luci, nginxlimit the log monitor to certain log terms
ban_loglimitoption100parse only the last stated number of log entries for suspicious events
ban_ssh_logcountoption3number of the failed ssh login repetitions of the same ip in the log before banning
ban_luci_logcountoption3number of the failed luci login repetitions of the same ip in the log before banning
ban_nginx_logcountoption5number of the failed nginx requests of the same ip in the log before banning

Examples

list/edit banIP sources:

receive banIP runtime information:

black-/whitelist handling:
banIP supports a local black & whitelist (IPv4, IPv6, CIDR notation or domain names), located by default in /etc/banip/banip.whitelist and /etc/banip/banip.blacklist.
Unsuccessful LuCI logins, suspicious nginx request or ssh login attempts via 'dropbear'/'sshd' could be tracked and automatically added to the local blacklist (see the 'ban_autoblacklist' option). Furthermore the uplink subnet could be automatically added to local whitelist (see 'ban_autowhitelist' option). The list behaviour could be further tweaked with different timeout and counter options (see the config options section above).
Last but not least, both lists also accept domain names as input to allow IP filtering based on these names. The corresponding IPs (IPv4 & IPv6) will be resolved in a detached background process and added to the IPsets. The detached name lookup takes place only during 'restart' or 'reload' action, 'start' and 'refresh' actions are using an auto-generated backup instead.

whitelist-only mode:
banIP supports a "whitelist only" mode. This option allows to restrict the internet access from/to a small number of secure websites/IPs, and block access from/to the rest of the internet. All IPs and Domains which are not listed in the whitelist are blocked. Please note: suspend/resume does not work in this mode.

Manually override the download options:
By default banIP uses the following pre-configured download options:

  • aria2c: --timeout=20 --allow-overwrite=true --auto-file-renaming=false --log-level=warn --dir=/ -o
  • curl: --connect-timeout 20 --silent --show-error --location -o
  • uclient-fetch: --timeout=20 -O
  • wget: --no-cache --no-cookies --max-redirect=0 --timeout=20 -O

To override the default set 'ban_fetchparm' manually to your needs.

generate an IPSet report:

Enable E-Mail notification via 'msmtp':
To use the email notification you have to install & configure the package 'msmtp'.
Modify the file '/etc/msmtprc', e.g.:

Finally enable E-Mail support and add a valid E-Mail receiver address in LuCI.

Edit, add new banIP sources:
The banIP blocklist sources are stored in an external, compressed JSON file '/etc/banip/banip.sources.gz'. This file is directly parsed in LuCI and accessible via CLI, just call /etc/init.d/banip list.

To add new or edit existing sources extract the compressed JSON file gunzip /etc/banip/banip.sources.gz.
A valid JSON source object contains the following required information, e.g.:

Add an unique object name, make the required changes to 'url_4', 'rule_4' (and/or 'url_6', 'rule_6'), 'focus' and 'descurl' and finally compress the changed JSON file gzip /etc/banip/banip.sources.gz to use the new source object in banIP.
Please note: if you're going to add new sources on your own, please make a copy of the default file and work with that copy further on, cause the default will be overwritten with every banIP update. To reference your copy set the option 'ban_srcarc' which points by default to '/etc/banip/banip.sources.gz'

Support

Please join the banIP discussion in this forum thread or contact me by mail dev@brenken.org

Removal

  • stop all banIP related services with /etc/init.d/banip stop
  • optional: remove the banip package (opkg remove banip)

Have fun!
Dirk