【问题标题】:Parsing Mod Security rules解析 Mod 安全规则
【发布时间】:2021-05-03 22:41:10
【问题描述】:

我需要解析 modsec 日志,以便只显示触发规则的日期和 ID。 比如我有这样的日志:

[1 月 29 日星期五 19:12:14 测试测试] [:error] ModSecurity:警告。使用 libinjection 检测到 XSS。 [file "/etc/apache2 r_configs/OWASP3/rules/REQUEST-941-APPLICATION-ATTACK-XSS.conf"] [line "37"] [id "941100"] [rev "2"] [msg "XSS Attack Detected通过 libinjection"] [数据"匹配数据:在 ARGS:data[] 中找到 x-forwarded-for:[vc_row full_width=\x22stretch_row\x22 initial_loading_animation=\x22fadeIn\x22 show_overlay=\x221\x22 pofo_enable_responsive_css=\x221\x22 pofo_hidden_​​markup_1507889268_2_4 =\x22\x22 css=\x22.vc_custom_1608665830226{背景图片:url(https://argeoslab.tech/wp-content/uploads/2020/12/geniemebanner.jpg?id=22321) !important;}\x22 ][vc_column width=\x221/4\x22 pofo_hidden_​​markup_1507901669_2_21=\x22\x22 pofo_hidden_​​markup_1507901601_2_49=\x22\x22 of..."] [严重性"CRITICAL"] [ver "OWASP_CRS/3.0.0"] [成熟度"1" ] [accuracy "9"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-xss"]

我需要在开头获取日期,然后是 ID。我可以通过以下方式获取 ID:

awk '{for (I=1;I<NF;I++) if ($I == "[id") print $(I+1)}'

我尝试用第二个 awk 将它通过管道传递,这样可以工作,但 if 语句会用于 $i == "Fri" || $i == "Mon" 等等,但效果不佳。

但是,我不知道如何同时获得日期([Fri Jan 29 19:12:14)和 ID。

我最初在 apache 日志中使用 modsec 的 grep 得到输出,所以输出会大得多,我需要遍历每一行,而不仅仅是第一次出现

感谢任何帮助,谢谢

【问题讨论】:

  • 我假设您想解析日志文件,而不是规则 - 是否正确?

标签: linux apache shell


【解决方案1】:

可能是其中之一......

$ grep -Eo '\[(Sun|Mon|Tue|Wed|Thu|Fri|Sat|id)[ a-zA-Z0-9:\"]+\]' filename
[Fri Jan 29 19:12:14 test test]
[id "941100"]

$ awk -F '(] )' '{ c=0; for(i=1;i<=NF;++i) if(match($(i),/^\[(Sun|Mon|Tue|Wed|Thu|Fri|Sat|id)/)) { ++c; print $(i)"]"; if(c==2) break }}' filename
[Fri Jan 29 19:12:14 test test]
[id "941100"]

$ awk -F '(] )' '{ for(i=1;i<=NF;++i) if(match($(i),/^\[(Sun|Mon|Tue|Wed|Thu|Fri|Sat|id)/)) { if(i==1) { s=$(i)"] " } else { s=$(i)"]"; i=NF } printf("%s",s) } print "" }' filename
[Fri Jan 29 19:12:14 test test] [id "941100"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-15
    • 2020-12-02
    • 1970-01-01
    • 2020-06-19
    • 2018-10-19
    • 2019-07-05
    • 2016-06-27
    • 1970-01-01
    相关资源
    最近更新 更多