<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>网络安全 on 我的文档站</title><link>https://www.eternal.foo/docs/debian/network_security/</link><description>Recent content in 网络安全 on 我的文档站</description><generator>Hugo</generator><language>zh-CN</language><copyright>Copyright (c) 2020-2026 Thulite</copyright><lastBuildDate>Mon, 01 Jan 0001 00:00:00 +0000</lastBuildDate><atom:link href="https://www.eternal.foo/docs/debian/network_security/index.xml" rel="self" type="application/rss+xml"/><item><title>Fail2ban - 扫描日志文件</title><link>https://www.eternal.foo/docs/debian/network_security/fail2ban-%E6%89%AB%E6%8F%8F%E6%97%A5%E5%BF%97%E6%96%87%E4%BB%B6/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://www.eternal.foo/docs/debian/network_security/fail2ban-%E6%89%AB%E6%8F%8F%E6%97%A5%E5%BF%97%E6%96%87%E4%BB%B6/</guid><description>&lt;p&gt;Fail2ban官方网站 https://www.fail2ban.org&lt;/p&gt;
&lt;h4 id="step-1安装fail2ban"&gt;Step 1:安装Fail2ban&lt;/h4&gt;



&lt;div class="expressive-code"&gt;
 &lt;figure class="frame not-content"&gt;
 &lt;figcaption class="header"&gt;
 &lt;span class="title"&gt;&lt;/span&gt;
 &lt;/figcaption&gt;
 &lt;pre tabindex="0"&gt;&lt;code&gt;apt update
apt install fail2ban&lt;/code&gt;&lt;/pre&gt;
 &lt;/figure&gt;
&lt;/div&gt;
&lt;h4 id="step-2复制配置"&gt;Step 2:复制配置&lt;/h4&gt;



&lt;div class="expressive-code"&gt;
 &lt;figure class="frame not-content"&gt;
 &lt;figcaption class="header"&gt;
 &lt;span class="title"&gt;&lt;/span&gt;
 &lt;/figcaption&gt;
 &lt;pre tabindex="0"&gt;&lt;code&gt;cp /etc/fail2ban/jail.{conf,local}&lt;/code&gt;&lt;/pre&gt;
 &lt;/figure&gt;
&lt;/div&gt;
&lt;h3 id="step-3根据需要修改fail2ban功能"&gt;Step 3:根据需要,修改Fail2ban功能&lt;/h3&gt;



&lt;div class="expressive-code"&gt;
 &lt;figure class="frame not-content"&gt;
 &lt;figcaption class="header"&gt;
 &lt;span class="title"&gt;&lt;/span&gt;
 &lt;/figcaption&gt;
 &lt;pre tabindex="0"&gt;&lt;code&gt;vi &amp;#34;/etc/fail2ban/jail.local&amp;#34;&lt;/code&gt;&lt;/pre&gt;
 &lt;/figure&gt;
&lt;/div&gt;
&lt;p&gt;举例:&lt;/p&gt;



&lt;div class="expressive-code"&gt;
 &lt;figure class="frame not-content"&gt;
 &lt;figcaption class="header"&gt;
 &lt;span class="title"&gt;&lt;/span&gt;
 &lt;/figcaption&gt;
 &lt;pre tabindex="0"&gt;&lt;code class="language-conf" data-lang="conf"&gt;#
# WARNING: heavily refactored in 0.9.0 release. Please review and
# customize settings for your setup.
#
# Changes: in most of the cases you should not modify this
# file, but provide customizations in jail.local file,
# or separate .conf files under jail.d/ directory, e.g.:
#
# HOW TO ACTIVATE JAILS:
#
# YOU SHOULD NOT MODIFY THIS FILE.
#
# It will probably be overwritten or improved in a distribution update.
#
# Provide customizations in a jail.local file or a jail.d/customisation.local.
# For example to change the default bantime for all jails and to enable the
# ssh-iptables jail the following (uncommented) would appear in the .local file.
# See man 5 jail.conf for details.
#
# [DEFAULT]
# bantime = 1h
#
# [sshd]
# enabled = true
#
# See jail.conf(5) man page for more information



# Comments: use &amp;#39;#&amp;#39; for comment lines and &amp;#39;;&amp;#39; (following a space) for inline comments


[INCLUDES]

#before = paths-distro.conf
before = paths-debian.conf

# The DEFAULT allows a global definition of the options. They can be overridden
# in each jail afterwards.

[DEFAULT]

#
# MISCELLANEOUS OPTIONS
#

