十年匠心定制 · 商业建站与技术教学双线并行 咨询热线:400-886-1026 service@lmnt.cn
ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

Protocol Name Specification

Protocol Name Specification Protocol Name Specification【免费下载链接】agentsMulti-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity项目地址: https://gitcode.com/GitHub_Trending/agents24/agentsOverviewBrief description of protocol purpose and design.TransportLayer: TCP/UDPPort: XXXXEncryption: TLS 1.2Message FormatHeader (12 bytes)OffsetSizeFieldDescription04Magic0x50524F54 (PROT)42VersionProtocol version (1)62TypeMessage type identifier84LengthPayload length in bytesMessage TypesTypeNameDescription0x01HELLOConnection initiation0x02HELLO_ACKConnection accepted0x03DATAApplication data0x04CLOSEConnection terminationType 0x01: HELLOOffsetSizeFieldDescription04ClientIDUnique client identifier42FlagsConnection flags6varExtensionsTLV-encoded extensionsState Machine该模板刻意采用表格化风格offset/size/field/description与逆向工程技能族对**数据结构的精确刻画**要求一致——例如 [memory-forensics](https://link.gitcode.com/i/f5e8fd0bfee60912a1b048020642c562) 中 _EPROCESS 的字段偏移描述、[binary-analysis-patterns](https://link.gitcode.com/i/caacee07320ee25ecf5ef6f29cf848c2) 中 struct Example 的字段偏移计算都是偏移 大小 语义的同一方法论。 ### 7.2 状态机描述 协议不仅是字节格式更是状态转换。模板给出了 Mermaid 之外的纯文本状态机表达[INIT] --HELLO-- [WAIT_ACK] --HELLO_ACK-- [CONNECTED] | DATA/DATA | [CLOSED] --CLOSE--对应的握手时序示例Client - Server: HELLO (ClientID0x12345678) Server - Client: HELLO_ACK (StatusOK) Client - Server: DATA (payload) **写作建议**规格文档的状态机 时序示例部分是后续编写 Dissector、模糊测试脚本、甚至互操作实现的地图缺失它会导致协议能解析但不知何时合法。 ### 7.3 Wireshark Lua Dissector让工具认识你的协议 技能文档给出了完整的 Lua Dissector 示例将其保存为 custom_protocol.lua 并放入 Wireshark 的 plugins 目录即可让 Wireshark 以可读方式解析该自定义协议 lua -- custom_protocol.lua local proto Proto(custom, Custom Protocol) -- 定义字段 local f_magic ProtoField.string(custom.magic, Magic) local f_version ProtoField.uint16(custom.version, Version) local f_type ProtoField.uint16(custom.type, Type) local f_length ProtoField.uint32(custom.length, Length) local f_payload ProtoField.bytes(custom.payload, Payload) proto.fields { f_magic, f_version, f_type, f_length, f_payload } -- 消息类型名称表 local msg_types { [0x01] HELLO, [0x02] HELLO_ACK, [0x03] DATA, [0x04] CLOSE } function proto.dissector(buffer, pinfo, tree) pinfo.cols.protocol CUSTOM local subtree tree:add(proto, buffer()) -- 解析头部 subtree:add(f_magic, buffer(0, 4)) subtree:add(f_version, buffer(4, 2)) local msg_type buffer(6, 2):uint() subtree:add(f_type, buffer(6, 2)):append_text( ( .. (msg_types[msg_type] or Unknown) .. ) ) local length buffer(8, 4):uint() subtree:add(f_length, buffer(8, 4)) if length 0 then subtree:add(f_payload, buffer(12, length)) end end -- 注册到 TCP 8888 端口 local tcp_table DissectorTable.get(tcp.port) tcp_table:add(8888, proto)这段脚本演示了 Dissector 的三个核心动作定义字段ProtoField.*与规格文档的 offset/size 一一对应、从字节缓冲切片取值buffer(offset, len)、注册到端口DissectorTable.get(tcp.port):add(...)。写完 Dissector 后再次打开 pcapWireshark 就能按字段展开显示——这本身就是对规格理解的一种验证。八、主动测试Fuzzing、重放与修改文档化的协议需要经过主动测试验证。技能文档给出两条路线Boofuzz 结构化模糊测试与 Scapy 重放。8.1 Boofuzz 协议模糊测试Boofuzz 是 Sulley 的继承者通过描述协议结构自动生成畸形报文from boofuzz import * def main(): session Session( targetTarget( connectionTCPSocketConnection(target, 8888) ) ) # 定义协议结构 s_initialize(HELLO) s_static(b\x50\x52\x4f\x54) # Magic PROT s_word(1, nameversion) # Version s_word(0x01, nametype) # Type (HELLO) s_size(payload, length4) # Length 字段自动与 payload 同步 s_block_start(payload) s_dword(0x12345678, nameclient_id) s_word(0, nameflags) s_block_end() session.connect(s_get(HELLO)) session.fuzz() if __name__ __main__: main()要点解析s_static固定魔数s_word/s_dword生成整数字段s_size自动维护长度字段与块内容的一致性——这是结构化模糊测试相对盲目随机变异的核心优势Boofuzz 会在每个变异用例后监控目标是否崩溃通过进程存活/端口响应从而定位触发崩溃的字段。8.2 Scapy 重放与修改from scapy.all import * # 重放捕获的流量把发往 8888 端口的包原样重发 packets rdpcap(capture.pcap) for pkt in packets: if pkt.haslayer(TCP) and pkt[TCP].dport 8888: send(pkt) # 修改并重放替换 payload 中的关键字 for pkt in packets: if pkt.haslayer(Raw): original pkt[Raw].load modified original.replace(bclient, bCLIENT) pkt[Raw].load modified # 修改后必须重算校验和否则对端会丢弃 del pkt[IP].chksum del pkt[TCP].chksum send(pkt)【免费下载链接】agentsMulti-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity项目地址: https://gitcode.com/GitHub_Trending/agents24/agents创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表