mmpi
,是一款使用python實現的開源郵件快速檢測工具庫,基於community
框架設計開發。mmpi
支持對郵件頭、郵件正文、郵件附件的解析檢測,並輸出json檢測報告。html
mmpi
,代碼項目地址:https://github.com/a232319779/mmpi,pypi項目地址https://pypi.org/project/mmpi/python
mmpi
,郵件快速檢測工具庫檢測邏輯:git
text
和html
格式的郵件正文,對text
郵件正文進行關鍵字匹配,對html
郵件正文進行解析分析檢測,實現探針郵件檢測
、釣魚郵件檢測
、垃圾郵件檢測
等其餘檢測。mmpi
的分析斷定檢測前提:郵件系統環境。脫離郵件環境上下文,檢測規則的依據就不可靠了。github
$ pip install mmpi
備註:windows
安裝yara-python
,能夠從這裏下載json
$ 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
庫進行解析,基於oletool
作定製化修改,支持對office
文檔和rtf
文檔的解析,再結合yara
實現對其餘文件的檢測。windows
. ├── mmpi │ ├── common │ ├── core │ ├── data │ │ ├── signatures │ │ │ ├── eml │ │ │ ├── html │ │ │ ├── ole │ │ │ ├── other │ │ │ ├── rtf │ │ │ └── zip │ │ ├── white │ │ └── yara │ │ ├── exe │ │ ├── pdf │ │ └── vba │ └── processing └── tests └── samples
mmpi/common
:基礎模塊,實現基本流程功能mmpi/core
:核心調度模塊,實現插件的加載及相關模塊的初始化mmpi/data
:核心檢測模塊,實現基本檢測規則及yara檢測規則mmpi/processing
:核心解析模塊,實現eml
、html
、zip
等文件格式的解析tests
:測試模塊檢測規則:壓縮包中文件名以.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
檢測規則:壓縮包中同時存在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
檢測規則: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文檔,屬於惡意郵件。spa
vba
和rtf
字段爲附件檢測基本信息。signatures
字段說明命中規則。{ "headers": [ { "From": [ { "name": "Mohd Mukhriz Ramli (MLNG/GNE)", "addr": "info@vm1599159.3ssd.had.wf" } ], "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: help@rehlat.co [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 } ] }