--- title: "Practical Python Malware Analysis - JunWei Song" tags: PyConTW2025, 2025-organize, 2025-共筆 --- # Practical Python Malware Analysis - JunWei Song {%hackmd L_RLmFdeSD--CldirtUhCw %} <iframe src=https://app.sli.do/event/42nvGwCnBZvq1WzJeoq7La height=450 width=100%></iframe> :::success 本演講提供 AI 翻譯字幕及摘要,請點選這裡前往 >> [PyCon Taiwan AI Notebook](https://pycontw.connyaku.app/?room=PxHOKFu8ASRSOhrGg7FI) AI translation subtitles and summaries are available for this talk. Click here to access >> [PyCon Taiwan AI Notebook](https://pycontw.connyaku.app/?room=PxHOKFu8ASRSOhrGg7FI) ::: > Collaborative writing start from below > 從這裡開始共筆 ### Python Malware - 惡意程式會上傳在 typosquatting 的 pypl 上,藏在 setup.py,會在原本的 setup.py 中插入或 overwrite method 植入惡意程式 - 藏在 __init__.py 並且加密成字串,在執行的時候將其解密當作 python 執行 - 打包:(PyInstaller)經過打包後難以分析 - 打包流程:.py file -> .pyc file(bycode)->.exe - 解包: - DiE (Detect it Easy): 初步了解這個exe檔 - pycdc, pyextractor去回朔得到源始碼 - 規避偵測: - 複雜化系統,讓他難以解讀(加密) - 字串加解密:https://gchq.github.io/CyberChef/ - 動態還原並執行(使用 __import__/getattr, exec & eval) ### 分析 exe - 檢查檔案 - [Detect-It-Easy](https://github.com/horsicq/Detect-It-Easy) - 還原程式 - [pycdc](https://github.com/zrax/pycdc) - 若失敗改為:輸出 bytecode (.pyc) - pycdas - 同時顯示上面兩個[Pylingual](https://github.com/syssec-utd/pylingual) - 惡意程式來源:透過 Google 精準搜尋(ex: 檔名) - 結果:https://github.com/mategol/PySilon-malware - 常見的沙箱 - Open source Sandbox: [Cuckoo Sandbox](https://github.com/cuckoosandbox/cuckoo) - All in one 沙箱:[Triage Sandbox](https://tria.ge/) - 支援連結到VM ### Defense & Prevention: - MFA - Verify package sources: 檢查 typo, hash, official sources - Code analysis: manually Static/Dynamic Analysis, sandbox - Trusted Publisher - Open Source Tools - `zizmor`: GitHub account check - `pip-audit`: pacakage security check - `GuardDog`: malicious indicator check ### Reference - 範例:[krnick/pycontw2025-demo](https://github.com/krnick/pycontw2025-demo) Below is the part that speaker updated the talk/tutorial after speech 講者於演講後有更新或勘誤投影片的部份