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.

376 lines
32 KiB

  1. <!-- markdownlint-disable -->
  2. # banIP - ban incoming and/or outgoing ip adresses via ipsets
  3. ## Description
  4. 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.
  5. ## Main Features
  6. * Support of the following fully pre-configured domain blocklist sources (free for private usage, for commercial use please check their individual licenses)
  7. | Source | Focus | Information |
  8. | :------------------ | :----------------------------: | :-------------------------------------------------------------------------------- |
  9. | asn | ASN block | [Link](https://asn.ipinfo.app) |
  10. | bogon | Bogon prefixes | [Link](https://team-cymru.com) |
  11. | country | Country blocks | [Link](https://www.ipdeny.com/ipblocks) |
  12. | darklist | blocks suspicious attacker IPs | [Link](https://darklist.de) |
  13. | debl | Fail2ban IP blacklist | [Link](https://www.blocklist.de) |
  14. | doh | Public DoH-Provider | [Link](https://github.com/dibdot/DoH-IP-blocklists) |
  15. | drop | Spamhaus drop compilation | [Link](https://www.spamhaus.org) |
  16. | dshield | Dshield IP blocklist | [Link](https://www.dshield.org) |
  17. | edrop | Spamhaus edrop compilation | [Link](https://www.spamhaus.org) |
  18. | feodo | Feodo Tracker | [Link](https://feodotracker.abuse.ch) |
  19. | firehol1 | Firehol Level 1 compilation | [Link](https://iplists.firehol.org/?ipset=firehol_level1) |
  20. | firehol2 | Firehol Level 2 compilation | [Link](https://iplists.firehol.org/?ipset=firehol_level2) |
  21. | firehol3 | Firehol Level 3 compilation | [Link](https://iplists.firehol.org/?ipset=firehol_level3) |
  22. | firehol4 | Firehol Level 4 compilation | [Link](https://iplists.firehol.org/?ipset=firehol_level4) |
  23. | greensnow | blocks suspicious server IPs | [Link](https://greensnow.co) |
  24. | iblockads | Advertising blocklist | [Link](https://www.iblocklist.com) |
  25. | iblockspy | Malicious spyware blocklist | [Link](https://www.iblocklist.com) |
  26. | myip | Myip Live IP blacklist | [Link](https://myip.ms) |
  27. | nixspam | iX spam protection | [Link](http://www.nixspam.org) |
  28. | proxy | Firehol list of open proxies | [Link](https://iplists.firehol.org/?ipset=proxylists) |
  29. | ssbl | SSL botnet IP blacklist | [Link](https://sslbl.abuse.ch) |
  30. | talos | Cisco Talos IP Blacklist | [Link](https://talosintelligence.com/reputation_center) |
  31. | threat | Emerging Threats | [Link](https://rules.emergingthreats.net) |
  32. | tor | Tor exit nodes | [Link](https://fissionrelays.net/lists) |
  33. | uceprotect1 | Spam protection level 1 | [Link](http://www.uceprotect.net/en/index.php) |
  34. | uceprotect2 | Spam protection level 2 | [Link](http://www.uceprotect.net/en/index.php) |
  35. | voip | VoIP fraud blocklist | [Link](http://www.voipbl.org) |
  36. | yoyo | Ad protection blacklist | [Link](https://pgl.yoyo.org/adservers/) |
  37. * zero-conf like automatic installation & setup, usually no manual changes needed
  38. * automatically selects one of the following download utilities: aria2c, curl, uclient-fetch, wget
  39. * Really fast downloads & list processing as they are handled in parallel as background jobs in a configurable 'Download Queue'
  40. * full IPv4 and IPv6 support
  41. * ipsets (one per source) are used to ban a large number of IP addresses
  42. * supports blocking by ASN numbers
  43. * supports blocking by iso country codes
  44. * supports local white & blacklist (IPv4, IPv6 & CIDR notation), located by default in /etc/banip/banip.whitelist and /etc/banip/banip.blacklist
  45. * auto-add unsuccessful LuCI and ssh login attempts via 'dropbear' or 'sshd' to local blacklist (see 'ban_autoblacklist' option)
  46. * auto-add the uplink subnet to local whitelist (see 'ban_autowhitelist' option)
  47. * provides a small background log monitor to ban unsuccessful login attempts in real-time
  48. * per source configuration of SRC (incoming) and DST (outgoing)
  49. * integrated IPSet-Lookup
  50. * integrated RIPE-Lookup
  51. * blocklist source parsing by fast & flexible regex rulesets
  52. * minimal status & error logging to syslog, enable debug logging to receive more output
  53. * procd based init system support (start/stop/restart/reload/refresh/status)
  54. * procd network interface trigger support
  55. * automatic blocklist backup & restore, they will be used in case of download errors or during startup
  56. * Provides comprehensive runtime information
  57. * Provides a detailed IPSet Report
  58. * Provides a powerful query function to quickly find blocked IPs/CIDR in banIP related IPSets
  59. * Provides an easily configurable blocklist update scheduler called 'Refresh Timer'
  60. * strong LuCI support
  61. * optional: add new banIP sources on your own
  62. ## Prerequisites
  63. * [OpenWrt](https://openwrt.org), tested with the stable release series (19.07.x) and with the latest rolling snapshot releases. On turris devices it has been successfully tested with TurrisOS 5.2.x
  64. <b>Please note:</b> Older OpenWrt releases like 18.06.x or 17.01.x are _not_ supported!
  65. <b>Please note:</b> Devices with less than 128 MByte RAM are _not_ supported!
  66. <b>Please note:</b> If you're updating from former banIP 0.3x please manually remove your config (/etc/config/banip) before you start!
  67. * A download utility with SSL support: 'wget', 'uclient-fetch' with one of the 'libustream-*' ssl libraries, 'aria2c' or 'curl' is required
  68. * A certificate store like 'ca-bundle', as banIP checks the validity of the SSL certificates of all download sites by default
  69. * Optional E-Mail notification support: for E-Mail notifications you need to install the additional 'msmtp' package
  70. ## Installation & Usage
  71. * Update your local opkg repository (_opkg update_)
  72. * Install 'banip' (_opkg install banip_). The banIP service is disabled by default
  73. * Install the LuCI companion package 'luci-app-banip' (_opkg install luci-app-banip_)
  74. * 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
  75. ## banIP CLI
  76. * All important banIP functions are accessible via CLI as well.
  77. <pre><code>
  78. ~# /etc/init.d/banip
  79. Syntax: /etc/init.d/banip [command]
  80. Available commands:
  81. start Start the service
  82. stop Stop the service
  83. restart Restart the service
  84. reload Reload configuration files (or restart if service does not implement reload)
  85. enable Enable service autostart
  86. disable Disable service autostart
  87. enabled Check if service is started on boot
  88. refresh Refresh ipsets without new list downloads
  89. suspend Suspend banIP processing
  90. resume Resume banIP processing
  91. query &lt;IP&gt; Query active banIP IPSets for a specific IP address
  92. report [&lt;cli&gt;|&lt;mail&gt;|&lt;gen&gt;|&lt;json&gt;] Print banIP related IPset statistics
  93. list [&lt;add&gt;|&lt;add_asn&gt;|&lt;add_country&gt;|&lt;remove>|&lt;remove_asn&gt;|&lt;remove_country&gt;] &lt;source(s)&gt; List/Edit available sources
  94. timer [&lt;add&gt; &lt;tasks&gt; &lt;hour&gt; [&lt;minute&gt;] [&lt;weekday&gt;]]|[&lt;remove&gt; &lt;line no.&gt;] List/Edit cron update intervals
  95. version Print version information
  96. running Check if service is running
  97. status Service status
  98. trace Start with syscall trace
  99. </code></pre>
  100. ## banIP config options
  101. * Usually the auto pre-configured banIP setup works quite well and no manual overrides are needed
  102. | Option | Type | Default | Description |
  103. | :---------------------- | :----- | :---------------------------- | :------------------------------------------------------------------------------------ |
  104. | ban_enabled | option | 0 | enable the banIP service |
  105. | ban_autodetect | option | 1 | auto-detect wan interfaces, devices and subnets |
  106. | ban_debug | option | 0 | enable banIP related debug logging |
  107. | ban_mail_enabled | option | 0 | enable the mail service |
  108. | ban_monitor_enabled | option | 0 | enable the log monitor, e.g. to catch failed ssh/luci logins |
  109. | ban_logsrc_enabled | option | 0 | enable the src-related logchain |
  110. | ban_logdst_enabled | option | 0 | enable the dst-related logchain |
  111. | ban_autoblacklist | option | 1 | add suspicious IPs automatically to the local blacklist |
  112. | ban_autowhitelist | option | 1 | add wan IPs/subnets automatically to the local whitelist |
  113. | ban_maxqueue | option | 4 | size of the download queue to handle downloads and processing in parallel |
  114. | ban_reportdir | option | /tmp/banIP-Report | directory where banIP stores the report files |
  115. | ban_backupdir | option | /tmp/banIP-Backup | directory where banIP stores the compressed backup files |
  116. | ban_ifaces | list | - | list option to add logical wan interfaces manually |
  117. | ban_sources | list | - | list option to add banIP sources |
  118. | ban_countries | list | - | list option to add certain countries as an alpha-2 ISO code, e.g. 'de' for germany |
  119. | ban_asns | list | - | list option to add certain ASNs (autonomous system number), e.g. '32934' for facebook |
  120. | ban_chain | option | banIP | name of the root chain used by banIP |
  121. | ban_global_settype | option | src+dst | global settype as default for all sources |
  122. | ban_settype_src | list | - | special SRC settype for a certain sources |
  123. | ban_settype_dst | list | - | special DST settype for a certain sources |
  124. | ban_settype_all | list | - | special SRC+DST settype for a certain sources |
  125. | ban_target_src | option | DROP | default src action (used by log chains as well) |
  126. | ban_target_dst | option | REJECT | default dst action (used by log chains as well) |
  127. | ban_lan_inputchains_4 | list | input_lan_rule | list option to add IPv4 lan input chains |
  128. | ban_lan_inputchains_6 | list | input_lan_rule | list option to add IPv6 lan input chains |
  129. | ban_lan_forwardchains_4 | list | forwarding_lan_rule | list option to add IPv4 lan forward chains |
  130. | ban_lan_forwardchains_6 | list | forwarding_lan_rule | list option to add IPv6 lan forward chains |
  131. | ban_wan_inputchains_4 | list | input_wan_rule | list option to add IPv4 wan input chains |
  132. | ban_wan_inputchains_6 | list | input_wan_rule | list option to add IPv6 wan input chains |
  133. | ban_wan_forwardchains_4 | list | forwarding_wan_rule | list option to add IPv4 wan forward chains |
  134. | ban_wan_forwardchains_6 | list | forwarding_wan_rule | list option to add IPv6 wan forward chains |
  135. | ban_mailreceiver | option | - | receiver address for banIP related notification E-Mails |
  136. | ban_mailsender | option | no-reply@banIP | sender address for banIP related notification E-Mails |
  137. | ban_mailtopic | option | banIP notification | topic for banIP related notification E-Mails |
  138. | ban_mailprofile | option | ban_notify | mail profile used in 'msmtp' for banIP related notification E-Mails |
  139. | ban_srcarc | option | /etc/banip/banip.sources.gz | full path to the compressed source archive file used by banIP |
  140. | ban_localsources | list | maclist, whitelist, blacklist | limit the selection to certain local sources |
  141. | ban_extrasources | list | - | add additional, non-banIP related IPSets e.g. for reporting or queries |
  142. | ban_maclist_timeout | option | - | individual maclist IPSet timeout |
  143. | ban_whitelist_timeout | option | - | individual whitelist IPSet timeout |
  144. | ban_blacklist_timeout | option | - | individual blacklist IPSet timeout |
  145. | ban_logterms | list | dropbear, sshd, luci, nginx | limit the log monitor to certain log terms |
  146. | ban_loglimit | option | 100 | parse only the last stated number of log entries for suspicious events |
  147. | ban_ssh_logcount | option | 3 | number of the failed ssh login repetitions of the same ip in the log before banning |
  148. | ban_luci_logcount | option | 3 | number of the failed luci login repetitions of the same ip in the log before banning |
  149. | ban_nginx_logcount | option | 5 | number of the failed nginx requests of the same ip in the log before banning |
  150. ## Examples
  151. **list/edit banIP sources:**
  152. <pre><code>
  153. ~# /etc/init.d/banip list
  154. ::: Available banIP sources
  155. :::
  156. Name Enabled Focus Info URL
  157. ---------------------------------------------------------------------------
  158. + asn ASN blocks https://asn.ipinfo.app
  159. + bogon Bogon prefixes https://team-cymru.com
  160. + country x Country blocks https://www.ipdeny.com/ipblocks
  161. + debl x Fail2ban IP blacklist https://www.blocklist.de
  162. + doh x Public DoH-Provider https://github.com/dibdot/DoH-IP-blocklists
  163. + drop x Spamhaus drop compilation https://www.spamhaus.org
  164. + dshield x Dshield IP blocklist https://www.dshield.org
  165. + edrop Spamhaus edrop compilation https://www.spamhaus.org
  166. + feodo x Feodo Tracker https://feodotracker.abuse.ch
  167. + firehol1 x Firehol Level 1 compilation https://iplists.firehol.org/?ipset=firehol_level1
  168. + firehol2 Firehol Level 2 compilation https://iplists.firehol.org/?ipset=firehol_level2
  169. + firehol3 Firehol Level 3 compilation https://iplists.firehol.org/?ipset=firehol_level3
  170. + firehol4 Firehol Level 4 compilation https://iplists.firehol.org/?ipset=firehol_level4
  171. + iblockads Advertising blocklist https://www.iblocklist.com
  172. + iblockspy x Malicious spyware blocklist https://www.iblocklist.com
  173. + myip Myip Live IP blacklist https://myip.ms
  174. + nixspam x iX spam protection http://www.nixspam.org
  175. + proxy Firehol list of open proxies https://iplists.firehol.org/?ipset=proxylists
  176. + sslbl x SSL botnet IP blacklist https://sslbl.abuse.ch
  177. + threat x Emerging Threats https://rules.emergingthreats.net
  178. + tor x Tor exit nodes https://fissionrelays.net/lists
  179. + uceprotect1 x Spam protection level 1 http://www.uceprotect.net/en/index.php
  180. + uceprotect2 Spam protection level 2 http://www.uceprotect.net/en/index.php
  181. + voip x VoIP fraud blocklist http://www.voipbl.org
  182. + yoyo x Ad protection blacklist https://pgl.yoyo.org/adservers/
  183. ---------------------------------------------------------------------------
  184. * Configured ASNs: -
  185. * Configured Countries: af, bd, br, cn, hk, hu, id, il, in, iq, ir, kp, kr, no, pk, pl, ro, ru, sa, th, tr, ua, gb
  186. </code></pre>
  187. **receive banIP runtime information:**
  188. <pre><code>
  189. ~# /etc/init.d/banip status
  190. ::: banIP runtime information
  191. + status : enabled
  192. + version : 0.7.0
  193. + ipset_info : 23 IPSets with 302008 IPs/Prefixes
  194. + active_sources : blacklist, country, debl, doh, drop, dshield, feodo, firehol1, iblockspy, nixspam, sslbl, threat,
  195. tor, uceprotect1, voip, whitelist, yoyo
  196. + active_devs : eth3
  197. + active_ifaces : wan, wan6
  198. + active_logterms : dropbear, sshd, luci
  199. + active_subnets : xxx.xxx.x.xxx/24, xxxx:xxxx:xxxx:x:xxxx:xxxx:xxxx:xxxx/64
  200. + run_infos : settype: src+dst, backup_dir: /mnt/data/banip, report_dir: /tmp/banIP-Report
  201. + run_flags : protocols (4/6): ✔/✔, log (src/dst): ✔/✘, monitor: ✔, mail: ✔
  202. + last_run : refresh, 0m 16s, 4019/3527/3680, 03.02.2021 19:57:46
  203. + system : PC Engines apu4, OpenWrt SNAPSHOT r15556-20a0d435d8
  204. </code></pre>
  205. **generate an IPSet report:**
  206. <pre><code>
  207. ~# /etc/init.d/banip report
  208. :::
  209. ::: report on all banIP related IPSets
  210. :::
  211. + Report timestamp ::: 04.02.2021 06:24:41
  212. + Number of all IPSets ::: 24
  213. + Number of all entries ::: 302448
  214. + Number of IP entries ::: 224748
  215. + Number of CIDR entries ::: 77700
  216. + Number of MAC entries ::: 0
  217. + Number of accessed entries ::: 36
  218. :::
  219. ::: IPSet details
  220. :::
  221. Name Type Count Cnt_IP Cnt_CIDR Cnt_MAC Cnt_ACC Entry details (Entry/Count)
  222. --------------------------------------------------------------------------------------------------------------------
  223. whitelist_4 src+dst 1 0 1 0 1
  224. xxx.xxxx.xxx.xxxx/24 85
  225. --------------------------------------------------------------------------------------------------------------------
  226. whitelist_6 src+dst 2 0 2 0 1
  227. xxxx:xxxx:xxxx::/64 29
  228. --------------------------------------------------------------------------------------------------------------------
  229. blacklist_4 src+dst 513 513 0 0 2
  230. 192.35.168.16 3
  231. 80.82.65.74 1
  232. --------------------------------------------------------------------------------------------------------------------
  233. blacklist_6 src+dst 1 1 0 0 0
  234. --------------------------------------------------------------------------------------------------------------------
  235. country_4 src 52150 0 52150 0 23
  236. 124.5.0.0/16 1
  237. 95.188.0.0/14 1
  238. 121.16.0.0/12 1
  239. 46.161.0.0/18 1
  240. 42.56.0.0/14 1
  241. 113.64.0.0/10 1
  242. 113.252.0.0/14 1
  243. 5.201.128.0/17 1
  244. 125.64.0.0/11 1
  245. 90.188.0.0/15 1
  246. 60.0.0.0/11 1
  247. 78.160.0.0/11 1
  248. 1.80.0.0/12 1
  249. 183.184.0.0/13 1
  250. 175.24.0.0/14 1
  251. 119.176.0.0/12 1
  252. 59.88.0.0/13 1
  253. 103.78.12.0/22 1
  254. 123.128.0.0/13 1
  255. 116.224.0.0/12 1
  256. 42.224.0.0/12 1
  257. 82.80.0.0/15 1
  258. 14.32.0.0/11 1
  259. --------------------------------------------------------------------------------------------------------------------
  260. country_6 src 20099 0 20099 0 0
  261. --------------------------------------------------------------------------------------------------------------------
  262. debl_4 src+dst 29389 29389 0 0 1
  263. 5.182.210.16 4
  264. --------------------------------------------------------------------------------------------------------------------
  265. debl_6 src+dst 64 64 0 0 0
  266. --------------------------------------------------------------------------------------------------------------------
  267. doh_4 src+dst 168 168 0 0 0
  268. --------------------------------------------------------------------------------------------------------------------
  269. doh_6 src+dst 122 122 0 0 0
  270. --------------------------------------------------------------------------------------------------------------------
  271. drop_4 src+dst 965 0 965 0 0
  272. --------------------------------------------------------------------------------------------------------------------
  273. drop_6 src+dst 36 0 36 0 0
  274. --------------------------------------------------------------------------------------------------------------------
  275. dshield_4 src+dst 20 0 20 0 1
  276. 89.248.165.0/24 1
  277. --------------------------------------------------------------------------------------------------------------------
  278. feodo_4 src+dst 325 325 0 0 0
  279. --------------------------------------------------------------------------------------------------------------------
  280. firehol1_4 src+dst 2763 403 2360 0 0
  281. --------------------------------------------------------------------------------------------------------------------
  282. iblockspy_4 src+dst 3650 2832 818 0 0
  283. --------------------------------------------------------------------------------------------------------------------
  284. nixspam_4 src+dst 9577 9577 0 0 0
  285. --------------------------------------------------------------------------------------------------------------------
  286. sslbl_4 src+dst 104 104 0 0 0
  287. --------------------------------------------------------------------------------------------------------------------
  288. threat_4 src+dst 1300 315 985 0 0
  289. --------------------------------------------------------------------------------------------------------------------
  290. tor_4 src+dst 1437 1437 0 0 0
  291. --------------------------------------------------------------------------------------------------------------------
  292. tor_6 src+dst 478 478 0 0 0
  293. --------------------------------------------------------------------------------------------------------------------
  294. uceprotect1_4 src+dst 156249 156249 0 0 6
  295. 192.241.220.137 1
  296. 128.14.137.178 1
  297. 61.219.11.153 1
  298. 138.34.32.33 1
  299. 107.174.133.130 2
  300. 180.232.99.46 1
  301. --------------------------------------------------------------------------------------------------------------------
  302. voip_4 src+dst 12563 12299 264 0 0
  303. --------------------------------------------------------------------------------------------------------------------
  304. yoyo_4 src+dst 10472 10472 0 0 1
  305. 204.79.197.200 2
  306. --------------------------------------------------------------------------------------------------------------------
  307. </code></pre>
  308. **Enable E-Mail notification via 'msmtp':**
  309. To use the email notification you have to install & configure the package 'msmtp'.
  310. Modify the file '/etc/msmtprc', e.g.:
  311. <pre><code>
  312. [...]
  313. defaults
  314. auth on
  315. tls on
  316. tls_certcheck off
  317. timeout 5
  318. syslog LOG_MAIL
  319. [...]
  320. account ban_notify
  321. host smtp.gmail.com
  322. port 587
  323. from <address>k@gmail.com
  324. user <gmail-user>
  325. password <password>
  326. </code></pre>
  327. Finally enable E-Mail support and add a valid E-Mail receiver address in LuCI.
  328. **Edit, add new banIP sources:**
  329. The banIP blocklist sources are stored in an external, compressed JSON file '/etc/banip/banip.sources.gz'.
  330. This file is directly parsed in LuCI and accessible via CLI, just call _/etc/init.d/banip list_.
  331. To add new or edit existing sources extract the compressed JSON file _gunzip /etc/banip/banip.sources.gz_.
  332. A valid JSON source object contains the following required information, e.g.:
  333. <pre><code>
  334. [...]
  335. "tor": {
  336. "url_4": "https://lists.fissionrelays.net/tor/exits-ipv4.txt",
  337. "url_6": "https://lists.fissionrelays.net/tor/exits-ipv6.txt",
  338. "rule_4": "/^(([0-9]{1,3}\\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])(\\/(1?[0-9]|2?[0-9]|3?[0-2]))?)([[:space:]]|$)/{print \"add tor_4 \"$1}",
  339. "rule_6": "/^(([0-9A-f]{0,4}:){1,7}[0-9A-f]{0,4}:?(\\/(1?[0-2][0-8]|[0-9][0-9]))?)([[:space:]]|$)/{print \"add tor_6 \"$1}",
  340. "focus": "Tor exit nodes",
  341. "descurl": "https://fissionrelays.net/lists"
  342. },
  343. [...]
  344. </code></pre>
  345. 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.
  346. <b>Please note:</b> 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'
  347. ## Support
  348. 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>
  349. ## Removal
  350. * stop all banIP related services with _/etc/init.d/banip stop_
  351. * optional: remove the banip package (_opkg remove banip_)
  352. Have fun!
  353. Dirk