Skip to content

bluetooth: add SDP layers and supporting HCI/L2CAP messages - #5261

Open
Stroumph wants to merge 2 commits into
secdev:masterfrom
Stroumph:bt_sdp
Open

Stroumph wants to merge 2 commits into
secdev:masterfrom
Stroumph:bt_sdp

Conversation

@Stroumph

Copy link
Copy Markdown

Description

Add the Service Discovery Protocol (SDP) layers to scapy.layers.bluetooth:
SDP_Hdr, SDP_DataElement, SDP_Continuation, and the service search /
attribute / search-attribute requests and responses and the error response.

Also add the HCI and L2CAP messages needed to reach an SDP service on a
target: HCI_Cmd_Switch_Role, HCI_Cmd_Read/Write_Simple_Pairing_Mode,
HCI_Event_Role_Change, HCI_Event_Authentication_Complete, and the
L2CAP_ConfSet options (MTU, flush timeout, QoS).

SDP runs over a dynamic L2CAP CID (PSM 0x0001), so no bind_layers is declared
for it.

This work was used for the security analysis presented at SSTIC 2025
(https://www.sstic.org/2025/presentation/300_secondes_chrono__prise_de_contrle_d
un_infodivertissement_automobile__distance/) and published at
https://ieeexplore.ieee.org/document/11632048. The SDP dissection test uses a
response captured from a real target.

Add the Service Discovery Protocol PDUs (SDP_Hdr, the service search,
attribute and search-attribute requests and responses, the error
response, SDP_DataElement and SDP_Continuation).

Add the HCI and L2CAP messages needed to reach an SDP service on a
target: HCI_Cmd_Switch_Role, HCI_Cmd_Read/Write_Simple_Pairing_Mode,
HCI_Event_Role_Change, HCI_Event_Authentication_Complete and the
L2CAP_ConfSet options (MTU, flush timeout, QoS).

Add UTScapy tests for the new layers.

AI-Assisted: no
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.56%. Comparing base (57dd077) to head (3f68b5e).

Files with missing lines Patch % Lines
scapy/layers/bluetooth.py 96.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5261      +/-   ##
==========================================
+ Coverage   80.55%   80.56%   +0.01%     
==========================================
  Files         375      375              
  Lines       98399    98489      +90     
==========================================
+ Hits        79261    79350      +89     
- Misses      19138    19139       +1     
Files with missing lines Coverage Δ
scapy/layers/bluetooth.py 91.04% <96.66%> (+0.39%) ⬆️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

SDP_DataElement dropped text string and URL data when built, as their
length came from `size`, which is only computed at build time. The
`size` field was also always packed on one byte for size_index 6 and
7, since MultipleTypeField only evaluates the second element of a
(cond, cond) tuple when the value is known. `post_build` hid these
issues and misplaced the size for size_index 6 and 7: remove it and let
FieldLenField compute `size`.

Also fix the SDP responses: the service record handle list was never
emitted, and the byte count fields of the attribute responses had a
non-None default, so they were never computed.

Add tests for the null, boolean, integer, UUID, text, URL and sequence
data elements, and for every SDP request and response.

AI-Assisted: No
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.

1 participant