身安不如心安,屋宽不如心宽 。

secure log怎么匹配出登陆用户?

Logstash | 作者 jianfzhu | 发布于2018年01月25日 | 阅读数:1605

用下面的可以匹配出 status 和 ClientIP, 怎样截取出user来? 
filter { 
    grok { 
          match => { "message" => ".* sshd\[\d+\]: (?<status>\S+) .* (?<ClientIP>(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?) .*" } 
      overwrite => ["message"] 
} }

 
++++++++log++++++++++
Jan 6 17:13:12 localhost sshd[3380]: Failed password for root from 172.16.0.39 port 58481 ssh2
Jan 6 17:11:51 localhost sshd[3358]: Accepted password for root from 172.16.0.13 port 38604 ssh2
 
已邀请:

medcl - 今晚打老虎。

赞同来自: laoyang360

grok pattern:
.* sshd\[\d+\]: (?<status>\S+) .* for (?<user>\w+) from (?<ClientIP>(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?) .*

http://grok.elasticsearch.cn/do/match#result 测试通过

medcl - 今晚打老虎。

赞同来自:

这个日志结构比较整齐,用 Logstash 新的 dissect filter,性能要快很多。

https://www.elastic.co/guide/e ... .html

jianfzhu

赞同来自:

还有一种输错用户名的,这个无法匹配user.  中间是3个单词了。
Jan 26 09:22:45 localhost sshd[3000]: Failed password for invalid user Hi from 192.168.61.1 port 55268 ssh2

medcl - 今晚打老虎。

赞同来自:

.* sshd\[\d \]: (?<status>\S ) .* for( invalid user)? (?<user>\w ) from (?<ClientIP>(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?) .*

Snip20180126_1.png

 

要回复问题请先登录注册