如何让 sec 正确忽略时间戳

Eth*_*lle 13 linux logging regex syslog

我有一个这样设置的规则;

在 /etc/sec/rules.d 我有;

type=SingleWithSuppress
ptype=regexp
pattern=(\S+) sshd\[\d+\]: PAM \d+ more authentication failures\; logname=.* uid=.* euid=.* tty=ssh ruser=.* rhost=(.*) user=(.*)
desc=Login Failure: $0
action=pipe '%s ' /bin/mail -s "login failure $2 to $3@$1" team@team.com
window=300
Run Code Online (Sandbox Code Playgroud)

因此,如果这是通过系统日志实现的;

Nov 21 11:24:10 servername.server.com sshd[26846]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost= user=kloggins
Run Code Online (Sandbox Code Playgroud)

它应该根据模式匹配这个(它根据我的正则表达式编辑器匹配);

servername.server.com sshd[26846]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost= user=kloggins
Run Code Online (Sandbox Code Playgroud)

我们遇到了垃圾邮件问题,因为时间戳正在发生变化。所以我重写了模式以匹配主机名之后的所有内容。

但是,这似乎不起作用,每次用户“身份验证失败”时,我仍然会收到一封电子邮件。

我一直在使用以下内容进行测试;

logger -p syslog.err 'sshd[26846]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost= user='
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我可能只是误解了秒。这是我第一次使用它!任何帮助将不胜感激。谢谢!

Eth*_*lle 11

好吧,经过将近一天的头发拉扯,我终于明白了 a) 怎么做 b) 我对秒的误解。

在阅读 sec 手册页时,它将 desc= 描述为基本上显示匹配。所以在我看来,这意味着它应该显示任何匹配的模式。嗯,是的,这是真的,在这种情况下,该模式中的匹配是; 主机名、rhost 和用户。

因此,当我执行 desc= Login Failure: $0 时,我正在关闭整条线路。那很糟。

因此,我将其更改为关闭用户名和主机名,然后使其遵守 window=300 规则,因为时间戳(整行)没有改变;又名,以下纲要;

/etc/sec/rules.d/ssh.sec

type=SingleWithSuppress
ptype=regexp
pattern=(\S+) sshd\[\d+\]: PAM \d+ more authentication failures\; logname=.* uid=.* euid=.* tty=ssh ruser=.* rhost=(.*) user=(.*)
desc=Login Failure: $3@$1
action=pipe '%s $0' /bin/mail -s "Login Failure: $3@$1" email@email.com
window=300
Run Code Online (Sandbox Code Playgroud)

错误行

Nov 21 01:58:10 test.test.com sshd[26846]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=test.test.com user=kloggins
Run Code Online (Sandbox Code Playgroud)

它会注意到用户 kloggins@test.test.com 并且不会报告它,除非它在 ​​300 秒后再次发生,因为它关闭了 kloggins@test.test.com。

我现在已经测试了几次,它是一个“werkin”。

  • 听说,这里。我为一个出色的、写得很好的、经过充分研究和有范围的问题以及在您获得所需的顿悟后回来并发布详细答案而给我 +1!谢谢你。 (4认同)