Exemplo n.º 1
0
def check_udp(data_3, src_port, dest_port, udp_size, newObject):
    if src_port == 1900 or dest_port == 1900:
        ssdp(data_3, newObject)
    elif src_port in [67, 68] or dest_port in [67, 68]:
        dhcp(data_3, newObject)
    elif src_port in [546, 547] or dest_port in [546, 547]:
        #dhcpv6(data_3,newObject)
        pass
    elif src_port is 53 or dest_port is 53:
        dns(data_3, udp_size, newObject)
        pass
    else:
        #print red_color+"data to this udp port haven't been implemented yet!"+end_color
        pass
Exemplo n.º 2
0
    def parse(self, raw):
        assert isinstance(raw, bytes)
        self.raw = raw
        dlen = len(raw)
        if dlen < udp.MIN_LEN:
            self.msg("(udp parse) warning UDP packet data too short to parse header: data len %u" % dlen)
            return

        (self.srcport, self.dstport, self.len, self.csum) = struct.unpack("!HHHH", raw[: udp.MIN_LEN])

        self.hdr_len = udp.MIN_LEN
        self.payload_len = self.len - self.hdr_len
        self.parsed = True

        if self.len < udp.MIN_LEN:
            self.msg("(udp parse) warning invalid UDP len %u" % self.len)
            return

        if self.dstport == dhcp.SERVER_PORT or self.dstport == dhcp.CLIENT_PORT:
            self.next = dhcp(raw=raw[udp.MIN_LEN :], prev=self)
        elif self.dstport == dns.SERVER_PORT or self.srcport == dns.SERVER_PORT:
            self.next = dns(raw=raw[udp.MIN_LEN :], prev=self)
        elif self.dstport == rip.RIP_PORT or self.srcport == rip.RIP_PORT:
            #               and isinstance(self.prev, _ipv4)
            #               and self.prev.dstip == rip.RIP2_ADDRESS ):
            self.next = rip(raw=raw[udp.MIN_LEN :], prev=self)
        elif dlen < self.len:
            self.msg("(udp parse) warning UDP packet data shorter than UDP len: %u < %u" % (dlen, self.len))
            return
        else:
            self.payload = raw[udp.MIN_LEN :]
Exemplo n.º 3
0
Arquivo: udp.py Projeto: YuShijia/POX
    def parse(self, raw):
        assert isinstance(raw, bytes)
        self.raw = raw
        dlen = len(raw)
        if dlen < udp.MIN_LEN:
            self.msg('(udp parse) warning UDP packet data too short to parse header: data len %u' % dlen)
            return

        (self.srcport, self.dstport, self.len, self.csum) \
            = struct.unpack('!HHHH', raw[:udp.MIN_LEN])

        self.hdr_len = udp.MIN_LEN
        self.payload_len = self.len - self.hdr_len
        self.parsed = True

        if self.len < udp.MIN_LEN:
            self.msg('(udp parse) warning invalid UDP len %u' % self.len)
            return

        if (self.dstport == dhcp.SERVER_PORT
                    or self.dstport == dhcp.CLIENT_PORT):
            self.next = dhcp(raw=raw[udp.MIN_LEN:],prev=self)
        elif (self.dstport == dns.SERVER_PORT
                    or self.srcport == dns.SERVER_PORT):
            self.next = dns(raw=raw[udp.MIN_LEN:],prev=self)
        elif dlen < self.len:
            self.msg('(udp parse) warning UDP packet data shorter than UDP len: %u < %u' % (dlen, self.len))
            return
        else:
            self.payload = raw[udp.MIN_LEN:]
