Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4431 - Allow DHCP Answering Machine to have multiple namesevers #4638

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
7 changes: 5 additions & 2 deletions scapy/layers/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,9 @@ def parse_options(self,
self.network = ltoa(atol(netw) & msk)
self.broadcast = ltoa(atol(self.network) | (0xffffffff & ~msk))
self.gw = gw
self.nameserver = nameserver or gw
realns = nameserver or gw
self.nameserver = tuple(realns.split(",")) if ("," in realns) else (realns,)

if isinstance(pool, str):
pool = Net(pool)
if isinstance(pool, Iterable):
Expand Down Expand Up @@ -677,12 +679,13 @@ def make_reply(self, req):
for op in req[DHCP].options
if isinstance(op, tuple) and op[0] == "message-type"
]

dhcp_options += [
x for x in [
("server_id", self.gw),
("domain", self.domain),
("router", self.gw),
("name_server", self.nameserver),
("name_server", *self.nameserver),
("broadcast_address", self.broadcast),
("subnet_mask", self.netmask),
("renewal_time", self.renewal_time),
Expand Down
11 changes: 11 additions & 0 deletions test/answering_machines.uts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,23 @@ test_am(BOOTP_am,
def check_DHCP_am_reply(packet):
assert DHCP in packet and len(packet[DHCP].options)
assert ("domain", b"localnet") in packet[DHCP].options
assert ('name_server', '192.168.1.1') in packet[DHCP].options

def check_ns_DHCP_am_reply(packet):
assert DHCP in packet and len(packet[DHCP].options)
assert ("domain", b"localnet") in packet[DHCP].options
assert ('name_server', '1.1.1.1', '2.2.2.2') in packet[DHCP].options

test_am(DHCP_am,
Ether()/IP()/UDP()/BOOTP(op=1)/DHCP(options=[('message-type', 'request')]),
check_DHCP_am_reply,
domain="localnet")

test_am(DHCP_am,
Ether()/IP()/UDP()/BOOTP(op=1)/DHCP(options=[('message-type', 'request')]),
check_ns_DHCP_am_reply,
domain="localnet",
nameserver="1.1.1.1,2.2.2.2")

= ARP_am
def check_ARP_am_reply(packet):
Expand Down