A SOCKS (SOCKS4, SOCKS4A and SOCKS5) Proxy Package for Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

508 lines
19 KiB

  1. Network Working Group M. Leech
  2. Request for Comments: 1928 Bell-Northern Research Ltd
  3. Category: Standards Track M. Ganis
  4. International Business Machines
  5. Y. Lee
  6. NEC Systems Laboratory
  7. R. Kuris
  8. Unify Corporation
  9. D. Koblas
  10. Independent Consultant
  11. L. Jones
  12. Hewlett-Packard Company
  13. March 1996
  14. SOCKS Protocol Version 5
  15. Status of this Memo
  16. This document specifies an Internet standards track protocol for the
  17. Internet community, and requests discussion and suggestions for
  18. improvements. Please refer to the current edition of the "Internet
  19. Official Protocol Standards" (STD 1) for the standardization state
  20. and status of this protocol. Distribution of this memo is unlimited.
  21. Acknowledgments
  22. This memo describes a protocol that is an evolution of the previous
  23. version of the protocol, version 4 [1]. This new protocol stems from
  24. active discussions and prototype implementations. The key
  25. contributors are: Marcus Leech: Bell-Northern Research, David Koblas:
  26. Independent Consultant, Ying-Da Lee: NEC Systems Laboratory, LaMont
  27. Jones: Hewlett-Packard Company, Ron Kuris: Unify Corporation, Matt
  28. Ganis: International Business Machines.
  29. 1. Introduction
  30. The use of network firewalls, systems that effectively isolate an
  31. organizations internal network structure from an exterior network,
  32. such as the INTERNET is becoming increasingly popular. These
  33. firewall systems typically act as application-layer gateways between
  34. networks, usually offering controlled TELNET, FTP, and SMTP access.
  35. With the emergence of more sophisticated application layer protocols
  36. designed to facilitate global information discovery, there exists a
  37. need to provide a general framework for these protocols to
  38. transparently and securely traverse a firewall.
  39. Leech, et al Standards Track [Page 1]
  40. RFC 1928 SOCKS Protocol Version 5 March 1996
  41. There exists, also, a need for strong authentication of such
  42. traversal in as fine-grained a manner as is practical. This
  43. requirement stems from the realization that client-server
  44. relationships emerge between the networks of various organizations,
  45. and that such relationships need to be controlled and often strongly
  46. authenticated.
  47. The protocol described here is designed to provide a framework for
  48. client-server applications in both the TCP and UDP domains to
  49. conveniently and securely use the services of a network firewall.
  50. The protocol is conceptually a "shim-layer" between the application
  51. layer and the transport layer, and as such does not provide network-
  52. layer gateway services, such as forwarding of ICMP messages.
  53. 2. Existing practice
  54. There currently exists a protocol, SOCKS Version 4, that provides for
  55. unsecured firewall traversal for TCP-based client-server
  56. applications, including TELNET, FTP and the popular information-
  57. discovery protocols such as HTTP, WAIS and GOPHER.
  58. This new protocol extends the SOCKS Version 4 model to include UDP,
  59. and extends the framework to include provisions for generalized
  60. strong authentication schemes, and extends the addressing scheme to
  61. encompass domain-name and V6 IP addresses.
  62. The implementation of the SOCKS protocol typically involves the
  63. recompilation or relinking of TCP-based client applications to use
  64. the appropriate encapsulation routines in the SOCKS library.
  65. Note:
  66. Unless otherwise noted, the decimal numbers appearing in packet-
  67. format diagrams represent the length of the corresponding field, in
  68. octets. Where a given octet must take on a specific value, the
  69. syntax X'hh' is used to denote the value of the single octet in that
  70. field. When the word 'Variable' is used, it indicates that the
  71. corresponding field has a variable length defined either by an
  72. associated (one or two octet) length field, or by a data type field.
  73. 3. Procedure for TCP-based clients
  74. When a TCP-based client wishes to establish a connection to an object
  75. that is reachable only via a firewall (such determination is left up
  76. to the implementation), it must open a TCP connection to the
  77. appropriate SOCKS port on the SOCKS server system. The SOCKS service
  78. is conventionally located on TCP port 1080. If the connection
  79. request succeeds, the client enters a negotiation for the
  80. Leech, et al Standards Track [Page 2]
  81. RFC 1928 SOCKS Protocol Version 5 March 1996
  82. authentication method to be used, authenticates with the chosen
  83. method, then sends a relay request. The SOCKS server evaluates the
  84. request, and either establishes the appropriate connection or denies
  85. it.
  86. Unless otherwise noted, the decimal numbers appearing in packet-
  87. format diagrams represent the length of the corresponding field, in
  88. octets. Where a given octet must take on a specific value, the
  89. syntax X'hh' is used to denote the value of the single octet in that
  90. field. When the word 'Variable' is used, it indicates that the
  91. corresponding field has a variable length defined either by an
  92. associated (one or two octet) length field, or by a data type field.
  93. The client connects to the server, and sends a version
  94. identifier/method selection message:
  95. +----+----------+----------+
  96. |VER | NMETHODS | METHODS |
  97. +----+----------+----------+
  98. | 1 | 1 | 1 to 255 |
  99. +----+----------+----------+
  100. The VER field is set to X'05' for this version of the protocol. The
  101. NMETHODS field contains the number of method identifier octets that
  102. appear in the METHODS field.
  103. The server selects from one of the methods given in METHODS, and
  104. sends a METHOD selection message:
  105. +----+--------+
  106. |VER | METHOD |
  107. +----+--------+
  108. | 1 | 1 |
  109. +----+--------+
  110. If the selected METHOD is X'FF', none of the methods listed by the
  111. client are acceptable, and the client MUST close the connection.
  112. The values currently defined for METHOD are:
  113. o X'00' NO AUTHENTICATION REQUIRED
  114. o X'01' GSSAPI
  115. o X'02' USERNAME/PASSWORD
  116. o X'03' to X'7F' IANA ASSIGNED
  117. o X'80' to X'FE' RESERVED FOR PRIVATE METHODS
  118. o X'FF' NO ACCEPTABLE METHODS
  119. The client and server then enter a method-specific sub-negotiation.
  120. Leech, et al Standards Track [Page 3]
  121. RFC 1928 SOCKS Protocol Version 5 March 1996
  122. Descriptions of the method-dependent sub-negotiations appear in
  123. separate memos.
  124. Developers of new METHOD support for this protocol should contact
  125. IANA for a METHOD number. The ASSIGNED NUMBERS document should be
  126. referred to for a current list of METHOD numbers and their
  127. corresponding protocols.
  128. Compliant implementations MUST support GSSAPI and SHOULD support
  129. USERNAME/PASSWORD authentication methods.
  130. 4. Requests
  131. Once the method-dependent subnegotiation has completed, the client
  132. sends the request details. If the negotiated method includes
  133. encapsulation for purposes of integrity checking and/or
  134. confidentiality, these requests MUST be encapsulated in the method-
  135. dependent encapsulation.
  136. The SOCKS request is formed as follows:
  137. +----+-----+-------+------+----------+----------+
  138. |VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT |
  139. +----+-----+-------+------+----------+----------+
  140. | 1 | 1 | X'00' | 1 | Variable | 2 |
  141. +----+-----+-------+------+----------+----------+
  142. Where:
  143. o VER protocol version: X'05'
  144. o CMD
  145. o CONNECT X'01'
  146. o BIND X'02'
  147. o UDP ASSOCIATE X'03'
  148. o RSV RESERVED
  149. o ATYP address type of following address
  150. o IP V4 address: X'01'
  151. o DOMAINNAME: X'03'
  152. o IP V6 address: X'04'
  153. o DST.ADDR desired destination address
  154. o DST.PORT desired destination port in network octet
  155. order
  156. The SOCKS server will typically evaluate the request based on source
  157. and destination addresses, and return one or more reply messages, as
  158. appropriate for the request type.
  159. Leech, et al Standards Track [Page 4]
  160. RFC 1928 SOCKS Protocol Version 5 March 1996
  161. 5. Addressing
  162. In an address field (DST.ADDR, BND.ADDR), the ATYP field specifies
  163. the type of address contained within the field:
  164. o X'01'
  165. the address is a version-4 IP address, with a length of 4 octets
  166. o X'03'
  167. the address field contains a fully-qualified domain name. The first
  168. octet of the address field contains the number of octets of name that
  169. follow, there is no terminating NUL octet.
  170. o X'04'
  171. the address is a version-6 IP address, with a length of 16 octets.
  172. 6. Replies
  173. The SOCKS request information is sent by the client as soon as it has
  174. established a connection to the SOCKS server, and completed the
  175. authentication negotiations. The server evaluates the request, and
  176. returns a reply formed as follows:
  177. +----+-----+-------+------+----------+----------+
  178. |VER | REP | RSV | ATYP | BND.ADDR | BND.PORT |
  179. +----+-----+-------+------+----------+----------+
  180. | 1 | 1 | X'00' | 1 | Variable | 2 |
  181. +----+-----+-------+------+----------+----------+
  182. Where:
  183. o VER protocol version: X'05'
  184. o REP Reply field:
  185. o X'00' succeeded
  186. o X'01' general SOCKS server failure
  187. o X'02' connection not allowed by ruleset
  188. o X'03' Network unreachable
  189. o X'04' Host unreachable
  190. o X'05' Connection refused
  191. o X'06' TTL expired
  192. o X'07' Command not supported
  193. o X'08' Address type not supported
  194. o X'09' to X'FF' unassigned
  195. o RSV RESERVED
  196. o ATYP address type of following address
  197. Leech, et al Standards Track [Page 5]
  198. RFC 1928 SOCKS Protocol Version 5 March 1996
  199. o IP V4 address: X'01'
  200. o DOMAINNAME: X'03'
  201. o IP V6 address: X'04'
  202. o BND.ADDR server bound address
  203. o BND.PORT server bound port in network octet order
  204. Fields marked RESERVED (RSV) must be set to X'00'.
  205. If the chosen method includes encapsulation for purposes of
  206. authentication, integrity and/or confidentiality, the replies are
  207. encapsulated in the method-dependent encapsulation.
  208. CONNECT
  209. In the reply to a CONNECT, BND.PORT contains the port number that the
  210. server assigned to connect to the target host, while BND.ADDR
  211. contains the associated IP address. The supplied BND.ADDR is often
  212. different from the IP address that the client uses to reach the SOCKS
  213. server, since such servers are often multi-homed. It is expected
  214. that the SOCKS server will use DST.ADDR and DST.PORT, and the
  215. client-side source address and port in evaluating the CONNECT
  216. request.
  217. BIND
  218. The BIND request is used in protocols which require the client to
  219. accept connections from the server. FTP is a well-known example,
  220. which uses the primary client-to-server connection for commands and
  221. status reports, but may use a server-to-client connection for
  222. transferring data on demand (e.g. LS, GET, PUT).
  223. It is expected that the client side of an application protocol will
  224. use the BIND request only to establish secondary connections after a
  225. primary connection is established using CONNECT. In is expected that
  226. a SOCKS server will use DST.ADDR and DST.PORT in evaluating the BIND
  227. request.
  228. Two replies are sent from the SOCKS server to the client during a
  229. BIND operation. The first is sent after the server creates and binds
  230. a new socket. The BND.PORT field contains the port number that the
  231. SOCKS server assigned to listen for an incoming connection. The
  232. BND.ADDR field contains the associated IP address. The client will
  233. typically use these pieces of information to notify (via the primary
  234. or control connection) the application server of the rendezvous
  235. address. The second reply occurs only after the anticipated incoming
  236. connection succeeds or fails.
  237. Leech, et al Standards Track [Page 6]
  238. RFC 1928 SOCKS Protocol Version 5 March 1996
  239. In the second reply, the BND.PORT and BND.ADDR fields contain the
  240. address and port number of the connecting host.
  241. UDP ASSOCIATE
  242. The UDP ASSOCIATE request is used to establish an association within
  243. the UDP relay process to handle UDP datagrams. The DST.ADDR and
  244. DST.PORT fields contain the address and port that the client expects
  245. to use to send UDP datagrams on for the association. The server MAY
  246. use this information to limit access to the association. If the
  247. client is not in possesion of the information at the time of the UDP
  248. ASSOCIATE, the client MUST use a port number and address of all
  249. zeros.
  250. A UDP association terminates when the TCP connection that the UDP
  251. ASSOCIATE request arrived on terminates.
  252. In the reply to a UDP ASSOCIATE request, the BND.PORT and BND.ADDR
  253. fields indicate the port number/address where the client MUST send
  254. UDP request messages to be relayed.
  255. Reply Processing
  256. When a reply (REP value other than X'00') indicates a failure, the
  257. SOCKS server MUST terminate the TCP connection shortly after sending
  258. the reply. This must be no more than 10 seconds after detecting the
  259. condition that caused a failure.
  260. If the reply code (REP value of X'00') indicates a success, and the
  261. request was either a BIND or a CONNECT, the client may now start
  262. passing data. If the selected authentication method supports
  263. encapsulation for the purposes of integrity, authentication and/or
  264. confidentiality, the data are encapsulated using the method-dependent
  265. encapsulation. Similarly, when data arrives at the SOCKS server for
  266. the client, the server MUST encapsulate the data as appropriate for
  267. the authentication method in use.
  268. 7. Procedure for UDP-based clients
  269. A UDP-based client MUST send its datagrams to the UDP relay server at
  270. the UDP port indicated by BND.PORT in the reply to the UDP ASSOCIATE
  271. request. If the selected authentication method provides
  272. encapsulation for the purposes of authenticity, integrity, and/or
  273. confidentiality, the datagram MUST be encapsulated using the
  274. appropriate encapsulation. Each UDP datagram carries a UDP request
  275. header with it:
  276. Leech, et al Standards Track [Page 7]
  277. RFC 1928 SOCKS Protocol Version 5 March 1996
  278. +----+------+------+----------+----------+----------+
  279. |RSV | FRAG | ATYP | DST.ADDR | DST.PORT | DATA |
  280. +----+------+------+----------+----------+----------+
  281. | 2 | 1 | 1 | Variable | 2 | Variable |
  282. +----+------+------+----------+----------+----------+
  283. The fields in the UDP request header are:
  284. o RSV Reserved X'0000'
  285. o FRAG Current fragment number
  286. o ATYP address type of following addresses:
  287. o IP V4 address: X'01'
  288. o DOMAINNAME: X'03'
  289. o IP V6 address: X'04'
  290. o DST.ADDR desired destination address
  291. o DST.PORT desired destination port
  292. o DATA user data
  293. When a UDP relay server decides to relay a UDP datagram, it does so
  294. silently, without any notification to the requesting client.
  295. Similarly, it will drop datagrams it cannot or will not relay. When
  296. a UDP relay server receives a reply datagram from a remote host, it
  297. MUST encapsulate that datagram using the above UDP request header,
  298. and any authentication-method-dependent encapsulation.
  299. The UDP relay server MUST acquire from the SOCKS server the expected
  300. IP address of the client that will send datagrams to the BND.PORT
  301. given in the reply to UDP ASSOCIATE. It MUST drop any datagrams
  302. arriving from any source IP address other than the one recorded for
  303. the particular association.
  304. The FRAG field indicates whether or not this datagram is one of a
  305. number of fragments. If implemented, the high-order bit indicates
  306. end-of-fragment sequence, while a value of X'00' indicates that this
  307. datagram is standalone. Values between 1 and 127 indicate the
  308. fragment position within a fragment sequence. Each receiver will
  309. have a REASSEMBLY QUEUE and a REASSEMBLY TIMER associated with these
  310. fragments. The reassembly queue must be reinitialized and the
  311. associated fragments abandoned whenever the REASSEMBLY TIMER expires,
  312. or a new datagram arrives carrying a FRAG field whose value is less
  313. than the highest FRAG value processed for this fragment sequence.
  314. The reassembly timer MUST be no less than 5 seconds. It is
  315. recommended that fragmentation be avoided by applications wherever
  316. possible.
  317. Implementation of fragmentation is optional; an implementation that
  318. does not support fragmentation MUST drop any datagram whose FRAG
  319. field is other than X'00'.
  320. Leech, et al Standards Track [Page 8]
  321. RFC 1928 SOCKS Protocol Version 5 March 1996
  322. The programming interface for a SOCKS-aware UDP MUST report an
  323. available buffer space for UDP datagrams that is smaller than the
  324. actual space provided by the operating system:
  325. o if ATYP is X'01' - 10+method_dependent octets smaller
  326. o if ATYP is X'03' - 262+method_dependent octets smaller
  327. o if ATYP is X'04' - 20+method_dependent octets smaller
  328. 8. Security Considerations
  329. This document describes a protocol for the application-layer
  330. traversal of IP network firewalls. The security of such traversal is
  331. highly dependent on the particular authentication and encapsulation
  332. methods provided in a particular implementation, and selected during
  333. negotiation between SOCKS client and SOCKS server.
  334. Careful consideration should be given by the administrator to the
  335. selection of authentication methods.
  336. 9. References
  337. [1] Koblas, D., "SOCKS", Proceedings: 1992 Usenix Security Symposium.
  338. Author's Address
  339. Marcus Leech
  340. Bell-Northern Research Ltd
  341. P.O. Box 3511, Stn. C,
  342. Ottawa, ON
  343. CANADA K1Y 4H7
  344. Phone: (613) 763-9145
  345. EMail: mleech@bnr.ca
  346. Leech, et al Standards Track [Page 9]