Translated ['src/generic-methodologies-and-resources/basic-forensic-meth

This commit is contained in:
Translator 2025-09-30 09:11:24 +00:00
parent 927b46d463
commit e7a83d727e
3 changed files with 306 additions and 53 deletions

View File

@ -37,6 +37,7 @@
- [Mobile Phishing Malicious Apps](generic-methodologies-and-resources/phishing-methodology/mobile-phishing-malicious-apps.md)
- [Phishing Files & Documents](generic-methodologies-and-resources/phishing-methodology/phishing-documents.md)
- [Basic Forensic Methodology](generic-methodologies-and-resources/basic-forensic-methodology/README.md)
- [Adaptixc2 Config Extraction And Ttps](generic-methodologies-and-resources/basic-forensic-methodology/adaptixc2-config-extraction-and-ttps.md)
- [Baseline Monitoring](generic-methodologies-and-resources/basic-forensic-methodology/file-integrity-monitoring.md)
- [Anti-Forensic Techniques](generic-methodologies-and-resources/basic-forensic-methodology/anti-forensic-techniques.md)
- [Docker Forensics](generic-methodologies-and-resources/basic-forensic-methodology/docker-forensics.md)
@ -130,6 +131,7 @@
- [Seccomp](linux-hardening/privilege-escalation/docker-security/seccomp.md)
- [Weaponizing Distroless](linux-hardening/privilege-escalation/docker-security/weaponizing-distroless.md)
- [Escaping from Jails](linux-hardening/privilege-escalation/escaping-from-limited-bash.md)
- [Posix Cpu Timers Toctou Cve 2025 38352](linux-hardening/privilege-escalation/linux-kernel-exploitation/posix-cpu-timers-toctou-cve-2025-38352.md)
- [euid, ruid, suid](linux-hardening/privilege-escalation/euid-ruid-suid.md)
- [Interesting Groups - Linux Privesc](linux-hardening/privilege-escalation/interesting-groups-linux-pe/README.md)
- [lxd/lxc Group - Privilege escalation](linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation.md)
@ -771,7 +773,7 @@
- [Stack Shellcode - arm64](binary-exploitation/stack-overflow/stack-shellcode/stack-shellcode-arm64.md)
- [Stack Pivoting - EBP2Ret - EBP chaining](binary-exploitation/stack-overflow/stack-pivoting-ebp2ret-ebp-chaining.md)
- [Uninitialized Variables](binary-exploitation/stack-overflow/uninitialized-variables.md)
- [ROP and JOP](binary-exploitation/rop-return-oriented-programing/README.md)
- [ROP & JOP](binary-exploitation/rop-return-oriented-programing/README.md)
- [BROP - Blind Return Oriented Programming](binary-exploitation/rop-return-oriented-programing/brop-blind-return-oriented-programming.md)
- [Ret2csu](binary-exploitation/rop-return-oriented-programing/ret2csu.md)
- [Ret2dlresolve](binary-exploitation/rop-return-oriented-programing/ret2dlresolve.md)
@ -840,6 +842,7 @@
- [WWW2Exec - GOT/PLT](binary-exploitation/arbitrary-write-2-exec/aw2exec-got-plt.md)
- [WWW2Exec - \_\_malloc_hook & \_\_free_hook](binary-exploitation/arbitrary-write-2-exec/aw2exec-__malloc_hook.md)
- [Common Exploiting Problems](binary-exploitation/common-exploiting-problems.md)
- [Linux kernel exploitation - toctou](binary-exploitation/linux-kernel-exploitation/posix-cpu-timers-toctou-cve-2025-38352.md)
- [Windows Exploiting (Basic Guide - OSCP lvl)](binary-exploitation/windows-exploiting-basic-guide-oscp-lvl.md)
- [iOS Exploiting](binary-exploitation/ios-exploiting/README.md)
- [ios CVE-2020-27950-mach_msg_trailer_t](binary-exploitation/ios-exploiting/CVE-2020-27950-mach_msg_trailer_t.md)
@ -938,5 +941,3 @@
- [Post Exploitation](todo/post-exploitation.md)
- [Investment Terms](todo/investment-terms.md)
- [Cookies Policy](todo/cookies-policy.md)
- [Posix Cpu Timers Toctou Cve 2025 38352](linux-hardening/privilege-escalation/linux-kernel-exploitation/posix-cpu-timers-toctou-cve-2025-38352.md)

View File

@ -0,0 +1,243 @@
# AdaptixC2 設定抽出とTTPs
{{#include ../../banners/hacktricks-training.md}}
AdaptixC2 はモジュラーでオープンソースの post-exploitation/C2 フレームワークで、Windows x86/x64 の beaconsEXE/DLL/service EXE/raw shellcodeと BOF をサポートします。 このページでは以下を記載します:
- RC4でパックされた構成がどのように埋め込まれているか、そして beacons からそれを抽出する方法
- HTTP/SMB/TCP リスナーのネットワーク/プロファイル指標
- 実際に観測された一般的な loader と persistence の TTPs、および関連する Windows 技術ページへのリンク
## Beacon プロファイルとフィールド
AdaptixC2 は主に 3 種類の beacon タイプをサポートします:
- BEACON_HTTP: web C2 で、servers/ports/SSL、method、URI、headers、user-agent、カスタムパラメータ名を設定可能
- BEACON_SMB: named-pipe の peer-to-peer C2イントラネット
- BEACON_TCP: 直接ソケット、任意でプロトコル開始を難読化するための先頭マーカーを付与
HTTP beacon の設定(復号後)で観測される典型的なプロファイルフィールド:
- agent_type (u32)
- use_ssl (bool)
- servers_count (u32), servers (array of strings), ports (array of u32)
- http_method, uri, parameter, user_agent, http_headers (lengthprefixed strings)
- ans_pre_size (u32), ans_size (u32) レスポンスサイズの解析に使用
- kill_date (u32), working_time (u32)
- sleep_delay (u32), jitter_delay (u32)
- listener_type (u32)
- download_chunk_size (u32)
Example default HTTP profile (from a beacon build):
```json
{
"agent_type": 3192652105,
"use_ssl": true,
"servers_count": 1,
"servers": ["172.16.196.1"],
"ports": [4443],
"http_method": "POST",
"uri": "/uri.php",
"parameter": "X-Beacon-Id",
"user_agent": "Mozilla/5.0 (Windows NT 6.2; rv:20.0) Gecko/20121202 Firefox/20.0",
"http_headers": "\r\n",
"ans_pre_size": 26,
"ans_size": 47,
"kill_date": 0,
"working_time": 0,
"sleep_delay": 2,
"jitter_delay": 0,
"listener_type": 0,
"download_chunk_size": 102400
}
```
観測された悪意のある HTTP プロファイル(実際の攻撃):
```json
{
"agent_type": 3192652105,
"use_ssl": true,
"servers_count": 1,
"servers": ["tech-system[.]online"],
"ports": [443],
"http_method": "POST",
"uri": "/endpoint/api",
"parameter": "X-App-Id",
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.6167.160 Safari/537.36",
"http_headers": "\r\n",
"ans_pre_size": 26,
"ans_size": 47,
"kill_date": 0,
"working_time": 0,
"sleep_delay": 4,
"jitter_delay": 0,
"listener_type": 0,
"download_chunk_size": 102400
}
```
## 暗号化された構成のパッキングとロードパス
ビルダーでオペレーターが Create をクリックすると、AdaptixC2 は暗号化されたプロファイルを beacon の末尾ブロブとして埋め込みます。フォーマットは次のとおりです:
- 4 バイト: configuration size (uint32, littleendian)
- N バイト: RC4encrypted configuration data
- 16 バイト: RC4 key
beacon loader は末尾から 16 バイトの key をコピーし、N バイトのブロックをその場で RC4 で復号します:
```c
ULONG profileSize = packer->Unpack32();
this->encrypt_key = (PBYTE) MemAllocLocal(16);
memcpy(this->encrypt_key, packer->data() + 4 + profileSize, 16);
DecryptRC4(packer->data()+4, profileSize, this->encrypt_key, 16);
```
実務上の影響:
- 構造全体はしばしばPEの .rdata セクション内に格納されている。
- 抽出は決定的サイズを読み、そのサイズ分のciphertextを読み、その直後に置かれた16byte keyを読み取ってからRC4decryptする。
## 設定抽出ワークフロー(防御者向け)
beacon logicを模倣する抽出ツールを書け:
1) PE内のblobを特定する一般的には.rdata。実用的な方法としては、.rdataをスキャンして妥当と思われる[size|ciphertext|16byte key]のレイアウトを探し、RC4で試すこと。
2) 最初の4バイトを読み → sizeuint32 LE
3) 次のN=sizeバイトを読み → ciphertext。
4) 最後の16バイトを読み → RC4 key。
5) ciphertextをRC4decryptする。その後、平文のprofileを以下のように解析する
- u32/boolean スカラー(上記の通り)
- 長さ接頭辞付き文字列u32長さの後にバイト列末尾にNULが存在することがある
- 配列servers_countの後に、その数だけ[string, u32 port]のペアが続く
事前に抽出したblobで動作する、外部依存なしの最小Python proofofconceptスタンドアロン
```python
import struct
from typing import List, Tuple
def rc4(key: bytes, data: bytes) -> bytes:
S = list(range(256))
j = 0
for i in range(256):
j = (j + S[i] + key[i % len(key)]) & 0xFF
S[i], S[j] = S[j], S[i]
i = j = 0
out = bytearray()
for b in data:
i = (i + 1) & 0xFF
j = (j + S[i]) & 0xFF
S[i], S[j] = S[j], S[i]
K = S[(S[i] + S[j]) & 0xFF]
out.append(b ^ K)
return bytes(out)
class P:
def __init__(self, buf: bytes):
self.b = buf; self.o = 0
def u32(self) -> int:
v = struct.unpack_from('<I', self.b, self.o)[0]; self.o += 4; return v
def u8(self) -> int:
v = self.b[self.o]; self.o += 1; return v
def s(self) -> str:
L = self.u32(); s = self.b[self.o:self.o+L]; self.o += L
return s[:-1].decode('utf-8','replace') if L and s[-1] == 0 else s.decode('utf-8','replace')
def parse_http_cfg(plain: bytes) -> dict:
p = P(plain)
cfg = {}
cfg['agent_type'] = p.u32()
cfg['use_ssl'] = bool(p.u8())
n = p.u32()
cfg['servers'] = []
cfg['ports'] = []
for _ in range(n):
cfg['servers'].append(p.s())
cfg['ports'].append(p.u32())
cfg['http_method'] = p.s()
cfg['uri'] = p.s()
cfg['parameter'] = p.s()
cfg['user_agent'] = p.s()
cfg['http_headers'] = p.s()
cfg['ans_pre_size'] = p.u32()
cfg['ans_size'] = p.u32() + cfg['ans_pre_size']
cfg['kill_date'] = p.u32()
cfg['working_time'] = p.u32()
cfg['sleep_delay'] = p.u32()
cfg['jitter_delay'] = p.u32()
cfg['listener_type'] = 0
cfg['download_chunk_size'] = 0x19000
return cfg
# Usage (when you have [size|ciphertext|key] bytes):
# blob = open('blob.bin','rb').read()
# size = struct.unpack_from('<I', blob, 0)[0]
# ct = blob[4:4+size]
# key = blob[4+size:4+size+16]
# pt = rc4(key, ct)
# cfg = parse_http_cfg(pt)
```
Tips:
- 自動化する際は、PE parser を使用して .rdata を読み、スライディングウィンドウを適用します: 各オフセット o について、size = u32(.rdata[o:o+4]) を試し、ct = .rdata[o+4:o+4+size]、candidate key を次の16バイトとして取得; RC4decrypt を行い、文字列フィールドが UTF8 としてデコードでき、長さが妥当かを確認します。
- 同じ lengthprefixed 規約に従って SMB/TCP プロファイルを解析します。
## ネットワークのフィンガープリンティングとハンティング
HTTP
- 一般的: オペレーターが選択した URI への POST (例: /uri.php, /endpoint/api)
- beacon ID に使われるカスタムヘッダーパラメータ (例: XBeaconId, XAppId)
- Useragent は Firefox 20 や同時期の Chrome ビルドを模したもの
- sleep_delay/jitter_delay を通じてポーリング間隔が可視化される
SMB/TCP
- web egress が制約されているイントラネット C2 向けに SMB namedpipe リスナーが使用される
- TCP ビーコンはプロトコル開始を難読化するため、トラフィックの前に数バイトを付加することがある
## インシデントで観察された Loader と persistence の TTPs
インメモリ PowerShell ローダー
- Base64/XOR ペイロードをダウンロード (InvokeRestMethod / WebClient)
- アンマネージドメモリを確保し、shellcode をコピーして、VirtualProtect を使い保護を 0x40 (PAGE_EXECUTE_READWRITE) に切り替える
- .NET の動的呼び出しで実行: Marshal.GetDelegateForFunctionPointer + delegate.Invoke()
Check these pages for inmemory execution and AMSI/ETW considerations:
{{#ref}}
../../windows-hardening/av-bypass.md
{{#endref}}
観察された persistence メカニズム
- Startup フォルダのショートカット (.lnk) によりログオン時にローダーを再起動
- Registry Run keys (HKCU/HKLM ...\CurrentVersion\Run)、多くは "Updater" のような無害に聞こえる名前で loader.ps1 を起動
- 脆弱なプロセス向けに %APPDATA%\Microsoft\Windows\Templates に msimg32.dll を配置して DLL searchorder hijack を行う
Technique deepdives and checks:
{{#ref}}
../../windows-hardening/windows-local-privilege-escalation/privilege-escalation-with-autorun-binaries.md
{{#endref}}
{{#ref}}
../../windows-hardening/windows-local-privilege-escalation/dll-hijacking/README.md
{{#endref}}
ハンティングのアイデア
- PowerShell での RW→RX への遷移: powershell.exe 内で VirtualProtect を使って PAGE_EXECUTE_READWRITE にする
- 動的呼び出しパターン (GetDelegateForFunctionPointer)
- ユーザーまたは共通の Startup フォルダ内の .lnk
- 不審な Run キー (例: "Updater")、および update.ps1/loader.ps1 のようなローダー名
- %APPDATA%\Microsoft\Windows\Templates にあるユーザー書き込み可能な DLL パスで msimg32.dll が含まれているもの
## OpSec フィールドに関する注意事項
- KillDate: エージェントが自己消滅する時刻のタイムスタンプ
- WorkingTime: 業務活動に溶け込むためにエージェントがアクティブにすべき時間帯
これらのフィールドはクラスタリングに利用したり、観測される静かな期間を説明するために使える。
## YARA と静的手がかり
Unit 42 published basic YARA for beacons (C/C++ and Go) and loader APIhashing constants. Consider complementing with rules that look for the [size|ciphertext|16bytekey] layout near PE .rdata end and the default HTTP profile strings.
## References
- [AdaptixC2: A New Open-Source Framework Leveraged in Real-World Attacks (Unit 42)](https://unit42.paloaltonetworks.com/adaptixc2-post-exploitation-framework/)
- [AdaptixC2 GitHub](https://github.com/Adaptix-Framework/AdaptixC2)
- [Adaptix Framework Docs](https://adaptix-framework.gitbook.io/adaptix-framework)
- [Marshal.GetDelegateForFunctionPointer Microsoft Docs](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.marshal.getdelegateforfunctionpointer)
- [VirtualProtect Microsoft Docs](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualprotect)
- [Memory protection constants Microsoft Docs](https://learn.microsoft.com/en-us/windows/win32/memory/memory-protection-constants)
- [Invoke-RestMethod PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod)
- [MITRE ATT&CK T1547.001 Registry Run Keys/Startup Folder](https://attack.mitre.org/techniques/T1547/001/)
{{#include ../../banners/hacktricks-training.md}}

View File

@ -22,10 +22,10 @@
```bash
sudo apt-get install -y yara
```
#### ルールを準備する
#### ルールの準備
このスクリプトを使って github からすべての yara malware rules をダウンロードして結合してください: [https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9](https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9)\
_**rules**_ ディレクトリを作成して実行してください。これにより、すべての yara rules for malware を含む _**malware_rules.yar**_ というファイルが作成されます。
このスクリプトを使用して github からすべての yara malware rules をダウンロードしてマージしてください: [https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9](https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9)\
_**rules**_ ディレクトリを作成して実行してください。これにより、malware のすべての yara rules を含む _**malware_rules.yar**_ というファイルが作成されます。
```bash
wget https://gist.githubusercontent.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9/raw/4ec711d37f1b428b63bed1f786b26a0654aa2f31/malware_yara_rules.py
mkdir rules
@ -36,9 +36,9 @@ python malware_yara_rules.py
yara -w malware_rules.yar image #Scan 1 file
yara -w malware_rules.yar folder #Scan the whole folder
```
#### YaraGen: malware をチェックしてルールを作成
#### YaraGen: Check for malware and Create rules
バイナリからyara rulesを生成するには、ツール [**YaraGen**](https://github.com/Neo23x0/yarGen) を使用できます。以下のチュートリアルを参照してください: [**Part 1**](https://www.nextron-systems.com/2015/02/16/write-simple-sound-yara-rules/), [**Part 2**](https://www.nextron-systems.com/2015/10/17/how-to-write-simple-but-sound-yara-rules-part-2/), [**Part 3**](https://www.nextron-systems.com/2016/04/15/how-to-write-simple-but-sound-yara-rules-part-3/)
ツール [**YaraGen**](https://github.com/Neo23x0/yarGen) を使って、binary から yara rules を生成できます。次のチュートリアルを参照してください: [**Part 1**](https://www.nextron-systems.com/2015/02/16/write-simple-sound-yara-rules/), [**Part 2**](https://www.nextron-systems.com/2015/10/17/how-to-write-simple-but-sound-yara-rules-part-2/), [**Part 3**](https://www.nextron-systems.com/2016/04/15/how-to-write-simple-but-sound-yara-rules-part-3/)
```bash
python3 yarGen.py --update
python3.exe yarGen.py --excludegood -m ../../mals/
@ -57,26 +57,26 @@ clamscan folderpath #Scan the whole folder
```
### [Capa](https://github.com/mandiant/capa)
**Capa** は実行ファイル: PE, ELF, .NET 内の潜在的に悪意のある **capabilities** を検出します。したがって、Att\&ck tactics のようなものや、次のような疑わしい capabilities を見つけます:
**Capa** は実行ファイルPE、ELF、.NET内の潜在的に悪意のある **capabilities** を検出します。したがって、Att\&ck の戦術や以下のような疑わしい機能を見つけます:
- OutputDebugString エラーをチェックする
- サービスとして実行する
- プロセスを作成する
- check for OutputDebugString error
- run as a service
- create process
入手は [**Github repo**](https://github.com/mandiant/capa) 。
入手は [**Github repo**](https://github.com/mandiant/capa)
### IOCs
IOC は Indicator Of Compromise を意味します。IOC は、潜在的に望ましくないソフトウェアや確認済みの **malware** を特定するための **conditions that identify** の集合です。Blue Teams はこの種の定義を使って、自組織の **systems****networks** 内で **search for this kind of malicious files** を行います。\
これらの定義を共有することは有用です。なぜなら、あるコンピュータ上で malware が確認され、その malware の IOC が作成されれば、他の Blue Teams はそれを使ってより速くその malware を特定できるからです。
IOC は Indicator Of Compromise の略です。IOC は潜在的に望ましくないソフトウェアや確定した **malware** を識別する一連の **conditions that identify** です。Blue Teams はこの種の定義を使って、**systems** や **networks** 内のこの種の悪意あるファイルを **search for this kind of malicious files**ます。\
これらの定義を共有することは非常に有用です。なぜなら、あるコンピュータでマルウェアが特定されそのマルウェア用の IOC が作成されると、他の Blue Teams はそれを使ってマルウェアをより速く特定できるからです。
A tool to create or modify IOCs is [**IOC Editor**](https://www.fireeye.com/services/freeware/ioc-editor.html)**.**\
You can use tools such as [**Redline**](https://www.fireeye.com/services/freeware/redline.html) to **search for defined IOCs in a device**.
IOC を作成または修正するツールには [**IOC Editor**](https://www.fireeye.com/services/freeware/ioc-editor.html)**.** があります。\
[**Redline**](https://www.fireeye.com/services/freeware/redline.html) のようなツールを使って、デバイス内で定義された IOCs を **search for defined IOCs in a device** することができます。
### Loki
[**Loki**](https://github.com/Neo23x0/Loki) は Simple Indicators of Compromise を対象としたスキャナです。\
Detection is based on four detection methods:
[**Loki**](https://github.com/Neo23x0/Loki) は Simple Indicators of Compromise を対象としたスキャナです。\
検出は四つの検出方法に基づいています:
```
1. File Name IOC
Regex match on full file path/name
@ -92,41 +92,41 @@ Compares process connection endpoints with C2 IOCs (new since version v.10)
```
### Linux Malware Detect
[**Linux Malware Detect (LMD)**](https://www.rfxn.com/projects/linux-malware-detect/) は GNU GPLv2 ライセンスで公開された Linux 用の malware scanner で、共有ホスティング環境で直面する脅威を考慮して設計されています。ネットワークエッジの intrusion detection systems から得た threat data を用いて、攻撃で実際に使われている malware を抽出し、検出用のシグネチャを生成します。さらに、threat data は LMD の checkout feature を使ったユーザー提出や malware community resources からも得られます。
[**Linux Malware Detect (LMD)**](https://www.rfxn.com/projects/linux-malware-detect/) は、GNU GPLv2 ライセンスで公開されている Linux 向けの malware scanner で、共有ホスティング環境が直面する脅威を想定して設計されています。ネットワークエッジの侵入検知システムからの脅威データを用いて、実際に攻撃で使用されている malware を抽出し、検出用のシグネチャを生成します。さらに、脅威データは LMD checkout feature を使ったユーザー提出や malware コミュニティのリソースからも得られます。
### rkhunter
[**rkhunter**](http://rkhunter.sourceforge.net) のようなツールは、ファイルシステムをチェックして可能性のある **rootkits** や malware を検出するために使用できます。
Tools like [**rkhunter**](http://rkhunter.sourceforge.net) can be used to check the filesystem for possible **rootkits** and malware.
```bash
sudo ./rkhunter --check -r / -l /tmp/rkhunter.log [--report-warnings-only] [--skip-keypress]
```
### FLOSS
[**FLOSS**](https://github.com/mandiant/flare-floss) は、さまざまな手法を用いて実行可能ファイル内の難読化された文字列を検出しようとするツールです。
[**FLOSS**](https://github.com/mandiant/flare-floss) は、様々な手法を用いて実行ファイル内の obfuscated strings を見つけようとするツールです。
### PEpper
[PEpper ](https://github.com/Th3Hurrican3/PEpper) は実行可能ファイル内部の基本的な項目バイナリデータ、エントロピー、URLs と IPs、いくつかの yara ルール)をチェックします
[PEpper ](https://github.com/Th3Hurrican3/PEpper) は実行ファイル内部の基本的な項目をチェックしますbinary data, entropy, URLs and IPs, some yara rules
### PEstudio
[PEstudio](https://www.winitor.com/download) は Windows の実行可能ファイルについて、インポート、エクスポート、ヘッダーなどの情報を取得できるツールで、virus total をチェックし、潜在的な Att\&ck テクニックを見つけます。
[PEstudio](https://www.winitor.com/download) は Windows executables の情報imports, exports, headersを取得でき、virus total の確認や潜在的な Att\&ck techniques の検出も行います。
### Detect It Easy(DiE)
[**DiE**](https://github.com/horsicq/Detect-It-Easy/) は、ファイルが **暗号化されている** かどうかを検出し、**パッカー** を見つけるツールです。
[**DiE**](https://github.com/horsicq/Detect-It-Easy/) はファイルが **encrypted** かどうかを検出し、**packers** も検出するツールです。
### NeoPI
[**NeoPI** ](https://github.com/CiscoCXSecurity/NeoPI) は、テキスト/スクリプトファイル内の **難読化された** および **暗号化された** コンテンツを検出するために、さまざまな **統計的手法** を用いる Python スクリプトです。NeoPI の目的は、**隠された web shell コードの検出** を支援することです。
[**NeoPI** ](https://github.com/CiscoCXSecurity/NeoPI) は Python スクリプトで、様々な **statistical methods** を使用して text/script files 内の **obfuscated** および **encrypted** コンテンツを検出します。NeoPI の目的は、**detection of hidden web shell code** を支援することです。
### **php-malware-finder**
[**PHP-malware-finder**](https://github.com/nbs-system/php-malware-finder) は **難読化された**/**不審なコード** を検出することに注力しており、また **PHP** 関数を多用する **マルウェア**/webshells を含むファイルも検出します。
[**PHP-malware-finder**](https://github.com/nbs-system/php-malware-finder) は **obfuscated**/**dodgy code** や、**malwares**/webshells でよく使われる **PHP** 関数を使用しているファイルの検出に尽力します。
### Apple Binary Signatures
いくつかの **マルウェアサンプル** をチェックする際は、バイナリの **署名を確認する** ことを常に行ってください。署名した **開発者** が既に **マルウェア** と関連している場合があります。
いくつかの **malware sample** を確認する際は、署名されたバイナリの **check the signature** を常に行ってください。署名した **developer** が既に **related** with **malware.** である可能性があります。
```bash
#Get signer
codesign -vv -d /bin/ls 2>&1 | grep -E "Authority|TeamIdentifier"
@ -137,27 +137,27 @@ codesign --verify --verbose /Applications/Safari.app
#Check if the signature is valid
spctl --assess --verbose /Applications/Safari.app
```
## Detection Techniques
## 検出手法
### File Stacking
### ファイルスタッキング
もしあるフォルダに含まれる **files****ある日付に最後に更新された** と分かっているなら、**web server** 上のすべての **files** の作成日・更新日を **確認** し、いずれかの日付が **疑わしい** 場合はそのファイルを確認してください。
もし特定のフォルダが **last updated on some date** だったことが分かっている場合、そのフォルダが web server の **files** を含んでいるなら、web server 内のすべての **files** の作成日・更新日を **Check** し、日付に **suspicious** な点があればそのファイルを確認してください。
### Baselines
### ベースライン
フォルダ内のファイルが **変更されてはいけない** 場合、フォルダの **original files****hash** を計算して現在のものと **compare** できます。変更されたものは **suspicious** です。
フォルダ内の **files** が本来 **shouldn't have been modified** はずであれば、フォルダ内の **original files****hash** を計算して **current** なものと **compare** します。変更されているものは **suspicious** です。
### Statistical Analysis
### 統計分析
情報が logs に保存されている場合、web server の各ファイルが何回アクセスされたかのような統計を **確認** できます。web shell が最も多くアクセスされているファイルの1つである可能性があります。
情報が logs に保存されている場合、**check statistics like how many times each file of a web server was accessed as a web shell might be one of the most** といった統計を確認できます。
---
### Android in-app native telemetry (no root)
### Android アプリ内ネイティブテレメトリ (no root)
Android では、ターゲットアプリプロセス内の native code に、他の JNI libs が初期化される前に小さな logger library を preload して計測を仕込むことができます。これによりシステム全体のフックや root を必要とせずにネイティブの挙動を早期に可視化できます。一般的なアプローチは SoTap対応する ABI 向けに libsotap.so を APK に入れ、早い段階static initializer や Application.onCreate など)で System.loadLibrary("sotap") を注入し、internal/external パスや Logcat フォールバックからログを収集します。
Android では、他の JNI ライブラリが初期化される前に小さな logger library をプリロードすることで、ターゲットアプリのプロセス内の native code にインストルメントを仕込み、system-wide hooks や root を必要とせずに native の挙動を早期に可視化できます。一般的なアプローチとして SoTap があり: 適切な ABI 向けに libsotap.so を APK に入れ、早い段階で System.loadLibrary("sotap") を挿入(例: static initializer や Application.onCreateし、internal/external paths からログを収集するか Logcat をフォールバックとして利用します。
See the Android native reversing page for setup details and log paths:
セットアップ手順とログパスの詳細は Android native reversing ページを参照してください:
{{#ref}}
../../mobile-pentesting/android-app-pentesting/reversing-native-libraries.md
@ -165,11 +165,11 @@ See the Android native reversing page for setup details and log paths:
---
## Deobfuscating Dynamic Control-Flow (JMP/CALL RAX Dispatchers)
## 難読化された動的制御フローの復号化 (JMP/CALL RAX Dispatchers)
Modern malware families heavily abuse Control-Flow Graph (CFG) obfuscation: instead of a direct jump/call they compute the destination at run-time and execute a `jmp rax` or `call rax`. A small *dispatcher* (typically nine instructions) sets the final target depending on the CPU `ZF`/`CF` flags, completely breaking static CFG recovery.
現代の malware ファミリーは Control-Flow Graph (CFG) の難読化を多用します。直接的な jump/call の代わりに実行時に宛先を計算して `jmp rax``call rax` を実行します。小さな *dispatcher*通常9命令ほどが CPU の `ZF`/`CF` フラグに応じて最終ターゲットを設定し、静的な CFG 復元を完全に破壊します。
The technique showcased by the SLOW#TEMPEST loader can be defeated with a three-step workflow that only relies on IDAPython and the Unicorn CPU emulator.
この手法は SLOW#TEMPEST loader によって示された例のように、IDAPython と Unicorn CPU emulator のみを用いる3ステップのワークフローで対処できます。
### 1. Locate every indirect jump / call
```python
@ -180,7 +180,7 @@ mnem = idc.print_insn_mnem(ea)
if mnem in ("jmp", "call") and idc.print_operand(ea, 0) == "rax":
print(f"[+] Dispatcher found @ {ea:X}")
```
### 2. dispatcher byte-code を抽出する
### 2. ディスパッチャのバイトコードを抽出する
```python
import idc
@ -195,7 +195,7 @@ size = jmp_ea + idc.get_item_size(jmp_ea) - start
code = idc.get_bytes(start, size)
open(f"{start:X}.bin", "wb").write(code)
```
### 3. Unicornで2回エミュレートする
### 3. Unicornでそれを2回エミュレートする
```python
from unicorn import *
from unicorn.x86_const import *
@ -211,9 +211,9 @@ mu.reg_write(UC_X86_REG_RAX, 0)
mu.emu_start(BASE, BASE+len(code))
return mu.reg_read(UC_X86_REG_RAX)
```
Run `run(code,0,0)``run(code,1,1)` を実行して、ブランチの *false**true* ターゲットを取得します。
`run(code,0,0)``run(code,1,1)` を実行して、*false* と *true* の分岐先を取得します。
### 4. 直接の jump / call をパッチで復元する
### 4. 直接ジャンプ/コールをパッチで戻す
```python
import struct, ida_bytes
@ -222,28 +222,37 @@ op = 0xE8 if is_call else 0xE9 # CALL rel32 or JMP rel32
disp = target - (ea + 5) & 0xFFFFFFFF
ida_bytes.patch_bytes(ea, bytes([op]) + struct.pack('<I', disp))
```
パッチ適用後、IDAにその関数を再解析させ、完全なCFGとHex-Raysの出力を復元してください:
パッチ適用後、IDAに関数を再解析させ、フルCFGとHex-Raysの出力を復元させる:
```python
import ida_auto, idaapi
idaapi.reanalyze_function(idc.get_func_attr(ea, idc.FUNCATTR_START))
```
### 5. 間接APIコールにラベルを付ける
`call rax` の実際の宛先が判明したら、IDA にそれを教えることでパラメータ型や変数名が自動的に復元されます:
すべての `call rax` の実際の宛先が判明したら、IDAにそれが何であるかを教えることで、パラメータの型や変数名が自動的に復元されます
```python
idc.set_callee_name(call_ea, resolved_addr, 0) # IDA 8.3+
```
### 実用的な利点
* 実際の CFG を復元 → decompilation が *10* 行から数千行に増加する。
* string-cross-reference & xrefs を可能にし、動作の再構築を容易にする。
* Scripts は再利用可能: 同じ手法で保護された任意の loader に投入するだけでよい
* 実際の CFG を復元する → 逆コンパイルは *10* 行から数千行に増える。
* 文字列のクロスリファレンス & xrefs を有効にし、挙動の再構築を容易にする。
* スクリプトは再利用可能:同じ手法で保護された任意の loader に投入すれば使える。
---
## 参考文献
## AdaptixC2: 設定抽出と TTPs
専用ページを参照:
{{#ref}}
adaptixc2-config-extraction-and-ttps.md
{{#endref}}
## 参考資料
- [Unit42 Evolving Tactics of SLOW#TEMPEST: A Deep Dive Into Advanced Malware Techniques](https://unit42.paloaltonetworks.com/slow-tempest-malware-obfuscation/)
- SoTap: Lightweight in-app JNI (.so) behavior logger [github.com/RezaArbabBot/SoTap](https://github.com/RezaArbabBot/SoTap)
- SoTap: 軽量な in-app JNI (.so) 振る舞いロガー [github.com/RezaArbabBot/SoTap](https://github.com/RezaArbabBot/SoTap)
- [Unit42 AdaptixC2: A New Open-Source Framework Leveraged in Real-World Attacks](https://unit42.paloaltonetworks.com/adaptixc2-post-exploitation-framework/)
{{#include ../../banners/hacktricks-training.md}}