Skip to content

Instantly share code, notes, and snippets.

@sebschrader
Created February 6, 2019 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebschrader/e031fedea629e4da80ef518a3315cb39 to your computer and use it in GitHub Desktop.
Save sebschrader/e031fedea629e4da80ef518a3315cb39 to your computer and use it in GitHub Desktop.
Spoof DHCP Requests with Scapy
import codecs
from scapy.all import BOOTP, DHCP, Ether, IP, UDP, sendp
def do_request(iface, hwaddr, ip):
pkt = Ether(src=hwaddr, dst="ff:ff:ff:ff:ff:ff")
pkt /= IP(src="0.0.0.0", dst="255.255.255.255")
pkt /= UDP(sport=68, dport=67)
pkt /= BOOTP(
chaddr=codecs.decode(hwaddr.replace(':', ''), 'hex'),
xid=random.randint(0, 2 ** 32),
)
pkt /= DHCP(options=[
("message-type", "request"),
("requested_addr", ip),
("end"),
])
sendp(pkt, iface=iface)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment