Learn Host-Based Intrusion Detection
- Exercise 1: TCP Wrappers
- Exercise 2: xinetd
- Exercise 3: Tripwire
- Exercise 4: Swatch
- Exercise 5: PortSentry
- Exercise 6: Auditing Your System
Exercise 1: TCP Wrappers
Description
For a connection request to be serviced, a process needs to be active and listening on its well-known port (ports less than 1024). This means that processor capacity and memory must be allocated for each service that a server is going to host. In the early days of Unix, this was a very expensive waste of valuable, scarce resources.
To make more effective use of these resources, inetd was developed to act as a super listener or meta dameon for connection requests. When a request for a new session is received, inetd activates the appropriate service. For example, if a server is to host FTP, Telnet, and SMTP (email), there should be an active service listening to ports 21, 23, and 25, respectively. With inetd running, only one process listens to all three ports. If a request for a new Telnet session is received, then inetd starts the Telnet service on port 25 for the session.
While this is an effective means to minimize demands on the processor, it does nothing for security. Most significantly, it leaves security to be handled by each service. This, in turn, leads to inconsistent and often weak security implementations for the network services that inetd assists. For example, there are no security mechanisms involved in establishing a Telnet session. It leaves security to the login process, which enforces security on the basis of username and password. This makes the system vulnerable to brute-force, password attacks and can also leak potentially useful information through the login banner.
TCP Wrappers addresses this shortcoming of inetd by inserting itself into the middle of the process that establishes connections. It does this by changing the inetd configuration file, inetd.conf, so instead of inetd activating the requested service, it actually activates the TCP Wrappers daemon, in.tcpd. If TCP Wrappers determines that the connection can be allowed, then it starts the service process.
It is the goal of TCP Wrappers to log the origination of incoming connection attempts and to provide more granular control of the process. This approach also makes it easier to configure a server, and it is a more consistent approach for securing the server.
While TCP Wrappers greatly improves the security of a system, it is not without its own weaknesses. It can provide a false sense of security because some of its checks are inadequate and user authentication is not reliable. But, its biggest drawback is that it relies too strongly on IP addresses, which can be spoofed undetectably.
Newer versions of Linux have replaced TCP Wrappers with their own version called xinetd.
Objective
Red Hat Linux 7.2 uses xinetd instead of TCP Wrappers. Consequently, we will not complete a hands-on session with TCP Wrappers. However, if you have access to a system that uses TCP Wrappers, you can follow this exercise to configure it. Since this exercise will use TCP Wrappers, you will not be able to perform the steps if your system uses xinetd.
The primary objective of this exercise is to examine the configuration files used by TCP Wrappers to perform its functions.
Requirements
Permission
If you are going to review the configuration of a system that utilizes TCP Wrappers, you should obtain authorization from the legal owner and/or your management team prior to conducting this exercise.Hardware
NoneSoftware
None
Challenge Procedure
The following are the steps you need to perform for this exercise:
Examine an entry from inetd.conf for a system that doesn't use TCP Wrappers.
Modify the entry to utilize TCP Wrappers.
Configure a system to selectively allow connections.
Configure a system to selectively deny connections.
Challenge Procedure Step-by-Step
The following are the steps you are going to perform for this exercise:
-
First, you'll examine an entry from inetd.conf for a system that doesn't use TCP Wrappers. The inetd daemon knows how to manage the services it controls based on the entries in /etc/inetd.conf. This file is a space-delimited file that consists of a series of single-line entries. Each entry corresponds to a service that is invoked by inetd. Each standard service that inetd can start has a well-known port assigned to it. Each service must have a valid entry in /etc/services. In the case of an internal service, its name must correspond to the official name of the service, which is the first field of the service entry in /etc/services. The following figure shows a sample entry from inetd.conf.
-
Modify the entry to utilize TCP Wrappers. Do this by logging in as root and then changing the directory to /etc:
-
Start vi to edit inetd.conf:
Change the daemon program from in.ftpd to in.tcpd.
-
Now, move your cursor to the f in /usr/sbin/in.ftpd.
-
Press Shift+R, and then type tcp. This should cause vi to overwrite the entry with TCP. Press the Esc key to exit overtype mode. Press ZZ to save the change and exit vi.
-
Next, you'll configure the system to selectively allow connections. After inetd has been configured, it is necessary to configure TCP Wrappers to tell it what connections to grant or deny. Two files are used for this purpose/etc/hosts.allow and /etc/hosts.deny. As their names imply, hosts.allow defines what connections to allow, and hosts.deny defines what connections to deny.
-
Start vi to edit hosts.deny:
-
Delete any other entries in the file. Press the colon (:) key. Your cursor should go to the bottom-left position on the screen. Type the following command:
-
Type a to append to the line. Make the following entry in the file:
-
Press Esc to exit append mode. Press ZZ to save the change and exit vi. Configure /etc/hosts.allow. To do this, start vi to edit hosts.allow:
-
Delete any other entries in the file. Press the colon key. Your cursor should go to the bottom-left position on the screen. Type the following command:
Type a to append to the line. Enter the following:
Press Esc to exit append mode. Press ZZ to save the change and exit vi.
-
Next, you'll configure a system to selectively deny connections. In this example, you set up a system with an allow-all-except policy. Since the system has been experiencing a lot of attacks from blackhats.com, systems from that domain will be denied access. All others will be granted access.
-
Configure hosts.deny. To do this, log in as root, and then change the directory to /etc:
-
Start vi to edit hosts.deny:
-
Delete any other entries in the file. Press the colon key. Your cursor should go to the bottom-left position on the screen. Type this command:
Type a to append to the line. Make the following entry into the file:
Press Esc to exit append mode. Press ZZ to save the change and exit vi.
-
Remove the hosts.allow file. By deleting hosts.allow it will not be processed, leaving hosts.deny as the only file to define access rights. To delete hosts.allow, enter the following command:
cd /etc
vi inetd.conf
The easiest approach to configuring TCP Wrappers is to determine the default network policy and then configure the files accordingly. It is very important to note that the hosts.allow file is processed before hosts.deny. This means that you should be careful not to make any entries in hosts.allow that may accidentally grant access to a system that is denied access in hosts.deny. In other words, if the default network policy is to deny all network connections except for a limited few, then you should configure hosts.deny to deny everyone and hosts.allow to allow only a few connections. But, if your default policy is to allow everyone except for a limited few, you should not configure hosts.allow to allow everyone and hosts.deny to deny a few. In this case, since there is a match in hosts.allow, hosts.deny will never be processed.
In this example, we will set up a system with a deny-all-except policy. Only systems from the sans.org domain will be granted access.
Configure /etc/hosts.deny. To do this, log in as root and change the directory to /etc:
cd /etc
vi hosts.deny
1,$d
Then, press Enter.
ALL : ALL
vi hosts.allow
1,$d
Then, press Enter.
ALL : .sans.org
cd /etc
vi hosts.deny
1,$d
Then, press Enter.
ALL : .blackhats.com
rm /etc/hosts.allow
Additional Reading
Arruda, Stacy M. "TCP WRAPPERSWhat Are They?" SANS Institute, http://www.sans.org/infosecFAQ/unix/TCP_wrappers2.htm.
Venema, Wietse. "The Development of TCP Wrappers," Presented to the Third UNIX Security Symposium, http://uiarchive.uiuc.edu/mirrors/ftp/ftp.porcupine.org/pub/security/tcp_wrapper.txt.Z.
Summary
TCP Wrappers provides a significant security enhancement to Unix-based systems. With it, you gain greater control over who can have access to your system's resources. But, don't let TCP Wrappers give you a false sense of security. It is also vulnerable to spoofing attacks.
In addition to increased access control, TCP Wrappers logs all incoming connection requests. Even if the login is successful, this information can still be useful for indicating if a system has been penetrated. For example, a review of the logs could indicate connections at unusual times. This may be an indication that the user's account has been compromised and is being used by another person. It may also indicate that a user is performing activities he is not normally authorized to perform.