我不确定如何logging与GOOD_IPS的IP地址匹配的成功的ssh尝试。 到目前为止,我只logging传入和传出的尝试是否允许相关的IP地址。 我将如何编写一条语句,logging所有成功的与GOOD_IPS中的地址匹配的SSHlogin尝试,以及从GOOD_IPS之外的地址logging成功和拒绝尝试的成功和拒绝的尝试?
#allow ssh for ip addresses in GOOD_IPS chain iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A OUTPUT -p TCP --sport 22 -m state --state NEW -j GOOD_IPS iptables -A OUTPUT -p tcp --sport 22 --syn -j LOG --log-prefix "iptables: ssh outgoing attempt" iptables -A OUTPUT -p TCP --sport 22 -m state --state NEW -j DROP iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -p tcp --dport 22 --syn -j LOG --log-prefix "iptables: ssh incoming attempt" iptables -A INPUT -p TCP --dport 22 -m state --state NEW -j GOOD_IPS iptables -A INPUT -p TCP --dport 22 -m state --state NEW -j DROP #ip addresses can be easily added iptables -A GOOD_IPS -s 192.168.182.132 -j ACCEPT #iptables -A GOOD_IPS -s 232.28.25.86 -j ACCEPT
我同意Brigo的说法, iptables不适合协议感知问题,如logging成功login; 这是sshd的日志logging。 但是你可以logging连接尝试
iptables -I INPUT 1 -p tcp --dport 22 -s abcd/e -m state --state NEW -j LOG --log-prefix "ssh login attempt: "
其中abcd/e是你的ip范围很好,带有掩码(例如10.4.0.0/16 )。
这是不可能的,因为iptables不能看到相关的数据。
就像iptables -A INPUT -m string --string "SUCCESS" -j LOG可能已经工作了,如果不是SSH正在encryption这个信息,那么它就不能用于iptables。
此外,所有(成功的)尝试都已经logging在/var/log/secure (或者你的发行版本中,以便将其记入日志)。 为什么不看那里?