def build(self): options = [ ('message-type', self.type) ] pxelinux = False for k, v in self.options.items(): if k == 'enabled': continue if not k in DHCPRevOptions: log.warning('Unknown DHCP option: %s' % k) continue if k.startswith('pxelinux'): pxelinux = True if isinstance(v, unicode): v = v.encode('ascii', 'ignore') options.append((k, v)) if pxelinux: options.append(('pxelinux-magic', '\xf1\x00\x75\x7e')) bootp_options = { 'op': 2, 'xid': self.request.packet.xid, 'ciaddr': '0.0.0.0', 'yiaddr': self.offerip, 'chaddr': self.request.packet.chaddr, } if 'tftp_server' in self.options: bootp_options['siaddr'] = self.options['tftp_server'] if 'tftp_filename' in self.options: bootp_options['file'] = self.options['tftp_filename'] for k, v in bootp_options.items(): if isinstance(v, unicode): bootp_options[k] = v.encode('ascii', 'ignore') pkt = BOOTP(**bootp_options)/DHCP(options=options) #pkt.show() return pkt.build()
def build(self): options = [("message-type", self.type)] pxelinux = False for k, v in self.options.items(): if k == "enabled": continue if not k in DHCPRevOptions: log.warning("Unknown DHCP option: %s" % k) continue if k.startswith("pxelinux"): pxelinux = True if isinstance(v, unicode): v = v.encode("ascii", "ignore") options.append((k, v)) if pxelinux: options.append(("pxelinux-magic", "\xf1\x00\x75\x7e")) bootp_options = { "op": 2, "xid": self.request.packet.xid, "ciaddr": self.offerip, "yiaddr": self.offerip, "chaddr": self.request.packet.chaddr, } if "tftp_server" in self.options: bootp_options["siaddr"] = self.options["tftp_server"] if "tftp_filename" in self.options: bootp_options["file"] = self.options["tftp_filename"] for k, v in bootp_options.items(): if isinstance(v, unicode): bootp_options[k] = v.encode("ascii", "ignore") pkt = BOOTP(**bootp_options) / DHCP(options=options) # pkt.show() return pkt.build()
from scapy.all import DHCP, ARP, BOOTP, Ether, UDP, TCP, IP # data link layer ethernet = Ether() ethernet.show() ethernet.dst = "ff:ff:ff:ff:ff:ff" # network layer ip = IP() ip.show() ip.dst = "255.255.255.255" # transport layer udp = UDP() udp.show() udp.sport = 68 udp.dport = 67 # application layer bootp = BOOTP() bootp.show() bootp.flags = 1 dhcp = DHCP() dhcp.show() dhcp.options = [("message-type", "discover"), "end"] packet = ethernet / ip / udp / bootp / dhcp sendp(packet)
# -*- coding: utf-8 -*- # vim:ts=4:sw=4:expandtab # Copyright 2016, 2017 juga (juga at riseup dot net), MIT license. """.""" from scapy.all import BOOTP, DHCP, IP, UDP, Ether # client packets dhcp_discover = ( Ether(src="00:01:02:03:04:05", dst="ff:ff:ff:ff:ff:ff") / IP(src="0.0.0.0", dst="255.255.255.255") / UDP(sport=68, dport=67) / BOOTP(chaddr=[b'\x00\x01\x02\x03\x04\x05'], xid=900000000) / DHCP(options=[('message-type', 'discover'), ("client_id", b'\x00\x01\x02\x03\x04\x05'), ("param_req_list", b"\x01\x03\x06\x0f\x1f\x21\x2b\x2c\x2e\x2f\x79\xf9\xfc" ), 'end'])) dhcp_request = ( Ether(src="00:01:02:03:04:05", dst="ff:ff:ff:ff:ff:ff") / IP(src="0.0.0.0", dst="255.255.255.255") / UDP(sport=68, dport=67) / BOOTP(chaddr=[b'\x00\x01\x02\x03\x04\x05'], xid=900000000) / DHCP(options=[('message-type', 'request'), ("client_id", b'\x00\x01\x02\x03\x04\x05'), ("param_req_list", b"\x01\x03\x06\x0f\x1f\x21\x2b\x2c\x2e\x2f\x79\xf9\xfc"), ("requested_addr", "192.168.1.23"), ("server_id", "192.168.1.1"), 'end'])) dhcp_request_unicast = ( Ether(src="00:01:02:03:04:05", dst="00:0a:0b:0c:0d:0f") /
''' Sample script to send a DHCP discover ''' from scapy.sendrecv import sendp, sniff from scapy.all import DHCP, ARP, BOOTP, Ether, UDP, TCP, IP, srp1 # data link layer ethernet = Ether() ethernet.dst = 'ff:ff:ff:ff:ff:ff' # network layer ip = IP() ip.dst = '192.168.0.255' # transport layer udp = UDP() udp.sport = 68 udp.dport = 67 # application layer bootp = BOOTP() bootp.flags = 1 dhcp = DHCP() dhcp.options = [("message-type", "discover"), "end"] packet = ethernet / ip / udp / bootp / dhcp ans = srp1(packet, iface='wlp4s0') ans.show()
from scapy.all import get_if_raw_hwaddr, Ether, IP, UDP, BOOTP, conf netcard = raw_input("Please enter network card name: ") fam, hw = get_if_raw_hwaddr(netcard) bcast = Ether(dst="ff:ff:ff:ff:ff:ff") ipbcast = IP(src='0.0.0.0', dst='255.255.255.255') dhcpclisrvports = UDP(sport=68, dport=67) dhcpproto = BOOTP(chaddr=hw) pktboot = bcast / ipbcast / dhcpclisrvports / dhcpproto conf.checkIPaddr = False