Mausezahn 是一个 网络流量生成与测试工具,主要用于模拟各种网络协议行为、测试网络设备性能、验证安全策略或进行故障排查。它支持从底层链路层(如 Ethernet、VLAN)到高层应用层(如 HTTP、DNS)的协议模拟,常用于网络工程师、安全研究人员和开发人员测试网络环境的健壮性。
核心功能
1. 多协议支持
- 链路层:Ethernet II、802.3 SNAP、VLAN(802.1Q)、STP、CDP 等。
- 网络层:IPv4/IPv6、ICMP、ARP、RIP、OSPF、BGP 等。
- 传输层:TCP、UDP、SCTP。
- 应用层:HTTP、DNS、DHCP、SIP、FTP、Telnet 等。
- 自定义协议:支持构造任意协议字段(如修改 TCP 标志位、IP TTL 等)。
2. 流量生成模式
- 持续发送:以固定速率或随机间隔发送数据包。
- 突发模式:模拟短时间高流量(如 DDoS 攻击测试)。
- 响应式发送:根据接收到的数据包动态生成响应(如 ARP 回复、ICMP Echo)。
3. 高级特性
- 随机化字段:可随机化 MAC/IP/端口等字段,模拟真实流量。
- 负载填充:支持自定义数据内容(如文本、二进制或随机数据)。
- 时间控制:精确控制数据包发送时间(微秒级精度)。
- 多线程/多接口:支持多网卡同时发送流量。
4. 典型应用场景
- 网络设备测试:验证交换机、路由器、防火墙的吞吐量、延迟和丢包率。
- 安全测试:模拟恶意流量(如端口扫描、SYN Flood、DNS 放大攻击)。
- 协议验证:测试自定义协议实现或第三方设备的协议兼容性。
- 故障排查:重现网络问题(如 CRC 错误、MTU 不匹配)。
基本用法
1. 发送 ICMP Echo 请求(Ping)
mausezahn eth0 icmp -A 192.168.1.1 -B 192.168.1.254 -c 10 |
-A
:源 IP。-B
:目标 IP。-c
:发送 10 个包。
2. 发送 UDP 洪水(模拟 DDoS)
mausezahn eth0 udp -A 192.168.1.1 -B 192.168.1.254 -p 53 -D "RANDOM_DATA" -f 1000 -i 0.001 |
-p
:目标端口(DNS 默认 53)。-D
:负载内容(随机数据)。-f
:每秒 1000 包。-i
:包间隔(毫秒)。
3. 构造自定义 TCP 包(修改标志位)
mausezahn eth0 tcp -A 192.168.1.1 -B 192.168.1.254 -S 12345 -D 80 --tcp-flags SYN,ACK |
-S
:源端口。-D
:目标端口。--tcp-flags
:设置 TCP 标志位(如SYN,ACK
)。
4. 模拟 HTTP GET 请求
mausezahn eth0 tcp -A 192.168.1.1 -B 8.8.8.8 -S 54321 -D 80 -T "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" |
-T
:指定 HTTP 请求内容。
与同类工具对比
工具 | 定位 | 优势 |
---|---|---|
Mausezahn | 全协议层流量生成 | 支持底层到高层的协议模拟,灵活性强,适合复杂场景测试。 |
Scapy | 交互式数据包构造 | Python 接口,适合脚本化测试,但性能较低。 |
hping3 | 网络探测与攻击模拟 | 专注 TCP/IP 层攻击(如端口扫描、防火墙绕过),但协议支持较少。 |
iperf3 | 带宽测试 | 专注于 TCP/UDP 吞吐量测试,不支持协议细节构造。 |
注意事项
- 权限要求:需
root
权限(直接操作网卡)。 - 网络影响:高流量测试可能影响生产环境,建议在隔离网络中使用。
- 协议兼容性:部分协议(如 BGP、OSPF)需深入理解协议细节才能有效测试。
- 替代方案:若需更简单的流量生成,可考虑
tcpreplay
(重放 PCAP 文件)或nmap
(端口扫描)。
一、安装前准备
-
安装Git和基础工具
用于从GitHub克隆源码:sudo yum install -y git gcc-c++ make
-
配置国内Yum源(可选)
解决依赖包下载慢的问题,推荐阿里云或清华源:sudo yum install -y wget sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo sudo yum clean all && sudo yum makecache
3. 下载安装包 #git clone https://github.com/uweber/mausezahn.git
二、安装依赖包
Mausezahn编译依赖以下开发库:
sudo yum install -y cmake libpcap-devel libnet-devel libcli-devel
注意:若提示
libcli-devel
找不到,需更换Yum源(如阿里云/清华源)12。
三、源码编译与安装
-
克隆源码仓库
git clone https://github.com/uweber/mausezahn.git cd mausezahn
-
编译安装
执行编译三部曲:cmake . # 生成Makefile ( 注意:cmake 空格 点) make # 编译源码(忽略告警) sudo make install # 安装到系统
若
cmake
失败,检查依赖包是否全部安装成功12。
安装依赖# sudo yum install -y cmake libpcap-devel libnet-devel libcli-devel
cmake . # 生成Makefile
make # 编译源码(忽略告警)
2060 cmake .
2061 make
2064 make install
2065 mz --help
# mz --help
mz: invalid option -- '-'mz/getopts: Option -c requires an argument.Invalid command line parameters!Mausezahn 0.40 - (C) 2007-2010 by Herbert Haas - http://www.perihel.at/sec/mz/
|
| USAGE: mz [options] [interface] keyword | arg_string | hex_string
|
| Short option description (see doc or manpage for more information):
| -h Prints this information.
| -4 IPv4 mode (default)
| -6 IPv6 mode
| -c <count> Send the packet count times (default: 1, infinite: 0).
| -d <delay> Apply delay between transmissions. The delay value can be
| specified in usec (default, no additional unit needed), or in
| msec (e. g. 100m or 100msec), or in seconds (e. g. 100s or 100sec).
| -r Multiplies the specified delay with a random value.
| -p <length> Pad the raw frame to specified length (using random bytes).
| -a <Src_MAC|keyword> Use specified source mac address, no matter what has
| been specified with other arguments. Keywords see below.
| Default is own interface MAC.
| -b <Dst_MAC|keyword> Same with destination mac address.
| Keywords are:
| rand use a random MAC address
| bc use a broadcast MAC address
| own use own interface MAC address (default for source MAC)
| stp use IEEE 802.1d STP multicast address
| cisco use Cisco multicast address as used for CDP, VTP, or PVST+
| -A <Src_IP> Use specified source IP address (default is own interface IP).
| -B <Dst_IP|DNS_name> Send packet to specified destination IP or domain name.
| -P <ASCII Payload> Use the specified ASCII payload.
| -f <filename> Read the ASCII payload from a file.
| -F <filename> Read the hexadecimal payload from a file.
| -Q <[CoS:]vlan> Specify 802.1Q VLAN tag and optional Class of Service. You can
| specify multiple 802.1Q VLAN tags (QinQ...) by separating them
| via a comma or a period (e. g. '5:10,20,2:30').
| -t <packet_type> Specify packet type for autobuild (you don't need to care for
| encapsulations in lower layers. Most packet types allow/require
| additional packet-specific arguments in an arg_string.
| Currently supported types: arp, bpdu, cdp, ip, icmp, udp, tcp,
| dns, rtp, syslog, lldp.
| For context-help use 'help' as arg_string!
| -T <packet_type> Specify packet type for server mode. Currently only rtp is supported.
| Enter -T help or -T rtp help for further information.
| -M <MPLS label> Insert a MPLS label. Enter '-M help' for a syntax description.
| -v|V Verbose and more verbose mode
| -q Quiet mode, i. e. even omit 'important standard short messages'.
| -S Simulation mode: DOES NOT put anything on the wire. This is
| typically combined with one of the verbose modes (v or V).