⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socks4.protocol

📁 Linux下的socks的程序源程序,用于socks的代理服务
💻 PROTOCOL
字号:
	SOCKS: A protocol for TCP proxy across firewalls			Ying-Da Lee		Principal Member Technical Staff		  NEC Systems Laboratory, CSTC			ylee@syl.dl.nec.comSOCKS was originally developed by David Koblas and subsequently modifiedand extended by me to its current running version -- version 4. It is aprotocol that relays TCP sessions at a firewall host to allow applicationusers transparent access across the firewall. Because the protocol isindependent of application protocols, it can be (and has been) used formany different services, such as telnet, ftp, finger, whois, gopher, WWW,etc. Access control can be applied at the beginning of each TCP session;thereafter the server simply relays the data between the client and theapplication server, incurring minimum processing overhead. Since SOCKSnever has to know anything about the application protocol, it should alsobe easy for it to accommodate applications which use encryption to protecttheir traffic from nosey snoopers.Two operations are defined: CONNECT and BIND.1) CONNECTThe client connects to the SOCKS server and sends a CONNECT request whenit wants to establish a connection to an application server. The clientincludes in the request packet the IP address and the port number of thedestination host, and userid, in the following format.		+----+----+----+----+----+----+----+----+----+----+....+----+		| VN | CD | DSTPORT |      DSTIP        | USERID       |NULL|		+----+----+----+----+----+----+----+----+----+----+....+----+ # of bytes:	   1    1      2              4           variable       1VN is the SOCKS protocol version number and should be 4. CD is theSOCKS command code and should be 1 for CONNECT request. NULL is a byteof all zero bits.The SOCKS server checks to see whether such a request should be grantedbased on any combination of source IP address, destination IP address,destination port number, the userid, and information it may obtain byconsulting IDENT, cf. RFC 1413.  If the request is granted, the SOCKSserver makes a connection to the specified port of the destination host.A reply packet is sent to the client when this connection is established,or when the request is rejected or the operation fails. 		+----+----+----+----+----+----+----+----+		| VN | CD | DSTPORT |      DSTIP        |		+----+----+----+----+----+----+----+----+ # of bytes:	   1    1      2              4VN is the version of the reply code and should be 0. CD is the resultcode with one of the following values:	90: request granted	91: request rejected or failed	92: request rejected becasue SOCKS server cannot connect to	    identd on the client	93: request rejected because the client program and identd	    report different user-idsThe remaining fields are ignored.The SOCKS server closes its connection immediately after notifyingthe client of a failed or rejected request. For a successful request,the SOCKS server gets ready to relay traffic on both directions. Thisenables the client to do I/O on its connection as if it were directlyconnected to the application server.2) BINDThe client connects to the SOCKS server and sends a BIND request whenit wants to prepare for an inbound connection from an application server.This should only happen after a primary connection to the applicationserver has been established with a CONNECT.  Typically, this is part ofthe sequence of actions:-bind(): obtain a socket-getsockname(): get the IP address and port number of the socket-listen(): ready to accept call from the application server-use the primary connection to inform the application server of the IP address and the port number that it should connect to.-accept(): accept a connection from the application serverThe purpose of SOCKS BIND operation is to support such a sequencebut using a socket on the SOCKS server rather than on the client.The client includes in the request packet the IP address of theapplication server, the destination port used in the primary connection,and the userid.		+----+----+----+----+----+----+----+----+----+----+....+----+		| VN | CD | DSTPORT |      DSTIP        | USERID       |NULL|		+----+----+----+----+----+----+----+----+----+----+....+----+ # of bytes:	   1    1      2              4           variable       1VN is again 4 for the SOCKS protocol version number. CD must be 2 toindicate BIND request.The SOCKS server uses the client information to decide whether therequest is to be granted. The reply it sends back to the client hasthe same format as the reply for CONNECT request, i.e.,		+----+----+----+----+----+----+----+----+		| VN | CD | DSTPORT |      DSTIP        |		+----+----+----+----+----+----+----+----+ # of bytes:	   1    1      2              4VN is the version of the reply code and should be 0. CD is the resultcode with one of the following values:	90: request granted	91: request rejected or failed	92: request rejected becasue SOCKS server cannot connect to	    identd on the client	93: request rejected because the client program and identd	    report different user-ids.However, for a granted request (CD is 90), the DSTPORT and DSTIP fieldsare meaningful.  In that case, the SOCKS server obtains a socket to waitfor an incoming connection and sends the port number and the IP addressof that socket to the client in DSTPORT and DSTIP, respectively. If theDSTIP in the reply is 0 (the value of constant INADDR_ANY), then theclient should replace it by the IP address of the SOCKS server to whichthe cleint is connected. (This happens if the SOCKS server is not amulti-homed host.)  In the typical scenario, these two numbers aremade available to the application client prgram via the result of thesubsequent getsockname() call.  The application protocol must provide away for these two pieces of information to be sent from the client tothe application server so that it can initiate the connection, whichconnects it to the SOCKS server rather than directly to the applicationclient as it normally would.The SOCKS server sends a second reply packet to the client when theanticipated connection from the application server is established.The SOCKS server checks the IP address of the originating host againstthe value of DSTIP specified in the client's BIND request.  If a mismatchis found, the CD field in the second reply is set to 91 and the SOCKSserver closes both connections.  If the two match, CD in the secondreply is set to 90 and the SOCKS server gets ready to relay the trafficon its two connections. From then on the client does I/O on its connectionto the SOCKS server as if it were directly connected to the applicationserver.For both CONNECT and BIND operations, the server sets a time limit(2 minutes in current CSTC implementation) for the establishment of itsconnection with the application server. If the connection is still notestabliched when the time limit expires, the server closes its connectionto the client and gives up.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -