Slapdash Safeguards

にわか仕込みのセキュリティ

Blue Team Labs Online - KeyKey Writeup

🔗 https://blueteamlabs.online/home/investigation/keykey-ada037c293

シナリオ

You have been provided with a suspected piece of malware alongside a network capture. Please investigate utilising the tooling provided and provide the relevant technical analysis for our senior stakeholders.

提供されたArtefactsは l0gg3r(shared library, 19.0 kB)と NetworkLogs.pcapng の2点。


Q1) Which event-based input device file is used by the malware?

まず l0gg3r に対して strings コマンドを実行し、文字列を抽出した。

strings /home/ubuntu/Desktop/Artifacts/l0gg3r

出力の中に以下の文字列を発見した。

/dev/input/event1
Error opening input device

スクリーンショット 2026-06-13 172828

Linuxのevdevインターフェースであるこのデバイスファイルをオープンし、キーボード入力イベントを直接フックしていると判断した。

Answer: /dev/input/event1


To which external server is the malware sending the key logs?)

同じく strings の出力からHTTP通信に関する文字列を確認した。

hostname=%s&status=Initiated
http://ubuntuserverr.com:8080
Initial connection failed: %s
curl_easy_perform() failed: %s

スクリーンショット 2026-06-13 173212

libcurl.so.4 が動的リンクされていることも合わせて確認でき、libcurl 経由でC2サーバーへ通信していると判断した。

スクリーンショット 2026-06-13 173549

Answer: http://ubuntuserverr.com:8080


Q3) What is the location of the key log file?

Q2で示したstrings の出力にログファイルの保存先を示すフォーマット文字列を発見した。

/home/%s/Public/stderr%d.log
Error creating log file

Answer: /home/%s/Public/stderr%d.log


Q4) Which encryption operation is the malware performing on the content before sending it to the attacker-controlled server?

strings の出力に以下の文字列を確認した。

Encrypted file content sent: %s

ファイル内容を何らかの方法で暗号化してから送信していることは読み取れたが、具体的なアルゴリズム名は strings の出力からは判明しなかった。そこでIDAによる静的解析に切り替えた。

IDAのStringsウィンドウ(Shift+F12)で Encrypted file content sent を検索し、X キーでクロスリファレンスを確認したところ、送信処理の直前に encrypt_content という関数が呼ばれていることが判明した。グラフビューで当該関数を開くと、以下のシンプルなループ構造が確認できた。

loc_1612:
    mov    rax, [rbp+var_8]
    cmp    rax, [rbp+var_20]
    jb     short loc_15EF

loc_15EF:
    mov    rdx, [rbp+var_18]
    mov    rax, [rbp+var_8]
    add    rax, rdx
    movzx  edx, byte ptr [rax]
    mov    rcx, [rbp+var_18]
    mov    rax, [rbp+var_8]
    add    rax, rcx
    xor    edx, 35h          ; ← ここでXOR演算
    mov    [rax], dl
    add    [rbp+var_8], 1

スクリーンショット 2026-06-13 174055

各バイトを固定キー 0x35(10進数: 53)でXOR演算しているだけのシンプルなストリーム暗号であることが確定した。

Answer: XOR


Q5) Using Network logs, find out what the secret project name was.

NetworkLogs.pcapng をWiresharkで開き、Statistics → Conversations → TCP でC2サーバー(139.162.45.103:8080)宛の通信を確認したところ、4つの独立したTCPストリームが存在することが分かった。 スクリーンショット 2026-06-20 011947

各ストリームを Follow → HTTP Stream で開き、Raw 形式で表示してPOSTデータ本体(hex文字列)を抽出した。これをCyberChefに投入し、Q4で判明した鍵を用いて以下のレシピで復号した。

From Hex
XOR (Key: 35, Format: Hex)

ストリームから、攻撃者が取得したシェル操作のキーログが復号できた。

スクリーンショット 2026-06-20 012243

sudo apt install gedit
irok
mkdit.r '.project .sunset'
ls

このマルウェアのキーロガーは、印字可能文字はそのまま記録する一方、Backspace・Spaceなどの非印字キーをすべて .(ドット)に置き換えて記録していると考えられる。mkdit.rmkdir のタイプミスとその場での修正の記録と判断した。

m, k, d, i, t  → "mkdit"(誤入力)
.              → Backspace('t' を削除)
r              → 正しい 'r' を入力
結果: "mkdir"

続く '.project .sunset' のドットはSpaceキーの記録と判断し、実際に実行されたコマンドは以下と特定した。

mkdir 'projectsunset'

project sunsetでは不正解であったため、おそらくここで使われているドットはShiftキーの意味であると推測し、Project Sunsetとしたところ、正解した。

Answer: Project Sunset


Q6) Can you find the password that got leaked in the key log file?

別のHTTPストリームをQ5と同様の手順で復号したところ、以下のテキストが得られた。

maintain confidentiality.
the password for admin access of project is 
.super.se........super.secretp.2ssw0rd

the access is given only to you.

スクリーンショット 2026-06-20 010117

Q5の mkdir の解析から、このキーロガーは非印字キー(Backspace・Space・Shift等)をすべて一律で . に変換して記録していることが分かっている。ドット単体ではどの制御キーかを特定できないため、文脈から推測する必要があった。

対象文字列 .super.se........super.secretp.2ssw0rd を以下の思考で復号した。

Step 1: 8連続ドット = Backspace連打

直前に入力された super.se(8キー: s, u, p, e, r, ., s, e)とちょうど同じ数の8連続ドットが続いていた。打ち間違えた分だけ遡って全消去するという典型的な訂正行動と一致するため、Backspaceの連打と判断し、ここまでの入力を全て破棄した。

Step 2: 単発ドット = Shiftキー

打ち直し後の super.secretp.2ssw0rd に含まれる単発ドット2箇所は以下のように解釈した。

  • super + .(Shift) + secretp → 直後の文字が大文字化され Secret となる
  • secretp + .(Shift) + 2ssw0rd → USキーボードで Shift + 2@ に対応する。password の表記として広く使われる p@ssw0rd という慣習とも一致するため、解釈の妥当性が高いと判断した。

復元結果

super + Secret + p@ssw0rd
= superSecretp@ssw0rd

Answer: superSecretp@ssw0rd


まとめ

今回のラボは、Linuxの /dev/input/eventX を直接読み取るシンプルなキーロガーマルウェアの解析だった。キーログの生データに含まれる非印字キー(Backspace・Shift・Space)を文脈から推論して人間の打鍵行動として再構築するプロセスは、単純なデコード作業ではないもので、興味深い内容だった。