# &amp;#34;bantime.increment&amp;#34; allows to use database for searching of previously banned ip&amp;#39;s to increase a 
# default ban time using special formula, default it is banTime * 1, 2, 4, 8, 16, 32...
#bantime.increment = true

# &amp;#34;bantime.rndtime&amp;#34; is the max number of seconds using for mixing with random time 
# to prevent &amp;#34;clever&amp;#34; botnets calculate exact time IP can be unbanned again:
#bantime.rndtime = 

# &amp;#34;bantime.maxtime&amp;#34; is the max number of seconds using the ban time can reach (doesn&amp;#39;t grow further)
#bantime.maxtime = 

# &amp;#34;bantime.factor&amp;#34; is a coefficient to calculate exponent growing of the formula or common multiplier,
# default value of factor is 1 and with default value of formula, the ban time 
# grows by 1, 2, 4, 8, 16 ...
#bantime.factor = 1

# &amp;#34;bantime.formula&amp;#34; used by default to calculate next value of ban time, default value below,
# the same ban time growing will be reached by multipliers 1, 2, 4, 8, 16, 32...
#bantime.formula = ban.Time * (1&amp;lt;&amp;lt;(ban.Count if ban.Count&amp;lt;20 else 20)) * banFactor
#
# more aggressive example of formula has the same values only for factor &amp;#34;2.0 / 2.885385&amp;#34; :
#bantime.formula = ban.Time * math.exp(float(ban.Count+1)*banFactor)/math.exp(1*banFactor)

# &amp;#34;bantime.multipliers&amp;#34; used to calculate next value of ban time instead of formula, corresponding
# previously ban count and given &amp;#34;bantime.factor&amp;#34; (for multipliers default is 1);
# following example grows ban time by 1, 2, 4, 8, 16 ... and if last ban count greater as multipliers count, 
# always used last multiplier (64 in example), for factor &amp;#39;1&amp;#39; and original ban time 600 - 10.6 hours
#bantime.multipliers = 1 2 4 8 16 32 64
# following example can be used for small initial ban time (bantime=60) - it grows more aggressive at begin,
# for bantime=60 the multipliers are minutes and equal: 1 min, 5 min, 30 min, 1 hour, 5 hour, 12 hour, 1 day, 2 day
#bantime.multipliers = 1 5 30 60 300 720 1440 2880

# &amp;#34;bantime.overalljails&amp;#34; (if true) specifies the search of IP in the database will be executed 
# cross over all jails, if false (default), only current jail of the ban IP will be searched
#bantime.overalljails = false

# --------------------

# &amp;#34;ignoreself&amp;#34; specifies whether the local resp. own IP addresses should be ignored
# (default is true). Fail2ban will not ban a host which matches such addresses.
#ignoreself = true

# &amp;#34;ignoreip&amp;#34; can be a list of IP addresses, CIDR masks or DNS hosts. Fail2ban
# will not ban a host which matches an address in this list. Several addresses
# can be defined using space (and/or comma) separator.
ignoreip = 127.0.0.1/32 ::1

# External command that will take an tagged arguments to ignore, e.g. &amp;lt;ip&amp;gt;,
# and return true if the IP is to be ignored. False otherwise.
#
# ignorecommand = /path/to/command &amp;lt;ip&amp;gt;
ignorecommand =

# &amp;#34;bantime&amp;#34; is the number of seconds that a host is banned.
bantime = 1h

# A host is banned if it has generated &amp;#34;maxretry&amp;#34; during the last &amp;#34;findtime&amp;#34;
# seconds.
findtime = 1d

# &amp;#34;maxretry&amp;#34; is the number of failures before a host get banned.
maxretry = 5

# &amp;#34;maxmatches&amp;#34; is the number of matches stored in ticket (resolvable via tag &amp;lt;matches&amp;gt; in actions).
maxmatches = %(maxretry)s

# &amp;#34;backend&amp;#34; specifies the backend used to get files modification.
# Available options are &amp;#34;pyinotify&amp;#34;, &amp;#34;gamin&amp;#34;, &amp;#34;polling&amp;#34;, &amp;#34;systemd&amp;#34; and &amp;#34;auto&amp;#34;.
# This option can be overridden in each jail as well.
#
# pyinotify: requires pyinotify (a file alteration monitor) to be installed.
# If pyinotify is not installed, Fail2ban will use auto.
# gamin: requires Gamin (a file alteration monitor) to be installed.
# If Gamin is not installed, Fail2ban will use auto.
# polling: uses a polling algorithm which does not require external libraries.
# systemd: uses systemd python library to access the systemd journal.
# Specifying &amp;#34;logpath&amp;#34; is not valid for this backend.
# See &amp;#34;journalmatch&amp;#34; in the jails associated filter config
# auto: will try to use the following backends, in order:
# pyinotify, gamin, polling.
#
# Note: if systemd backend is chosen as the default but you enable a jail
# for which logs are present only in its own log files, specify some other
# backend for that jail (e.g. polling) and provide empty value for
# journalmatch. See https://github.com/fail2ban/fail2ban/issues/959#issuecomment-74901200
backend = auto

