ubuntu

Ubuntu Sniffer配置方法

小樊
46
2025-09-22 14:13:45
栏目: 智能运维

Ubuntu Sniffer配置方法
Sniffer(嗅探器)是网络诊断和安全分析的常用工具,Ubuntu系统可通过多种工具实现数据包捕获。以下是具体配置流程及注意事项:

一、常用Sniffer工具选择

Ubuntu下常用的Sniffer工具包括:

二、通用前置准备

  1. 安装基础工具
    无论使用哪种工具,需先安装net-tools(提供ifconfig命令)和iw(管理无线网卡模式):

    sudo apt update
    sudo apt install net-tools iw
    
  2. 查看网络接口
    使用以下命令确认网卡名称(有线为eth0/enpXsY,无线为wlan0/wlpXsY):

    ip link show  # 或 sudo ifconfig(若未安装net-tools)
    
  3. 权限设置
    捕获数据包需root权限。可选择:

    • 临时用sudo运行命令;
    • 将用户加入wireshark组(图形化工具推荐):
      sudo usermod -aG wireshark $(whoami)
      sudo systemctl restart wireshark  # 重启生效
      

三、图形化工具:Wireshark配置

  1. 安装Wireshark
    添加官方PPA以获取最新版本,安装时选择“允许非root用户捕获”:

    sudo add-apt-repository ppa:wireshark-dev/stable
    sudo apt update
    sudo apt install wireshark
    
  2. 启动与接口选择

    • 直接运行wireshark,选择要捕获的接口(如wlp0s20f3);
    • 若无线网卡未显示,需确保已加入wireshark组并重启系统。
  3. 过滤与保存

    • 实时过滤:在过滤栏输入表达式(如tcp.port == 80捕获HTTP流量);
    • 保存数据:点击“File”→“Save As”将捕获的.pcap文件存至本地,便于后续分析。

四、命令行工具:tcpdump配置

  1. 基本捕获
    指定接口捕获数据包(如eth0),-w参数保存至文件:

    sudo tcpdump -i eth0 -w capture.pcap
    
  2. 过滤数据包
    通过表达式缩小范围(常见示例):

    • 捕获特定IP:sudo tcpdump -i eth0 host 192.168.1.100
    • 捕获HTTP流量:sudo tcpdump -i eth0 port 80
    • 捕获TCP SYN包:sudo tcpdump -i eth0 'tcp[tcpflags] & (tcp-syn) != 0'
  3. 读取与分析
    tcpdump读取保存的文件:

    sudo tcpdump -r capture.pcap -nn  # -nn显示IP和端口而非域名
    

五、无线网卡Monitor模式配置(aircrack-ng)

无线嗅探需将网卡设置为Monitor模式(监听所有空口数据包),步骤如下:

  1. 停止干扰进程
    关闭网络管理服务,避免网卡自动切回Managed模式:

    sudo systemctl stop NetworkManager
    sudo systemctl stop wpa_supplicant
    
  2. 设置Monitor模式

    • 查看网卡接口名:iw dev(记下Interface字段,如wlx24ec99d071f6);
    • 关闭网卡:sudo ifconfig wlx24ec99d071f6 down
    • 设置模式:sudo iw dev wlx24ec99d071f6 set type monitor
    • 启动网卡:sudo ifconfig wlx24ec99d071f6 up
  3. 设置信道
    捕获特定信道的流量(如信道52):

    sudo iw dev wlx24ec99d071f6 set channel 52
    
  4. 启动捕获
    用Wireshark或tcpdump捕获wlan0mon(Monitor模式生成的接口):

    sudo wireshark -i wlan0mon
    # 或
    sudo tcpdump -i wlan0mon -w wireless_capture.pcap
    
  5. 退出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
    

六、合法性注意事项

0
看了该问题的人还看了