@netkitty/codec 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +352 -0
- package/README.zh-CN.md +342 -0
- package/dist/Codec.d.ts +133 -0
- package/dist/Codec.js +632 -0
- package/dist/PacketHeaders.d.ts +189 -0
- package/dist/PacketHeaders.js +384 -0
- package/dist/abstracts/BaseHeader.d.ts +325 -0
- package/dist/abstracts/BaseHeader.js +734 -0
- package/dist/errors/CodecSchemaValidateError.d.ts +4 -0
- package/dist/errors/CodecSchemaValidateError.js +11 -0
- package/dist/headers/ADSAMS.d.ts +33 -0
- package/dist/headers/ADSAMS.js +208 -0
- package/dist/headers/AH.d.ts +28 -0
- package/dist/headers/AH.js +137 -0
- package/dist/headers/AMQP.d.ts +31 -0
- package/dist/headers/AMQP.js +316 -0
- package/dist/headers/ARP.d.ts +26 -0
- package/dist/headers/ARP.js +243 -0
- package/dist/headers/BACnetIP.d.ts +27 -0
- package/dist/headers/BACnetIP.js +97 -0
- package/dist/headers/BFD.d.ts +28 -0
- package/dist/headers/BFD.js +155 -0
- package/dist/headers/BGP.d.ts +27 -0
- package/dist/headers/BGP.js +111 -0
- package/dist/headers/BSAPIP.d.ts +33 -0
- package/dist/headers/BSAPIP.js +78 -0
- package/dist/headers/Babel.d.ts +32 -0
- package/dist/headers/Babel.js +224 -0
- package/dist/headers/BitTorrent.d.ts +28 -0
- package/dist/headers/BitTorrent.js +72 -0
- package/dist/headers/C37118.d.ts +26 -0
- package/dist/headers/C37118.js +147 -0
- package/dist/headers/CAPWAP.d.ts +38 -0
- package/dist/headers/CAPWAP.js +275 -0
- package/dist/headers/CDP.d.ts +25 -0
- package/dist/headers/CDP.js +117 -0
- package/dist/headers/CMS.d.ts +33 -0
- package/dist/headers/CMS.js +238 -0
- package/dist/headers/COTP.d.ts +30 -0
- package/dist/headers/COTP.js +193 -0
- package/dist/headers/CassandraCQL.d.ts +28 -0
- package/dist/headers/CassandraCQL.js +117 -0
- package/dist/headers/CoAP.d.ts +29 -0
- package/dist/headers/CoAP.js +140 -0
- package/dist/headers/Codesys.d.ts +32 -0
- package/dist/headers/Codesys.js +119 -0
- package/dist/headers/Collectd.d.ts +29 -0
- package/dist/headers/Collectd.js +154 -0
- package/dist/headers/DCCP.d.ts +30 -0
- package/dist/headers/DCCP.js +204 -0
- package/dist/headers/DHCP.d.ts +26 -0
- package/dist/headers/DHCP.js +148 -0
- package/dist/headers/DHCPFailover.d.ts +30 -0
- package/dist/headers/DHCPFailover.js +104 -0
- package/dist/headers/DHCPv6.d.ts +25 -0
- package/dist/headers/DHCPv6.js +145 -0
- package/dist/headers/DNP3.d.ts +27 -0
- package/dist/headers/DNP3.js +150 -0
- package/dist/headers/DNS.d.ts +55 -0
- package/dist/headers/DNS.js +309 -0
- package/dist/headers/DTLS.d.ts +33 -0
- package/dist/headers/DTLS.js +142 -0
- package/dist/headers/Diameter.d.ts +34 -0
- package/dist/headers/Diameter.js +229 -0
- package/dist/headers/EAPOL.d.ts +32 -0
- package/dist/headers/EAPOL.js +135 -0
- package/dist/headers/EIGRP.d.ts +28 -0
- package/dist/headers/EIGRP.js +165 -0
- package/dist/headers/ENIP.d.ts +31 -0
- package/dist/headers/ENIP.js +164 -0
- package/dist/headers/ESP.d.ts +27 -0
- package/dist/headers/ESP.js +140 -0
- package/dist/headers/Elasticsearch.d.ts +30 -0
- package/dist/headers/Elasticsearch.js +125 -0
- package/dist/headers/EtherCAT.d.ts +35 -0
- package/dist/headers/EtherCAT.js +150 -0
- package/dist/headers/EthernetII.d.ts +28 -0
- package/dist/headers/EthernetII.js +117 -0
- package/dist/headers/FCoE.d.ts +38 -0
- package/dist/headers/FCoE.js +210 -0
- package/dist/headers/FTP.d.ts +34 -0
- package/dist/headers/FTP.js +158 -0
- package/dist/headers/Finger.d.ts +41 -0
- package/dist/headers/Finger.js +135 -0
- package/dist/headers/FoundationFieldbusHSE.d.ts +43 -0
- package/dist/headers/FoundationFieldbusHSE.js +163 -0
- package/dist/headers/GELF.d.ts +35 -0
- package/dist/headers/GELF.js +261 -0
- package/dist/headers/GENEVE.d.ts +26 -0
- package/dist/headers/GENEVE.js +209 -0
- package/dist/headers/GESRTP.d.ts +32 -0
- package/dist/headers/GESRTP.js +141 -0
- package/dist/headers/GLBP.d.ts +29 -0
- package/dist/headers/GLBP.js +159 -0
- package/dist/headers/GRE.d.ts +27 -0
- package/dist/headers/GRE.js +181 -0
- package/dist/headers/GTPU.d.ts +25 -0
- package/dist/headers/GTPU.js +203 -0
- package/dist/headers/GTPv2C.d.ts +30 -0
- package/dist/headers/GTPv2C.js +281 -0
- package/dist/headers/GitProtocol.d.ts +34 -0
- package/dist/headers/GitProtocol.js +141 -0
- package/dist/headers/Goose.d.ts +115 -0
- package/dist/headers/Goose.js +1067 -0
- package/dist/headers/Gopher.d.ts +43 -0
- package/dist/headers/Gopher.js +182 -0
- package/dist/headers/HARTIP.d.ts +30 -0
- package/dist/headers/HARTIP.js +145 -0
- package/dist/headers/HSR.d.ts +27 -0
- package/dist/headers/HSR.js +105 -0
- package/dist/headers/HSRP.d.ts +26 -0
- package/dist/headers/HSRP.js +173 -0
- package/dist/headers/HTTP.d.ts +32 -0
- package/dist/headers/HTTP.js +153 -0
- package/dist/headers/HTTP2.d.ts +34 -0
- package/dist/headers/HTTP2.js +190 -0
- package/dist/headers/IAX2.d.ts +33 -0
- package/dist/headers/IAX2.js +274 -0
- package/dist/headers/ICMP.d.ts +15 -0
- package/dist/headers/ICMP.js +148 -0
- package/dist/headers/ICMPv6.d.ts +15 -0
- package/dist/headers/ICMPv6.js +129 -0
- package/dist/headers/IEC104_I_Frame.d.ts +23 -0
- package/dist/headers/IEC104_I_Frame.js +6489 -0
- package/dist/headers/IEC104_S_Frame.d.ts +26 -0
- package/dist/headers/IEC104_S_Frame.js +135 -0
- package/dist/headers/IEC104_U_Frame.d.ts +27 -0
- package/dist/headers/IEC104_U_Frame.js +176 -0
- package/dist/headers/IEC61850SampledValues.d.ts +20 -0
- package/dist/headers/IEC61850SampledValues.js +420 -0
- package/dist/headers/IGMP.d.ts +31 -0
- package/dist/headers/IGMP.js +274 -0
- package/dist/headers/IMAP.d.ts +32 -0
- package/dist/headers/IMAP.js +185 -0
- package/dist/headers/IPFIX.d.ts +29 -0
- package/dist/headers/IPFIX.js +156 -0
- package/dist/headers/IPv4.d.ts +20 -0
- package/dist/headers/IPv4.js +370 -0
- package/dist/headers/IPv6.d.ts +29 -0
- package/dist/headers/IPv6.js +209 -0
- package/dist/headers/IPv6HopByHopOptions.d.ts +81 -0
- package/dist/headers/IPv6HopByHopOptions.js +495 -0
- package/dist/headers/IRC.d.ts +34 -0
- package/dist/headers/IRC.js +175 -0
- package/dist/headers/ISAKMP.d.ts +29 -0
- package/dist/headers/ISAKMP.js +197 -0
- package/dist/headers/ISCSI.d.ts +39 -0
- package/dist/headers/ISCSI.js +289 -0
- package/dist/headers/ISIS.d.ts +25 -0
- package/dist/headers/ISIS.js +79 -0
- package/dist/headers/ISOSession.d.ts +27 -0
- package/dist/headers/ISOSession.js +343 -0
- package/dist/headers/Ident.d.ts +42 -0
- package/dist/headers/Ident.js +184 -0
- package/dist/headers/KNXnetIP.d.ts +30 -0
- package/dist/headers/KNXnetIP.js +135 -0
- package/dist/headers/Kafka.d.ts +35 -0
- package/dist/headers/Kafka.js +128 -0
- package/dist/headers/Kerberos.d.ts +30 -0
- package/dist/headers/Kerberos.js +217 -0
- package/dist/headers/L2TP.d.ts +26 -0
- package/dist/headers/L2TP.js +297 -0
- package/dist/headers/LACP.d.ts +31 -0
- package/dist/headers/LACP.js +151 -0
- package/dist/headers/LDAP.d.ts +31 -0
- package/dist/headers/LDAP.js +226 -0
- package/dist/headers/LDP.d.ts +31 -0
- package/dist/headers/LDP.js +138 -0
- package/dist/headers/LISP.d.ts +30 -0
- package/dist/headers/LISP.js +103 -0
- package/dist/headers/LLC.d.ts +27 -0
- package/dist/headers/LLC.js +81 -0
- package/dist/headers/LLDP.d.ts +26 -0
- package/dist/headers/LLDP.js +126 -0
- package/dist/headers/LLMNR.d.ts +23 -0
- package/dist/headers/LLMNR.js +40 -0
- package/dist/headers/LPD.d.ts +31 -0
- package/dist/headers/LPD.js +159 -0
- package/dist/headers/MACsec.d.ts +34 -0
- package/dist/headers/MACsec.js +178 -0
- package/dist/headers/MDNS.d.ts +26 -0
- package/dist/headers/MDNS.js +45 -0
- package/dist/headers/MGCP.d.ts +30 -0
- package/dist/headers/MGCP.js +155 -0
- package/dist/headers/MMS.d.ts +29 -0
- package/dist/headers/MMS.js +243 -0
- package/dist/headers/MPLS.d.ts +31 -0
- package/dist/headers/MPLS.js +145 -0
- package/dist/headers/MQTT.d.ts +30 -0
- package/dist/headers/MQTT.js +173 -0
- package/dist/headers/MQTTSN.d.ts +34 -0
- package/dist/headers/MQTTSN.js +177 -0
- package/dist/headers/MarkerProtocol.d.ts +32 -0
- package/dist/headers/MarkerProtocol.js +153 -0
- package/dist/headers/Megaco.d.ts +32 -0
- package/dist/headers/Megaco.js +144 -0
- package/dist/headers/Memcached.d.ts +44 -0
- package/dist/headers/Memcached.js +285 -0
- package/dist/headers/ModbusTCP.d.ts +25 -0
- package/dist/headers/ModbusTCP.js +99 -0
- package/dist/headers/ModbusUDP.d.ts +26 -0
- package/dist/headers/ModbusUDP.js +100 -0
- package/dist/headers/MongoDB.d.ts +33 -0
- package/dist/headers/MongoDB.js +143 -0
- package/dist/headers/MySQL.d.ts +30 -0
- package/dist/headers/MySQL.js +114 -0
- package/dist/headers/NATS.d.ts +29 -0
- package/dist/headers/NATS.js +135 -0
- package/dist/headers/NBDS.d.ts +34 -0
- package/dist/headers/NBDS.js +176 -0
- package/dist/headers/NBNS.d.ts +34 -0
- package/dist/headers/NBNS.js +78 -0
- package/dist/headers/NBSS.d.ts +36 -0
- package/dist/headers/NBSS.js +137 -0
- package/dist/headers/NFS.d.ts +36 -0
- package/dist/headers/NFS.js +273 -0
- package/dist/headers/NHRP.d.ts +32 -0
- package/dist/headers/NHRP.js +154 -0
- package/dist/headers/NNTP.d.ts +35 -0
- package/dist/headers/NNTP.js +162 -0
- package/dist/headers/NTP.d.ts +18 -0
- package/dist/headers/NTP.js +73 -0
- package/dist/headers/NetFlowV5.d.ts +28 -0
- package/dist/headers/NetFlowV5.js +205 -0
- package/dist/headers/OLSR.d.ts +31 -0
- package/dist/headers/OLSR.js +213 -0
- package/dist/headers/OPCUA.d.ts +33 -0
- package/dist/headers/OPCUA.js +165 -0
- package/dist/headers/OPCUAPubSub.d.ts +33 -0
- package/dist/headers/OPCUAPubSub.js +144 -0
- package/dist/headers/OSPF.d.ts +31 -0
- package/dist/headers/OSPF.js +365 -0
- package/dist/headers/OmronFINS.d.ts +31 -0
- package/dist/headers/OmronFINS.js +90 -0
- package/dist/headers/OpenFlow.d.ts +30 -0
- package/dist/headers/OpenFlow.js +113 -0
- package/dist/headers/OpenVPN.d.ts +35 -0
- package/dist/headers/OpenVPN.js +214 -0
- package/dist/headers/PCWorx.d.ts +35 -0
- package/dist/headers/PCWorx.js +115 -0
- package/dist/headers/PIM.d.ts +27 -0
- package/dist/headers/PIM.js +129 -0
- package/dist/headers/POP3.d.ts +31 -0
- package/dist/headers/POP3.js +152 -0
- package/dist/headers/POWERLINK.d.ts +28 -0
- package/dist/headers/POWERLINK.js +116 -0
- package/dist/headers/PPPoEDiscovery.d.ts +29 -0
- package/dist/headers/PPPoEDiscovery.js +198 -0
- package/dist/headers/PPPoESession.d.ts +28 -0
- package/dist/headers/PPPoESession.js +125 -0
- package/dist/headers/PPTP.d.ts +30 -0
- package/dist/headers/PPTP.js +122 -0
- package/dist/headers/PROFINETRT.d.ts +28 -0
- package/dist/headers/PROFINETRT.js +74 -0
- package/dist/headers/PTP.d.ts +34 -0
- package/dist/headers/PTP.js +213 -0
- package/dist/headers/PostgreSQL.d.ts +40 -0
- package/dist/headers/PostgreSQL.js +236 -0
- package/dist/headers/QUIC.d.ts +34 -0
- package/dist/headers/QUIC.js +308 -0
- package/dist/headers/RADIUS.d.ts +24 -0
- package/dist/headers/RADIUS.js +138 -0
- package/dist/headers/RDP.d.ts +27 -0
- package/dist/headers/RDP.js +93 -0
- package/dist/headers/RFB.d.ts +39 -0
- package/dist/headers/RFB.js +151 -0
- package/dist/headers/RGoose.d.ts +72 -0
- package/dist/headers/RGoose.js +340 -0
- package/dist/headers/RIP.d.ts +29 -0
- package/dist/headers/RIP.js +133 -0
- package/dist/headers/RIPng.d.ts +26 -0
- package/dist/headers/RIPng.js +140 -0
- package/dist/headers/RMCP.d.ts +26 -0
- package/dist/headers/RMCP.js +155 -0
- package/dist/headers/RSVP.d.ts +31 -0
- package/dist/headers/RSVP.js +263 -0
- package/dist/headers/RTCP.d.ts +34 -0
- package/dist/headers/RTCP.js +217 -0
- package/dist/headers/RTP.d.ts +33 -0
- package/dist/headers/RTP.js +291 -0
- package/dist/headers/RTPS.d.ts +33 -0
- package/dist/headers/RTPS.js +182 -0
- package/dist/headers/RTSP.d.ts +36 -0
- package/dist/headers/RTSP.js +184 -0
- package/dist/headers/RawData.d.ts +17 -0
- package/dist/headers/RawData.js +43 -0
- package/dist/headers/Redis.d.ts +32 -0
- package/dist/headers/Redis.js +202 -0
- package/dist/headers/Rlogin.d.ts +42 -0
- package/dist/headers/Rlogin.js +139 -0
- package/dist/headers/Rsync.d.ts +28 -0
- package/dist/headers/Rsync.js +117 -0
- package/dist/headers/S7comm.d.ts +36 -0
- package/dist/headers/S7comm.js +244 -0
- package/dist/headers/SCTP.d.ts +35 -0
- package/dist/headers/SCTP.js +174 -0
- package/dist/headers/SFlow.d.ts +29 -0
- package/dist/headers/SFlow.js +242 -0
- package/dist/headers/SIP.d.ts +27 -0
- package/dist/headers/SIP.js +146 -0
- package/dist/headers/SLMP.d.ts +36 -0
- package/dist/headers/SLMP.js +154 -0
- package/dist/headers/SLP.d.ts +30 -0
- package/dist/headers/SLP.js +207 -0
- package/dist/headers/SLPv1.d.ts +32 -0
- package/dist/headers/SLPv1.js +138 -0
- package/dist/headers/SMB1.d.ts +37 -0
- package/dist/headers/SMB1.js +200 -0
- package/dist/headers/SMB2.d.ts +36 -0
- package/dist/headers/SMB2.js +203 -0
- package/dist/headers/SMPP.d.ts +33 -0
- package/dist/headers/SMPP.js +119 -0
- package/dist/headers/SMTP.d.ts +33 -0
- package/dist/headers/SMTP.js +157 -0
- package/dist/headers/SNAP.d.ts +22 -0
- package/dist/headers/SNAP.js +68 -0
- package/dist/headers/SNMP.d.ts +28 -0
- package/dist/headers/SNMP.js +302 -0
- package/dist/headers/SOCKS4.d.ts +42 -0
- package/dist/headers/SOCKS4.js +302 -0
- package/dist/headers/SOCKS5.d.ts +45 -0
- package/dist/headers/SOCKS5.js +223 -0
- package/dist/headers/SSDP.d.ts +27 -0
- package/dist/headers/SSDP.js +161 -0
- package/dist/headers/SSH.d.ts +44 -0
- package/dist/headers/SSH.js +274 -0
- package/dist/headers/STOMP.d.ts +48 -0
- package/dist/headers/STOMP.js +177 -0
- package/dist/headers/STP.d.ts +26 -0
- package/dist/headers/STP.js +150 -0
- package/dist/headers/STUN.d.ts +25 -0
- package/dist/headers/STUN.js +183 -0
- package/dist/headers/SercosIII.d.ts +43 -0
- package/dist/headers/SercosIII.js +199 -0
- package/dist/headers/Skinny.d.ts +32 -0
- package/dist/headers/Skinny.js +139 -0
- package/dist/headers/StatsD.d.ts +27 -0
- package/dist/headers/StatsD.js +134 -0
- package/dist/headers/SunRPC.d.ts +34 -0
- package/dist/headers/SunRPC.js +268 -0
- package/dist/headers/Syslog.d.ts +21 -0
- package/dist/headers/Syslog.js +91 -0
- package/dist/headers/TCP.d.ts +19 -0
- package/dist/headers/TCP.js +905 -0
- package/dist/headers/TFTP.d.ts +28 -0
- package/dist/headers/TFTP.js +224 -0
- package/dist/headers/TLS_Alert.d.ts +24 -0
- package/dist/headers/TLS_Alert.js +639 -0
- package/dist/headers/TLS_ApplicationData.d.ts +24 -0
- package/dist/headers/TLS_ApplicationData.js +170 -0
- package/dist/headers/TLS_ChangeCipherSpec.d.ts +23 -0
- package/dist/headers/TLS_ChangeCipherSpec.js +168 -0
- package/dist/headers/TLS_Handshake.d.ts +65 -0
- package/dist/headers/TLS_Handshake.js +860 -0
- package/dist/headers/TLS_Heartbeat.d.ts +27 -0
- package/dist/headers/TLS_Heartbeat.js +247 -0
- package/dist/headers/TPKT.d.ts +26 -0
- package/dist/headers/TPKT.js +99 -0
- package/dist/headers/TacacsPlus.d.ts +27 -0
- package/dist/headers/TacacsPlus.js +133 -0
- package/dist/headers/Telnet.d.ts +40 -0
- package/dist/headers/Telnet.js +193 -0
- package/dist/headers/Teredo.d.ts +40 -0
- package/dist/headers/Teredo.js +251 -0
- package/dist/headers/TimeProtocol.d.ts +25 -0
- package/dist/headers/TimeProtocol.js +53 -0
- package/dist/headers/UDP.d.ts +19 -0
- package/dist/headers/UDP.js +171 -0
- package/dist/headers/VLAN_802dot1Q.d.ts +24 -0
- package/dist/headers/VLAN_802dot1Q.js +96 -0
- package/dist/headers/VRRP.d.ts +26 -0
- package/dist/headers/VRRP.js +309 -0
- package/dist/headers/VXLAN.d.ts +24 -0
- package/dist/headers/VXLAN.js +75 -0
- package/dist/headers/WCCP.d.ts +29 -0
- package/dist/headers/WCCP.js +117 -0
- package/dist/headers/WHOIS.d.ts +37 -0
- package/dist/headers/WHOIS.js +126 -0
- package/dist/headers/WSDiscovery.d.ts +29 -0
- package/dist/headers/WSDiscovery.js +118 -0
- package/dist/headers/WakeOnLAN.d.ts +30 -0
- package/dist/headers/WakeOnLAN.js +126 -0
- package/dist/headers/WebSocket.d.ts +26 -0
- package/dist/headers/WebSocket.js +173 -0
- package/dist/headers/WireGuard.d.ts +38 -0
- package/dist/headers/WireGuard.js +216 -0
- package/dist/headers/XMPP.d.ts +37 -0
- package/dist/headers/XMPP.js +149 -0
- package/dist/headers/Zabbix.d.ts +35 -0
- package/dist/headers/Zabbix.js +153 -0
- package/dist/headers/cms/AcsiPdu.d.ts +45 -0
- package/dist/headers/cms/AcsiPdu.js +112 -0
- package/dist/headers/cms/PerDecoder.d.ts +68 -0
- package/dist/headers/cms/PerDecoder.js +211 -0
- package/dist/headers/cms/PerReader.d.ts +64 -0
- package/dist/headers/cms/PerReader.js +155 -0
- package/dist/helper/BufferToHex.d.ts +5 -0
- package/dist/helper/BufferToHex.js +10 -0
- package/dist/helper/BufferToIP.d.ts +12 -0
- package/dist/helper/BufferToIP.js +23 -0
- package/dist/helper/BufferToNumber.d.ts +18 -0
- package/dist/helper/BufferToNumber.js +47 -0
- package/dist/helper/HexToBuffer.d.ts +7 -0
- package/dist/helper/HexToBuffer.js +27 -0
- package/dist/helper/HexToNumber.d.ts +18 -0
- package/dist/helper/HexToNumber.js +48 -0
- package/dist/helper/IPToBuffer.d.ts +12 -0
- package/dist/helper/IPToBuffer.js +34 -0
- package/dist/helper/NumberToBERBuffer.d.ts +18 -0
- package/dist/helper/NumberToBERBuffer.js +31 -0
- package/dist/helper/NumberToBERHex.d.ts +18 -0
- package/dist/helper/NumberToBERHex.js +52 -0
- package/dist/helper/NumberToBuffer.d.ts +18 -0
- package/dist/helper/NumberToBuffer.js +38 -0
- package/dist/helper/NumberToHex.d.ts +18 -0
- package/dist/helper/NumberToHex.js +35 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +113 -0
- package/dist/lib/FlexibleObject.d.ts +27 -0
- package/dist/lib/FlexibleObject.js +113 -0
- package/dist/lib/GetBERIntegerLengthFromBuffer.d.ts +6 -0
- package/dist/lib/GetBERIntegerLengthFromBuffer.js +16 -0
- package/dist/lib/ProcessPacketPostHandlers.d.ts +13 -0
- package/dist/lib/ProcessPacketPostHandlers.js +53 -0
- package/dist/lib/SortPostHandlers.d.ts +7 -0
- package/dist/lib/SortPostHandlers.js +11 -0
- package/dist/lib/StringContentEncodingEnum.d.ts +10 -0
- package/dist/lib/StringContentEncodingEnum.js +14 -0
- package/dist/schema/ProtocolFieldJSONSchema.d.ts +35 -0
- package/dist/schema/ProtocolFieldJSONSchema.js +2 -0
- package/dist/schema/ProtocolFieldJSONSchemaDefinition.d.ts +2 -0
- package/dist/schema/ProtocolFieldJSONSchemaDefinition.js +2 -0
- package/dist/schema/ProtocolJSONSchema.d.ts +32 -0
- package/dist/schema/ProtocolJSONSchema.js +2 -0
- package/dist/types/CodecData.d.ts +7 -0
- package/dist/types/CodecData.js +2 -0
- package/dist/types/CodecDecodeResult.d.ts +10 -0
- package/dist/types/CodecDecodeResult.js +2 -0
- package/dist/types/CodecEncodeInput.d.ts +2 -0
- package/dist/types/CodecEncodeInput.js +2 -0
- package/dist/types/CodecEncodeResult.d.ts +5 -0
- package/dist/types/CodecEncodeResult.js +2 -0
- package/dist/types/CodecErrorInfo.d.ts +5 -0
- package/dist/types/CodecErrorInfo.js +2 -0
- package/dist/types/CodecModule.d.ts +2 -0
- package/dist/types/CodecModule.js +2 -0
- package/dist/types/CodecModuleConstructor.d.ts +2 -0
- package/dist/types/CodecModuleConstructor.js +2 -0
- package/dist/types/CodecSchema.d.ts +6 -0
- package/dist/types/CodecSchema.js +2 -0
- package/dist/types/DemuxProducer.d.ts +23 -0
- package/dist/types/DemuxProducer.js +2 -0
- package/dist/types/Dissection.d.ts +23 -0
- package/dist/types/Dissection.js +2 -0
- package/dist/types/HeaderTreeNode.d.ts +4 -0
- package/dist/types/HeaderTreeNode.js +2 -0
- package/dist/types/LayerGraph.d.ts +32 -0
- package/dist/types/LayerGraph.js +2 -0
- package/dist/types/PostHandlerItem.d.ts +4 -0
- package/dist/types/PostHandlerItem.js +2 -0
- package/package.json +141 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SOCKS4 = void 0;
|
|
4
|
+
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
5
|
+
const BufferToNumber_1 = require("../helper/BufferToNumber");
|
|
6
|
+
const NumberToBuffer_1 = require("../helper/NumberToBuffer");
|
|
7
|
+
const BufferToIP_1 = require("../helper/BufferToIP");
|
|
8
|
+
const IPToBuffer_1 = require("../helper/IPToBuffer");
|
|
9
|
+
/**
|
|
10
|
+
* SOCKS4 — the SOCKS Protocol Version 4 (and the SOCKS4a extension), carried over TCP well-known
|
|
11
|
+
* port 1080. Only two message shapes travel on the wire, discriminated by their leading octet:
|
|
12
|
+
*
|
|
13
|
+
* 1. Client request : version(1,=4) · command(1: 1 CONNECT / 2 BIND) · dstPort(2, BE) ·
|
|
14
|
+
* dstIp(4, IPv4) · userId(null-terminated ASCII) [· domain(null-terminated)]
|
|
15
|
+
* 2. Server reply : null(1,=0) · status(1: 0x5A granted, 0x5B/0x5C/0x5D rejected) ·
|
|
16
|
+
* dstPort(2, BE) · dstIp(4, IPv4) — always exactly 8 octets
|
|
17
|
+
*
|
|
18
|
+
* The two shapes share their tail exactly — dstPort at offset 2 and dstIp at offset 4 — so those
|
|
19
|
+
* fields are common to both; only the leading octet (version 4 vs null 0), the second octet
|
|
20
|
+
* (command vs status), and the request's trailing user-id are shape-specific. A `messageType`
|
|
21
|
+
* display field ('request' | 'reply') is the discriminator, decoded from the leading octet
|
|
22
|
+
* (4 → request, 0 → reply) and driving every field below.
|
|
23
|
+
*
|
|
24
|
+
* SOCKS4a: when the request's dstIp is 0.0.0.x (first three octets zero, last non-zero) the client
|
|
25
|
+
* could not resolve the host and appends a second null-terminated string — the destination domain —
|
|
26
|
+
* after the user-id. The codec structures that trailing string as `domain` whenever bytes remain
|
|
27
|
+
* after the user-id's terminator, so both plain SOCKS4 and SOCKS4a requests round-trip byte-for-byte.
|
|
28
|
+
* (A request whose user-id lacks its RFC-mandated null terminator is malformed: it decodes
|
|
29
|
+
* best-effort but re-emits with the terminator, so the byte-perfect guarantee is for conformant
|
|
30
|
+
* SOCKS4 only.)
|
|
31
|
+
*
|
|
32
|
+
* Matching rationale (NO heuristicFallback): SOCKS4 is claimed ONLY on the tcp:1080 bucket. Its only
|
|
33
|
+
* content signature is a single leading octet of 0x04 (request) or 0x00 (reply) — a signature that
|
|
34
|
+
* matches enormous amounts of arbitrary binary TCP data; recognition therefore depends entirely on
|
|
35
|
+
* the well-known port. Joining the global content-heuristic chain would mislabel unrelated binary
|
|
36
|
+
* traffic on any port, so SOCKS4 is confined to tcp:1080 and alt-port SOCKS4 falls losslessly to raw.
|
|
37
|
+
*/
|
|
38
|
+
class SOCKS4 extends BaseHeader_1.BaseHeader {
|
|
39
|
+
constructor() {
|
|
40
|
+
super(...arguments);
|
|
41
|
+
this.id = 'socks4';
|
|
42
|
+
this.name = 'SOCKS4';
|
|
43
|
+
this.nickname = 'SOCKS4';
|
|
44
|
+
//SOCKS4 is recognized ONLY on the well-known port 1080 — deliberately NOT via heuristicFallback.
|
|
45
|
+
//Its only content signature is a single leading 0x04/0x00 octet, which matches vast amounts of
|
|
46
|
+
//arbitrary binary TCP data; recognition depends entirely on the port bucket. See the class doc.
|
|
47
|
+
this.matchKeys = ['tcpport:1080'];
|
|
48
|
+
//A leaf header — SOCKS4 tunnels an arbitrary application stream once the request is granted; its
|
|
49
|
+
//relayed payload is not demuxed off this header.
|
|
50
|
+
this.demuxProducers = [];
|
|
51
|
+
}
|
|
52
|
+
static #schemaCache;
|
|
53
|
+
get SCHEMA() {
|
|
54
|
+
return (SOCKS4.#schemaCache ??= SOCKS4.#buildSchema());
|
|
55
|
+
}
|
|
56
|
+
/** Bytes available to this header: SOCKS4 rides on TCP, which has no per-message length. */
|
|
57
|
+
#payloadLength() {
|
|
58
|
+
const available = this.packet.length - this.startPos;
|
|
59
|
+
return available < 0 ? 0 : available;
|
|
60
|
+
}
|
|
61
|
+
/** True when the leading octet marks a client request (version 4) rather than a server reply. */
|
|
62
|
+
#isRequest() {
|
|
63
|
+
return this.instance.messageType.getValue('request') === 'request';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Read a null-terminated latin1 string at `offset` (bounded by the captured length); returns its
|
|
67
|
+
* value plus the offset one past the terminator (or the end of buffer if never terminated).
|
|
68
|
+
*/
|
|
69
|
+
#readCString(offset, available) {
|
|
70
|
+
let p = offset;
|
|
71
|
+
while (p < available && this.readBytes(p, 1, true)[0] !== 0)
|
|
72
|
+
p++;
|
|
73
|
+
const value = p > offset ? this.readBytes(offset, p - offset).toString('latin1') : '';
|
|
74
|
+
let next = p;
|
|
75
|
+
if (p < available) {
|
|
76
|
+
this.readBytes(p, 1); //consume the null terminator (extends headerLength)
|
|
77
|
+
next = p + 1;
|
|
78
|
+
}
|
|
79
|
+
return { value: value, next: next };
|
|
80
|
+
}
|
|
81
|
+
/** Write a latin1 string plus its null terminator at `offset`; returns the offset past the terminator. */
|
|
82
|
+
#writeCString(offset, value) {
|
|
83
|
+
const bytes = Buffer.from(value ? value : '', 'latin1');
|
|
84
|
+
this.writeBytes(offset, bytes);
|
|
85
|
+
this.writeBytes(offset + bytes.length, Buffer.from([0]));
|
|
86
|
+
return offset + bytes.length + 1;
|
|
87
|
+
}
|
|
88
|
+
static #buildSchema() {
|
|
89
|
+
return {
|
|
90
|
+
type: 'object',
|
|
91
|
+
summary: 'SOCKS4 ${messageType}',
|
|
92
|
+
properties: {
|
|
93
|
+
//Discriminator + display field. Decoded from the leading octet (4 → request, 0 →
|
|
94
|
+
//reply); on encode it is supplied by the input (default 'request') and read by every
|
|
95
|
+
//field below to decide which bytes it owns.
|
|
96
|
+
messageType: {
|
|
97
|
+
type: 'string',
|
|
98
|
+
label: 'Message Type',
|
|
99
|
+
enum: ['request', 'reply'],
|
|
100
|
+
default: 'request',
|
|
101
|
+
decode: function () {
|
|
102
|
+
const lead = this.#payloadLength() >= 1 ? this.readBytes(0, 1, true).readUInt8(0) : 4;
|
|
103
|
+
this.instance.messageType.setValue(lead === 0 ? 'reply' : 'request');
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
//Leading octet, common to both shapes: 0x04 for a request, 0x00 (the "null" byte) for
|
|
107
|
+
//a reply. Structured for both so the common tail (port, ip) sits at fixed offsets.
|
|
108
|
+
version: {
|
|
109
|
+
type: 'integer',
|
|
110
|
+
label: 'Version',
|
|
111
|
+
minimum: 0,
|
|
112
|
+
maximum: 255,
|
|
113
|
+
default: 4,
|
|
114
|
+
decode: function () {
|
|
115
|
+
this.instance.version.setValue(this.readBytes(0, 1).readUInt8(0));
|
|
116
|
+
},
|
|
117
|
+
encode: function () {
|
|
118
|
+
const node = this.instance.version;
|
|
119
|
+
let value = node.getValue(this.#isRequest() ? 4 : 0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
120
|
+
if (value > 255) {
|
|
121
|
+
this.recordError(node.getPath(), 'Maximum value is 255');
|
|
122
|
+
value = 255;
|
|
123
|
+
}
|
|
124
|
+
if (value < 0) {
|
|
125
|
+
this.recordError(node.getPath(), 'Minimum value is 0');
|
|
126
|
+
value = 0;
|
|
127
|
+
}
|
|
128
|
+
node.setValue(value);
|
|
129
|
+
this.writeBytes(0, Buffer.from([value]));
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
//REQUEST shape: the SOCKS command at offset 1 (1 = CONNECT, 2 = BIND).
|
|
133
|
+
command: {
|
|
134
|
+
type: 'integer',
|
|
135
|
+
label: 'Command',
|
|
136
|
+
enum: [1, 2],
|
|
137
|
+
minimum: 0,
|
|
138
|
+
maximum: 255,
|
|
139
|
+
default: 1,
|
|
140
|
+
decode: function () {
|
|
141
|
+
if (!this.#isRequest()) {
|
|
142
|
+
this.instance.command.setValue(1);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
this.instance.command.setValue(this.readBytes(1, 1).readUInt8(0));
|
|
146
|
+
},
|
|
147
|
+
encode: function () {
|
|
148
|
+
if (!this.#isRequest())
|
|
149
|
+
return;
|
|
150
|
+
const node = this.instance.command;
|
|
151
|
+
let value = node.getValue(1, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
152
|
+
if (value > 255) {
|
|
153
|
+
this.recordError(node.getPath(), 'Maximum value is 255');
|
|
154
|
+
value = 255;
|
|
155
|
+
}
|
|
156
|
+
if (value < 0) {
|
|
157
|
+
this.recordError(node.getPath(), 'Minimum value is 0');
|
|
158
|
+
value = 0;
|
|
159
|
+
}
|
|
160
|
+
node.setValue(value);
|
|
161
|
+
this.writeBytes(1, Buffer.from([value]));
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
//REPLY shape: the reply status code at offset 1 (0x5A granted, 0x5B request rejected
|
|
165
|
+
//or failed, 0x5C/0x5D identd failures).
|
|
166
|
+
status: {
|
|
167
|
+
type: 'integer',
|
|
168
|
+
label: 'Status',
|
|
169
|
+
enum: [0x5a, 0x5b, 0x5c, 0x5d],
|
|
170
|
+
minimum: 0,
|
|
171
|
+
maximum: 255,
|
|
172
|
+
default: 0x5a,
|
|
173
|
+
decode: function () {
|
|
174
|
+
if (this.#isRequest()) {
|
|
175
|
+
this.instance.status.setValue(0x5a);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
this.instance.status.setValue(this.readBytes(1, 1).readUInt8(0));
|
|
179
|
+
},
|
|
180
|
+
encode: function () {
|
|
181
|
+
if (this.#isRequest())
|
|
182
|
+
return;
|
|
183
|
+
const node = this.instance.status;
|
|
184
|
+
let value = node.getValue(0x5a, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
185
|
+
if (value > 255) {
|
|
186
|
+
this.recordError(node.getPath(), 'Maximum value is 255');
|
|
187
|
+
value = 255;
|
|
188
|
+
}
|
|
189
|
+
if (value < 0) {
|
|
190
|
+
this.recordError(node.getPath(), 'Minimum value is 0');
|
|
191
|
+
value = 0;
|
|
192
|
+
}
|
|
193
|
+
node.setValue(value);
|
|
194
|
+
this.writeBytes(1, Buffer.from([value]));
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
//Common to both shapes: the destination (request) / bound (reply) port at offset 2,
|
|
198
|
+
//big-endian.
|
|
199
|
+
dstPort: {
|
|
200
|
+
type: 'integer',
|
|
201
|
+
label: 'Destination Port',
|
|
202
|
+
minimum: 0,
|
|
203
|
+
maximum: 65535,
|
|
204
|
+
default: 0,
|
|
205
|
+
decode: function () {
|
|
206
|
+
this.instance.dstPort.setValue(this.#payloadLength() >= 4 ? (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)) : 0);
|
|
207
|
+
},
|
|
208
|
+
encode: function () {
|
|
209
|
+
const node = this.instance.dstPort;
|
|
210
|
+
let value = node.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
211
|
+
if (value > 65535) {
|
|
212
|
+
this.recordError(node.getPath(), 'Maximum value is 65535');
|
|
213
|
+
value = 65535;
|
|
214
|
+
}
|
|
215
|
+
if (value < 0) {
|
|
216
|
+
this.recordError(node.getPath(), 'Minimum value is 0');
|
|
217
|
+
value = 0;
|
|
218
|
+
}
|
|
219
|
+
node.setValue(value);
|
|
220
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(value));
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
//Common to both shapes: the destination (request) / bound (reply) IPv4 address at
|
|
224
|
+
//offset 4. A request whose first three octets are zero and last non-zero is SOCKS4a
|
|
225
|
+
//(the real host is carried by the trailing `domain`).
|
|
226
|
+
dstIp: {
|
|
227
|
+
type: 'string',
|
|
228
|
+
label: 'Destination IP',
|
|
229
|
+
default: '0.0.0.0',
|
|
230
|
+
decode: function () {
|
|
231
|
+
this.instance.dstIp.setValue(this.#payloadLength() >= 8 ? (0, BufferToIP_1.BufferToIPv4)(this.readBytes(4, 4)) : '0.0.0.0');
|
|
232
|
+
},
|
|
233
|
+
encode: function () {
|
|
234
|
+
const value = this.instance.dstIp.getValue('0.0.0.0');
|
|
235
|
+
this.writeBytes(4, (0, IPToBuffer_1.IPv4ToBuffer)(value ? value : '0.0.0.0'));
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
//REQUEST shape: the null-terminated user-id (SOCKS4 authentication identifier) at
|
|
239
|
+
//offset 8. Kept verbatim (latin1) and re-emitted with its null terminator.
|
|
240
|
+
userId: {
|
|
241
|
+
type: 'string',
|
|
242
|
+
label: 'User ID',
|
|
243
|
+
default: '',
|
|
244
|
+
decode: function () {
|
|
245
|
+
if (!this.#isRequest()) {
|
|
246
|
+
this.instance.userId.setValue('');
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const available = this.#payloadLength();
|
|
250
|
+
this.instance.userId.setValue(this.#readCString(8, available).value);
|
|
251
|
+
},
|
|
252
|
+
encode: function () {
|
|
253
|
+
if (!this.#isRequest())
|
|
254
|
+
return;
|
|
255
|
+
this.#writeCString(8, this.instance.userId.getValue(''));
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
//REQUEST shape (SOCKS4a): the null-terminated destination domain that follows the
|
|
259
|
+
//user-id when the client could not resolve the host (dstIp 0.0.0.x). Structured
|
|
260
|
+
//whenever bytes remain after the user-id terminator, so SOCKS4a round-trips exactly.
|
|
261
|
+
domain: {
|
|
262
|
+
type: 'string',
|
|
263
|
+
label: 'Domain',
|
|
264
|
+
default: '',
|
|
265
|
+
decode: function () {
|
|
266
|
+
if (!this.#isRequest()) {
|
|
267
|
+
this.instance.domain.setValue('');
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const available = this.#payloadLength();
|
|
271
|
+
const afterUser = this.#readCString(8, available).next;
|
|
272
|
+
this.instance.domain.setValue(afterUser < available ? this.#readCString(afterUser, available).value : '');
|
|
273
|
+
},
|
|
274
|
+
encode: function () {
|
|
275
|
+
if (!this.#isRequest())
|
|
276
|
+
return;
|
|
277
|
+
const domain = this.instance.domain.getValue('');
|
|
278
|
+
if (!domain)
|
|
279
|
+
return;
|
|
280
|
+
const userBytes = Buffer.from(this.instance.userId.getValue(''), 'latin1');
|
|
281
|
+
this.#writeCString(8 + userBytes.length + 1, domain);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
match() {
|
|
288
|
+
//Port-bucket (tcp:1080) + leading-octet signature. Reached only on the tcp:1080 bucket.
|
|
289
|
+
if (!this.prevCodecModule)
|
|
290
|
+
return false;
|
|
291
|
+
if (this.prevCodecModule.id !== 'tcp')
|
|
292
|
+
return false;
|
|
293
|
+
const available = this.#payloadLength();
|
|
294
|
+
//A reply is exactly 8 octets; a request is at least 9 (its user-id contributes a terminator).
|
|
295
|
+
//Require the 8-octet common span and a leading 0x04 (request) or 0x00 (reply).
|
|
296
|
+
if (available < 8)
|
|
297
|
+
return false;
|
|
298
|
+
const lead = this.readBytes(0, 1, true).readUInt8(0);
|
|
299
|
+
return lead === 4 || lead === 0;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
exports.SOCKS4 = SOCKS4;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
2
|
+
import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
|
|
3
|
+
import { DemuxProducer } from '../types/DemuxProducer';
|
|
4
|
+
/**
|
|
5
|
+
* SOCKS5 — the SOCKS Protocol Version 5 (RFC 1928), carried over TCP well-known port 1080.
|
|
6
|
+
*
|
|
7
|
+
* A SOCKS5 conversation is a short handshake of four message shapes, all beginning with a version octet
|
|
8
|
+
* (0x05):
|
|
9
|
+
*
|
|
10
|
+
* 1. Client greeting : version(1,=5) · nMethods(1) · methods(nMethods)
|
|
11
|
+
* 2. Server method selection : version(1,=5) · method(1)
|
|
12
|
+
* 3. Client request : version(1,=5) · cmd(1) · rsv(1,=0) · atyp(1) · dstAddr(var) · dstPort(2)
|
|
13
|
+
* 4. Server reply : version(1,=5) · rep(1) · rsv(1,=0) · atyp(1) · bndAddr(var) · bndPort(2)
|
|
14
|
+
*
|
|
15
|
+
* Design choice (documented): only the CLIENT GREETING is fully structured — it is the one message whose
|
|
16
|
+
* length is self-describing (nMethods exactly bounds the methods list), so it can be recognized and split
|
|
17
|
+
* with no ambiguity. The other three shapes carry a conditional, address-type-dependent address whose
|
|
18
|
+
* structuring is a later slice; here they are kept BYTE-VERBATIM after the common version octet as a
|
|
19
|
+
* single `data` hex field. So every SOCKS5 message is: version (structured) + either {nMethods, methods}
|
|
20
|
+
* (greeting) or {data} (everything else). A `messageType` display field ('greeting' | 'other') is the
|
|
21
|
+
* discriminator, and drives the one-line summary. Any well-formed message round-trips byte-for-byte.
|
|
22
|
+
*
|
|
23
|
+
* Greeting recognition is exact: version 5, at least one method offered (nMethods ≥ 1), and the payload
|
|
24
|
+
* length equal to 2 + nMethods (the octets nMethods claims are exactly the octets present). This keeps a
|
|
25
|
+
* two-byte server method-selection (`05 xx`, nMethods would read as 0) out of the greeting shape, and a
|
|
26
|
+
* lying nMethods that over-claims the remaining bytes is NOT mistaken for a greeting — it stays 'other'
|
|
27
|
+
* and is preserved verbatim, so the decoder never trusts nMethods to read past the captured bytes.
|
|
28
|
+
*
|
|
29
|
+
* Matching rationale (NO heuristicFallback): SOCKS5 is claimed ONLY on the tcp:1080 bucket. Its only
|
|
30
|
+
* content signature is a leading 0x05 version octet — a single byte with no further magic, which matches
|
|
31
|
+
* an enormous amount of arbitrary binary TCP data. Recognition therefore depends entirely on the
|
|
32
|
+
* well-known port; joining the global content-heuristic chain would mislabel unrelated binary traffic on
|
|
33
|
+
* any port. Confining SOCKS5 to tcp:1080 keeps that impossible; alt-port SOCKS5 is rare and falls
|
|
34
|
+
* losslessly to raw.
|
|
35
|
+
*/
|
|
36
|
+
export declare class SOCKS5 extends BaseHeader {
|
|
37
|
+
#private;
|
|
38
|
+
get SCHEMA(): ProtocolJSONSchema;
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly nickname: string;
|
|
42
|
+
readonly matchKeys: string[];
|
|
43
|
+
match(): boolean;
|
|
44
|
+
readonly demuxProducers: DemuxProducer[];
|
|
45
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SOCKS5 = void 0;
|
|
4
|
+
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
5
|
+
const BufferToHex_1 = require("../helper/BufferToHex");
|
|
6
|
+
const HexToBuffer_1 = require("../helper/HexToBuffer");
|
|
7
|
+
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
8
|
+
/**
|
|
9
|
+
* SOCKS5 — the SOCKS Protocol Version 5 (RFC 1928), carried over TCP well-known port 1080.
|
|
10
|
+
*
|
|
11
|
+
* A SOCKS5 conversation is a short handshake of four message shapes, all beginning with a version octet
|
|
12
|
+
* (0x05):
|
|
13
|
+
*
|
|
14
|
+
* 1. Client greeting : version(1,=5) · nMethods(1) · methods(nMethods)
|
|
15
|
+
* 2. Server method selection : version(1,=5) · method(1)
|
|
16
|
+
* 3. Client request : version(1,=5) · cmd(1) · rsv(1,=0) · atyp(1) · dstAddr(var) · dstPort(2)
|
|
17
|
+
* 4. Server reply : version(1,=5) · rep(1) · rsv(1,=0) · atyp(1) · bndAddr(var) · bndPort(2)
|
|
18
|
+
*
|
|
19
|
+
* Design choice (documented): only the CLIENT GREETING is fully structured — it is the one message whose
|
|
20
|
+
* length is self-describing (nMethods exactly bounds the methods list), so it can be recognized and split
|
|
21
|
+
* with no ambiguity. The other three shapes carry a conditional, address-type-dependent address whose
|
|
22
|
+
* structuring is a later slice; here they are kept BYTE-VERBATIM after the common version octet as a
|
|
23
|
+
* single `data` hex field. So every SOCKS5 message is: version (structured) + either {nMethods, methods}
|
|
24
|
+
* (greeting) or {data} (everything else). A `messageType` display field ('greeting' | 'other') is the
|
|
25
|
+
* discriminator, and drives the one-line summary. Any well-formed message round-trips byte-for-byte.
|
|
26
|
+
*
|
|
27
|
+
* Greeting recognition is exact: version 5, at least one method offered (nMethods ≥ 1), and the payload
|
|
28
|
+
* length equal to 2 + nMethods (the octets nMethods claims are exactly the octets present). This keeps a
|
|
29
|
+
* two-byte server method-selection (`05 xx`, nMethods would read as 0) out of the greeting shape, and a
|
|
30
|
+
* lying nMethods that over-claims the remaining bytes is NOT mistaken for a greeting — it stays 'other'
|
|
31
|
+
* and is preserved verbatim, so the decoder never trusts nMethods to read past the captured bytes.
|
|
32
|
+
*
|
|
33
|
+
* Matching rationale (NO heuristicFallback): SOCKS5 is claimed ONLY on the tcp:1080 bucket. Its only
|
|
34
|
+
* content signature is a leading 0x05 version octet — a single byte with no further magic, which matches
|
|
35
|
+
* an enormous amount of arbitrary binary TCP data. Recognition therefore depends entirely on the
|
|
36
|
+
* well-known port; joining the global content-heuristic chain would mislabel unrelated binary traffic on
|
|
37
|
+
* any port. Confining SOCKS5 to tcp:1080 keeps that impossible; alt-port SOCKS5 is rare and falls
|
|
38
|
+
* losslessly to raw.
|
|
39
|
+
*/
|
|
40
|
+
class SOCKS5 extends BaseHeader_1.BaseHeader {
|
|
41
|
+
constructor() {
|
|
42
|
+
super(...arguments);
|
|
43
|
+
this.id = 'socks5';
|
|
44
|
+
this.name = 'SOCKS5';
|
|
45
|
+
this.nickname = 'SOCKS5';
|
|
46
|
+
//SOCKS5 is recognized ONLY on the well-known port 1080 — deliberately NOT via heuristicFallback. Its
|
|
47
|
+
//only content signature is a single 0x05 version octet, which matches vast amounts of arbitrary
|
|
48
|
+
//binary TCP data; recognition depends entirely on the port bucket. See the class doc for the full
|
|
49
|
+
//rationale.
|
|
50
|
+
this.matchKeys = ['tcpport:1080'];
|
|
51
|
+
//A leaf header — SOCKS5 tunnels an arbitrary application stream once the handshake completes; its
|
|
52
|
+
//relayed payload is not demuxed off this header.
|
|
53
|
+
this.demuxProducers = [];
|
|
54
|
+
}
|
|
55
|
+
static #schemaCache;
|
|
56
|
+
get SCHEMA() {
|
|
57
|
+
return (SOCKS5.#schemaCache ??= SOCKS5.#buildSchema());
|
|
58
|
+
}
|
|
59
|
+
/** Bytes available to this header: SOCKS5 rides on TCP, which has no per-message length. */
|
|
60
|
+
#payloadLength() {
|
|
61
|
+
const available = this.packet.length - this.startPos;
|
|
62
|
+
return available < 0 ? 0 : available;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* True when the payload is a well-formed client greeting: version 5, at least one method offered,
|
|
66
|
+
* and the captured length is exactly 2 + nMethods (nMethods bounds the methods list precisely).
|
|
67
|
+
* Never over-reads: only inspects the first two octets.
|
|
68
|
+
*/
|
|
69
|
+
#isGreeting() {
|
|
70
|
+
const available = this.#payloadLength();
|
|
71
|
+
if (available < 3)
|
|
72
|
+
return false;
|
|
73
|
+
const head = this.readBytes(0, 2, true);
|
|
74
|
+
if (head.readUInt8(0) !== 5)
|
|
75
|
+
return false;
|
|
76
|
+
const nMethods = head.readUInt8(1);
|
|
77
|
+
if (nMethods < 1)
|
|
78
|
+
return false;
|
|
79
|
+
return available === 2 + nMethods;
|
|
80
|
+
}
|
|
81
|
+
static #buildSchema() {
|
|
82
|
+
return {
|
|
83
|
+
type: 'object',
|
|
84
|
+
summary: 'SOCKS5 ${messageType}',
|
|
85
|
+
properties: {
|
|
86
|
+
//Discriminator + display field. Decoded from the payload shape; on encode it is supplied
|
|
87
|
+
//by the input (default 'other') and read by every field below to decide which bytes it
|
|
88
|
+
//owns. 'greeting' → {version, nMethods, methods}; 'other' → {version, data}.
|
|
89
|
+
messageType: {
|
|
90
|
+
type: 'string',
|
|
91
|
+
label: 'Message Type',
|
|
92
|
+
enum: ['greeting', 'other'],
|
|
93
|
+
default: 'other',
|
|
94
|
+
decode: function () {
|
|
95
|
+
this.instance.messageType.setValue(this.#isGreeting() ? 'greeting' : 'other');
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
//Common to every SOCKS5 message: the version octet (always 0x05). Structured for both
|
|
99
|
+
//shapes, so the verbatim `data` of a non-greeting holds only the bytes AFTER the version.
|
|
100
|
+
version: {
|
|
101
|
+
type: 'integer',
|
|
102
|
+
label: 'Version',
|
|
103
|
+
minimum: 0,
|
|
104
|
+
maximum: 255,
|
|
105
|
+
default: 5,
|
|
106
|
+
decode: function () {
|
|
107
|
+
this.instance.version.setValue(this.readBytes(0, 1).readUInt8(0));
|
|
108
|
+
},
|
|
109
|
+
encode: function () {
|
|
110
|
+
const node = this.instance.version;
|
|
111
|
+
let value = node.getValue(5, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
112
|
+
if (value > 255) {
|
|
113
|
+
this.recordError(node.getPath(), 'Maximum value is 255');
|
|
114
|
+
value = 255;
|
|
115
|
+
}
|
|
116
|
+
if (value < 0) {
|
|
117
|
+
this.recordError(node.getPath(), 'Minimum value is 0');
|
|
118
|
+
value = 0;
|
|
119
|
+
}
|
|
120
|
+
node.setValue(value);
|
|
121
|
+
this.writeBytes(0, Buffer.from([value]));
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
//GREETING shape: the count of authentication methods the client offers.
|
|
125
|
+
nMethods: {
|
|
126
|
+
type: 'integer',
|
|
127
|
+
label: 'Number of Methods',
|
|
128
|
+
minimum: 0,
|
|
129
|
+
maximum: 255,
|
|
130
|
+
default: 0,
|
|
131
|
+
decode: function () {
|
|
132
|
+
if (this.instance.messageType.getValue('other') !== 'greeting') {
|
|
133
|
+
this.instance.nMethods.setValue(0);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.instance.nMethods.setValue(this.readBytes(1, 1).readUInt8(0));
|
|
137
|
+
},
|
|
138
|
+
encode: function () {
|
|
139
|
+
if (this.instance.messageType.getValue('other') !== 'greeting')
|
|
140
|
+
return;
|
|
141
|
+
const node = this.instance.nMethods;
|
|
142
|
+
let value = node.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
143
|
+
if (value > 255) {
|
|
144
|
+
this.recordError(node.getPath(), 'Maximum value is 255');
|
|
145
|
+
value = 255;
|
|
146
|
+
}
|
|
147
|
+
if (value < 0) {
|
|
148
|
+
this.recordError(node.getPath(), 'Minimum value is 0');
|
|
149
|
+
value = 0;
|
|
150
|
+
}
|
|
151
|
+
node.setValue(value);
|
|
152
|
+
this.writeBytes(1, Buffer.from([value]));
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
//GREETING shape: the offered method identifiers, kept verbatim as hex. Bounded by nMethods
|
|
156
|
+
//AND by the captured bytes — a lying nMethods can never make this read past the buffer.
|
|
157
|
+
methods: {
|
|
158
|
+
type: 'string',
|
|
159
|
+
label: 'Methods',
|
|
160
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
161
|
+
default: '',
|
|
162
|
+
decode: function () {
|
|
163
|
+
if (this.instance.messageType.getValue('other') !== 'greeting') {
|
|
164
|
+
this.instance.methods.setValue('');
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const nMethods = this.instance.nMethods.getValue(0);
|
|
168
|
+
const remaining = this.#payloadLength() - 2;
|
|
169
|
+
const count = nMethods < remaining ? nMethods : (remaining < 0 ? 0 : remaining);
|
|
170
|
+
this.instance.methods.setValue(count > 0 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(2, count)) : '');
|
|
171
|
+
},
|
|
172
|
+
encode: function () {
|
|
173
|
+
if (this.instance.messageType.getValue('other') !== 'greeting')
|
|
174
|
+
return;
|
|
175
|
+
const methods = this.instance.methods.getValue('');
|
|
176
|
+
if (methods)
|
|
177
|
+
this.writeBytes(2, (0, HexToBuffer_1.HexToBuffer)(methods));
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
//NON-GREETING shape ('other'): every SOCKS5 message that is not a client greeting
|
|
181
|
+
//(method selection, request, reply) is kept BYTE-VERBATIM after the version octet — from
|
|
182
|
+
//offset 1 to the end of the captured bytes. Structuring the request/reply address is a
|
|
183
|
+
//later slice; this preserves the exact bytes and round-trips them untouched.
|
|
184
|
+
data: {
|
|
185
|
+
type: 'string',
|
|
186
|
+
label: 'Data',
|
|
187
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
188
|
+
default: '',
|
|
189
|
+
decode: function () {
|
|
190
|
+
if (this.instance.messageType.getValue('other') === 'greeting') {
|
|
191
|
+
this.instance.data.setValue('');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const remaining = this.#payloadLength() - 1;
|
|
195
|
+
this.instance.data.setValue(remaining > 0 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(1, remaining)) : '');
|
|
196
|
+
},
|
|
197
|
+
encode: function () {
|
|
198
|
+
if (this.instance.messageType.getValue('other') === 'greeting')
|
|
199
|
+
return;
|
|
200
|
+
const data = this.instance.data.getValue('');
|
|
201
|
+
if (data)
|
|
202
|
+
this.writeBytes(1, (0, HexToBuffer_1.HexToBuffer)(data));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
match() {
|
|
209
|
+
//Port-bucket (tcp:1080) + version-5 signature. Reached only on the tcp:1080 bucket.
|
|
210
|
+
if (!this.prevCodecModule)
|
|
211
|
+
return false;
|
|
212
|
+
if (this.prevCodecModule.id !== 'tcp')
|
|
213
|
+
return false;
|
|
214
|
+
const available = this.#payloadLength();
|
|
215
|
+
//Every SOCKS5 message is at least 2 octets (version + one more) and starts with version 0x05.
|
|
216
|
+
if (available < 2)
|
|
217
|
+
return false;
|
|
218
|
+
if (this.readBytes(0, 1, true).readUInt8(0) !== 5)
|
|
219
|
+
return false;
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
exports.SOCKS5 = SOCKS5;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
2
|
+
import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
|
|
3
|
+
import { DemuxProducer } from '../types/DemuxProducer';
|
|
4
|
+
/**
|
|
5
|
+
* SSDP — the Simple Service Discovery Protocol (UPnP Device Architecture), the discovery layer of UPnP
|
|
6
|
+
* carried over UDP port 1900 (advertisements/searches to the multicast group 239.255.255.250, unicast
|
|
7
|
+
* search responses). An SSDP message is HTTP/1.1-shaped US-ASCII text but is NOT HTTP: a start-line,
|
|
8
|
+
* then header lines, and a terminating CRLF. Requests use `NOTIFY * HTTP/1.1` (advertise) or
|
|
9
|
+
* `M-SEARCH * HTTP/1.1` (search); responses use a `HTTP/1.1 200 OK` Status-Line.
|
|
10
|
+
*
|
|
11
|
+
* Like SIP and HTTP, the message body is text whose full internal structure (HOST/NT/NTS/USN/ST/MAN/…
|
|
12
|
+
* header fields, significant whitespace/header ordering/casing) is far richer than a form needs. So the
|
|
13
|
+
* ENTIRE raw message is kept verbatim as the authoritative `message` field (hex) and re-emitted
|
|
14
|
+
* untouched; only the start-line is parsed on decode into display-only metadata (method/uri/version or
|
|
15
|
+
* status-code/reason). Encode never reconstructs the message from the parsed fields — it writes
|
|
16
|
+
* `message` back byte-for-byte — so any conformant (or even malformed) SSDP message round-trips exactly.
|
|
17
|
+
*/
|
|
18
|
+
export declare class SSDP extends BaseHeader {
|
|
19
|
+
#private;
|
|
20
|
+
get SCHEMA(): ProtocolJSONSchema;
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly nickname: string;
|
|
24
|
+
readonly matchKeys: string[];
|
|
25
|
+
match(): boolean;
|
|
26
|
+
readonly demuxProducers: DemuxProducer[];
|
|
27
|
+
}
|