# &amp;#34;usedns&amp;#34; specifies if jails should trust hostnames in logs,
# warn when DNS lookups are performed, or ignore all hostnames in logs
#
# yes: if a hostname is encountered, a DNS lookup will be performed.
# warn: if a hostname is encountered, a DNS lookup will be performed,
# but it will be logged as a warning.
# no: if a hostname is encountered, will not be used for banning,
# but it will be logged as info.
# raw: use raw value (no hostname), allow use it for no-host filters/actions (example user)
usedns = warn

# &amp;#34;logencoding&amp;#34; specifies the encoding of the log files handled by the jail
# This is used to decode the lines from the log file.
# Typical examples: &amp;#34;ascii&amp;#34;, &amp;#34;utf-8&amp;#34;
#
# auto: will use the system locale setting
logencoding = auto

# &amp;#34;enabled&amp;#34; enables the jails.
# By default all jails are disabled, and it should stay this way.
# Enable only relevant to your setup jails in your .local or jail.d/*.conf
#
# true: jail will be enabled and log files will get monitored for changes
# false: jail is not enabled
enabled = false


# &amp;#34;mode&amp;#34; defines the mode of the filter (see corresponding filter implementation for more info).
mode = normal

# &amp;#34;filter&amp;#34; defines the filter to use by the jail.
# By default jails have names matching their filter name
#
filter = %(__name__)s[mode=%(mode)s]


#
# ACTIONS
#

# Some options used for actions

# Destination email address used solely for the interpolations in
# jail.{conf,local,d/*} configuration files.
destemail = root@localhost

# Sender email address used solely for some actions
sender = root@&amp;lt;fq-hostname&amp;gt;

# E-mail action. Since 0.8.1 Fail2Ban uses sendmail MTA for the
# mailing. Change mta configuration parameter to mail if you want to
# revert to conventional &amp;#39;mail&amp;#39;.
mta = sendmail

# Default protocol
protocol = tcp

# Specify chain where jumps would need to be added in ban-actions expecting parameter chain
chain = &amp;lt;known/chain&amp;gt;

# Ports to be banned
# Usually should be overridden in a particular jail
port = 0:65535

# Format of user-agent https://tools.ietf.org/html/rfc7231#section-5.5.3
fail2ban_agent = Fail2Ban/%(fail2ban_version)s

#
# Action shortcuts. To be used to define action parameter

# Default banning action (e.g. iptables, iptables-new,
# iptables-multiport, shorewall, etc) It is used to define
# action_* variables. Can be overridden globally or per
# section within jail.local file
#banaction = iptables-multiport
banaction = shorewall
banaction_allports = iptables-allports

