Yuri Slobodyanyuk Blog on Information Security 2024年09月12日
awk weekly - Security rule hits statistics . Checkpoint
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

文章介绍了将防火墙日志导出为人类可读格式后,可进行诸多操作,如统计各安全规则的命中次数,并通过脚本进行处理和排序,还提到了更新的使用规则 ID 的脚本及运行时间。

🔥文章首先提到将防火墙日志导出为可读格式后,可通过脚本来统计每个安全规则被命中的次数,且明确只计算在安全选项卡中看到的规则,如Smartdashboard中的规则,而Smartview Tracker中的其他规则不计入,如SmartDefense、WebFiltering等。

💻接着讲述了如何对命中次数进行排序,以查看哪些规则被使用得最多,并给出了相应的awk命令示例及处理结果。

🔄之后提到了更新的脚本,使用规则ID代替规则顺序编号,这样改变规则顺序不会影响统计结果,该脚本还能匹配非安全规则,同时说明了不想因额外格式化而减慢处理速度。

⏱最后给出了对一个900Mb大小、470万条记录的文件的运行时间,包括实际时间、用户时间和系统时间。

As I mentioned before once you export firewall logs into human-readable format you can do lots of interesting things - for example script that gives statistics of how many times each Security rule was hit .Be aware that this counts explicit Security rules only - i.e. the ones you see in Security tab of the Smartdashboard. No other rules you usually see in Smartview Tracker are counted - e.g. SmartDefense,Web Filtering etc. Also afterwards I sort it by number of hits to see what rules are used most:

awk -F\;  ' {match($0,/rule: +([0-9]+)/,rules);rule_count[rules[1]]++} END {for (rule_number in rule_count) print " Rule number: "  rule_number " Hits: " rule_count[rule_number]}' ./fw.log.txt | sort -n -k5 
    Rule number:  Hits: 1197330 <strong> Ignore this line as it counts non-matched lines I dont want to filter with additional conditions and added time processing</strong>     Rule number: 2 Hits: 9     Rule number: 5 Hits: 366     Rule number: 11 Hits: 12296     Rule number: 9 Hits: 14457     Rule number: 0 Hits: 17094     Rule number: 1 Hits: 44066     Rule number: 7 Hits: 233643     Rule number: 10 Hits: 366275     Rule number: 6 Hits: 424639 

Update 2012 Below is the script to use Rule ID instead of Rule sequential numbers - this way changing rules order will not affect statistics. The script matches also non-security rules - e.g. email session id, that are a bit shorter then Rule ID, but I didn't want to slow down the processing with additional formatting .

awk -F\;  ' {match($0,/{([[:print:]]+)}/,rules);rule_count[rules[1]]++} END {for (rule_number in rule_count) print " Rule number: "  rule_number " Hits: " rule_count[rule_number]}' ./fw.log.txt | sort -n -k5 
    Rule number: D199972C-ED3E-4EB4-8B83-813333156D18 Hits: 175     Rule number: 85A905A7-951E-4100-A4BA-E13333151D29 Hits: 219     Rule number: 81333316-E942-4313-BB7D-E1333315802F Hits: 1519     Rule number: 71333215-2DB5-4A3A-95BC-5080AD0F5564 Hits: 2298     Rule number: 11331315-AE52-44E0-A42A-711029B5768E Hits: 3755     Rule number: 01333315-D290-4B05-AFE7-23BF24D889FF Hits: 4116     Rule number: 121FA62F-3885-4328-8090-BF1333315eB1 Hits: 399793     Rule number: FE40E076-BAEB-4979-8E41-5EF1333315e6 Hits: 440101     Rule number: BB3F6772-4D38-4D5A-952A-301333315de8 Hits: 1354341    Running time for a file of 900 Mb with 4.7 million records    real    5m50.287s    user    4m22.890s    sys     0m3.190s

Follow me on https://www.linkedin.com/in/yurislobodyanyuk/ not to miss what I publish on Linkedin, Github, blog, and more.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

防火墙日志 安全规则 规则ID 运行时间
相关文章