Home > Articles > Security > General Security and Privacy

Learn Host-Based Intrusion Detection

Follow the step-by-step examples to learn how to use five major host-based intrusion detection tools: TCP Wrappers, xinetd, Tripwire, Swatch, and PortSentry. You will also be introduced to simple tools that can be used to create powerful baseline and auditing methods for your systems.
This chapter is from the book

Exercise 1: TCP Wrappers


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.


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.


  • 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

  • Software

Challenge Procedure

The following are the steps you need to perform for this exercise:

  1. Examine an entry from inetd.conf for a system that doesn't use TCP Wrappers.

  2. Modify the entry to utilize TCP Wrappers.

  3. Configure a system to selectively allow connections.

  4. 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:

  1. 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.

  2. Figure 3.1

  3. Modify the entry to utilize TCP Wrappers. Do this by logging in as root and then changing the directory to /etc:

  4. cd /etc

  5. Start vi to edit inetd.conf:

  6. vi inetd.conf

  7. Change the daemon program from in.ftpd to in.tcpd.

  8. Figure 3.2

  9. Now, move your cursor to the f in /usr/sbin/in.ftpd.

  10. Figure 3.3

  11. 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.

  12. 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.

  13. 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

  14. Start vi to edit hosts.deny:

  15. vi hosts.deny

  16. 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:

  17. 1,$d

    Then, press Enter.

    Figure 3.4

  18. Type a to append to the line. Make the following entry in the file:

  19. ALL : ALL

    Figure 3.5

  20. 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:

  21. vi hosts.allow

  22. 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:

  23. 1,$d

    Then, press Enter.

    Figure 3.6

  24. Type a to append to the line. Enter the following:

  25. ALL : .sans.org

    Figure 3.7

  26. Press Esc to exit append mode. Press ZZ to save the change and exit vi.

  27. 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.

  28. Configure hosts.deny. To do this, log in as root, and then change the directory to /etc:

  29. cd /etc

  30. Start vi to edit hosts.deny:

  31. vi hosts.deny

  32. 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:

  33. 1,$d

    Then, press Enter.

    Figure 3.8

  34. Type a to append to the line. Make the following entry into the file:

  35. ALL : .blackhats.com

    Figure 3.9

  36. Press Esc to exit append mode. Press ZZ to save the change and exit vi.

  37. 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:

  38. rm /etc/hosts.allow

    Figure 3.10

Additional Reading

Arruda, Stacy M. "TCP WRAPPERS—What 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.


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.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020