Skip to content

Add Scapy packet/field design skill with UTScapy, session, and payload binding guidance#34

Draft
Copilot wants to merge 3 commits into
masterfrom
copilot/add-study-fields-packet-skill
Draft

Add Scapy packet/field design skill with UTScapy, session, and payload binding guidance#34
Copilot wants to merge 3 commits into
masterfrom
copilot/add-study-fields-packet-skill

Conversation

Copy link
Copy Markdown

Copilot AI commented May 16, 2026

This PR adds a focused skill document that distills how Scapy Packet/Field abstractions are used across layers, and extends it with UTScapy usage so protocol work and regression coverage are documented in one place.

  • What was added

    • New skill file: .github/skills/scapy-packet-fields/SKILL.md
    • Frontmatter metadata (name, description) so the skill is discoverable and purpose-scoped.
  • Packet/Field implementation patterns captured

    • Layer authoring model (Packet subclasses + fields_desc).
    • Field conversion lifecycle (h2i, i2h, i2m, m2i, any2i).
    • Core extension points for protocol correctness:
      • post_build for deferred values (len/checksum/data offset),
      • extract_padding for explicit-length payload separation,
      • payload dispatch and binding guidance across guess_payload_class, bind_layers, bind_bottom_up, and bind_top_down.
    • Expanded specialized field coverage, including a complete scapy.fields catalog grouped by intended usage:
      • base/wrapper and control fields,
      • address/network identity fields,
      • integer and floating/scaled numeric fields,
      • string/bytes, packet/container, and length-coupling fields,
      • bit/flags/enum/time field families,
      • RawVal usage for intentional conversion bypass.
  • Request/response and session behavior guidance added

    • hashret() usage for stable request/response correlation keys.
    • answers(other) usage for protocol-level reply matching.
    • Session reassembly guidance with IPSession, TCPSession, and tcp_reassemble(data, metadata, session) patterns.
  • Payload dispatch patterns expanded

    • Clarifies default payload_guess-based dispatch and fallback behavior.
    • Documents the base-class dispatch pattern using dispatch_hook where a base layer decodes into a concrete sibling/subclass (e.g. Ether/Dot3).
  • Layer usage references included

    • Concrete patterns drawn from:
      • scapy/packet.py
      • scapy/fields.py
      • scapy/layers/inet.py
      • scapy/layers/l2.py
      • scapy/sessions.py
      • doc/scapy/build_dissect.rst
  • UTScapy section added

    • Campaign syntax model (%, +, =, ~, *) and result semantics (last expression truthiness).
    • High-signal CLI options (-t, -k, -K, -n, -c, -f, -R, -N) and intended usage.
    • Workflow guidance for coupling protocol changes with UTScapy regression cases.
class UDP(Packet):
    fields_desc = [
        ShortEnumField("sport", 53, UDP_SERVICES),
        ShortEnumField("dport", 53, UDP_SERVICES),
        ShortField("len", None),
        XShortField("chksum", None),
    ]

    def post_build(self, p, pay):
        p += pay
        if self.len is None:
            p = p[:4] + struct.pack("!H", len(p)) + p[6:]
        return p

- Extensive bindings in `scapy/layers/l2.py` and `scapy/layers/inet.py`
- Custom dispatch in `ICMP.guess_payload_class`

### 5) Use specialized field helpers for protocol correctness
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more information about specialised fields

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a dedicated expansion of specialized fields (length-coupled, bit-packed, conditional/variant typing, container/composition, enum/display helpers, and RawVal) with concrete layer examples in commit 14995ed.

- `UDP.post_build`: len + checksum
- `GRE.post_build`: conditional checksum

### 3) Split payload/padding with `extract_padding` when length is explicit
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add information about hashret and answers and session reassemble

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new section covering hashret, answers, and session reassembly hooks (IPSession, TCPSession, and tcp_reassemble(data, metadata, session)) in commit 14995ed.

Copilot AI changed the title Add Scapy packet/field design skill with UTScapy testing guidance Add Scapy packet/field design skill with UTScapy testing and session guidance May 16, 2026
Copilot AI requested a review from polybassa May 16, 2026 14:54
Copy link
Copy Markdown
Owner

@polybassa polybassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describe guess_payload and the pattern where a layer base class encodes the actual packets.

Add a list of all existing field types and their purpose and intended use.

Describe bind_layers and bind up and buttom

Copy link
Copy Markdown
Author

Copilot AI commented May 16, 2026

Describe guess_payload and the pattern where a layer base class encodes the actual packets.

Add a list of all existing field types and their purpose and intended use. ...

Added guess_payload_class behavior, base-class dispatch_hook concrete-packet pattern, explicit bind_layers/bind_bottom_up/bind_top_down guidance, and a complete scapy.fields field-type catalog with intended usage in commit 161b061. Screenshot: not applicable (documentation-only change, no UI).

Copilot AI changed the title Add Scapy packet/field design skill with UTScapy testing and session guidance Add Scapy packet/field design skill with UTScapy, session, and payload binding guidance May 16, 2026
Copilot AI requested a review from polybassa May 16, 2026 15:09
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.

2 participants