Yuri Slobodyanyuk Blog on Information Security 2024年09月12日
awk weekly – Checkpoint Anti Spam statistics or viva les Open Relays
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

作者讲述处理客户邮件安全问题的过程,包括发现Exchange被用作开放中继、利用脚本分析邮件数据等情况

😮发现Exchange被用作开放中继,导致大量垃圾邮件被传递。作者通过tcpdump发现此问题,尽管防火墙有反垃圾邮件订阅服务,但仍未能阻止

📊作者为衡量事件影响,将UTM的fw.log导出为文本格式,并使用awk进行数据分析,得出在28小时内有402804封垃圾邮件被拦截的结果

📈作者还分析了从LAN到Internet的被接受邮件情况,发现257940封邮件被视为干净邮件发出,同时计算了从外部进入被拦截的垃圾邮件数量

🔍作者通过一系列脚本收集了被拦截邮件的统计信息及来源IP,发现存在大量来自不同IP的垃圾邮件

Goooood day everyone again,today I have had another fight with the spam that my client fell victim of. Once upon a time there was not so powerful UTM providing internet to not so crowded office in not so security-aware Central Europe.All would be good and well if not this problem - they could not send emails outside as the IP of the firewall entered every imaginable blacklist on the Earth. Hmm, but the firewall has AntiSpam subscription service up and running.LAN is blocked on port 25 outbound except the Exchange. Antivirus is everywhere so low chance of spam coming from LAN. In SmartView Tracker lots of SMTP rule logs in red - spam entering Exchange is blocked .

So what the ...? tcpdump with -w option for 5 minutes was all I needed to see that Exchange was open relay and kindly offered to relay spam from everyone to everywhere.To really measure the impact of the event I had to have some statistics and Checkpoint didn't help me much with that , eventhough this UTM has also SmartView Monitor license it is not suited for the task. So I exported fw.log on the UTM into text human-awk-readable format , that took some 40 mins on 300 Mb log file and produced text file of 475 Mb, and then did whatever I wanted with the data using awk.Now get some action:
Script 1 - Find all mails rejected in direction from LAN (interface Internal, remember it is UTM) to the Internet (interface External) , then gather statistics of how many mails came from what ip [less relevant here as all mails come from Exchnage, but in environment where hosts send mails directly outside it is] and show us :

# awk -F\; '/Internal to External/ && /reject/ {print $2}' ./fw.log.txt | awk ' {match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/,IP); IPS[IP[0]]++ } END { for (spammer_ips in IPS) print spammer_ips " " IPS[spammer_ips]}' | sort -n -k2,2
192.168.14.12 402804

Yahooooo! In the timeframe of 28 hours there were blocked 402804 mails as spam coming from Exchange!Not bad at all - all this without any malware installed on the client side [my educated by Wireshark guess here as I dont have access to the Exchange],just amazing!

Now let's have a look at overal number of mails that was accepted and sent outside to the Internet :Script 2 - Find all mails accepted in direction from LAN (interface Internal) to the Internet (interface External) , then gather statistics of how many mails came from what ip and show us :

# awk -F\; '/Internal to External/ && /accept/ {print $2}' ./fw.log.txt | awk ' {match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/,IP); IPS[IP[0]]++ } END { for (spammer_ips in IPS) print spammer_ips " " IPS[spammer_ips]}' | sort -n -k2,2192.168.14.12 257940

Wow! in addition to 402804 mails blocked by Checkpoint firewall as spam 257940 mails were sent out as clean, given that this is a very small office hardly sending 300 mails a day we get ratio of 39% spam passing through the Checkpoint Antispam , pity . Antispam blocking rate of 61% ? In 21st century ? Wake up !

Just for statistics I also calculated how many spam emails were blocked from outside inbound:Script 3 - gather how many mails from outside coming in were rejected by Checkpoint as spam.

# awk -F\; '/External to Internal/ && /reject/ {print $2}' ./fw.log.txt | wc
# 5593 11186 112648

So only 5593 incoming spam emails and almost half a million outgoing ones - that's what I call effectiveness.Script 4 - gather statistics on blocked emails and IPs it came from:

# awk -F\; '/External to Internal/ && /reject/ {print $2}' ./fw.log.txt | awk ' {match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/,IP); IPS[IP[0]]++ } END { for (spam_ips in IPS) print spam_ips " " IPS[spam_ips]}' | sort -n -k2,2 

And here are some results

93.81.26.2 7591.121.114.1 81220.168.57.1 8758.9.205.2 129122.102.101.1 14958.137.99.7 160189.35.231.6 18960.248.174.6 631

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

相关标签

邮件安全 Exchange 垃圾邮件 数据分析
相关文章