Ubuntu Sniffer配置方法
Sniffer(嗅探器)是网络诊断和安全分析的常用工具,Ubuntu系统可通过多种工具实现数据包捕获。以下是具体配置流程及注意事项:
Ubuntu下常用的Sniffer工具包括:
安装基础工具:
无论使用哪种工具,需先安装net-tools(提供ifconfig命令)和iw(管理无线网卡模式):
sudo apt update
sudo apt install net-tools iw
查看网络接口:
使用以下命令确认网卡名称(有线为eth0/enpXsY,无线为wlan0/wlpXsY):
ip link show # 或 sudo ifconfig(若未安装net-tools)
权限设置:
捕获数据包需root权限。可选择:
sudo运行命令;wireshark组(图形化工具推荐):sudo usermod -aG wireshark $(whoami)
sudo systemctl restart wireshark # 重启生效
安装Wireshark:
添加官方PPA以获取最新版本,安装时选择“允许非root用户捕获”:
sudo add-apt-repository ppa:wireshark-dev/stable
sudo apt update
sudo apt install wireshark
启动与接口选择:
wireshark,选择要捕获的接口(如wlp0s20f3);wireshark组并重启系统。过滤与保存:
tcp.port == 80捕获HTTP流量);.pcap文件存至本地,便于后续分析。基本捕获:
指定接口捕获数据包(如eth0),-w参数保存至文件:
sudo tcpdump -i eth0 -w capture.pcap
过滤数据包:
通过表达式缩小范围(常见示例):
sudo tcpdump -i eth0 host 192.168.1.100;sudo tcpdump -i eth0 port 80;sudo tcpdump -i eth0 'tcp[tcpflags] & (tcp-syn) != 0'。读取与分析:
用tcpdump读取保存的文件:
sudo tcpdump -r capture.pcap -nn # -nn显示IP和端口而非域名
无线嗅探需将网卡设置为Monitor模式(监听所有空口数据包),步骤如下:
停止干扰进程:
关闭网络管理服务,避免网卡自动切回Managed模式:
sudo systemctl stop NetworkManager
sudo systemctl stop wpa_supplicant
设置Monitor模式:
iw dev(记下Interface字段,如wlx24ec99d071f6);sudo ifconfig wlx24ec99d071f6 down;sudo iw dev wlx24ec99d071f6 set type monitor;sudo ifconfig wlx24ec99d071f6 up。设置信道:
捕获特定信道的流量(如信道52):
sudo iw dev wlx24ec99d071f6 set channel 52
启动捕获:
用Wireshark或tcpdump捕获wlan0mon(Monitor模式生成的接口):
sudo wireshark -i wlan0mon
# 或
sudo tcpdump -i wlan0mon -w wireless_capture.pcap
退出Monitor模式:
恢复网卡至Managed模式,重启网络服务:
sudo ifconfig wlan0mon down
sudo iw dev wlan0mon set type managed
sudo ifconfig wlan0mon up
sudo systemctl start NetworkManager
sudo systemctl start wpa_supplicant