Linux无线网络之Monitor模式及radiotap
Linux无线网络之Monitor模式及radiotap
无线网络接口的Monitor模式(监听模式)和Radiotap是进行无线网络分析与调试的重要工具。
一、Monitor 模式
1. Monitor 模式概念
Monitor mode is a passive-only mode, no packets are transmitted. All incoming packets are handed over to the host computer completely unfiltered. This mode is useful to see what’s going on on the network.
With mac80211, it is possible to have a network device in monitor mode in addition to a regular device, this is useful to observe the network whilst using it. However, not all hardware fully supports this as not all hardware can be configured to show all packets while in one of the other operating modes, monitor mode interfaces always work on a “best effort” basis.
With mac80211, it’s also possible to transmit packets in monitor mode, which is known as packet injection. This is useful for applications that wish to implement MLME work in userspace, for example to support nonstandard MAC extensions of IEEE 802.11.
Monitor 模式(监听模式)是无线网卡的一种特殊工作模式,允许网卡:
- 捕获所有无线流量(包括非目标流量)
- 查看 802.11 帧头信息
- 不关联任何 AP
- 可用于无线网络分析、安全审计等
Monitor模式简单配置
1. 检查网卡是否支持 Monitor 模式
iw list | grep "Supported interface modes" -A 8
输出应包含 monitor
.
2. 设置 Monitor 模式
# 使用iwconfig,需安装 wireless-tools 包
sudo ifconfig wlan0 down
sudo iwconfig wlan0 mode monitor
sudo ifconfig wlan0 up
# 使用iw工具(推荐)
sudo ip link set wlan0 down
sudo iw dev wlan0 set type monitor
sudo ip link set wlan0 up
# 指定信道(如信道6)
sudo iw dev wlan0 set channel 6
3. 验证 Monitor 模式
iw dev wlan0 info
输出应包含 type monitor
二、Radiotap 头部解析
1. Radiotap 简介
Radiotap is a de facto standard for 802.11 frame injection and reception.
Radiotap头部是一种标准格式,用于携带额外的无线帧元信息(如信号强度、噪声水平等),这些信息通常不包含在标准的802.11帧中, 包含在捕获的无线帧前。
当您在Monitor模式下捕获数据时,Wireshark或其他类似的抓包工具会显示Radiotap头部的信息,它主要提供:
- 信号强度(RSSI)
- 噪声水平
- 数据速率
- 信道频率
- 帧标志等信息
2. Radiotap 头部结构
典型 Radiotap 头部包含:
| Header | Present flags | Data fields | ... | 802.11 frame |
3. 解析 Radiotap 数据
使用 Wireshark 或以下工具查看:
# 使用tcpdump查看
sudo tcpdump -i wlan0 -n -e
# 使用radiotap库解析(C语言示例)
#include <radiotap/radiotap.h>
void parse_radiotap(uint8_t *data) {
struct ieee80211_radiotap_header *rtap = (struct ieee80211_radiotap_header *)data;
uint32_t present = rtap->it_present;
// 解析各个字段...
}
三、高级应用
1. 使用 aircrack-ng 套件
# 捕获数据包
sudo airodump-ng wlan0
# 指定信道和BSSID捕获
sudo airodump-ng -c 6 --bssid AP:MAC:ADDR -w output wlan0
2. 数据包注入(需支持注入的网卡)
# 发送deauth帧
sudo aireplay-ng -0 5 -a AP:MAC:ADDR -c CLIENT:MAC wlan0
3. 使用 Scapy 处理无线帧
from scapy.all import *
def packet_handler(pkt):
if pkt.haslayer(Dot11):
if pkt.type == 0 and pkt.subtype == 8: # 管理帧:信标帧
print(f"Beacon frame from: {pkt.addr2}")
sniff(iface="wlan0", prn=packet_handler)
四、常见问题
1. 无法看到 Radiotap 头部
- 确保使用正确的捕获工具:
sudo tcpdump -i wlan0 -y IEEE802_11_RADIO -w capture.pcap
- 检查网卡驱动是否正确报告信息
2. 性能优化
# 增加缓冲区大小
sudo sysctl -w net.core.rmem_max=26214400
sudo sysctl -w net.core.wmem_max=26214400
# 禁用ARP和IPv6
sudo ifconfig wlan0 -arp
echo 1 | sudo tee /proc/sys/net/ipv6/conf/wlan0/disable_ipv6
五、参考
Radiotap 官方文档:
Linux 无线开发文档:
内核相关头文件:
/usr/include/net/ieee80211_radiotap.h
/usr/include/linux/if_ether.h
通过 Monitor 模式和 Radiotap 头部分析,开发者可以深入理解无线通信细节,实现高级无线网络工具和应用程序。