22.4 SOCKSSOCKS is a system that allows computers behind a firewall to access services on the Internet. The program allows you to centrally control how programs on your organization's network communicate with the Internet. With SOCKS , you can allow specific services to specific computers, disable access to individual hosts on the Internet, and log as much or as little as you want. SOCKS was originally written by David Koblas and Michelle Koblas. It has since been extended by Ying-Da Lee at NEC 's Systems Laboratory, and a commercially supported version is available from NEC . The name SOCKS stands for " SOCK -et-S." According to the SOCKS FAQ , "it was one of those `development names' that never left." SOCKS consists of two parts:
The standard SOCKS distribution comes with client programs for finger , ftp , telnet , and whois . SOCKS also includes a library you can use to create other SOCKS clients at will. Furthermore, many programs, such as NCSA Mosaic, include provisions for using SOCKS to negotiate firewalls. SOCKS is available for most versions of UNIX , including SunOS, Sun Solaris, IRIX , Ultrix, HP-UX , AIX , Interactive Systems UNIX , OSF /1, Net BSD , UNIX Ware, and Linux. A version called PC SOCKS , by Cornell Kinderknecht, is available for Microsoft Windows. A Macintosh version is under development. 22.4.1 What SOCKS DoesThe SOCKS client software works by replacing calls to the UNIX socket functions - connect (), getsocketname (), bind (), accept (), listen () and select () - with its own versions of these functions. In practice, this replacement is done by adding a few macro definitions to the CFLAGS in the Makefile of the program that is used to compile the network client program, and then linking the resulting program with the SOCKS library. When a SOCKS -modified client attempts to connect to a server on the Internet, the SOCKS library intercepts the connection attempt and instead opens up a connection to the SOCKS server. After the connection is established, the SOCKS client sends through the following information:
The SOCKS server then checks its access control list to see if the connection should be accepted or rejected. If the connection is accepted, the server opens up a connection to the remote machine and then relays all information back and forth. If the connection is rejected, the server disconnects from the client. This configuration is shown graphically in Figure 22.1 . Figure 22.1: : Using SOCKS for proxyingSOCKS can also be used to allow computers behind a firewall to receive connections. In this case, a connection is opened to the SOCKS server, which in turn gets ready to accept connections from the Internet. SOCKS works only with TCP/IP ; for UDP services (such as Archie), use UDP Relayer as described later in this chapter. 22.4.2 Getting SOCKSSocks may be freely downloaded from the Internet. The address is:
If you operate two nameservers to hide information from the Internet, you will also need to download the file Rgethostbyname.c . This file contains a function that can be used to query multiple nameservers to resolve a hostname. There is a mailing list devoted to SOCKS and related issues. To join it, send the message "subscribe socks your-email-address " to majordomo@syl.dl.nec.com.
22.4.3 Getting SOCKS RunningAfter you have downloaded the system, you will need to follow these steps to get the system running:
22.4.4 SOCKS and UsernamesSOCKS permits you to allow or deny access to Internet services based on both IP address and the username of the person on the local network making the request. There are two ways that SOCKS can determine the username of a person on the internal network:
22.4.5 SOCKS Identification PolicyThe choice of identification policy is determined by the way in which the sockd program is invoked and by the /etc/sockd.conf configuration file. Normally, sockd is invoked with one of three options: sockd [-ver | -i | -I] These options have the following meanings:
The identification options -i and -I can be overridden by a statement in the SOCKS configuration file, /etc/sockd.conf. 22.4.6 The SOCKS Server Configuration File: /etc/sockd.confThe sockd configuration file, /etc/sockd.conf, allows you to control which TCP/IP connections are passed by the sockd daemon. As the daemon usually runs on a computer that has access to both your organization's internal network and the Internet, the sockd.conf file controls, in part, which services are passed between the two. The sockd program doesn't know the difference between your internal and external networks. It simply receives connections, determines the parameters of the connections (username, source, requested destination, and TCP/IP service), then scans rules in the /etc/sockd.conf file to determine if the connections should be permitted or denied. The /etc/sockd.conf file is an ASCII text file. Each line consists of a rule to either allow connections or reject (deny) them. The sockd program scans the file from the first line to the last line until a match is found. When a match is found, the action specified by the line is followed. Lines in the /etc/sockd.conf file may be up to 1023 characters long. Each line has the following form: [allow | deny] [?=auth] [*=username(s)|filename(s)] source-address source-mask [destination-address destination-mask] [operator destination-port] [: shell-command] Fields are separated by spaces or tabs. If a number sign (#) is found on the line, everything after the number sign is assumed to be a comment, except as noted below. If an incoming TCP/IP connection does not match any of the lines in the /etc/sockd.conf configuration file, it is rejected. Here is an explanation of the fields:
Obviously, token expansions that require that sockd look up a value in a database (such as %A, %S, and %Z) will take longer to execute than token expansions that merely report an IP or port number (such as %a, %s and %z). This example command runs finger to determine the users on a particular computer, and then sends the results to the root account of the computer that is running sockd: /usr/ucb/finger @%A | /bin/mailx -s 'SOCKS: rejected %u@%A' root 22.4.6.1 #NO_IDENTD and #BAD_IDIn addition to the pattern matching described above, sockd allows you to specify rules that will match any computer contacting the sockd daemon which is not running the ident protocol, or for which the username returned by the ident protocol is different from the username provided in the initial sockd contact. These lines have the form: #NO_IDENTD: command #BAD_ID: command 22.4.6.2 Example /etc/sockd.conf configuration filesHere are some example lines from an /etc/sockd.conf configuration file. The configuration file is designed to protect an organization that has placed a set of UNIX workstations on IP subnet 204.99.90.
This rather complex rule denies any attempted login to the organization's internal network. In addition to stopping the logins, it also does a finger of the computer from where the attempt is coming and sends email to the root account of the computer running sockd . If the remote machine is running the ident protocol, the username will be sent as well.
22.4.7 SOCKS Client Configuration File: /etc/socks.confEach client that wishes to use the sockd server must also have its own configuration file. The configuration file has a syntax that is similar to, but slightly different from, the syntax of the /etc/sockd .conf file. When a SOCKS client attempts to make an outgoing connection to another host on the Internet, or when it calls the Rbind() function to accept an incoming connection, the SOCKS library scans the /etc/socks.conf configuration file line by line, starting with the first line, until it finds a line that matches the requested connection. The library then performs the action that is specified in the file. Each line in the file can have the following form: deny [*=username(s)|filename(s)] destination-address destination-mask [operator destination-port] [: shell-command] direct [*=username(s)|filename(s)] destination-address destination-mask [operator destination-port] [: shell-command] sockd [@=serverlist] [*=username(s)|filename(s)] destination-address destination-mask [operator destination-port] [: shell-command] Most of these fields are similar to those in the /etc/sockd.conf file. The differences are described below:
sockd @=socks1,socks2,sock3 0.0.0.0 0.0.0.0 In SOCKS version 4.2, the servers are tried in the order in which they appear in the configuration file. Thus, you can specify different servers in different orders on different clients to distribute the load. (A more intelligent approach, though, would be for the servers to be tried in random order.) 22.4.7.1 Example /etc/socks.conf fileThis simple configuration file, for an organization administrating the subnet 204.90.80, specifies that all connections to organization's internal subnet should go direct, while all connections to the outside network should go through the SOCKS server: direct 204.90.80.0 255.255.255.0 sockd @=socks-server 0.0.0.0 0.0.0.0 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|