Esempio n. 1
0
    def printResultsTable(self):
        osDetectPack = sc.IP(dst=self.targIp) / scli.ICMP(
        )  # Crafting packet that will be used to determine target's OS
        osResponse = sc.sr1(osDetectPack, timeout=2,
                            verbose=False)  # Actually sending the packet
        targetOS = ""  # String that will hold what the target OS is
        if osResponse == None:  # Checks if the packet had a response and it's present
            targetOS = colored(
                "Could not identify OS!", "red"
            )  # If not then inform user that the OS could not be known

        # Otherwise, if there is a response and it contains an IP layer try to identify the OS
        elif osResponse.haslayer(scli.IP):
            if osResponse[
                    scli.
                    IP].ttl == 64:  # Unix/Linux/FreeBSD systems use a ttl length of 64
                targetOS = colored(
                    "Unix, Linux, or FreeBSD",
                    "green")  # Inform user that it could be one of the 3
            elif osResponse[
                    scli.
                    IP].ttl == 128:  # Unix/Linux/FreeBSD systems use a ttl length of 128
                targetOS = colored("Windows",
                                   "green")  # Inform user it's Windows
        print(f"Target: {colored(self.targIp, 'green')}")  # Specifies target
        print(f"Detected target Operating System: {targetOS}\n"
              )  # Prints target OS
        # Header of results Table
        print(
            "Port:\t\t\tStatus:\t\t\tService:\n------------------------------------------------------------"
        )
Esempio n. 2
0
def icmp(dst: str, count=1, timeout=2, verbose=False) -> int:
    """
    Send an ICMP ping

    Returns: count of responses
    """
    c = 0
    for i in range(count):
        packet = inet.IP(dst=dst) / inet.ICMP(seq=i)
        if sr1(packet, timeout=2, verbose=verbose) is not None:
            c += 1
    return c
Esempio n. 3
0
    def refreshAll(self, frame=None):
        if not frame:
            frame = self.getFrame()

        ip_packet = inet.IP(frame.payload)

        if frame.payload.payload.name == "NoPayload":
            self.statusBar.showMessage(
                "Sorry, only correct packets can be loaded. Loading L2 and L3...",
                1000)
            if self.tab_L3_Widget.currentIndex() == 0:
                self.fillIPv4(ip_packet)
            else:
                self.fillICMP(ip_packet)
            # TODO: according to current tab place values in ipv4 or icmp DONE

        if frame.payload.payload.name == "TCP":
            tcp_packet = inet.TCP(ip_packet.payload)
            self.tab_L3_Widget.setCurrentIndex(0)
            self.tab_L4_Widget.setCurrentIndex(0)
            self.fillIPv4(ip_packet)
            self.fillTCP(tcp_packet)
        elif frame.payload.payload.name == "UDP":
            udp_packet = inet.UDP(ip_packet.payload)
            self.tab_L3_Widget.setCurrentIndex(0)
            self.tab_L4_Widget.setCurrentIndex(1)
            self.fillIPv4(ip_packet)
            self.fillUDP(udp_packet)
        elif frame.payload.payload.name == "Raw" or frame.payload.payload.name == "Padding":  # ICMP, but need to be carefull if want to use this later
            self.fillICMP(ip_packet)
        elif frame.payload.payload.name == "ICMP":
            self.fillICMP(ip_packet)
            icmp_packet = inet.ICMP(ip_packet.payload)
            self.spinBox_icmp_Type.setValue(
                icmp_packet.getfield_and_val('type')[1])
            self.spinBox_icmp_Code.setValue(
                icmp_packet.getfield_and_val('code')[1])
            # TODO checksum not implemented

        self.fillEther(frame)
 def test_getClientServerProtocolFrom_when_ICMP(self):
     icmp_packet = scapy_layers.ICMP()
     with self.assertRaises(SystemExit) as se:
         protocol = pcap_helper.getClientServerProtocolFrom(icmp_packet)
     self.assertEqual(se.exception.code, 0)
Esempio n. 5
0
        for NICname in addrs.keys():
            self.comboInterfacesBox.addItem(NICname)

    def getFrame(self):
        frame = l2.Ether()
        ipPacket = inet.IP()

        if (srcmac := self.lineEdit_mac_SRCMAC.text()) != ":::::":
            frame.src = srcmac
        if (dstmac := self.lineEdit_mac_DSTMAC.text()) != ":::::":
            frame.dst = dstmac
        if (crc := self.lineEdit_mac_Checksum.text()) != "":
            frame.chksum = int(crc)

        if self.tab_L3_Widget.currentIndex() == 1:  # ICMP
            icmpPacket = inet.ICMP()
            if (ipVer := self.spinBox_icmp_Version.value()) != 0:
                ipPacket.version = ipVer
            if (ihl := self.spinBox_icmp_HeaderLenght.value()) != 0:
                ipPacket.ihl = ihl
            if (tos := self.spinBox_icmp_ToS.value()) != 0:
                ipPacket.tos = tos
            if (len := self.spinBox_icmp_TotalLenght.value()) != 0:
                ipPacket.len = len
            if (id := self.spinBox_icmp_Identifier.value()) != 0:
                ipPacket.id = id
            ipPacket.flags = (int(self.checkBox_icmp_MF.isChecked()) +
                              int(self.checkBox_icmp_DF.isChecked() << 1) +
                              int(self.checkBox_icmp_Res.isChecked() << 2))
            if (frag := self.spinBox_icmp_FragmentOffset.value()) != 0:
                ipPacket.frag = frag