You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
8.0 KiB

  1. # banIP - ban incoming and/or outgoing ip adresses via ipsets
  2. ## Description
  3. 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.
  4. ## Main Features
  5. * support many IP blocklist sources (free for private usage, for commercial use please check their individual licenses):
  6. * zero-conf like automatic installation & setup, usually no manual changes needed
  7. * automatically selects one of the following download utilities: aria2c, curl, uclient-fetch, wget
  8. * Really fast downloads & list processing as they are handled in parallel as background jobs in a configurable 'Download Queue'
  9. * full IPv4 and IPv6 support
  10. * ipsets (one per source) are used to ban a large number of IP addresses
  11. * supports blocking by ASN numbers
  12. * supports blocking by iso country codes
  13. * supports local white & blacklist (IPv4, IPv6 & CIDR notation), located by default in /etc/banip/banip.whitelist and /etc/banip/banip.blacklist
  14. * auto-add unsuccessful LuCI and ssh login attempts via 'dropbear' or 'sshd' to local blacklist (see 'ban_autoblacklist' option)
  15. * auto-add the uplink subnet to local whitelist (see 'ban_autowhitelist' option)
  16. * provides a small background log monitor to ban unsuccessful login attempts in real-time
  17. * per source configuration of SRC (incoming) and DST (outgoing)
  18. * integrated IPSet-Lookup
  19. * integrated RIPE-Lookup
  20. * blocklist source parsing by fast & flexible regex rulesets
  21. * minimal status & error logging to syslog, enable debug logging to receive more output
  22. * procd based init system support (start/stop/restart/reload/refresh/status)
  23. * procd network interface trigger support
  24. * automatic blocklist backup & restore, they will be used in case of download errors or during startup
  25. * output comprehensive runtime information via LuCI or via 'status' init command
  26. * strong LuCI support
  27. * optional: add new banIP sources on your own
  28. * optional: log banned inbound and/or outbound IP to syslog.
  29. ## Prerequisites
  30. * [OpenWrt](https://openwrt.org), tested with the stable release series (19.07) and with the latest snapshot
  31. * download utility: 'uclient-fetch' with one of the 'libustream-*' ssl libraries, 'wget', 'aria2c' or 'curl' is required
  32. ## Installation & Usage
  33. * install 'banip' (_opkg install banip_)
  34. * at minimum configure the needed IP blocklist sources, the download utility and enable the banIP service in _/etc/config/banip_
  35. * control the banip service manually with _/etc/init.d/banip_ start/stop/restart/reload/refresh/status or use the LuCI frontend
  36. ## LuCI banIP companion package
  37. * it's recommended to use the provided LuCI frontend to control all aspects of banIP
  38. * install 'luci-app-banip' (_opkg install luci-app-banip_)
  39. * the application is located in LuCI under 'Services' menu
  40. ## banIP config options
  41. * usually the pre-configured banIP setup works quite well and no manual overrides are needed
  42. * the following options apply to the 'global' config section:
  43. * ban\_enabled => main switch to enable/disable banIP service (bool/default: '0', disabled)
  44. * ban\_automatic => determine the L2/L3 WAN network device automatically (bool/default: '1', enabled)
  45. * ban\_iface => space separated list of WAN network interface(s)/device(s) used by banIP (default: not set, automatically detected)
  46. * ban\_realtime => a small log/banIP background monitor to block SSH/LuCI brute force attacks in realtime (bool/default: 'false', disabled)
  47. * ban\_target\_src => action to perform when banning inbound IPv4 packets ('DROP'/'REJECT', default: 'DROP')
  48. * ban\_target\_src\_6 => action to perform when banning inbound IPv6 packets ('DROP'/'REJECT', default: 'DROP')
  49. * ban\_target\_dst => action to perform when banning outbound IPv4 packets ('DROP'/'REJECT', default: 'REJECT')
  50. * ban\_target\_dst\_6 => action to perform when banning outbound IPv6 packets ('DROP'/'REJECT', default: 'REJECT')
  51. * ban\_log\_src => switch to enable/disable logging of banned inbound IPv4 packets (bool/default: '0', disabled)
  52. * ban\_log\_dst => switch to enable/disable logging of banned outbound IPv4 packets (bool/default: '0', disabled)
  53. * the following options apply to the 'extra' config section:
  54. * ban\_debug => enable/disable banIP debug output (bool/default: '0', disabled)
  55. * ban\_nice => set the nice level of the banIP process and all sub-processes (int/default: '0', standard priority)
  56. * ban\_triggerdelay => additional trigger delay in seconds before banIP processing begins (int/default: '2')
  57. * ban\_backupdir => target directory for banIP backups (default: '/tmp')
  58. * ban\_sshdaemon => select the SSH daemon for logfile parsing, 'dropbear' or 'sshd' (default: 'dropbear')
  59. * ban\_starttype => select the used start type during boot, 'start', 'refresh' or 'reload' (default: 'start')
  60. * ban\_maxqueue => size of the download queue to handle downloads & IPSet processing in parallel (int/default: '4')
  61. * ban\_fetchutil => name of the used download utility: 'uclient-fetch', 'wget', 'curl', 'aria2c' (default: not set, automatically detected)
  62. * ban\_fetchparm => special config options for the download utility (default: not set)
  63. * ban\_autoblacklist => store auto-addons temporary in ipset and permanently in local blacklist as well (bool/default: '1', enabled)
  64. * ban\_autowhitelist => store auto-addons temporary in ipset and permanently in local whitelist as well (bool/default: '1', enabled)
  65. ## Logging of banned packets
  66. * by setting ban\_log\_src=1 / ban\_log\_dst=1 in the config options, banIP will log banned inbound / outbound packets to syslog.
  67. * example of a logged inbound (dst) and outbound (src) packet:
  68. <pre><code>
  69. Oct 2 12:49:14 gateway kernel: [434134.855130] REJECT(dst banIP) IN=br-lan OUT=br-wan MAC=xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx SRC=x.x.x.x DST=x.x.x.x LEN=100 TOS=0x00 PREC=0x00 TTL=63 ID=7938 PROTO=UDP SPT=16393 DPT=16393 LEN=80
  70. Oct 3 14:11:13 gateway kernel: [11290.429712] DROP(src banIP) IN=br-wan OUT= MAC=xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx SRC=x.x.x.x DST=x.x.x.x LEN=40 TOS=0x00 PREC=0x00 TTL=235 ID=63275 PROTO=TCP SPT=48246 DPT=37860 WINDOW=1024 RES=0x00 SYN URGP=0
  71. </code></pre>
  72. * to change the default logging behavior, the following options can be added to the 'global' config section:
  73. * ban\_log\_src\_opts => IPv4 iptables LOG options for banned inbound packets (default: '-m limit --limit 10/sec')
  74. * ban\_log\_src\_opts\_6 => IPv6 iptables LOG options for banned inbound packets (default: '-m limit --limit 10/sec')
  75. * ban\_log\_src\_prefix (default: '<ban\_target\_src>(src banIP) ', typically 'DROP(src banIP) ')
  76. * ban\_log\_src\_prefix\_6 (default: '<ban\_target\_src\_6>(src banIP) ', typically 'DROP('src banIP)' )
  77. * ban\_log\_dst\_opts => IPv4 iptables LOG options for banned outbound packets (default: '-m limit --limit 10/sec')
  78. * ban\_log\_dst\_opts\_6 => IPv6 iptables LOG options for banned outbound packets (default: '-m limit --limit 10/sec')
  79. * ban\_log\_dst\_prefix (default: '<ban\_target\_dst>(dst banIP) ', typically 'REJECT(dst banIP) ')
  80. * ban\_log\_dst\_prefix\_6 (default: '<ban\_target\_dst\_6>(dst banIP) ', typically 'REJECT('dst banIP)' )
  81. ## Examples
  82. **receive banIP runtime information:**
  83. # /etc/init.d/banip status
  84. ::: banIP runtime information
  85. + status : enabled
  86. + version : 0.3.0
  87. + util_info : /usr/bin/aria2c, true
  88. + ipset_info : 10 IPSets with overall 106729 IPs/Prefixes
  89. + backup_dir : /tmp
  90. + last_run : 03.10.2019 19:15:25
  91. + system : UBNT-ERX, OpenWrt SNAPSHOT r11102-ced4c0e635
  92. **cronjob for a regular IPSet blocklist update (/etc/crontabs/root):**
  93. # Every day at 06:00, update the IPSets of banIP
  94. 00 06 * * * /etc/init.d/banip reload
  95. ## Support
  96. Please join the banIP discussion in this [forum thread](https://forum.openwrt.org/t/banip-support-thread/16985) or contact me by mail <dev@brenken.org>
  97. ## Removal
  98. * stop all banIP related services with _/etc/init.d/banip stop_
  99. * optional: remove the banip package (_opkg remove banip_)
  100. Have fun!
  101. Dirk