# The simplest action to take: ban only
action_ = %(banaction)s[port=&amp;#34;%(port)s&amp;#34;, protocol=&amp;#34;%(protocol)s&amp;#34;, chain=&amp;#34;%(chain)s&amp;#34;]

# ban &amp;amp; send an e-mail with whois report to the destemail.
action_mw = %(action_)s
 %(mta)s-whois[sender=&amp;#34;%(sender)s&amp;#34;, dest=&amp;#34;%(destemail)s&amp;#34;, protocol=&amp;#34;%(protocol)s&amp;#34;, chain=&amp;#34;%(chain)s&amp;#34;]

# ban &amp;amp; send an e-mail with whois report and relevant log lines
# to the destemail.
action_mwl = %(action_)s
 %(mta)s-whois-lines[sender=&amp;#34;%(sender)s&amp;#34;, dest=&amp;#34;%(destemail)s&amp;#34;, logpath=&amp;#34;%(logpath)s&amp;#34;, chain=&amp;#34;%(chain)s&amp;#34;]

# See the IMPORTANT note in action.d/xarf-login-attack for when to use this action
#
# ban &amp;amp; send a xarf e-mail to abuse contact of IP address and include relevant log lines
# to the destemail.
action_xarf = %(action_)s
 xarf-login-attack[service=%(__name__)s, sender=&amp;#34;%(sender)s&amp;#34;, logpath=&amp;#34;%(logpath)s&amp;#34;, port=&amp;#34;%(port)s&amp;#34;]

# ban &amp;amp; send a notification to one or more of the 50+ services supported by Apprise.
# See https://github.com/caronc/apprise/wiki for details on what is supported.
#
# You may optionally over-ride the default configuration line (containing the Apprise URLs)
# by using &amp;#39;apprise[config=&amp;#34;/alternate/path/to/apprise.cfg&amp;#34;]&amp;#39; otherwise
# /etc/fail2ban/apprise.conf is sourced for your supported notification configuration.
# action = %(action_)s
# apprise

# ban IP on CloudFlare &amp;amp; send an e-mail with whois report and relevant log lines
# to the destemail.
action_cf_mwl = cloudflare[cfuser=&amp;#34;%(cfemail)s&amp;#34;, cftoken=&amp;#34;%(cfapikey)s&amp;#34;]
 %(mta)s-whois-lines[sender=&amp;#34;%(sender)s&amp;#34;, dest=&amp;#34;%(destemail)s&amp;#34;, logpath=&amp;#34;%(logpath)s&amp;#34;, chain=&amp;#34;%(chain)s&amp;#34;]

# Report block via blocklist.de fail2ban reporting service API
# 
# See the IMPORTANT note in action.d/blocklist_de.conf for when to use this action.
# Specify expected parameters in file action.d/blocklist_de.local or if the interpolation
# `action_blocklist_de` used for the action, set value of `blocklist_de_apikey`
# in your `jail.local` globally (section [DEFAULT]) or per specific jail section (resp. in 
# corresponding jail.d/my-jail.local file).
#
action_blocklist_de = blocklist_de[email=&amp;#34;%(sender)s&amp;#34;, service=&amp;#34;%(__name__)s&amp;#34;, apikey=&amp;#34;%(blocklist_de_apikey)s&amp;#34;, agent=&amp;#34;%(fail2ban_agent)s&amp;#34;]

# Report ban via abuseipdb.com.
#
# See action.d/abuseipdb.conf for usage example and details.
#
action_abuseipdb = abuseipdb

# Choose default action. To change, just override value of &amp;#39;action&amp;#39; with the
# interpolation to the chosen action shortcut (e.g. action_mw, action_mwl, etc) in jail.local
# globally (section [DEFAULT]) or per specific section
action = %(action_)s
 %(action_abuseipdb)s[abuseipdb_apikey=&amp;#34;AbuseIPDB KEY&amp;#34;, abuseipdb_category=&amp;#34;14&amp;#34;]

#
# JAILS
#

#
# SSH servers
#


[sshd]
enabled = true

# To use more aggressive sshd modes set filter parameter &amp;#34;mode&amp;#34; in jail.local:
# normal (default), ddos, extra or aggressive (combines all).
# See &amp;#34;tests/files/logs/sshd&amp;#34; or &amp;#34;filter.d/sshd.conf&amp;#34; for usage example and details.
mode = aggressive
port = ssh,1022
logpath = %(sshd_log)s
backend = %(sshd_backend)s
bantime = 1h
findtime = 1d
maxretry = 5
banaction = shorewall
# Ban IP and report to AbuseIPDB for SSH Brute-Forcing
action = %(action_)s
 %(action_abuseipdb)s[abuseipdb_apikey=&amp;#34;AbuseIPDB KEY&amp;#34;, abuseipdb_category=&amp;#34;18,22&amp;#34;]



[scanlogd]
enabled = true
logpath = /var/log/messages
bantime = 1h
findtime = 1w
maxretry = 64
banaction = shorewall
action = %(action_)s
 %(action_abuseipdb)s[abuseipdb_apikey=&amp;#34;AbuseIPDB KEY&amp;#34;, abuseipdb_category=&amp;#34;14&amp;#34;]
 
 
[recidive]
enabled = true
logpath = /var/log/fail2ban.log
bantime = 1y
findtime = 1w
maxretry = 5&lt;/code&gt;&lt;/pre&gt;
 &lt;/figure&gt;
&lt;/div&gt;
&lt;h4 id="扫描日志-修改过滤规则"&gt;扫描日志-修改过滤规则&lt;/h4&gt;



&lt;div class="expressive-code"&gt;
 &lt;figure class="frame not-content"&gt;
 &lt;figcaption class="header"&gt;
 &lt;span class="title"&gt;&lt;/span&gt;
 &lt;/figcaption&gt;
 &lt;pre tabindex="0"&gt;&lt;code&gt;vi &amp;#34;/etc/fail2ban/filter.d/scanlogd.conf&amp;#34;&lt;/code&gt;&lt;/pre&gt;
 &lt;/figure&gt;
&lt;/div&gt;
&lt;p&gt;修改为:&lt;/p&gt;</description></item></channel></rss>