Skip to content

DHCP: implement RFC 3396 encoding of long options (fixes #4642)#4950

Open
StrugglingKeyboard wants to merge 1 commit intosecdev:masterfrom
StrugglingKeyboard:master
Open

DHCP: implement RFC 3396 encoding of long options (fixes #4642)#4950
StrugglingKeyboard wants to merge 1 commit intosecdev:masterfrom
StrugglingKeyboard:master

Conversation

@StrugglingKeyboard
Copy link

Description

Implements RFC 3396 (Encoding Long Options in DHCPv4) in Scapy's DHCP layer.
Fixes #4642

Problem

raw(DHCP(options=[('captive-portal', 'a'*256)])) was raising struct.error: ubyte format requires 0 <= number <= 255 because the option length field is encoded as a single unsigned byte, limiting option values to 255 bytes. Similarly, receiving a DHCP packet containing consecutive options with the same code (as produced by RFC 3396 encoding) results in incorrect dissection.

Changes

All changes are in scapy/layers/dhcp.py, within the class DHCPOptionsField:

  • i2m: options with values exceeding 255 bytes are automatically split into consecutive TLV fragments of at most 255 bytes each, all carrying the same option code.
  • _concat_fragments (new): helper method that concatenates consecutive raw fragments with the same option code.
  • m2i: uses _concat_fragments to reassemble fragmented options before interpretation, for both known and unknown option codes.
  • _find_overload (new): scans the raw options buffer for option overload (code 52).
  • getfield: when option overload is present, builds the aggregate option buffer from the options, file and sname fields (RFC 3396 section 5) before passing it to m2i.

Tests

Added a test covering: encoding (split at 256 bytes), decoding (fragment concatenation for typed fields, non-concatenation of non-consecutive fragments, unknown option codes), roundtrip (encode then decode), and option overload (negative and positive cases).

Note: Two pre-existing test failures in test/scapy/layers/dhcp.uts (tests "DHCP - build" and "DHCP - dissection", both on the s5/p5 packet) are unrelated to this change and also fail on the current master branch.

Split DHCP options longer than 255 bytes into multiple consecutive
TLV entries during serialization (i2m), and concatenate consecutive
options with the same code during dissection (m2i), as specified
by RFC 3396.

Also add support for option overload (code 52) in getfield, building
the aggregate option buffer from the options, file and sname fields
as described in RFC 3396 section 5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFE: long DHCPv4 options (RFC 3396)

1 participant