Exemplo n.º 4
0
    def parse(self):
        dlen = len(self.arr)
        if dlen < udp.MIN_LEN:
            self.msg(
                '(udp parse) warning UDP packet data too short to parse header: data len %u'
                % dlen)
            return

        (self.srcport, self.dstport, self.len, self.csum) \
            = struct.unpack('!HHHH', self.arr[:udp.MIN_LEN])

        self.hdr_len = udp.MIN_LEN
        self.payload_len = self.len - self.hdr_len
        self.parsed = True

        if self.len < udp.MIN_LEN:
            self.msg('(udp parse) warning invalid UDP len %u' % self.len)
            return

        if (self.dstport == dhcp.SERVER_PORT
                or self.dstport == dhcp.CLIENT_PORT):
            self.next = dhcp(arr=self.arr[udp.MIN_LEN:], prev=self)
        elif (self.dstport == dns.SERVER_PORT
              or self.srcport == dns.SERVER_PORT):
            self.next = dns(arr=self.arr[udp.MIN_LEN:], prev=self)
        elif dlen < self.len:
            self.msg(
                '(udp parse) warning UDP packet data shorter than UDP len: %u < %u'
                % (dlen, self.len))
            return

        self.payload = self.arr[udp.MIN_LEN:]
Exemplo n.º 5
0
    def parse(self):
        dlen = len(self.arr)
        if dlen < udp.MIN_LEN:
            self.msg('(udp parse) warning UDP packet data too short to parse header: data len %u' % dlen)
            return

        (self.srcport, self.dstport, self.len, self.csum) \
            = struct.unpack('!HHHH', self.arr[:udp.MIN_LEN])

        self.hdr_len = udp.MIN_LEN
        self.payload_len = self.len - self.hdr_len
        self.parsed = True

        if self.len < udp.MIN_LEN:
            self.msg('(udp parse) warning invalid UDP len %u' % self.len)
            return

        if (self.dstport == dhcp.SERVER_PORT 
                    or self.dstport == dhcp.CLIENT_PORT):
            self.next = dhcp(arr=self.arr[udp.MIN_LEN:],prev=self)
        elif (self.dstport == dns.SERVER_PORT 
                    or self.srcport == dns.SERVER_PORT):
            self.next = dns(arr=self.arr[udp.MIN_LEN:],prev=self)
        elif dlen < self.len:
            self.msg('(udp parse) warning UDP packet data shorter than UDP len: %u < %u' % (dlen, self.len))
            return

        self.payload = self.arr[udp.MIN_LEN:]     
Exemplo n.º 6
0
    def parse(self, raw):
        assert isinstance(raw, bytes)
        self.raw = raw
        dlen = len(raw)
        if dlen < udp.MIN_LEN:
            self.msg(
                '(udp parse) warning UDP packet data too short to parse header: data len %u'
                % dlen)
            return

        (self.srcport, self.dstport, self.len, self.csum) \
            = struct.unpack('!HHHH', raw[:udp.MIN_LEN])

        self.hdr_len = udp.MIN_LEN
        self.payload_len = self.len - self.hdr_len
        self.parsed = True

        if self.len < udp.MIN_LEN:
            self.msg('(udp parse) warning invalid UDP len %u' % self.len)
            return

        #TODO: DHCPv6, etc.

        if (self.dstport == dhcp.SERVER_PORT
                or self.dstport == dhcp.CLIENT_PORT):
            self.next = dhcp(raw=raw[udp.MIN_LEN:], prev=self)
        elif (self.dstport == dns.SERVER_PORT
              or self.srcport == dns.SERVER_PORT):
            self.next = dns(raw=raw[udp.MIN_LEN:], prev=self)
        elif (self.dstport == dns.MDNS_PORT or self.srcport == dns.MDNS_PORT):
            self.next = dns(raw=raw[udp.MIN_LEN:], prev=self)
        elif ((self.dstport == rip.RIP_PORT or self.srcport == rip.RIP_PORT)):
            #               and isinstance(self.prev, _ipv4)
            #               and self.prev.dstip == rip.RIP2_ADDRESS ):
            self.next = rip(raw=raw[udp.MIN_LEN:], prev=self)
        elif (self.dstport == vxlan.VXLAN_PORT
              or self.srcport == vxlan.VXLAN_PORT):
            self.next = vxlan(raw=raw[udp.MIN_LEN:], prev=self)
        elif dlen < self.len:
            self.msg(
                '(udp parse) warning UDP packet data shorter than UDP len: %u < %u'
                % (dlen, self.len))
            return
        else:
            self.payload = raw[udp.MIN_LEN:]