1
0
mirror of https://github.com/nganhkhoa/malware.git synced 2024-06-10 21:32:07 +07:00
mether049-malware/malware-tech_ref_and_memo.md
2020-08-19 00:22:35 +09:00

615 lines
33 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Anti-analysis/detection
- Anti-analysisに利用されるAPIファイル名プロセス名dllレジストリ等の一覧まとめ<br>
[Collection of Anti-Malware Analysis Tricks.(2016-10)](https://forum.tuts4you.com/topic/38931-collection-of-anti-malware-analysis-tricks/)
- マルウェアが使用する各検知回避テクニックについてのまとめ<br>
[Evasion techniques,checkpoint,2020](https://evasions.checkpoint.com/)
- マルウェアの関連技術の解説記事<br>
[The Art Of Malware - Bringing the dead back to life,0x00sec,2020](https://0x00sec.org/t/the-art-of-malware-bringing-the-dead-back-to-life/19599)
- マルウェア関連技術を検索できるサイト<br>
[UNPROTECT PROJECT](https://search.unprotect.it/)<br>
## Injection/Hollowing
- 正規プロセス等のアドレス空間にコードを注入することで検知や分析を妨害するTechnique
- 利用される正規プロセスsvchost.exe,explorer.exe,regsvr32.exe,etc.
- Heaven's Gateと組み合わせて利用される場合あり
**ref:**<br>
- 各種Injection/Hollowingで利用されるAPIの一覧<br>
[HUNTING PROCESS INJECTION BY WINDOWSAPI CALLS (2019-11)](https://malwareanalysis.co/wp-content/uploads/2019/11/Hunting-Process-Injection-by-Windows-API-Calls.pdf)<br>
- 図で分かりやすく説明<br>
[Ten Process Injection Techniques: A Technical Survey Of Common And Trending Process Injection Techniques](https://www.endgame.com/blog/technical-blog/ten-process-injection-techniques-technical-survey-common-and-trending-process)
- プログラムベースの説明<br>
[Code & Process Injection,Red Teaming Experiments](https://ired.team/offensive-security/code-injection-process-injection)
- 環境変数とコマンドラインのProcess Injectionへの活用<br>
[Windows Process Injection: Command Line and Environment Variables](https://modexp.wordpress.com/2020/07/31/wpi-cmdline-envar/)<br>
- 各種Injectionについて<br>
[Windows Process Injection](https://github.com/odzhan/injection)<br>
### Dll Injection
- 正規プロセス探索->プロセスのハンドル取得->メモリ領域確保->悪性DLL注入->実行
- e.g. CreateToolhelp32Snapshot,Process32First,Process32Next->OpenProcess->VirtualAllocEx->WriteProcessMemory->CreateRemoteThread<br>
[07b8f25e7b536f5b6f686c12d04edc37e11347c8acd5c53f98a174723078c365](https://www.virustotal.com/gui/file/07b8f25e7b536f5b6f686c12d04edc37e11347c8acd5c53f98a174723078c365/detection)
### Thread Execution Hijacking
- 正規プロセス,スレッド探索->スレッドのハンドル取得->スレッド停止->メモリ領域確保->悪性コード注入->EIP書き換え->実行
- e.g. CreateToolhelp32Snapshot,Thread32First,Thread32Next->OpenThread->SuspendThread->VirtualAllocEx->WriteProcessMemory->SetThreadContext->ResumeThread
[787cbc8a6d1bc58ea169e51e1ad029a637f22560660cc129ab8a099a745bd50e](https://www.virustotal.com/gui/file/787cbc8a6d1bc58ea169e51e1ad029a637f22560660cc129ab8a099a745bd50e/detection)
### Dll Injection Using SetWindowsHookEx(Hook Injection)
- Hooking:
> Hooking is a technique used to intercept function calls.
- SetWindowsHookEx
> - The first argument is the type of event. The events reflect the range of hook types, and vary from pressing keys on the keyboard (WH_KEYBOARD) to inputs to the mouse (WH_MOUSE), CBT, etc.
> - The second argument is a pointer to the function the malware wants to invoke upon the event execution.
> - The third argument is a module that contains the function.
> - The last argument to this function is the thread with which the hook procedure is to be associated.
- dll読み込み->アドレス解決->正規プロセス,スレッドの探索->フック
- e.g. LoadLibrary->GetProcAddress->CreateToolhelp32Snapshot,Thred32First,Thread32Next->SetWindowsHookEx
[5d6ddb8458ee5ab99f3e7d9a21490ff4e5bc9808e18b9e20b6dc2c5b27927ba1](https://www.virustotal.com/gui/file/5d6ddb8458ee5ab99f3e7d9a21490ff4e5bc9808e18b9e20b6dc2c5b27927ba1/detection)
### Process Hollowing
- 正規プロセス作成(サスペンド状態)->空洞化->メモリ領域確保->悪性コード注入->エントリポイント設定->実行<br>
- e.g. CreateProcess->ZwUnmapViewOfSection(NtUnmapViewOfSection)->VirtualAllocEx->WriteProcessMemory->SetThreadContext->ResumeThread<br>
[eae72d803bf67df22526f50fc7ab84d838efb2865c27aef1a61592b1c520d144](https://www.virustotal.com/gui/file/eae72d803bf67df22526f50fc7ab84d838efb2865c27aef1a61592b1c520d144/detection)
### APC Injection
- プロセス,スレッド探索->アラート状態->ハンドル取得->キューに追加
- e.g. Createtoolhelp32Snapshot,Thread32First,Thread32Next->WaitForMultipleObjectEx->OpenThread->VirtualAllocEx->WriteProcessMemory->QueueUserAPC
- QueueUserAPC
> - First args: a handle to the target thread
> - Second args: a pointer to the function that the malware wants to run
> - Third args: the parameter that is passed to the function pointer.
[f74399cc0be275376dad23151e3d0c2e2a1c966e6db6a695a05ec1a30551c0ad](https://www.virustotal.com/gui/file/f74399cc0be275376dad23151e3d0c2e2a1c966e6db6a695a05ec1a30551c0ad/detection)
### ATOM BOMBING
to do...
### Shell Tray Window Injection
to do...
### Shim Injection
to do...
### IAT and Inline Hooking
to do...
### ALPC Injection
to do...
### REFLECTIVE PE Injection
to do...
### LOCKPOS
to do...
### KERNEL CALLBACK TABLE
to do...
### CLIPBRDWNDCLASS
to do...
### PROGATE
to do...
### EARLY BIRD
to do...
### CONSOLE WINDOW CLASS
to do...
### TOOLTIP Process Injection
to do...
### Persistence
- **Applnit_Dlls**<br>
to do...
- **AppCertDlls**<br>
to do...
- **IFEO**<br>
to do...
## Heaven's Gate
- 0x33セグメントセレクターを使用して32ビットWOW64プロセスで64ビットコードを実行するTechnique<br>
- x86用ユーザモードデバッガでの追跡が難しい<br>
- WinDBG等のカーネルモードデバッガでは追跡することができる<br>
- 名前の由来はVX Heavenに投稿されたから<br>
- 少なくともtrickbot,locky,emotet等では利用されていた<br>
- LinuxにおけるHeaven's Gateについて
- [Unlocking Heaven's Gate on Linux](https://redcanary.com/blog/heavens-gate-technique-on-linux/)<br>
**ref:**<br>
[Knockin on Heavens Gate Dynamic Processor Mode Switching(2012-09)](http://rce.co/knockin-on-heavens-gate-dynamic-processor-mode-switching/)<br>
[The 0x33 Segment Selector (Heavens Gate)](https://www.malwaretech.com/2014/02/the-0x33-segment-selector-heavens-gate.html)<br>
## API obfuscation
[A Museum of API Obfuscation on Win32](https://www.symantec.com/content/en/us/enterprise/media/security_response/whitepapers/a_museum_of_api_obfuscation_on_win32.pdf)<br>
### Using GetProcAddress and GetModulehandleA
- GetProcAddressを利用して呼び出したいAPIのアドレスを動的に解決することでAPIの呼び出し解析を回避する
- GetProcAddressの引数は第一引数に対象dllのハンドルを指定(e.g. GetModuleHandleA("kernel32.dll"))し第二引数にdllから呼び出したいAPI名を指定
```cpp
// Get a handle on kernel32.dll
HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
// Define the prototype of 'OpenProcess' (see https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openprocess)
using OpenProcessPrototype = HANDLE(WINAPI*)(DWORD, BOOL, DWORD);
// Perform the dynamic resolving using GetProcAddress
OpenProcessPrototype OpenProcess = (OpenProcessPrototype)GetProcAddress(kernel32, "OpenProcess");
```
- GetProcAddressやGetModuleWのみインポートすること自体が怪しまれる可能性がある
- ref:
- [Hidden in PEB Sight: Hiding Windows API Imports With a Custom Loader,2020-02](https://blog.christophetd.fr/hiding-windows-api-imports-with-a-customer-loader/)
- [Salted algorithm - part 1,virusbulletin.,2014](https://www.virusbulletin.com/virusbulletin/2014/01/salted-algorithm-part-1)
### Using PEB
- GetProcAddressやGetModulehanleWのアドレスも動的に解決させることができる
- PEB(Process Environmental Block)の[PEB_LDR_DATA](https://docs.microsoft.com/en-us/windows/win32/api/winternl/ns-winternl-peb_ldr_data)構造体や[LDR_DATA_TABLE_ENTRY](https://docs.microsoft.com/en-us/windows/win32/api/winternl/ns-winternl-peb_ldr_data#remarks)構造体のリストを反復処理して目的のDLL名を探しアドレスを取得する
- 目的のDLLのメモリ内のエクスポートテーブルから呼び出す対象のAPIを探しアドレスを取得する
- ref:
- [Hidden in PEB Sight: Hiding Windows API Imports With a Custom Loader,2020-02](https://blog.christophetd.fr/hiding-windows-api-imports-with-a-customer-loader/)
- [Salted algorithm - part 1,virusbulletin.,2014](https://www.virusbulletin.com/virusbulletin/2014/01/salted-algorithm-part-1)
## PowerShell Script obfuscation
- 難読化ツール<br>
[Invoke-Obfuscation](https://github.com/danielbohannon/Invoke-Obfuscation)
- PS内の文字列(Mimikatz,DumpCreds,コメントetc.)の置換のみでVirusTotal上でMimikatzの検知率を0にしたという検証<br>
[How to Bypass Anti-Virus to Run Mimikatz,2017](https://www.blackhillsinfosec.com/bypass-anti-virus-run-mimikatz/)
- Powershell Script内で用いられる難読化技術について
### Case-insensitive
- コマンドレット名や変数名に大文字,小文字を混ぜる
- PowerShellでは区別されない
```
INvOke-eXpReSsiOn
```
### Alias
- コマンドのエイリアスを用いる
- エイリアスの確認方法
```
get-alias # すべてのエイリアスの確認
get-alias iex #iexのエイリアス(Invoke-Expression)の確認
```
- よく利用されるエイリアス
```
iex -> Invoke-Expression
sal -> Set-Alias
```
- エイリアスの設定
```
set-alias <Name> <Value>
sal ping iex
```
### Dot expression and amp expression(Invoke-Expression)
- 文字列で表現されたコマンドレットを実行
```
.("get-alias")
&('gal')
iex("GeT-AliAs")
```
### Combining characters
- 文字や文字列の結合
```
'i'+'ex'
```
### Backticks
- コマンドレットや変数にバッククォートを挿入
```
`i`e`x("`gal `gal")
```
### Split method
- 文字列の分割
```
'bob@alice'-split('@') -> bob alice
'bob@alice' -split '@' -split "i" -> bob al ce
```
### Join method
- リストの結合
```
"bob","alice" -join "@" -> bob@alice
```
### Concatenation operations
- 文字列の並べ替えおよび連結
```
"{1} {0}" -f "Alice","Bob" -> Bob Alice
"{1} {0}" -f "Alice",("{1}{2}{0}" -f "b","B","o") -> Bob Alice
```
### No Space
- 空白の省略
```
"bob","alice"-join"@"
```
### Pipe operator
- パイプによる引数の引き渡し
```
'Write-host 1' | iex
```
### $ENV variable
- 環境変数の値を文字列の作成等に利用
```
.($seLLId[1]+$shEllId[13]+'x') -> .(iex)
&($EnV:cOmSpEc[4,15,25]-JOIN'') -> &(iex)
```
### Encode
- xor
- 文字16進数10進数等で指定可能
```
10-bxor"10" -> 0
"0xa"-bxor10 -> 0
```
- base64
```
[System.Convert]::FromBase64String("Ym9iYWxpY2UK") -> bobalice
```
- zlib
```
New-Object System.IO.Compression.DeflateStream([iO.mEmoRySTream] [sysTEM.ConVert]::frOMBASE64STrING("Ym9iYWxpY2UK"))
```
- unicode
```
[System.Text.Encoding]::Unicode.GetString($unicodeBytes)
```
### Ascii code
- 文字などをasciiコードの10進数16進数表記で示す
```
[string][char[]](0x69,0x65,0x58) -> i e X
```
### Replace method
- 文字や文字列を置換する
```
'i e x'-replace ' ','' -> ieX
```
### %(foreach-object)
- foreach-objectの省略系で%を利用
```
((0x69, 0x65, 0x58) | %{([char] [int] $_)})-jOIN'' -> ieX
```
### Comment out
- コメントアウト
```
<#bobalice#>
```
**ref:**<br>
[Powershell Static Analysis & Emotet results](https://hatching.io/blog/powershell-analysis)<br>
## Living Off The Land(LOL)
- システムに備わっている信頼性の高いツールを悪用する
- LOLで利用される各種Binary(LOLBin), Script(LOLScript), Library(LOLLib)のドキュメント<br>
[LOLBAS](https://lolbas-project.github.io/)<br>[GTFOBins(UNIX ver)](https://gtfobins.github.io/)
- LOLBinsとしてのの条件
> Be a Microsoft-signed file, either native to the OS or downloaded from Microsoft.
- LOLBinsで可能なこと
- UAC Bypass,AppLocker Bypass,Dumping process memory,Credential theft,Log evasion/modification,Persistence,File operations,etc.
- よく利用されるLOLBins
- [Certutil.exe](https://lolbas-project.github.io/lolbas/Binaries/Certutil/)
- エンコードされたバイナリをCertutil.exeでダウンロード->ダウンロードしたバイナリをCertutil.exeでデコード->デコードしたバイナリを,[Forfiles.exe](https://lolbas-project.github.io/lolbas/Binaries/Forfiles/)で実行
- [eventvwr.exe](https://lolbas-project.github.io/lolbas/Binaries/Eventvwr/)
- [Msbuild.exe](https://lolbas-project.github.io/lolbas/Binaries/Msbuild/)
- [Mshta.exe](https://lolbas-project.github.io/lolbas/Binaries/Mshta/)
- [Odbcconf.exe](https://lolbas-project.github.io/lolbas/Binaries/Odbcconf/)
- [Regasm.exe](https://lolbas-project.github.io/lolbas/Binaries/Regasm/) / [Regsvcs.exe](https://lolbas-project.github.io/lolbas/Binaries/Regsvcs/)
- [Regsvr32.exe](https://lolbas-project.github.io/lolbas/Binaries/Regsvr32/)
- [Wmic.exe](https://lolbas-project.github.io/lolbas/Binaries/Wmic/)
- Powershell.exe
- [Bitsadmin.exe](https://lolbas-project.github.io/lolbas/Binaries/Bitsadmin/)
- Wingding.tff
- Disk Cleanup
- werfault.exe
### UAC bypass
- Windows Publisherによってデジタル署名されている且つセキュリティ保護されたフォルダに存在するプログラム(Trusted binary)はUACプロンプトを表示せずにそのプログラムまたはそのプログラムを経由して実行されるプログラムを管理者権限で実行させることができる
- マルウェアはUACなしで自身を管理者権限で実行させたりセキュリティソフトのホワイトリストに自身を追加することができるようになる
- プログラムのデジタル署名の確認はWindows Sysinternalsのsigcheckと呼ばれるプログラムで確認することができる<br>
**ref:**
- UAC Bypassについて<br>
[Bypass User Account Control, MITRE ATT&CK](https://attack.mitre.org/techniques/T1088/)<br>
- UAC Bypassのメソッドの紹介及びそれらを利用するためのツール<br>
[UACMe](https://github.com/hfiref0x/UACME)
- fodhelper.exeによるUAC Bypass[Trickbotによって利用されるとの情報あり](https://www.bleepingcomputer.com/news/security/trickbot-now-uses-a-windows-10-uac-bypass-to-evade-detection/)(2020-01-16)<br>
[First entry: Welcome and fileless UAC bypass](https://winscripting.blog/2017/05/12/first-entry-welcome-and-uac-bypass/)
## DGA
- ドメイン生成アルゴリズム<br>
- 数学的なアルゴリズムを利用して一定間隔ごとに異なる通信先ドメインを生成することにより,ドメイン名での検知を困難にする<br>
- 43ファミリのDGAに対してseedタイプDGAタイプエントロピーTLD等様々な観点から比較<br>
- [A Comprehensive Measurement Study of Domain Generating Malware,USENIX2016](https://www.usenix.org/conference/usenixsecurity16/technical-sessions/presentation/plohmann)
- 各マルウェアにけるDGAのpython実装
- [Domain Generation Algorithms,github](https://github.com/baderj/domain_generation_algorithms)
## Fast Flux
- ドメインに対応するIPアドレスを短い期間で切り替えることにより悪意のあるサイト(マルウェア配布c2フィッシング)を維持させる手法
- IPアドレスにはボットネットが用いられることがある
- 切り替えは平均5分
**ref:**<br>
[Fast Flux networks: What are they and how do they work?](https://www.welivesecurity.com/2017/01/12/fast-flux-networks-work/)
## Convert to c2 Proxy server(Using UPnP)
- 感染したマシンをUPnP機能を用いてc2サーバのプロキシとして利用する
- ルータのLAN側にある感染端末を外部から接続できるようにUPnP機能を用いてポートマッピングする
- フロー:
- 239.255.255.250:1900宛にマルチキャスト通信してUPnP対応ルータを探索(SSDP利用)
- ST(Search Target)に以下のいずれか?を設定
- urnschemas-upnp-orgdeviceInternetGatewayDevice1
- urnschemas-upnp-orgserviceWANIPConnection1
- urnschemas-upnp-orgserviceWANPPPConnection1
- upnprootdevice
- ルータが見つかり応答があった場合応答内容からLocation(UPnPに関する情報(ドキュメント)を取得するためのアドレス(url):IP+port+path)を取得
- LocationにHTTP GETでアクセスして応答(xml)からControlURL(UPnPの設定をするためのIPアドレス)を取得
- ルータの外部IPアドレス(x.x.x.x)取得(SOUP POST),SOUPでGetExternlIPAddress関数利用
- ポートマッピングの設定をルータに送る(SOUP POST)
-
```
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<m:AddPortMapping xmlns:m="urn:schemas-upnp-org:service:WANPPPConnection:1">
<NewRemoteHost>x.x.x.x</NewRemoteHost>
<NewExternalPort>449</NewExternalPort>
<NewProtocol>TCP</NewProtocol>
<NewInternalPort>449</NewInternalPort>
<NewInternalClient>192.168.1.2</NewInternalClient>
<NewEnabled>1</NewEnabled>
<NewPortMappingDescription>Test</NewPortMappingDescription>
<NewLeaseDuration>0</NewLeaseDuration>
</m:AddPortMapping>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
```
- マルウェアの例
- Emotet
- Qakbot
- **ref:**
- [McAfee Discovers Pinkslipbot Exploiting Infected Machines as Control Servers; Releases Free Tool to Detect, Disable Trojan](https://www.mcafee.com/blogs/other-blogs/mcafee-labs/mcafee-discovers-pinkslipbot-exploiting-infected-machines-as-control-servers-releases-free-tool-to-detect-disable-trojan/)
## DNS Tunneling
- C2通信としてDNSを利用しファイアウォールやプロキシでの検出を回避する
- e.g.
- サブドメインにコマンド要求処理結果等のデータを付加してDNSで各種レコードの問い合わせを行うことでC2サーバとの通信を行う
- Aレコードに含まれるIPアドレスの~オクテットの値をc2サーバからのコマンドとして解釈し処理する
- TXTレコードに含まれるテキストをc2サーバからのコマンドとして解釈し処理する
- sample:
- [477296cc6b85584f0706d2384f22b96e,PoisonFrog](https://www.virustotal.com/gui/file/0f20995d431abce885b8bd7dec1013cc1ef7c73886029c67df53101ea330436c/detection)
- [ANY.RUN](https://app.any.run/tasks/3befa970-3e7f-47ee-9c2d-be5494b8e2f2/)
- [6e86c57385d26a59c0df1580454b9967,Glimpse](https://www.virustotal.com/gui/file/eb1ded644e7491f3f60982be9652cbe40b0c819329927ea654cb43e40acb9b1c/detection)
- [ANY.RUN](https://app.any.run/tasks/1009047d-aea0-46c9-918d-6fe6ecb68ee8/)
- ref:
- [Chirp of the PoisonFrog](https://ironnet.com/blog/chirp-of-the-poisonfrog/)
- [Glimpse to Glimpse](https://ironnet.com/blog/a-glimpse-into-glimpse/)
## Using SSL/TLS
- サーバからのコマンドやデータの送受信や追加のモジュールやペイロードのダウンロードの検出を抑制する目的でSSL/TLSを用いることがある
- 特にInformation stealersでは比較的使用される傾向にある(2020/02時点の調査では44%のInformation stealersがSSL/TLSを用いてたらしい)
- 代表的なマルウェア
- Trickbot
- c2,モジュールをダウンロードしたり、機密情報をサーバーに送信したりするのにhttps(443,449)を利用
- IcedID
- c2,構成ファイルをダウンロードにhttpsを利用(httpも利用する)
- Dridex
- c2,ぺイロードモジュールをダウンロードしたり、収集したデータを送信したりするのにhttps(443)を利用
- ref:
- [Nearly a quarter of malware now communicates using TLS](https://news.sophos.com/en-us/2020/02/18/nearly-a-quarter-of-malware-now-communicates-using-tls/?cmp=30728)
## Packing
- 実行形式を保持したまま,実行ファイルを圧縮
- パッキング後のプログラムには展開ルーチン,圧縮されたオリジナルコードが含まれる
- アンパック後のオリジナルコードはProcessHollowing後のプロセス上でのみ実行されるケースも多い
- オリジナルコードを静的解析するためにはアンパッキングが必要
- 特徴
- 特徴的なセクション名
- 可読性のある文字列が少ない
- インポートされているAPIが少ない(オリジナルコードの展開ルーチンに利用するAPI?)
- 展開ルーチンの流れ(簡易)
- オリジナルコードをデコード
- ローダによりオリジナルコードのIATを再構築
- OEPに制御を移しオリジナルコードを実行
- プログラムをパッキングするまでの流れ(簡易)
- PEヘッダから下記のパッキングに必要な各種情報(AddressOfEntryPoint,ImageBase,SectionTable(VirtualAddress,VirtualSize,PointerToRawData,SizeOfRawData),etc.)を取得
- コードセクションのエンコード(PointerToRawからSizeOFRawData分の領域まで)
- 展開ルーチンの追加
- コードセクションの使われていない後方領域(0パディングされた領域)を利用(FileAlignment,VirtualSize,SizeOfRawDataから算出)
- PEヘッダの修正
- 展開ルーチン追加後のVirtualSize
- 展開ルーチンの先頭を示すAddressOfEntryPoint
- コードセクションへの書き込み属性の付与
- 既知のパッカー
- UPX
- [ASProtect](http://www.aspack.com/asprotect32.html)
- Stolen Bytesを利用
- tELock
- Import Redirectionを利用
- Themida
- 商用パッカー
- VMProtect
- 商用パッカー
- [ConfuserEx](https://yck1509.github.io/ConfuserEx/)
- .NET用
- [CypherIT](https://cypherit.org/)
- オンラインサービスでパッキング可能(Packing as a Searvice)
- リバースエンジニアリングを回避するための正規のサービスとして販売されている
- Pakcking以外にもAnti-SandBox,Anti-MemoryScanner,Anti-VirtualMachine,Bypass-UAC,Persistence等の機能をバイナリに付与することができる
- 上記の機能はAutoIT Scriptとしてバイナリに埋め込まれる
- AutoIT Scriptは難読化されている
> - Change the character order.<br>
> - Change the strings to hexadecimal.<br>
> - XOR with constant values.<br>
> - Rotate the strings.<br>
> - Embed many non-ASCII characters.<br>
- ref:
- [DeCypherIT All eggs in one basket](https://research.checkpoint.com/2019/decypherit-all-eggs-in-one-basket/)
## Anti-Unpacking
### Stolen Bytes(Stolen Codes)
- 展開ルーチンのコードの中にオリジナルコードの先頭部分(OEP付近)をあらかじめ含めて実行させることで展開ルーチンによって展開させるオリジナルコードをその先頭部分から後ろのみにし本来のOEPの特定を難化させる(展開されたオリジナルコードの領域監視によるOEP特定の難化)
### Import Redirection
- IATの再構築を妨害
- IATにAPIのアドレスではなくAPIを呼び出すための関数をsetする
- 関数内
- レジスタにAPIのアドレスをsetしてjmpしてAPIを呼び出し
- スタックにAPIのアドレスをsetしてretでAPIを呼び出し
## Mutex
- 本来はプロセス間の同期や排他制御を行うことが目的に作成されるが,マルウェアでは1つのホストで2重で感染させるのを回避する目的で利用されることが多い。
- ロック状態で該当プロセスが終了すると,自動解放される
- Mutexは感染ホスト固有の情報を用いて作成される場合があるため同一マルウェアでもシステムごとに異なるという可能性を考慮する必要がある
- e.g.
- OpenMutex():Mutexの状態確認
- CreateMutex():Mutexの作成
- OpenMutex()で状態を確認→ロック状態の場合自プロセス終了またはロックしているプロセス終了。アンロック状態の場合Mutexの作成。
- ref:
- [How Malware Generates Mutex Names to Evade Detection](https://isc.sans.edu/forums/diary/How+Malware+Generates+Mutex+Names+to+Evade+Detection/19429/#comments)
## Poisoning CRT Library
- C/C++ランタイム(CRT)ライブラリに悪性コードを注入,特定のランタイムライブラリ関数の改ざん
- libcmt.libやmsvcrt.libの上書き不正なライブラリファイルの指定
- 改ざんされた事例があるランタイム関数
- __crtExitProcess():プロセスの終了。管理アプリケーションか否かのチェック
- __scrt_common_main_seh():cランタイムライブラリ_mainCRTStartupのEntryPoint
- _security_init_cookie():セキュリティチェックを行う関数。バッファオバーフローを防ぐ
- _initterm():関数インポートテーブルのエントリー呼び出し
- e.g.
- DllEntryPoint() -> __DllmainCRTStartup() -> _CRT_INIT() -> _initterm() -> __imp_initterm() -> malicious_code()
- コンパイル時点のレベルで改ざんされ,サプライチェーン攻撃として利用されることがある
- e.g. ShadowPad,CCLeaner,Operation ShadowHammer,etc.
- ref:
- [Analyzing C/C++ Runtime Library Code Tampering in Software Supply Chain Attacks](https://blog.trendmicro.com/trendlabs-security-intelligence/analyzing-c-c-runtime-library-code-tampering-in-software-supply-chain-attacks/)
- [Mutex List,Hexacorn,2015](http://hexacorn.com/examples/2015-04-05_easter_bunny_with_a_bag_full_of_events.txt)
# Persistence
## Registry
- 利用されるWin32API
- RegCreateKey
- RegSetValue
- 利用されるレジストリ
```
- HKCU\Software\Microsoft\Windows\CurrentVersion\Run
- HKLM\Software\Microsoft\Windows\CurrentVersion\Run
- HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce
- HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
- HKCU\Software\Microsoft\Windows\CurrentVersion\RunServices
- HKLM\Software\Microsoft\Windows\CurrentVersion\RunServices
- HKCU\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce
- HKLM\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce
- HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run
- HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run
- HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnceEx
- HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\SharedTaskScheduler
```
## Starup Folder
- 現在ログイン中のユーザのみ
```
C:\Users\<Username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
```
- 全ユーザ
```
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
```
# Gathering Information
## Public IP address
- HTTP経由
- webサービスを利用してコンピュータのPublic IP addressを確認する
- サービス一覧とcurlコマンド例
```
curl http://httpbin.org/ip
curl http://ifconfig.me
curl http://whatismyip.akamai.com
curl http://icanhazip.com
curl http://ident.me
curl http://v6.ident.me # IPv6
curl http://checkip.amazonaws.com/
curl http://wgetip.com/
curl http://wtfismyip.com/text
```
- DNS経由
- dnsサービスでコンピュータのPublic IP addressを確認する
- [opendnsがUrsnifで用いられていた](https://unit42.paloaltonetworks.jp/wireshark-tutorial-examining-ursnif-infections/)
- サービス一覧とdigコマンドでの例
```
dig myip.opendns.com @resolver1.opendns.com
dig -t txt o-o.myaddr.l.google.com @8.8.8.8 # TXT record
dig whoami.akamai.net @ns1-1.akamaitech.net
```
# Deleting, Disabling, Exiting, Killing, Terminating
### Delete Volume Shadow
- ランサムウェアはバックアップからの復元を防ぐためにvolume shadowを削除することが多い
```
vssadmin Delete Shadows /All /Quiet
```
### Delete Service
```
sc delete
```
### Kill Task
```
taskkill -f -im
```
### Terminate Process
- TerminateProcess APIの使用
# maldoc
## Obfuscation/Encryption
- ドキュメントテキストスプレッドシートのセルファイルプロパティVBA forms,etc.の中にデータを隠す
- [Variable Object(Word)](https://msdn.microsoft.com/library/office/ff839708.aspx)の利用
- [CallByName関数](https://msdn.microsoft.com/en-us/library/office/gg278760.aspx)の利用
- ファイルの暗号化(Office 2007 or later)
- VelvetSweatshopの利用(Only Excel)
- ExcelでパスワードにVelvetSweatshopを設定して暗号化するとパスワード入力要求を表示せずにファイルを開くことができる
- VelvetSweatshopはExcelのデフォルトパスワードとして利用されておりまずこのパスワードを利用してファイルを復号しようと試みる
- LibreOfficeでも同様
- [VBad](https://github.com/Pepitoh/VBad)の利用
- VBAの難読化・暗号化ツール
- 関数名や文字列の難読化,暗号化
- Tab,Spaceの削除
- 偽の鍵の追加
- 異なるハッシュ値のファイル生成
- VBA Developper Toolからの隠蔽
- ref:
- [Re: Hidden malicious modules in MS VBA (Visual Basic for Applications](https://seclists.org/fulldisclosure/2017/Mar/90)
- [Evolution of Excel 4.0 Macro Weaponization](https://www.lastline.com/labsblog/evolution-of-excel-4-0-macro-weaponization/)
## VBA Stomping
- VBAソースコードを削除しVBAコードをコンパイルしたp-code(中間コード)のみファイル内に残す
- VBAソースコードによる検出を回避する
- VBAのソースコードは0クリアして削除可能
- p-codeに対してはdebuggerでの解析が困難
- [EvilClippy](https://github.com/outflanknl/EvilClippy)
- VBA Stompingを行うツール
- Locked / Unviewable属性の設定や削除も可能保護機能
- ref:
- [VBA Stomping — Advanced Maldoc Techniques](https://medium.com/walmartlabs/vba-stomping-advanced-maldoc-techniques-612c484ab278)
- [Example VBA Stomped Documents Repository](https://github.com/clr2of8/VBAstomp)
- [VBA Project Locked; Project is Unviewable](https://medium.com/walmartlabs/vba-project-locked-project-is-unviewable-4d6a0b2e7cac)
- Execution of another process
- WMI
- PowerShell
- cmd.exe
- VBS,JavaScript(cscript,wscript,mshta)
- shell code
- ref:
- [17JAN2017 - Abusing native Windows functions for shellcode execution](http://ropgadget.com/posts/abusing_win_functions.html)
- [Evasive VBA — Advanced Maldoc Techniques](https://medium.com/walmartlabs/evasive-vba-advanced-maldoc-techniques-1365e9373f80)
# Malicious JavaScript
### Formjacking
- ref:
- [Anatomy of Formjacking Attacks](https://unit42.paloaltonetworks.com/anatomy-of-formjacking-attacks/)
### Malvertising
- ref:
- [Angler EK Malvertising via Hacked Revive Adserve](https://blog.checkpoint.com/2016/04/01/angler-ek-malvertising-via-hacked-revive-adserver/)
# Shell Backdoor
- Web Shell等
- 様々なShell Backdoor(PHP/ASP)<br>
[Shell Backdoor List - PHP / ASP Shell Backdoor List](https://www.kitploit.com/2020/01/shell-backdoor-list-php-asp-shell.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+PentestTools+%28PenTest+Tools%29)
# rootkit
## LKM rootkit
- 動的にカーネルに組み込めるモジュールであるLKM(Loadable Kernel Module)を利用してsys_call_tableの特定のカーネル関数のアドレスを任意の関数のアドレスへと書き換えることで本来とは異なるカーネル関数であるrootkitのカーネル関数等が呼び出せるようになる(システムコールフック)
- sys_call_tableへのアクセスは特権モードが必要であるためLKMを利用される
- rootkitの関数内で本来呼び出されるはずの正規のカーネル関数をあえて呼び出すことで正規の処理を行っているように見せかけることができる
- /proc/modulesからの隠ぺいも可能
- LKMについて
- init_module関数...カーネルにロードする際に最初に実行される関数LKM rootkitではsys_calltableを書き換える処理を記載
- clean_module関数...カーネルからアンロードする際に実行される関数LKM rootkitではsys_call_tableを元に戻す処理を記載
- LKMのロード
```
insmod [lkm_name].ko
```
- LKMのアンロード
```
rmmod [lkm_name].ko
```
**ref:**<br>
- LKMのrootkitへの応用について<br>
[侵入者の不利な情報を隠すLKM rootkitの仕組み,2003](https://www.atmarkit.co.jp/fsecurity/rensai/rootkit03/rootkit02.html)<br>
- LKM rootkit(work on Linux kernels 2.6.32-38 and 4.4.0-22 )<br>
[Linux Rootkit](https://github.com/nurupo/rootkit)
- LKM rootkitその2(developed using linux kernel version 4.4.13)<br>
[rootkit-kernel-module](https://github.com/croemheld/lkm-rootkit)
- LKM rootkitその3(runs on kernel 2.6.x/3.x/4.x)<br>
[Reptile](https://github.com/f0rb1dd3n/Reptile)
- LKM rootkitその4(Tested on Linux kernel [4.19.62] & [4.15.0])<br>
[Sutekh](https://github.com/PinkP4nther/Sutekh)