[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75G8133DBM63YXS4Y3P27NF":3,"skill-same:01M75G8133DBM63YXS4Y3P27NF":44},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M75G8133DBM63YXS4Y3P27NF","protocol-reverse-engineering",null,"Master network protocol reverse engineering including packet analysis, protocol dissection, and custom protocol documentation. Use when analyzing network traffic, understanding proprietary protocols, or debugging network communication.","RudyCity\u002Fsuperagent","RudyCity","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F82188919?v=4","01M75FP5X8AW8ACBH0SH34WS7M","01M75FP5YAHJK8M1Q52BWXB82K",70,"MIT","https:\u002F\u002Fgithub.com\u002FRudyCity\u002Fsuperagent\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fprotocol-reverse-engineering\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: protocol-reverse-engineering\ndescription: Master network protocol reverse engineering including packet analysis, protocol dissection, and custom protocol documentation. Use when analyzing network traffic, understanding proprietary protocols, or debugging network communication.\n---\n\n# Protocol Reverse Engineering\n\nComprehensive techniques for capturing, analyzing, and documenting network protocols for security research, interoperability, and debugging.\n\n## Traffic Capture\n\n### Wireshark Capture\n\n```bash\n# Capture on specific interface\nwireshark -i eth0 -k\n\n# Capture with filter\nwireshark -i eth0 -k -f \"port 443\"\n\n# Capture to file\ntshark -i eth0 -w capture.pcap\n\n# Ring buffer capture (rotate files)\ntshark -i eth0 -b filesize:100000 -b files:10 -w capture.pcap\n```\n\n### tcpdump Capture\n\n```bash\n# Basic capture\ntcpdump -i eth0 -w capture.pcap\n\n# With filter\ntcpdump -i eth0 port 8080 -w capture.pcap\n\n# Capture specific bytes\ntcpdump -i eth0 -s 0 -w capture.pcap  # Full packet\n\n# Real-time display\ntcpdump -i eth0 -X port 80\n```\n\n### Man-in-the-Middle Capture\n\n```bash\n# mitmproxy for HTTP\u002FHTTPS\nmitmproxy --mode transparent -p 8080\n\n# SSL\u002FTLS interception\nmitmproxy --mode transparent --ssl-insecure\n\n# Dump to file\nmitmdump -w traffic.mitm\n\n# Burp Suite\n# Configure browser proxy to 127.0.0.1:8080\n```\n\n## Protocol Analysis\n\n### Wireshark Analysis\n\n```\n# Display filters\ntcp.port == 8080\nhttp.request.method == \"POST\"\nip.addr == 192.168.1.1\ntcp.flags.syn == 1 && tcp.flags.ack == 0\nframe contains \"password\"\n\n# Following streams\nRight-click > Follow > TCP Stream\nRight-click > Follow > HTTP Stream\n\n# Export objects\nFile > Export Objects > HTTP\n\n# Decryption\nEdit > Preferences > Protocols > TLS\n  - (Pre)-Master-Secret log filename\n  - RSA keys list\n```\n\n### tshark Analysis\n\n```bash\n# Extract specific fields\ntshark -r capture.pcap -T fields -e ip.src -e ip.dst -e tcp.port\n\n# Statistics\ntshark -r capture.pcap -q -z conv,tcp\ntshark -r capture.pcap -q -z endpoints,ip\n\n# Filter and extract\ntshark -r capture.pcap -Y \"http\" -T json > http_traffic.json\n\n# Protocol hierarchy\ntshark -r capture.pcap -q -z io,phs\n```\n\n### Scapy for Custom Analysis\n\n```python\nfrom scapy.all import *\n\n# Read pcap\npackets = rdpcap(\"capture.pcap\")\n\n# Analyze packets\nfor pkt in packets:\n    if pkt.haslayer(TCP):\n        print(f\"Src: {pkt[IP].src}:{pkt[TCP].sport}\")\n        print(f\"Dst: {pkt[IP].dst}:{pkt[TCP].dport}\")\n        if pkt.haslayer(Raw):\n            print(f\"Data: {pkt[Raw].load[:50]}\")\n\n# Filter packets\nhttp_packets = [p for p in packets if p.haslayer(TCP)\n                and (p[TCP].sport == 80 or p[TCP].dport == 80)]\n\n# Create custom packets\npkt = IP(dst=\"target\")\u002FTCP(dport=80)\u002FRaw(load=\"GET \u002F HTTP\u002F1.1\\r\\n\")\nsend(pkt)\n```\n\n## Protocol Identification\n\n### Common Protocol Signatures\n\n```\nHTTP        - \"HTTP\u002F1.\" or \"GET \" or \"POST \" at start\nTLS\u002FSSL     - 0x16 0x03 (record layer)\nDNS         - UDP port 53, specific header format\nSMB         - 0xFF 0x53 0x4D 0x42 (\"SMB\" signature)\nSSH         - \"SSH-2.0\" banner\nFTP         - \"220 \" response, \"USER \" command\nSMTP        - \"220 \" banner, \"EHLO\" command\nMySQL       - 0x00 length prefix, protocol version\nPostgreSQL  - 0x00 0x00 0x00 startup length\nRedis       - \"*\" RESP array prefix\nMongoDB     - BSON documents with specific header\n```\n\n### Protocol Header Patterns\n\n```\n+--------+--------+--------+--------+\n|  Magic number \u002F Signature         |\n+--------+--------+--------+--------+\n|  Version       |  Flags          |\n+--------+--------+--------+--------+\n|  Length        |  Message Type   |\n+--------+--------+--------+--------+\n|  Sequence Number \u002F Session ID     |\n+--------+--------+--------+--------+\n|  Payload...                       |\n+--------+--------+--------+--------+\n```\n\n## Binary Protocol Analysis\n\n### Structure Identification\n\n```python\n# Common patterns in binary protocols\n\n# Length-prefixed message\nstruct Message {\n    uint32_t length;      # Total message length\n    uint16_t msg_type;    # Message type identifier\n    uint8_t  flags;       # Flags\u002Foptions\n    uint8_t  reserved;    # Padding\u002Falignment\n    uint8_t  payload[];   # Variable-length payload\n};\n\n# Type-Length-Value (TLV)\nstruct TLV {\n    uint8_t  type;        # Field type\n    uint16_t length;      # Field length\n    uint8_t  value[];     # Field data\n};\n\n# Fixed header + variable payload\nstruct Packet {\n    uint8_t  magic[4];    # \"ABCD\" signature\n    uint32_t version;\n    uint32_t payload_len;\n    uint32_t checksum;    # CRC32 or similar\n    uint8_t  payload[];\n};\n```\n\n### Python Protocol Parser\n\n```python\nimport struct\nfrom dataclasses import dataclass\n\n@dataclass\nclass MessageHeader:\n    magic: bytes\n    version: int\n    msg_type: int\n    length: int\n\n    @classmethod\n    def from_bytes(cls, data: bytes):\n        magic, version, msg_type, length = struct.unpack(\n            \">4sHHI\", data[:12]\n        )\n        return cls(magic, version, msg_type, length)\n\ndef parse_messages(data: bytes):\n    offset = 0\n    messages = []\n\n    while offset \u003C len(data):\n        header = MessageHeader.from_bytes(data[offset:])\n        payload = data[offset+12:offset+12+header.length]\n        messages.append((header, payload))\n        offset += 12 + header.length\n\n    return messages\n\n# Parse TLV structure\ndef parse_tlv(data: bytes):\n    fields = []\n    offset = 0\n\n    while offset \u003C len(data):\n        field_type = data[offset]\n        length = struct.unpack(\">H\", data[offset+1:offset+3])[0]\n        value = data[offset+3:offset+3+length]\n        fields.append((field_type, value))\n        offset += 3 + length\n\n    return fields\n```\n\n### Hex Dump Analysis\n\n```python\ndef hexdump(data: bytes, width: int = 16):\n    \"\"\"Format binary data as hex dump.\"\"\"\n    lines = []\n    for i in range(0, len(data), width):\n        chunk = data[i:i+width]\n        hex_part = ' '.join(f'{b:02x}' for b in chunk)\n        ascii_part = ''.join(\n            chr(b) if 32 \u003C= b \u003C 127 else '.'\n            for b in chunk\n        )\n        lines.append(f'{i:08x}  {hex_part:\u003C{width*3}}  {ascii_part}')\n    return '\\n'.join(lines)\n\n# Example output:\n# 00000000  48 54 54 50 2f 31 2e 31  20 32 30 30 20 4f 4b 0d  HTTP\u002F1.1 200 OK.\n# 00000010  0a 43 6f 6e 74 65 6e 74  2d 54 79 70 65 3a 20 74  .Content-Type: t\n```\n\n## Encryption Analysis\n\n### Identifying Encryption\n\n```python\n# Entropy analysis - high entropy suggests encryption\u002Fcompression\nimport math\nfrom collections import Counter\n\ndef entropy(data: bytes) -> float:\n    if not data:\n        return 0.0\n    counter = Counter(data)\n    probs = [count \u002F len(data) for count in counter.values()]\n    return -sum(p * math.log2(p) for p in probs)\n\n# Entropy thresholds:\n# \u003C 6.0: Likely plaintext or structured data\n# 6.0-7.5: Possibly compressed\n# > 7.5: Likely encrypted or random\n\n# Common encryption indicators\n# - High, uniform entropy\n# - No obvious structure or patterns\n# - Length often multiple of block size (16 for AES)\n# - Possible IV at start (16 bytes for AES-CBC)\n```\n\n### TLS Analysis\n\n```bash\n# Extract TLS metadata\ntshark -r capture.pcap -Y \"ssl.handshake\" \\\n    -T fields -e ip.src -e ssl.handshake.ciphersuite\n\n# JA3 fingerprinting (client)\ntshark -r capture.pcap -Y \"ssl.handshake.type == 1\" \\\n    -T fields -e ssl.handshake.ja3\n\n# JA3S fingerprinting (server)\ntshark -r capture.pcap -Y \"ssl.handshake.type == 2\" \\\n    -T fields -e ssl.handshake.ja3s\n\n# Certificate extraction\ntshark -r capture.pcap -Y \"ssl.handshake.certificate\" \\\n    -T fields -e x509sat.printableString\n```\n\n### Decryption Approaches\n\n```bash\n# Pre-master secret log (browser)\nexport SSLKEYLOGFILE=\u002Ftmp\u002Fkeys.log\n\n# Configure Wireshark\n# Edit > Preferences > Protocols > TLS\n# (Pre)-Master-Secret log filename: \u002Ftmp\u002Fkeys.log\n\n# Decrypt with private key (if available)\n# Only works for RSA key exchange\n# Edit > Preferences > Protocols > TLS > RSA keys list\n```\n\n## Custom Protocol Documentation\n\n### Protocol Specification Template\n\n```markdown\n# Protocol Name Specification\n\n## Overview\n\nBrief description of protocol purpose and design.\n\n## Transport\n\n- Layer: TCP\u002FUDP\n- Port: XXXX\n- Encryption: TLS 1.2+\n\n## Message Format\n\n### Header (12 bytes)\n\n| Offset | Size | Field   | Description             |\n| ------ | ---- | ------- | ----------------------- |\n| 0      | 4    | Magic   | 0x50524F54 (\"PROT\")     |\n| 4      | 2    | Version | Protocol version (1)    |\n| 6      | 2    | Type    | Message type identifier |\n| 8      | 4    | Length  | Payload length in bytes |\n\n### Message Types\n\n| Type | Name      | Description            |\n| ---- | --------- | ---------------------- |\n| 0x01 | HELLO     | Connection initiation  |\n| 0x02 | HELLO_ACK | Connection accepted    |\n| 0x03 | DATA      | Application data       |\n| 0x04 | CLOSE     | Connection termination |\n\n### Type 0x01: HELLO\n\n| Offset | Size | Field      | Description              |\n| ------ | ---- | ---------- | ------------------------ |\n| 0      | 4    | ClientID   | Unique client identifier |\n| 4      | 2    | Flags      | Connection flags         |\n| 6      | var  | Extensions | TLV-encoded extensions   |\n\n## State Machine\n```\n\n[INIT] --HELLO--> [WAIT_ACK] --HELLO_ACK--> [CONNECTED]\n|\nDATA\u002FDATA\n|\n[CLOSED] \u003C--CLOSE--+\n\n```\n\n## Examples\n### Connection Establishment\n```\n\nClient -> Server: HELLO (ClientID=0x12345678)\nServer -> Client: HELLO_ACK (Status=OK)\nClient -> Server: DATA (payload)\n\n```\n\n```\n\n### Wireshark Dissector (Lua)\n\n```lua\n-- custom_protocol.lua\nlocal proto = Proto(\"custom\", \"Custom Protocol\")\n\n-- Define fields\nlocal f_magic = ProtoField.string(\"custom.magic\", \"Magic\")\nlocal f_version = ProtoField.uint16(\"custom.version\", \"Version\")\nlocal f_type = ProtoField.uint16(\"custom.type\", \"Type\")\nlocal f_length = ProtoField.uint32(\"custom.length\", \"Length\")\nlocal f_payload = ProtoField.bytes(\"custom.payload\", \"Payload\")\n\nproto.fields = { f_magic, f_version, f_type, f_length, f_payload }\n\n-- Message type names\nlocal msg_types = {\n    [0x01] = \"HELLO\",\n    [0x02] = \"HELLO_ACK\",\n    [0x03] = \"DATA\",\n    [0x04] = \"CLOSE\"\n}\n\nfunction proto.dissector(buffer, pinfo, tree)\n    pinfo.cols.protocol = \"CUSTOM\"\n\n    local subtree = tree:add(proto, buffer())\n\n    -- Parse header\n    subtree:add(f_magic, buffer(0, 4))\n    subtree:add(f_version, buffer(4, 2))\n\n    local msg_type = buffer(6, 2):uint()\n    subtree:add(f_type, buffer(6, 2)):append_text(\n        \" (\" .. (msg_types[msg_type] or \"Unknown\") .. \")\"\n    )\n\n    local length = buffer(8, 4):uint()\n    subtree:add(f_length, buffer(8, 4))\n\n    if length > 0 then\n        subtree:add(f_payload, buffer(12, length))\n    end\nend\n\n-- Register for TCP port\nlocal tcp_table = DissectorTable.get(\"tcp.port\")\ntcp_table:add(8888, proto)\n```\n\n## Active Testing\n\n### Fuzzing with Boofuzz\n\n```python\nfrom boofuzz import *\n\ndef main():\n    session = Session(\n        target=Target(\n            connection=TCPSocketConnection(\"target\", 8888)\n        )\n    )\n\n    # Define protocol structure\n    s_initialize(\"HELLO\")\n    s_static(b\"\\x50\\x52\\x4f\\x54\")  # Magic\n    s_word(1, name=\"version\")       # Version\n    s_word(0x01, name=\"type\")       # Type (HELLO)\n    s_size(\"payload\", length=4)     # Length field\n    s_block_start(\"payload\")\n    s_dword(0x12345678, name=\"client_id\")\n    s_word(0, name=\"flags\")\n    s_block_end()\n\n    session.connect(s_get(\"HELLO\"))\n    session.fuzz()\n\nif __name__ == \"__main__\":\n    main()\n```\n\n### Replay and Modification\n\n```python\nfrom scapy.all import *\n\n# Replay captured traffic\npackets = rdpcap(\"capture.pcap\")\nfor pkt in packets:\n    if pkt.haslayer(TCP) and pkt[TCP].dport == 8888:\n        send(pkt)\n\n# Modify and replay\nfor pkt in packets:\n    if pkt.haslayer(Raw):\n        # Modify payload\n        original = pkt[Raw].load\n        modified = original.replace(b\"client\", b\"CLIENT\")\n        pkt[Raw].load = modified\n        # Recalculate checksums\n        del pkt[IP].chksum\n        del pkt[TCP].chksum\n        send(pkt)\n```\n\n## Best Practices\n\n### Analysis Workflow\n\n1. **Capture traffic**: Multiple sessions, different scenarios\n2. **Identify boundaries**: Message start\u002Fend markers\n3. **Map structure**: Fixed header, variable payload\n4. **Identify fields**: Compare multiple samples\n5. **Document format**: Create specification\n6. **Validate understanding**: Implement parser\u002Fgenerator\n7. **Test edge cases**: Fuzzing, boundary conditions\n\n### Common Patterns to Look For\n\n- Magic numbers\u002Fsignatures at message start\n- Version fields for compatibility\n- Length fields (often before variable data)\n- Type\u002Fopcode fields for message identification\n- Sequence numbers for ordering\n- Checksums\u002FCRCs for integrity\n- Timestamps for timing\n- Session\u002Fconnection identifiers\n","# Protocol Reverse Engineering\n\nComprehensive techniques for capturing, analyzing, and documenting network protocols for security research, interoperability, and debugging.\n\n## Traffic Capture\n\n### Wireshark Capture\n\n```bash\n# Capture on specific interface\nwireshark -i eth0 -k\n\n# Capture with filter\nwireshark -i eth0 -k -f \"port 443\"\n\n# Capture to file\ntshark -i eth0 -w capture.pcap\n\n# Ring buffer capture (rotate files)\ntshark -i eth0 -b filesize:100000 -b files:10 -w capture.pcap\n```\n\n### tcpdump Capture\n\n```bash\n# Basic capture\ntcpdump -i eth0 -w capture.pcap\n\n# With filter\ntcpdump -i eth0 port 8080 -w capture.pcap\n\n# Capture specific bytes\ntcpdump -i eth0 -s 0 -w capture.pcap  # Full packet\n\n# Real-time display\ntcpdump -i eth0 -X port 80\n```\n\n### Man-in-the-Middle Capture\n\n```bash\n# mitmproxy for HTTP\u002FHTTPS\nmitmproxy --mode transparent -p 8080\n\n# SSL\u002FTLS interception\nmitmproxy --mode transparent --ssl-insecure\n\n# Dump to file\nmitmdump -w traffic.mitm\n\n# Burp Suite\n# Configure browser proxy to 127.0.0.1:8080\n```\n\n## Protocol Analysis\n\n### Wireshark Analysis\n\n```\n# Display filters\ntcp.port == 8080\nhttp.request.method == \"POST\"\nip.addr == 192.168.1.1\ntcp.flags.syn == 1 && tcp.flags.ack == 0\nframe contains \"password\"\n\n# Following streams\nRight-click > Follow > TCP Stream\nRight-click > Follow > HTTP Stream\n\n# Export objects\nFile > Export Objects > HTTP\n\n# Decryption\nEdit > Preferences > Protocols > TLS\n  - (Pre)-Master-Secret log filename\n  - RSA keys list\n```\n\n### tshark Analysis\n\n```bash\n# Extract specific fields\ntshark -r capture.pcap -T fields -e ip.src -e ip.dst -e tcp.port\n\n# Statistics\ntshark -r capture.pcap -q -z conv,tcp\ntshark -r capture.pcap -q -z endpoints,ip\n\n# Filter and extract\ntshark -r capture.pcap -Y \"http\" -T json > http_traffic.json\n\n# Protocol hierarchy\ntshark -r capture.pcap -q -z io,phs\n```\n\n### Scapy for Custom Analysis\n\n```python\nfrom scapy.all import *\n\n# Read pcap\npackets = rdpcap(\"capture.pcap\")\n\n# Analyze packets\nfor pkt in packets:\n    if pkt.haslayer(TCP):\n        print(f\"Src: {pkt[IP].src}:{pkt[TCP].sport}\")\n        print(f\"Dst: {pkt[IP].dst}:{pkt[TCP].dport}\")\n        if pkt.haslayer(Raw):\n            print(f\"Data: {pkt[Raw].load[:50]}\")\n\n# Filter packets\nhttp_packets = [p for p in packets if p.haslayer(TCP)\n                and (p[TCP].sport == 80 or p[TCP].dport == 80)]\n\n# Create custom packets\npkt = IP(dst=\"target\")\u002FTCP(dport=80)\u002FRaw(load=\"GET \u002F HTTP\u002F1.1\\r\\n\")\nsend(pkt)\n```\n\n## Protocol Identification\n\n### Common Protocol Signatures\n\n```\nHTTP        - \"HTTP\u002F1.\" or \"GET \" or \"POST \" at start\nTLS\u002FSSL     - 0x16 0x03 (record layer)\nDNS         - UDP port 53, specific header format\nSMB         - 0xFF 0x53 0x4D 0x42 (\"SMB\" signature)\nSSH         - \"SSH-2.0\" banner\nFTP         - \"220 \" response, \"USER \" command\nSMTP        - \"220 \" banner, \"EHLO\" command\nMySQL       - 0x00 length prefix, protocol version\nPostgreSQL  - 0x00 0x00 0x00 startup length\nRedis       - \"*\" RESP array prefix\nMongoDB     - BSON documents with specific header\n```\n\n### Protocol Header Patterns\n\n```\n+--------+--------+--------+--------+\n|  Magic number \u002F Signature         |\n+--------+--------+--------+--------+\n|  Version       |  Flags          |\n+--------+--------+--------+--------+\n|  Length        |  Message Type   |\n+--------+--------+--------+--------+\n|  Sequence Number \u002F Session ID     |\n+--------+--------+--------+--------+\n|  Payload...                       |\n+--------+--------+--------+--------+\n```\n\n## Binary Protocol Analysis\n\n### Structure Identification\n\n```python\n# Common patterns in binary protocols\n\n# Length-prefixed message\nstruct Message {\n    uint32_t length;      # Total message length\n    uint16_t msg_type;    # Message type identifier\n    uint8_t  flags;       # Flags\u002Foptions\n    uint8_t  reserved;    # Padding\u002Falignment\n    uint8_t  payload[];   # Variable-length payload\n};\n\n# Type-Length-Value (TLV)\nstruct TLV {\n    uint8_t  type;        # Field type\n    uint16_t length;      # Field length\n    uint8_t  value[];     # Field data\n};\n\n# Fixed header + variable payload\nstruct Packet {\n    uint8_t  magic[4];    # \"ABCD\" signature\n    uint32_t version;\n    uint32_t payload_len;\n    uint32_t checksum;    # CRC32 or similar\n    uint8_t  payload[];\n};\n```\n\n### Python Protocol Parser\n\n```python\nimport struct\nfrom dataclasses import dataclass\n\n@dataclass\nclass MessageHeader:\n    magic: bytes\n    version: int\n    msg_type: int\n    length: int\n\n    @classmethod\n    def from_bytes(cls, data: bytes):\n        magic, version, msg_type, length = struct.unpack(\n            \">4sHHI\", data[:12]\n        )\n        return cls(magic, version, msg_type, length)\n\ndef parse_messages(data: bytes):\n    offset = 0\n    messages = []\n\n    while offset \u003C len(data):\n        header = MessageHeader.from_bytes(data[offset:])\n        payload = data[offset+12:offset+12+header.length]\n        messages.append((header, payload))\n        offset += 12 + header.length\n\n    return messages\n\n# Parse TLV structure\ndef parse_tlv(data: bytes):\n    fields = []\n    offset = 0\n\n    while offset \u003C len(data):\n        field_type = data[offset]\n        length = struct.unpack(\">H\", data[offset+1:offset+3])[0]\n        value = data[offset+3:offset+3+length]\n        fields.append((field_type, value))\n        offset += 3 + length\n\n    return fields\n```\n\n### Hex Dump Analysis\n\n```python\ndef hexdump(data: bytes, width: int = 16):\n    \"\"\"Format binary data as hex dump.\"\"\"\n    lines = []\n    for i in range(0, len(data), width):\n        chunk = data[i:i+width]\n        hex_part = ' '.join(f'{b:02x}' for b in chunk)\n        ascii_part = ''.join(\n            chr(b) if 32 \u003C= b \u003C 127 else '.'\n            for b in chunk\n        )\n        lines.append(f'{i:08x}  {hex_part:\u003C{width*3}}  {ascii_part}')\n    return '\\n'.join(lines)\n\n# Example output:\n# 00000000  48 54 54 50 2f 31 2e 31  20 32 30 30 20 4f 4b 0d  HTTP\u002F1.1 200 OK.\n# 00000010  0a 43 6f 6e 74 65 6e 74  2d 54 79 70 65 3a 20 74  .Content-Type: t\n```\n\n## Encryption Analysis\n\n### Identifying Encryption\n\n```python\n# Entropy analysis - high entropy suggests encryption\u002Fcompression\nimport math\nfrom collections import Counter\n\ndef entropy(data: bytes) -> float:\n    if not data:\n        return 0.0\n    counter = Counter(data)\n    probs = [count \u002F len(data) for count in counter.values()]\n    return -sum(p * math.log2(p) for p in probs)\n\n# Entropy thresholds:\n# \u003C 6.0: Likely plaintext or structured data\n# 6.0-7.5: Possibly compressed\n# > 7.5: Likely encrypted or random\n\n# Common encryption indicators\n# - High, uniform entropy\n# - No obvious structure or patterns\n# - Length often multiple of block size (16 for AES)\n# - Possible IV at start (16 bytes for AES-CBC)\n```\n\n### TLS Analysis\n\n```bash\n# Extract TLS metadata\ntshark -r capture.pcap -Y \"ssl.handshake\" \\\n    -T fields -e ip.src -e ssl.handshake.ciphersuite\n\n# JA3 fingerprinting (client)\ntshark -r capture.pcap -Y \"ssl.handshake.type == 1\" \\\n    -T fields -e ssl.handshake.ja3\n\n# JA3S fingerprinting (server)\ntshark -r capture.pcap -Y \"ssl.handshake.type == 2\" \\\n    -T fields -e ssl.handshake.ja3s\n\n# Certificate extraction\ntshark -r capture.pcap -Y \"ssl.handshake.certificate\" \\\n    -T fields -e x509sat.printableString\n```\n\n### Decryption Approaches\n\n```bash\n# Pre-master secret log (browser)\nexport SSLKEYLOGFILE=\u002Ftmp\u002Fkeys.log\n\n# Configure Wireshark\n# Edit > Preferences > Protocols > TLS\n# (Pre)-Master-Secret log filename: \u002Ftmp\u002Fkeys.log\n\n# Decrypt with private key (if available)\n# Only works for RSA key exchange\n# Edit > Preferences > Protocols > TLS > RSA keys list\n```\n\n## Custom Protocol Documentation\n\n### Protocol Specification Template\n\n```markdown\n# Protocol Name Specification\n\n## Overview\n\nBrief description of protocol purpose and design.\n\n## Transport\n\n- Layer: TCP\u002FUDP\n- Port: XXXX\n- Encryption: TLS 1.2+\n\n## Message Format\n\n### Header (12 bytes)\n\n| Offset | Size | Field   | Description             |\n| ------ | ---- | ------- | ----------------------- |\n| 0      | 4    | Magic   | 0x50524F54 (\"PROT\")     |\n| 4      | 2    | Version | Protocol version (1)    |\n| 6      | 2    | Type    | Message type identifier |\n| 8      | 4    | Length  | Payload length in bytes |\n\n### Message Types\n\n| Type | Name      | Description            |\n| ---- | --------- | ---------------------- |\n| 0x01 | HELLO     | Connection initiation  |\n| 0x02 | HELLO_ACK | Connection accepted    |\n| 0x03 | DATA      | Application data       |\n| 0x04 | CLOSE     | Connection termination |\n\n### Type 0x01: HELLO\n\n| Offset | Size | Field      | Description              |\n| ------ | ---- | ---------- | ------------------------ |\n| 0      | 4    | ClientID   | Unique client identifier |\n| 4      | 2    | Flags      | Connection flags         |\n| 6      | var  | Extensions | TLV-encoded extensions   |\n\n## State Machine\n```\n\n[INIT] --HELLO--> [WAIT_ACK] --HELLO_ACK--> [CONNECTED]\n|\nDATA\u002FDATA\n|\n[CLOSED] \u003C--CLOSE--+\n\n```\n\n## Examples\n### Connection Establishment\n```\n\nClient -> Server: HELLO (ClientID=0x12345678)\nServer -> Client: HELLO_ACK (Status=OK)\nClient -> Server: DATA (payload)\n\n```\n\n```\n\n### Wireshark Dissector (Lua)\n\n```lua\n-- custom_protocol.lua\nlocal proto = Proto(\"custom\", \"Custom Protocol\")\n\n-- Define fields\nlocal f_magic = ProtoField.string(\"custom.magic\", \"Magic\")\nlocal f_version = ProtoField.uint16(\"custom.version\", \"Version\")\nlocal f_type = ProtoField.uint16(\"custom.type\", \"Type\")\nlocal f_length = ProtoField.uint32(\"custom.length\", \"Length\")\nlocal f_payload = ProtoField.bytes(\"custom.payload\", \"Payload\")\n\nproto.fields = { f_magic, f_version, f_type, f_length, f_payload }\n\n-- Message type names\nlocal msg_types = {\n    [0x01] = \"HELLO\",\n    [0x02] = \"HELLO_ACK\",\n    [0x03] = \"DATA\",\n    [0x04] = \"CLOSE\"\n}\n\nfunction proto.dissector(buffer, pinfo, tree)\n    pinfo.cols.protocol = \"CUSTOM\"\n\n    local subtree = tree:add(proto, buffer())\n\n    -- Parse header\n    subtree:add(f_magic, buffer(0, 4))\n    subtree:add(f_version, buffer(4, 2))\n\n    local msg_type = buffer(6, 2):uint()\n    subtree:add(f_type, buffer(6, 2)):append_text(\n        \" (\" .. (msg_types[msg_type] or \"Unknown\") .. \")\"\n    )\n\n    local length = buffer(8, 4):uint()\n    subtree:add(f_length, buffer(8, 4))\n\n    if length > 0 then\n        subtree:add(f_payload, buffer(12, length))\n    end\nend\n\n-- Register for TCP port\nlocal tcp_table = DissectorTable.get(\"tcp.port\")\ntcp_table:add(8888, proto)\n```\n\n## Active Testing\n\n### Fuzzing with Boofuzz\n\n```python\nfrom boofuzz import *\n\ndef main():\n    session = Session(\n        target=Target(\n            connection=TCPSocketConnection(\"target\", 8888)\n        )\n    )\n\n    # Define protocol structure\n    s_initialize(\"HELLO\")\n    s_static(b\"\\x50\\x52\\x4f\\x54\")  # Magic\n    s_word(1, name=\"version\")       # Version\n    s_word(0x01, name=\"type\")       # Type (HELLO)\n    s_size(\"payload\", length=4)     # Length field\n    s_block_start(\"payload\")\n    s_dword(0x12345678, name=\"client_id\")\n    s_word(0, name=\"flags\")\n    s_block_end()\n\n    session.connect(s_get(\"HELLO\"))\n    session.fuzz()\n\nif __name__ == \"__main__\":\n    main()\n```\n\n### Replay and Modification\n\n```python\nfrom scapy.all import *\n\n# Replay captured traffic\npackets = rdpcap(\"capture.pcap\")\nfor pkt in packets:\n    if pkt.haslayer(TCP) and pkt[TCP].dport == 8888:\n        send(pkt)\n\n# Modify and replay\nfor pkt in packets:\n    if pkt.haslayer(Raw):\n        # Modify payload\n        original = pkt[Raw].load\n        modified = original.replace(b\"client\", b\"CLIENT\")\n        pkt[Raw].load = modified\n        # Recalculate checksums\n        del pkt[IP].chksum\n        del pkt[TCP].chksum\n        send(pkt)\n```\n\n## Best Practices\n\n### Analysis Workflow\n\n1. **Capture traffic**: Multiple sessions, different scenarios\n2. **Identify boundaries**: Message start\u002Fend markers\n3. **Map structure**: Fixed header, variable payload\n4. **Identify fields**: Compare multiple samples\n5. **Document format**: Create specification\n6. **Validate understanding**: Implement parser\u002Fgenerator\n7. **Test edge cases**: Fuzzing, boundary conditions\n\n### Common Patterns to Look For\n\n- Magic numbers\u002Fsignatures at message start\n- Version fields for compatibility\n- Length fields (often before variable data)\n- Type\u002Fopcode fields for message identification\n- Sequence numbers for ordering\n- Checksums\u002FCRCs for integrity\n- Timestamps for timing\n- Session\u002Fconnection identifiers\n",{"name":5,"description":7},"main","62c7af5ced2c21355d148c243edb6d5921cca1a6",".agents\u002Fskills\u002Fprotocol-reverse-engineering",8,"https:\u002F\u002Fgithub.com\u002FRudyCity\u002Fsuperagent","https:\u002F\u002Fgithub.com\u002FRudyCity","2026-11-14 22:58:49",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add RudyCity\u002Fsuperagent --skill protocol-reverse-engineering",{"tool":36,"command":37},"bunx","bunx skills add RudyCity\u002Fsuperagent --skill protocol-reverse-engineering",{"tool":39,"command":40},"pnpm","pnpm dlx skills add RudyCity\u002Fsuperagent --skill protocol-reverse-engineering","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FRudyCity\u002Fsuperagent\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fprotocol-reverse-engineering\u002FSKILL.md",true,[],[45,52,59,66,73,80],{"skillNo":46,"name":47,"nameZh":6,"description":48,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":49,"categories":50,"keywords":51,"publishedAt":18},"01M75GP28CM6QCSXSHKFF3NNKS","telegram_bot","Use Telegram Bot when the user asks for Telegram Bot or this provider's API.","https:\u002F\u002Fgithub.com\u002FRudyCity\u002Fsuperagent\u002Fblob\u002Fmain\u002Fmuse-bridge-kit\u002Fskills\u002Ftelegram-bot\u002FSKILL.md",[],[],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":18},"01M75GNZGZYM7NWDV6MBP3HS14","superagent-bridge","Operate the Muse\u003C->superagent Telegram bridge: poll the private group for task_request\u002Ftask_result envelopes, validate senders, and reply with task_batch\u002Ftask_done as Muse (the remote brain).","https:\u002F\u002Fgithub.com\u002FRudyCity\u002Fsuperagent\u002Fblob\u002Fmain\u002Fmuse-bridge-kit\u002Fskills\u002Fsuperagent-bridge\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":18},"01M75GNHN19HJWZ7NAPM5E5JCV","Writing Skills","TDD for process documentation - test with subagents before writing, iterate until bulletproof","https:\u002F\u002Fgithub.com\u002FRudyCity\u002Fsuperagent\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fwriting-skills\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":18},"01M75GNCQEKVRA4FH161NZPZNB","writing-shape","Take a markdown file of raw material and shape it into an article through a conversational session — drafting candidate openings, growing the piece paragraph by paragraph, arguing about format (lists, tables, callouts, quotes) at each step. Use when the user has a pile of notes, fragments, or a rough draft and wants help turning it into something publishable.","https:\u002F\u002Fgithub.com\u002FRudyCity\u002Fsuperagent\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fwriting-shape\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":18},"01M75GNAF9NAYCSTBDZDGMK0DZ","Writing Plans","Create detailed implementation plans with bite-sized tasks for engineers with zero codebase context","https:\u002F\u002Fgithub.com\u002FRudyCity\u002Fsuperagent\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fwriting-plans\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":18},"01M75GN72EV0V5NQAW9CSPFRFH","writing-guidelines","Review docs\u002Fprose for Writing Guidelines compliance. Use when asked to \"review my docs\", \"check writing style\", \"audit prose\", \"review docs voice and tone\", or \"check this page against the writing handbook\".","https:\u002F\u002Fgithub.com\u002FRudyCity\u002Fsuperagent\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fwriting-guidelines\u002FSKILL.md",[],[]]