mmpi,是一款使用python实现的开源邮件快速检测工具库,基于community框架设计开发。mmpi支持对邮件头、邮件正文、邮件附件的解析检测,并输出json检测报告。
代码项目地址:mmpi
pypi项目地址:pypi
mmpi,邮件快速检测工具库检测逻辑:
mmpi的分析判定检测前提:邮件系统环境。脱离邮件环境上下文,检测规则的依据就不可靠了。
$ pip install mmpi
备注:windows安装yara-python,点击这里下载
$ mmpi-run $email_path
from mmpi import mmpi def main(): emp = mmpi() emp.parse('test.eml') report = emp.get_report() print(report) if __name__ == "__main__": main()
{ // 固定字段 "headers": [], "body": [], "attachments": [], "signatures": [] // 动态字段 "vba": [], "rtf": [], ...... }
mmpi完全基于python开发,使用python原生email、html、zip库进行解析,基于oletools做定制化修改,支持对office文档和rtf文档的解析,再结合yara实现对其他文件的检测。
. ├── mmpi │ ├── common │ ├── core │ ├── data │ │ ├── signatures │ │ │ ├── eml │ │ │ ├── html │ │ │ ├── ole │ │ │ ├── other │ │ │ ├── rtf │ │ │ └── zip │ │ ├── white │ │ └── yara │ │ ├── exe │ │ ├── pdf │ │ └── vba │ └── processing └── tests └── samples
1. PE文件伪装文档类检测
检测规则:压缩包中文件名以.exe结尾,并且中间插入20个以上空格的
class PEFakeDocument(Signature): authors = ["ddvv"] sig_type = 'zip' name = "pe_fake_document" severity = 9 description = "PE File Fake Document" def on_complete(self): results = self.get_results() for result in results: if result.get('type', '') == self.sig_type: infos = result.get('value', {}).get('infos', []) for info in infos: file_type = info.get('type') file_name = info.get('name') space_count = file_name.count(' ') if 'exe' == file_type and space_count > 20: self.mark(type="zip", tag=self.name, data=info.get('name')) return self.has_marks() return None
2. DLL劫持检测
检测规则:压缩包中同时存在exe和dll文件
class DLLHijacking(Signature): authors = ["ddvv"] sig_type = 'zip' name = "dll_hijacking" severity = 9 description = "DLL Hijacking" def on_complete(self): results = self.get_results() for result in results: if result.get('type', '') == self.sig_type: infos = result.get('value', {}).get('infos', []) file_types = [info.get('type') for info in infos] if set(['exe', 'dll']).issubset(file_types): self.mark(type="zip", tag=self.name) return self.has_marks() return None
3. RTF漏洞利用检测
检测规则:RTF文档中存在OLE对象,并且class_name是OLE2Link或者以equation开头
class RTFExploitDetected(Signature): authors = ["ddvv"] sig_type = 'rtf' name = "rtf_exploit_detected" severity = 9 description = "RTF Exploit Detected" def on_complete(self): results = self.get_results() for result in results: if result.get('type', '') == self.sig_type: infos = result.get('value', {}).get('infos', []) for info in infos: if info.get('is_ole', False): class_name = info.get('class_name', '') if class_name == 'OLE2Link' or class_name.lower().startswith('equation'): self.mark(type="rtf", tag=self.name) return self.has_marks() return None
结果说明:邮件包含漏洞利用的RTF文档,属于恶意邮件。
{ "headers": [ { "From": [ { "name": "Mohd Mukhriz Ramli (MLNG/GNE)", "addr": "[email protected]" } ], "To": [ { "name": "", "addr": "" } ], "Subject": "Re: Proforma Invoice", "Date": "2020-11-24 12:37:38 UTC+01:00", "X-Originating-IP": [] } ], "body": [ { "type": "text", "content": " \nDEAR SIR, \n\nPLEASE SIGN THE PROFORMA INVOICE SO THAT I CAN PAY AS SOON AS POSSIBLE.\n\nATTACHED IS THE PROFORMA INVOICE,\n\nPLEASE REPLY QUICKLY, \n\nTHANKS & REGARDS' \n\nRAJASHEKAR \n\n Dubai I Kuwait I Saudi Arabia I India I Egypt \nKuwait: +965 22261501 \nSaudi Arabia: +966 920033029 \nUAE: +971 42431343 \nEmail ID: [email protected] [1]m\n \n\nLinks:\n------\n[1]\nhttps://deref-mail.com/mail/client/OV1N7sILlK8/dereferrer/?redirectUrl=https%3A%2F%2Fe.mail.ru%2Fcompose%2F%3Fmailto%3Dmailto%253ahelp%40rehlat.com" } ], "attachments": [ { "type": "doc", "filename": "Proforma Invoice.doc", "filesize": 1826535, "md5": "558c4aa596b0c4259182253a86b35e8c", "sha1": "63982d410879c09ca090a64873bc582fcc7d802b" } ], "vba": [], "rtf": [ { "is_ole": true, "format_id": 2, "format_type": "Embedded", "class_name": "EQUATion.3", "data_size": 912305, "md5": "a5cee525de80eb537cfea247271ad714" } ], "signatures": [ { "name": "rtf_suspicious_detected", "description": "RTF Suspicious Detected", "severity": 3, "marks": [ { "type": "rtf", "tag": "rtf_suspicious_detected" } ], "markcount": 1 }, { "name": "rtf_exploit_detected", "description": "RTF Exploit Detected", "severity": 9, "marks": [ { "type": "rtf", "tag": "rtf_exploit_detected" } ], "markcount": 1 } ] }