def get_signal_rssi(pkt):
    if pkt.haslayer(Dot11):
        if pkt.addr2 is not None:
            # check available Radiotap fields
            field, val = pkt.getfield_and_val("present")
            names = [
                field.names[i][0] for i in range(len(field.names))
                if (1 << i) & val != 0
            ]
            # check if we measured signal strength
            if "dBm_AntSignal" in names:
                # decode radiotap header
                fmt = "<"
                rssipos = 0
                for name in names:
                    # some fields consist of more than one value
                    if name == "dBm_AntSignal":
                        # correct for little endian format sign
                        rssipos = len(fmt) - 1
                    fmt = fmt + radiotap_formats[name]
                # unfortunately not all platforms work equally well and on my arm
                # platform notdecoded was padded with a ton of zeros without
                # indicating more fields in pkt.len and/or padding in pkt.pad
                decoded = struct.unpack(fmt,
                                        pkt.notdecoded[:struct.calcsize(fmt)])
                return decoded[rssipos]
    return None
Exemple #2
0
        def sniff_icmp():
            """Sniff for ICMP responses"""

            sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW,
                                    socket.IPPROTO_ICMP)
            sniffer.bind((self.int_address, 0))
            sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

            while True:
                raw_buffer = sniffer.recvfrom(65565)[0]
                ip_header = raw_buffer[0:20]
                iph = struct.unpack('!BBHHHBBH4s4s', ip_header)

                # protocol = iph[6]
                version_ihl = iph[0]
                ihl = version_ihl & 0xF
                iph_length = ihl * 4
                src_addr = socket.inet_ntoa(iph[8])

                buf = raw_buffer[iph_length:iph_length + ctypes.sizeof(ICMP)]
                icmp_header = ICMP(buf)

                if self.proxies is not None and \
                        src_addr in [el.split(":")[0] for el in self.proxies]:
                    if icmp_header.code == 3 and icmp_header.type == 3:
                        scan_data[scan_data[src_addr]["current_ip"]][
                            scan_data[src_addr]["current_port"]] = "Closed"
                    else:
                        scan_data[scan_data[src_addr]["current_ip"]][
                            scan_data[src_addr]["current_port"]] = "Filtered"
Exemple #3
0
 def addfield(self, pkt, s, val):
     ip_msn = struct.unpack('B', s[-1:])[0] & 0xF
     value = struct.pack('B', self.i2m(pkt, val) | ip_msn)
     return s[:-1] + value
Exemple #4
0
 def getfield(self, pkt, s):
     val = self.m2i(pkt, struct.unpack('B', s[0:1])[0])
     return s[1:], val
Exemple #5
0
 def getfield(self, pkt, s):
     val = self.m2i(pkt, struct.unpack(self.fmt, s[0:2])[0] & 0xFFF)
     # Don't consume whole pkt so that Trainer Status Bit field can use low order bits
     return s[1:], val
Exemple #6
0
def ip_to_int(addr):
    return struct.unpack("!I", socket.inet_aton(addr))[0]