home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / HOWTOs / SECURITY < prev    next >
Text File  |  1999-11-04  |  112KB  |  2,773 lines

  1.   Linux Security HOWTO
  2.   Kevin Fenzi, kevin@scrye.com & Dave Wreski, dave@nic.com
  3.   v0.9.11, 1 May 1998
  4.  
  5.   This document is a general overview of security issues that face the
  6.   administrator of Linux systems. It covers general security philosophy
  7.   and a number of specific examples of how to better secure your Linux
  8.   system from intruders. Also included are pointers to security related
  9.   material and programs. NOTE: This is a beta version of this document.
  10.   Improvements, constructive criticism,  additions and corrections are
  11.   gratefully accepted. Please mail your feedback to both authors. Be
  12.   sure and include "Linux", "security" or "HOWTO" in the subject line of
  13.   your mail to avoid spam filters and to bring your mail to the quick
  14.   attention of the authors.
  15.   ______________________________________________________________________
  16.  
  17.   Table of Contents
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.   1. Introduction
  68.  
  69.      1.1 New Versions of this Document
  70.      1.2 Feedback
  71.      1.3 Disclaimer
  72.      1.4 Copyright Information
  73.  
  74.   2. Overview
  75.  
  76.      2.1 Why Do We Need Security?
  77.      2.2 How Secure Is Secure?
  78.      2.3 What Are You Trying to Protect?
  79.      2.4 Developing A Security Policy
  80.      2.5 Means of Securing Your Site
  81.         2.5.1 Host Security
  82.         2.5.2 Your Network Security
  83.         2.5.3 Security Through Obscurity
  84.      2.6 Organization of This Document
  85.  
  86.   3. Physical Security
  87.  
  88.      3.1 Computer locks
  89.      3.2 BIOS Security
  90.      3.3 Boot Loader Security
  91.      3.4 xlock and vlock
  92.      3.5 Detecting Physical Security Compromises
  93.  
  94.   4. Local Security
  95.  
  96.      4.1 Creating New Accounts
  97.      4.2 Root Security
  98.  
  99.   5. Files and Filesystem Security
  100.  
  101.      5.1 Umask Settings
  102.      5.2 File Permissions
  103.      5.3 Integrity Checking with Tripwire
  104.      5.4 Trojan Horses
  105.  
  106.   6. Password Security & Encryption
  107.  
  108.      6.1 PGP and Public Key Cryptography
  109.      6.2 SSL, S-HTTP, HTTPS and S/MIME
  110.      6.3 Linux x-kernel IPSEC Implementation
  111.      6.4 SSH (Secure Shell), stelnet
  112.      6.5 PAM - Pluggable Authentication Modules
  113.      6.6 Cryptographic IP Encapsulation (CIPE)
  114.      6.7 Kerberos
  115.      6.8 Shadow Passwords.
  116.      6.9 Crack and John the Ripper
  117.      6.10 CFS - Cryptographic File System and TCFS - transparent cryptographic File System
  118.      6.11 X11, SVGA and display security
  119.         6.11.1 X11
  120.         6.11.2 SVGA
  121.         6.11.3 GGI (Generic Graphics Interface project)
  122.  
  123.   7. Kernel Security
  124.  
  125.      7.1 Kernel Compile Options
  126.      7.2 Kernel Devices
  127.  
  128.   8. Network Security
  129.  
  130.      8.1 Packet Sniffers
  131.      8.2 System services and tcp_wrappers
  132.      8.3 Verify Your DNS Information
  133.      8.4 identd
  134.      8.5 SATAN , ISS, and Other Network Scanners
  135.      8.6 Sendmail, qmail and MTA's.
  136.      8.7 Denial of Service Attacks
  137.      8.8 NFS (Network File System) Security.
  138.      8.9 NIS (Network Information Service) (formerly YP).
  139.      8.10 Firewalls
  140.  
  141.   9. Security Preparation (before you go on-line)
  142.  
  143.      9.1 Make a Full Backup of Your Machine
  144.      9.2 Choosing a Good Backup Schedule
  145.      9.3 Backup Your RPM or Debian File Database
  146.      9.4 Keep Track of Your System Accounting Data
  147.      9.5 Apply All New System Updates.
  148.  
  149.   10. What To Do During and After a Breakin
  150.  
  151.      10.1 Security Compromise under way.
  152.      10.2 Security Compromise has already happened
  153.         10.2.1 Closing the Hole
  154.         10.2.2 Assessing the Damage
  155.         10.2.3 Backups, Backups, Backups!
  156.         10.2.4 Tracking Down the Intruder.
  157.  
  158.   11. Security Sources
  159.  
  160.      11.1 FTP sites
  161.      11.2 Web Sites
  162.      11.3 Mailing Lists
  163.      11.4 Books - Printed Reading Material.
  164.  
  165.   12. Glossary
  166.  
  167.   13. Frequently Asked Questions
  168.  
  169.   14. Conclusion
  170.  
  171.   15. Thanks to
  172.  
  173.  
  174.  
  175.   ______________________________________________________________________
  176.  
  177.  
  178.  
  179.   1.  Introduction
  180.  
  181.   This document covers some of the main security issues that affect
  182.   Linux security. General philosophy and net born resources are
  183.   discussed.
  184.  
  185.   A number of other HOWTO documents overlap with security issues, and
  186.   those have been pointed to wherever appropriate.
  187.  
  188.   This document is NOT meant to be a up to date exploits document. Large
  189.   numbers of new exploits happen all the time. This document will tell
  190.   you where to look for such up to date information, and some general
  191.   methods to prevent such exploits from taking place.
  192.  
  193.  
  194.  
  195.   1.1.  New Versions of this Document
  196.  
  197.   New versions of this document will be periodically posted to
  198.   comp.os.linux.answers.  They will also be added to the various
  199.   anonymous FTP sites who archive such information, including:
  200.  
  201.   ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO
  202.  
  203.   In addition, you should generally be able to find this document on the
  204.   Linux Worldwide Web home page via:
  205.  
  206.   http://sunsite.unc.edu/mdw/linux.html
  207.  
  208.   Finally, the very latest version of this document should also be
  209.   available in various formats from:
  210.  
  211.   http://scrye.com/~kevin/lsh/
  212.  
  213.  
  214.   1.2.  Feedback
  215.  
  216.   All comments, error reports, additional information and criticism of
  217.   all sorts should be directed to:
  218.  
  219.   kevin@scrye.com
  220.  
  221.   and
  222.  
  223.   dave@nic.com
  224.  
  225.   NOTE: Please send your feedback to _both_ authors. Also, be sure and
  226.   include "Linux" "security" or "HOWTO" in your subject to avoid kevin's
  227.   spam filter.
  228.  
  229.  
  230.   1.3.  Disclaimer
  231.  
  232.   No liability for the contents of this documents can be accepted.  Use
  233.   the concepts, examples and other content at your own risk.
  234.   Additionally, this is an early version, with many possibilities for
  235.   inaccuracies and errors.
  236.  
  237.   A number of the examples and descriptions use the RedHat(tm) package
  238.   layout and system setup. Your mileage may vary.
  239.  
  240.   As far as we know, only programs that under certain terms may be used
  241.   or evaluated for personal purposes will be described. Most of the
  242.   programs will be available complete with source under GNU-like terms.
  243.  
  244.  
  245.   1.4.  Copyright Information
  246.  
  247.   This document is copyrighted (c)1998 Kevin Fenzi and Dave Wreski, and
  248.   distributed under the following terms:
  249.  
  250.  
  251.  
  252.   o  Linux HOWTO documents may be reproduced and distributed in whole or
  253.      in part, in any medium physical or electronic, as long as this
  254.      copyright notice is retained on all copies. Commercial
  255.      redistribution is allowed and encouraged; however, the authors
  256.      would like to be notified of any such distributions.
  257.  
  258.   o  All translations, derivative works, or aggregate works
  259.      incorporating any Linux HOWTO documents must be covered under this
  260.      copyright notice.  That is, you may not produce a derivative work
  261.      from a HOWTO and impose additional restrictions on its
  262.      distribution. Exceptions to these rules may be granted under
  263.      certain conditions; please contact the Linux HOWTO coordinator at
  264.      the address given below.
  265.   o  If you have questions, please contact Tim Bynum, the Linux HOWTO
  266.      coordinator, at
  267.  
  268.   linux-howto@sunsite.unc.edu
  269.  
  270.  
  271.   2.  Overview
  272.  
  273.   This document will attempt to explain some procedures and commonly
  274.   used software to help your Linux system be more secure.  It is
  275.   important to discuss some of the basic concepts first, and create a
  276.   security foundatation before we get started.
  277.  
  278.   2.1.  Why Do We Need Security?
  279.  
  280.   In the ever-changing world of global data communications, inexpensive
  281.   Internet connections, and fast-paced software development, security is
  282.   becomming more and more of an issue.  Security is now a basic
  283.   requirement because global computing is inherently insecure.  As your
  284.   data goes from point A to point B on the Internet, for example, it may
  285.   pass through several other points along the way, giving other users
  286.   the opportunity to intercept, and even alter, your data.  Even other
  287.   users on your system may maliciously transform your data into
  288.   something you did not intend.  Unauthorized access to your system may
  289.   be obtained by intruders, also known as "crackers", who then use
  290.   advanced knowledge to impersonate you, steal information from you, or
  291.   even deny you access to your own resources.  If you're still wondering
  292.   what the difference is between a "Hacker" and a "Cracker", see Eric
  293.   Raymond's document, "How to Become A Hacker", available at
  294.   http://sagan.earthspace.net/~esr/faqs/hacker-howto.html.
  295.  
  296.  
  297.   2.2.  How Secure Is Secure?
  298.  
  299.   First, keep in mind that no computer system can ever be "completely
  300.   secure". All you can do is make it increasingly difficult for someone
  301.   to compromise your system. For the average home Linux user, not much
  302.   is required to keep the casual cracker at bay. For high profile Linux
  303.   users (banks, telecommunications companies, etc), much more work is
  304.   required.
  305.  
  306.   Another factor to take into account is that the more secure your
  307.   system is the more intrusive your security becomes. You need to decide
  308.   where in this balancing act your system is still usable and yet secure
  309.   for your purposes. For instance, you could require everyone dialing
  310.   into your system to use a call back modem to call them back at their
  311.   home number. This is more secure, but if someone is not at home, it
  312.   makes it difficult for them to login. You could also setup your Linux
  313.   system with no network or connection to the Internet, but this makes
  314.   it harder to surf the web.
  315.  
  316.   If you are a large to medium-sized site, you should establish a
  317.   "Security Policy" stating how much security is required by your site
  318.   and what auditing is in place to check it. You can find a well-known
  319.   security policy example at http://ds.internic.net/rfc/rfc2196.txt.  It
  320.   has been recently updated, and contains a great framework for
  321.   establishing a security policy for your company.
  322.  
  323.  
  324.   2.3.  What Are You Trying to Protect?
  325.  
  326.   Before you attempt to secure your system, you should determine what
  327.   level of threat you have to protect against, what risks you should or
  328.   should not take, and how vulnerable your system is as a result.  You
  329.   should analyze your system to know what you're protecting, why you're
  330.   protecting it, what value it has, and who has responsibility for your
  331.   data and other assets.
  332.  
  333.  
  334.   o  Risk is the possibility that an intruder may be successful in
  335.      attempting to access your computer.  Can an intruder read, write
  336.      files, or execute programs that could cause damage?  Can they
  337.      delete critical data? Prevent you or your company from getting
  338.      important work done? Don't forget, someone gaining access to your
  339.      account, or your system, can also impersonate you.
  340.  
  341.      Additionally, having one insecure account on your system can result
  342.      in your entire network being compromised.  A single user that is
  343.      allowed to login using an rhosts file, or allowing the use of an
  344.      insecure service, such as tftp, you risk an intruder using this to
  345.      'get his foot in the door'.  Once the intruder has a user account
  346.      on your system, or someone else's system, it can be used to gain
  347.      access to another system, or another account.
  348.  
  349.  
  350.   o  Threat is typically from someone with motivation to gain
  351.      unathorized access to your network, or computer.  You must decide
  352.      who you trust to have access to your system, and what threat they
  353.      could impose.
  354.  
  355.      There are several types of intruders, and it is useful to keep the
  356.      different characteristics in mind as you are securing your systems.
  357.  
  358.  
  359.   o  The Curious - This type of intruder is basically interested in
  360.      finding out what type of system and data, you have.
  361.  
  362.   o  The Malicious - This type of intruder is out to either bring down
  363.      your systems, or deface your web page, or otherwise cause you time
  364.      and money to recover.
  365.  
  366.   o  The High-Profile Intruder - This type of intruder is trying to use
  367.      your system to gain popularity and infamy.  He might use your high-
  368.      profile system to advertise his abilities.
  369.  
  370.   o  The Competition - This type of intruder is interested in what data
  371.      you have on your system.  It might be someone who thinks you have
  372.      something that could benefit him financially, or otherwise.
  373.  
  374.  
  375.   o  Vulnerability describes how well protected your computer is from
  376.      another network, and the potential for someone gaining unathorized
  377.      access.
  378.  
  379.      What's at stake if someone breaks into your system?  Of course the
  380.      concerns of a dynamic PPP home user will be different than those of
  381.      a company connecting their machine to the Internet, or another
  382.      large network.
  383.  
  384.      How much time would it take to retrieve/recreate any data that was
  385.      lost?  An initial time investment now can save ten times more time
  386.      later if you have to recreate data that was lost.  Have you checked
  387.      your backup strategy, and verified your data lately?
  388.  
  389.  
  390.   2.4.  Developing A Security Policy
  391.  
  392.   Create a simple, generic policy for your system that your users can
  393.   readily understand and follow.  It should protect the data you're
  394.   safeguarding, as well as the privacy of the users.  Some things to
  395.   consider adding are who has access to the system (Can my friend use my
  396.   account?), who's allowed to install software on the system, who owns
  397.   what data, disaster recovery, and appropriate use of the system.
  398.  
  399.   A generally accepted security policy starts with the phrase:
  400.  
  401.  
  402.                     "That which is not permitted is prohibited"
  403.  
  404.  
  405.   This means that unless you grant access to a service for a user, that
  406.   user shouldn't be using that service until you do grant access. Make
  407.   sure the policies work on your regular user account, Saying, "Ah, I
  408.   can't figure this permissions problem out, I'll just do it as root"
  409.   can lead to security holes that are very obvious, and even ones that
  410.   haven't been exploited yet.
  411.  
  412.  
  413.   2.5.  Means of Securing Your Site
  414.  
  415.   This document will discuss various means in which you can secure the
  416.   assets you have worked hard for: your local machine, data, users,
  417.   network, even your reputation.  What would happen to your reputation
  418.   if an intruder deleted some of your user's data?  Or defaced your web
  419.   site?  Or published your company's corporate project plan for next
  420.   quarter?  If you are planning a network installation, there are many
  421.   factors you must take into account before adding a single machine to
  422.   your network.
  423.  
  424.   Even if you have a single dialup PPP account, or just a small site,
  425.   this does not mean intruders won't be interested in your systems.
  426.   Large, high profile sites are not the only targets, many intruders
  427.   simply want to exploit as many sites as possible, regardless of their
  428.   size. Additionally, they may use a security hole in your site to gain
  429.   access to other sites you're connected to.
  430.  
  431.   Intruders have a lot of time on their hands, and can avoid guessing
  432.   how you've obscured your system just by trying all the possibilities.
  433.   There are also several reasons an intruder may be interested in your
  434.   systems, which we will discuss later.
  435.  
  436.  
  437.  
  438.   2.5.1.  Host Security
  439.  
  440.   Perhaps the area of most concentration on security is done with host-
  441.   based security.  This typically involves making sure your own system
  442.   is secure, and hoping everyone else on your network does the same.
  443.   Choosing good passwords, securing your host's local network services,
  444.   keeping good accounting records, and upgrading programs with known
  445.   security exploits are among the things the local security
  446.   administrator is responsible for doing.  Although this is absolutely
  447.   necessary, it can become a daunting task once your network of machines
  448.   becomes larger.
  449.  
  450.  
  451.   2.5.2.  Your Network Security
  452.  
  453.   Network security is also as necessary as local host security.  With
  454.   your single system, or a distributed computing network, the Internet,
  455.   or hundreds, if not thousands or more computers on the same network,
  456.   you can't rely on each one of those systems being secure.  Making sure
  457.   authorized users are the only ones permitted to use your network
  458.   resources, building firewalls, using strong encryption, and ensuring
  459.   there are no rogue, or unsecured, machines on your network are all
  460.   part of the network security administrator's duties.
  461.  
  462.  
  463.   This document will discuss some of the techniques used to secure your
  464.   site, and hopefully show you some of the ways to prevent an intruder
  465.   from gaining access to what you are trying to protect.
  466.  
  467.  
  468.   2.5.3.  Security Through Obscurity
  469.  
  470.  
  471.   One type of security that must be discussed is "security through
  472.   obscurity". This means that by doing something like changing the login
  473.   name from 'root' to 'toor', for example, to try and obscure someone
  474.   from breaking into your system as root is only a false sense of
  475.   security, and will result in very unpleasant consequences. Rest
  476.   assured that any system attacker will quickly see through such empty
  477.   security measures.  Simply because you may have a small site, or
  478.   relatively low profile does not mean an intruder won't be interested
  479.   in what you have.  We'll discuss what your protecting in the next
  480.   sections.
  481.  
  482.  
  483.   2.6.  Organization of This Document
  484.  
  485.   This document has been segregated into a number of sections. They
  486.   cover several broad kinds of security issues. The first, physical
  487.   security, covers how you need to protect your physical machine from
  488.   tampering. The second describes how to protect your system from
  489.   tampering by local users. The third, files and filesystem security
  490.   show you how to setup your filesystems and premissions on your files.
  491.   The next, password security and encryption discusses how to use
  492.   encryption to better secure your machine and network. Kernel security
  493.   discusses what kernel options you should set or be aware of for a more
  494.   secure machine. network security, describes how to better secure your
  495.   Linux system from network attacks. Security preperation discusses how
  496.   to prepair your machine(s) before bringing the on-line. The next
  497.   discusses what to do when you detect a system compromise in progress
  498.   or detect one that has recently happened. Then links to other security
  499.   resources are enumerated, and finally some questions and answers and a
  500.   few closing words.
  501.  
  502.   The two main points to realize when reading this document are:
  503.  
  504.  
  505.   o  Be aware of your system. Check system logs such as
  506.      /var/log/messages and keep an eye on your system, and
  507.  
  508.   o  Two, keep your system up to date by making sure you have installed
  509.      the current versions of software and have upgraded per security
  510.      alerts.  Just doing this will help make your system markedly more
  511.      secure.
  512.  
  513.  
  514.   3.  Physical Security
  515.  
  516.   The first "layer" of security you need to take into account is the
  517.   physical security of your computer systems. Who has direct physical
  518.   access to your machine? Should they? Can you protect your machine from
  519.   their tampering? Should you?
  520.  
  521.   How much physical security you need on your system is very dependent
  522.   on your situation, and/or budget.
  523.  
  524.   If you are a home user, you probably don't need a lot (although you
  525.   might need to protect your machine from tampering by children or
  526.   annoying relatives).  If you are in a Lab environment, you need
  527.   considerably more, but users will still need to be able to get work
  528.   done on the machines. Many of the following sections will help out. If
  529.   you are in a Office, you may or may not need to secure your machine
  530.   off hours or while you are away. At some companies, leaving your
  531.   console unsecured is a termination offense.
  532.  
  533.   Obvious physical security methods such as locks on doors, cables,
  534.   locked cabinets, and video survailance are all a good idea, but beyond
  535.   the scope of this document. :)
  536.  
  537.  
  538.   3.1.  Computer locks
  539.  
  540.   Many more modern pc cases include a "locking" feature. Usually this
  541.   will be a socket on the front of the case that allows you to turn an
  542.   included key to a locked or unlocked position. Case locks can help
  543.   prevent someone from stealing your pc, or opening up the case and
  544.   directly manipulating/stealing your hardware. They can also sometimes
  545.   prevent someone from rebooting your computer on their own floppy or
  546.   other hardware.
  547.  
  548.   These case locks do different things according to the support in the
  549.   motherboard and how the case is constructed. On many pc's they make it
  550.   so you have to break the case to get the case open. On some others
  551.   they make it so that it will not let you plug in new keyboards and
  552.   mice. Check your motherboard or case instructions for more
  553.   information. This can sometimes be a very useful feature, even though
  554.   the locks are usually very low quality and can easily be defeated by
  555.   attackers with locksmithing.
  556.  
  557.   Some cases (most notably sparcs and macs) have a dongle on the back
  558.   that if you put a cable through attackers would have to cut the cable
  559.   or break the case to get into it. Just putting a padlock or combo lock
  560.   through these can be a good deterrent to someone stealing your
  561.   machine.
  562.  
  563.  
  564.  
  565.   3.2.  BIOS Security
  566.  
  567.   The BIOS is the lowest level of software that configures or
  568.   manipulates your x86 based hardware. LILO and other Linux boot methods
  569.   access the BIOS to determine how to boot up your Linux machine. Other
  570.   hardware that Linux runs on has similar software (OpenFirmware on macs
  571.   and new suns, sun boot prom, etc...). You can use your BIOS to prevent
  572.   attackers from rebooting your machine and manipulating your linux
  573.   system.
  574.  
  575.   Under Linux/x86 many PC BIOSs let you set a boot password. This
  576.   doesn't provide all that much security (bios can be reset, or removed
  577.   if someone can get into the case), but might be a good deterant (ie it
  578.   will take time and leave traces of tampering).
  579.  
  580.   Many x86 bioses also allow you to specify various other good security
  581.   settings. Check your bios manual or look at it the next time you boot
  582.   up. Some examples are: disallow booting from floppy drives and
  583.   passwords to access some bios features.
  584.  
  585.   On Linux/Sparc, your SPARC EEPROM can be set to require a boot-up
  586.   password. This might slow attackers down.
  587.  
  588.   NOTE: If you have a server machine, and you setup a boot password,
  589.   your machine will not boot up unattended. Keep in mind that you will
  590.   need to come in and supply the password in the even of a power
  591.   failure. ;(
  592.  
  593.  
  594.  
  595.   3.3.  Boot Loader Security
  596.  
  597.   The various Linux boot loaders also can have a boot password set.
  598.   Using lilo, take a look at the "restricted" and "password" settings.
  599.   "password" allows you to set a bootup password. "restricted" will let
  600.   the machine boot _unless_ someone specifies options at the lilo:
  601.   prompt (like 'single').
  602.  
  603.   Keep in mind when setting all these passwords that you need to
  604.   remember them. :) Also remember that these passwords will mearly slow
  605.   the determined attacker.  This won't prevent someone from booting from
  606.   a floppy, and mounting your root partition.  If you are using security
  607.   in conjunction with a boot loader, you might as well disable booting
  608.   from a floppy in your computer's BIOS, as well as password-protecting
  609.   your computer's BIOS.
  610.  
  611.   If anyone has security related information from a different boot
  612.   loader, we would love to hear it. (grub, silo, milo, linload, etc).
  613.  
  614.   NOTE: If you have a server machine, and you setup a boot password,
  615.   your machine will not boot up unattended. Keep in mind that you will
  616.   need to come in and supply the password in the even of a power
  617.   failure. ;(
  618.  
  619.  
  620.   3.4.  xlock and vlock
  621.  
  622.   If you wander away from your machine from time to time, it is nice to
  623.   be able to "lock" your console so that no one tampers with or looks at
  624.   your work. Two programs that do this are: xlock and vlock.
  625.  
  626.   Xlock is a X display locker. It should be included in any Linux
  627.   distributions that support X. Check out the man page for it for more
  628.   options, but in general you can run xlock from any xterm on your
  629.   console and it will lock the display and require your password to
  630.   unlock.
  631.  
  632.   vlock is a simple little program that allows you to lock some or all
  633.   of the virtual consoles on your Linux box. You can lock just the one
  634.   you are working in or all of them. If you just lock one, others can
  635.   come in and use the console, they will just not be able to use your
  636.   vty until you unlock it. vlock ships with redhat Linux, but your
  637.   mileage may vary.
  638.  
  639.   Of course locking your console will prevent someone from tampering
  640.   with your work, but does not prevent them from rebooting your machine
  641.   or otherwise disrupting your work. It also does not prevent them from
  642.   accessing your machine from another machine on the network and causing
  643.   problems.
  644.  
  645.  
  646.   3.5.  Detecting Physical Security Compromises
  647.  
  648.   The first thing to always note is when your machine was rebooted.
  649.   Since Linux is a robust and stable OS, the only times your machine
  650.   should reboot is when YOU take it down for OS upgrades, hardware
  651.   swapping, or the like. If your machine has rebooted without you doing
  652.   it, a trouble light should go on. Many of the ways that your machine
  653.   can be compromised require the intruder to reboot or power off your
  654.   machine.
  655.  
  656.   Check for signs of tampering on the case and computer area. Although
  657.   many intruders clean traces of their presence out of logs, it's a good
  658.   idea to check through them all and note any discrepancy.
  659.  
  660.  
  661.   Some things to check for in your logs:
  662.  
  663.   o  Short or incomplete logs.
  664.  
  665.   o  Logs containing strange timestamps.
  666.  
  667.   o  Logs with incorrect permissions or ownership.
  668.  
  669.   o  Records of reboots or restarting of services.
  670.  
  671.   o  missing logs.
  672.  
  673.   o  su entries or logins from strange places.
  674.  
  675.   We will discuss system log data later in the HOWTO.
  676.  
  677.  
  678.   4.  Local Security
  679.  
  680.   The next thing to take a look at is the security in your system
  681.   against attacks from local users. Did we just say _local_ users? yes.
  682.  
  683.   Getting access to a local user is one of the first things that system
  684.   intruders attempt, while on their way to exploiting the root account.
  685.   With lax local security, they can then "upgrade" their normal user
  686.   access to root access using a variety of bugs and poorly setup local
  687.   services. If you make sure your local security is tight, then the
  688.   intruder will have another hurdle to jump.
  689.  
  690.   Local users can also cause a lot of havoc with your system even
  691.   (especially) if they really are who they say they are. Providing
  692.   accounts to people you don't know or have no contact information for
  693.   is a very bad idea.
  694.  
  695.  
  696.   4.1.  Creating New Accounts
  697.  
  698.   You should make sure to provide user accounts with only the minimal
  699.   requirements for the task they need to do. If you provide your son
  700.   (age 10) with an account, you might want them to only have access to a
  701.   word processor or drawing program, but be unable to delete data that
  702.   is not his.
  703.  
  704.   Several good rules of thumb when allowing other people legitimate
  705.   access to your Linux machine:
  706.  
  707.  
  708.   o  Give them the minimal amount of privileges they need.
  709.  
  710.   o  Be aware when/where they login from, or should be logging in from.
  711.  
  712.   o  Make sure and remove their account when they no longer need the
  713.      access.
  714.  
  715.   Many local user accounts that are used in security compromises are
  716.   ones that have not been used in months or years. Since no one is using
  717.   them they provide the ideal attack vehicle.
  718.  
  719.  
  720.   4.2.  Root Security
  721.  
  722.   The most sought-after account on your machine is the superuser
  723.   account.  This account has authority over the entire machine, which
  724.   may also include authority over other machines on the network.
  725.   Remember that you should only use the root account for very short
  726.   specific tasks and should mostly run as a normal user. Running as root
  727.   all the time is a very very very bad idea.
  728.  
  729.   Several tricks to avoid messing up your own box as root:
  730.  
  731.   o  When doing some complex command, try running it first in a non
  732.      destructive way...especially commands that use globbing: ie, you
  733.      are going to do a "rm foo*.bak", instead, first do: "ls foo*.bak"
  734.      and make sure you are going to delete the files you think you are.
  735.      Using echo in place of destructive commands also sometimes works.
  736.  
  737.   o  Some people find it helpfull to do a "touch /-i" on their systems.
  738.      This will make commands like: "rm -rf *" ask you if you really want
  739.      to delete all the files. (It does this by your shell resolving the
  740.      "-i" file first, and treating it as the -i option to rm.) This will
  741.      not help with rm statements with no * in them. ;(
  742.  
  743.   o   Only become root to do single specific tasks. If you find yourself
  744.      trying to figure out how to do something, go back to a normal user
  745.      shell until you are sure what needs to be done by root.
  746.  
  747.   o  The command path for the root user is very important.  The command
  748.      path, or the PATH environment variable, defines the location the
  749.      shell searches for programs.  Try and limit the command path for
  750.      the root user as much as possible, and never use '.', meaning 'the
  751.      current directory', in your PATH statement.  Additionally, never
  752.      have writable directories in your search path, as this can allow
  753.      attackers to modify or place new binaries in your search path,
  754.      allowing them to run as root the next time you run that command.
  755.  
  756.   o  Never use the rlogin/rsh/rexec (called the r-utilities) suite of
  757.      tools as root. They are subject to many sorts of attacks, and are
  758.      downright dangerous run as root. Never create a .rhosts file for
  759.      root.
  760.  
  761.   o  The /etc/securetty file contains a list of terminals that root can
  762.      login from. By default (on Red Hat Linux) this is set to only the
  763.      local virtual consoles(vtys). Be very careful of adding anything
  764.      else to this file. You should be able to login remotely as your
  765.      regular user account and then 'su' if you need to (hopefully over
  766.      ssh or other encrypted channel), so there is no need to be able to
  767.      login directly as root.
  768.  
  769.   o  Always be slow and deliberate running as root. Your actions could
  770.      affect a lot of things. Think before you type!
  771.  
  772.   If you absolutely positively need to allow someone (hopefully very
  773.   trusted) to have superuser access to your machine, there are a few
  774.   tools that can help. Sudo allows users to use their password to access
  775.   a limited set of commands as root. This would allow you to, for
  776.   instance, let a user be able to eject and mount removable media on
  777.   your Linux box, but have no other root privileges. sudo also keeps a
  778.   log of all successfull and unsuccessful sudo attempts, allowing you to
  779.   track down who used what command to do what. For this reason sudo
  780.   works well even in places where a number of people have root access,
  781.   but use sudo so you can keep track of changes made.
  782.  
  783.   Although sudo can be used to give specific users specific privileges
  784.   for specific tasks, it does have several shortcomings. It should be
  785.   used only for a limited set of tasks, like restarting a server, or
  786.   adding new users.  Any program that offers a shell escape will give
  787.   the user root access.  This includes most editors, for example.  Also,
  788.   a program as innocous as /bin/cat can be used to overwrite files,
  789.   which could allow root to be exploited.  Consider sudo as a means for
  790.   accountability, and don't expect it to replace the root user yet be
  791.   secure.
  792.  
  793.   5.  Files and Filesystem Security
  794.  
  795.   A few minutes of preparation and planning ahead before putting your
  796.   systems online can help to protect your system, and the data that is
  797.   stored on them.
  798.  
  799.   o  There should never be a reason for user's home directories to allow
  800.      SUID/SGID programs to be run from there.  Use the `nosuid' option
  801.      in /etc/fstab for partitions that are writable by others than root.
  802.      You may also wish to use `nodev' and `noexec' on user's home
  803.      partitions, as well as /var, which prohibit execution of programs,
  804.      and creation of character or block devices, which should never be
  805.      necessary anyway.
  806.  
  807.   o  If you are exporting filesystems using NFS, be sure to configure
  808.      /etc/exports with the most restrictive access possible.  This means
  809.      not using wildcards, not allowing root write access, and mounting
  810.      read-only wherever possible.
  811.  
  812.   o  Configure your user's file-creation umask to be as restrictive as
  813.      possible.  Commonly used settings are 022, 033, and the most
  814.      restrictive 077, and are added to /etc/profile.
  815.  
  816.   o  Set filesystem limits instead of allowing `unlimited' as is the
  817.      default.  You can control the per-user limits using the resource-
  818.      limits PAM module and /etc/pam.d/limits.conf.  For example, limits
  819.      for group `users' might look like this:
  820.  
  821.  
  822.  
  823.                        @users     hard  core    0
  824.                        @users     hard  nproc   50
  825.                        @users     hard  rss     5000
  826.  
  827.  
  828.  
  829.  
  830.   This says to prohibit the creation of core files, restrict the number
  831.   of processes to 50, and restrict memory usage per user to 5M.
  832.  
  833.  
  834.   o  The /var/log/wtmp and /var/run/utmp files contain the login records
  835.      for all users on your system.  Its integrity must be maintained
  836.      because it can be used to determine when and from where a user (or
  837.      potential intruder) has entered your system.  These files should
  838.      also have 644 permissions, without affecting normal system
  839.      operation.
  840.  
  841.  
  842.   o  The immutable bit can be used to prevent accidentally deleting or
  843.      overwriting a file that must be protected.  It also prevents
  844.      someone from creating a symbolic link to this file, which has been
  845.      the source of attacks involving deleting /etc/passwd or
  846.      /etc/shadow.  See the chattr(1) man page for information on the
  847.      immutable bit.
  848.  
  849.  
  850.   o  SUID and SGID files on your system are a potential security risk,
  851.      and should be monitored closely.  Because these programs grant
  852.      special privileges to the user who is executing them, it is
  853.      necessary to ensure that insecure programs are not installed.  A
  854.      favorite trick of crackers is to exploit SUID "root" programs, then
  855.      leave a SUID program as a backdoor to get in the next time, even if
  856.      the original hole is plugged.
  857.  
  858.      Find all SUID/SGID programs on your system, and keep track of what
  859.      they are, so you are aware of any changes which could indicate a
  860.      potential intruder.  Use the following command to find all
  861.      SUID/SGID programs on your system:
  862.  
  863.  
  864.  
  865.                        root#  find / -type f \( -perm -04000 -o -perm -02000 \)
  866.  
  867.  
  868.  
  869.  
  870.   You can descriminitely remove the SUID or SGID permissions on a suspi-
  871.   cious program with chmod(1), then change it back if you absolutely
  872.   feel it is necessary.
  873.  
  874.  
  875.   o  World-writable files, particularly system files, can be a security
  876.      hole if a cracker gains access to your system and modifies them.
  877.      Additionally, world-writable directories are dangerous, since they
  878.      allow a cracker to add or delete files as he wishes.  To locate all
  879.      world-writable files on your system, use the following command:
  880.  
  881.  
  882.  
  883.                        root# find / -perm -2 -print
  884.  
  885.  
  886.  
  887.  
  888.   and be sure you know why those files are writable.  In the normal
  889.   course of operation, several files will be writable, including some
  890.   from /dev, and symbolic links.
  891.  
  892.   o
  893.  
  894.      Unowned files may also be an indication an intruder has accessed
  895.      your system.  You can locate files on your system that do not have
  896.      an owner, or belong to a group with the command:
  897.  
  898.  
  899.  
  900.                        root# find / -nouser -o -nogroup -print
  901.  
  902.  
  903.  
  904.  
  905.  
  906.   o  Finding .rhosts Files should be a part of your regular system
  907.      administration duties, as these files should not be permitted on
  908.      your system.  Remember, a cracker only needs one insecure account
  909.      to potentially gain access to your entire network.  You can locate
  910.      all .rhosts files on your system with the following command:
  911.  
  912.  
  913.                        root# find /home -name .rhosts -print
  914.  
  915.  
  916.  
  917.  
  918.   o
  919.  
  920.      Finally, before changing permissions on any system files, make sure
  921.      you understand what you are doing. Never change permissions on a
  922.      file because it seems like the easy way to get things working.
  923.      Always determine why the file has that permission before changing
  924.      it.
  925.   5.1.  Umask Settings
  926.  
  927.   The umask command can be used to determine the default file creation
  928.   mode on your system. It is the octal complement of the desired file
  929.   mode. If files are created without any regard to their permissions
  930.   settings, the user could inadvertantly give read or write permission
  931.   to someone that should not have this permission. Typically umask
  932.   settings include 022, 027, and 077, which is the most restrictive.
  933.   Normally the umask is set in /etc/profile, so it applies to all users
  934.   on the system. For example, you may have a line that looks like this:
  935.  
  936.  
  937.  
  938.                        # Set the user's default umask
  939.                        umask 033
  940.  
  941.  
  942.  
  943.  
  944.   Be sure to make root's umask 077, which will disable read, write, and
  945.   execute permission for other users, unless explicitly changed using
  946.   chmod(1).
  947.  
  948.   If you are using Red Hat, and adhered to their user and group ID
  949.   creation scheme (User Private Groups), it is only necessary to use 002
  950.   for a umask.  This is due to the fact that the default configuration
  951.   is one user per group.
  952.  
  953.  
  954.   5.2.  File Permissions
  955.  
  956.   It's important to insure that your system files are not open for
  957.   casual editing by users and groups who shouldn't be doing such system
  958.   maintance.
  959.  
  960.   UNIX seperates access control on files and directories according to
  961.   three characteristics:  owner, group, and other.  There is always
  962.   exactly one owner, any number of members of the group, and everyone
  963.   else.
  964.  
  965.   A quick explanation of unix permissions:
  966.  
  967.   Ownership      - Which user(s) and group(s) retain(s) control of the
  968.   permission settings of the node and parent of the node
  969.  
  970.   Permissions    - Bits capable of being set or reset to allow certain
  971.   types of access to it.  Permissions for directories may have a
  972.   different meaning than the same set of permissions on files.
  973.  
  974.   Read:
  975.  
  976.   o  To be able to view contents of a file
  977.  
  978.   o  To be able to read a directory
  979.  
  980.   Write:
  981.  
  982.   o  To be able to add to or change a file
  983.  
  984.   o  To be able to delete or move files in a directory
  985.  
  986.   Execute:
  987.  
  988.   o  To be able to run a binary program or shell script
  989.  
  990.  
  991.   o  To be able to search in a directory, combined with read permission
  992.  
  993.  
  994.      Save Text Attribute: (For directories)
  995.         The sticky bit also has a different meaning when applied to
  996.         directories.  If the sticky bit is set on a directory, then a
  997.         user may only delete files that the user owns or for which he
  998.         has explicit write permission granted, even when he has write
  999.         access to the directory.  This is designed for directories like
  1000.         /tmp, which are world-writable, but where it may not be
  1001.         desirable to allow any user to delete files at will.  The sticky
  1002.         bit is seen as a 't' in a long directory listing.
  1003.  
  1004.  
  1005.      SUID Attribute: (For Files)
  1006.         This describes set-user-id permissions on the file.  When the
  1007.         set user ID access mode is set in the owner permissions, and the
  1008.         file is executable, processes which run it are granted access to
  1009.         system resources based on the user who created the process.
  1010.         This is the cause of many 'buffer overflow' exploits.
  1011.  
  1012.  
  1013.      SGID Attribute: (For Files)
  1014.         If set in the group permissions, this bit controls the "set
  1015.         group id" status of a file.  This behaves the same way as SUID,
  1016.         except the group is affected instead.  The file must also be
  1017.         executable for this to have any effect.
  1018.  
  1019.  
  1020.      SGID Attribute: (For directories)
  1021.         If you set the SGID bit on a directory (with "chmod g+s
  1022.         directory"), files created in that directory will have their
  1023.         group set to the directory's group.
  1024.  
  1025.   You          - The owner of the file
  1026.  
  1027.   Group        - The group you belong to
  1028.  
  1029.   Everyone     - Anyone on the system that is not the owner or a member
  1030.   of the group
  1031.  
  1032.  
  1033.   File Example:
  1034.  
  1035.  
  1036.  
  1037.                -rw-r--r--  1 kevin  users         114 Aug 28  1997 .zlogin
  1038.                1st bit - directory?             (no)
  1039.                 2nd bit - read by owner?         (yes, by kevin)
  1040.                  3rd bit - write by owner?        (yes, by kevin)
  1041.                   4th bit - execute by owner?      (no)
  1042.                    5th bit - read by group?         (yes, by users)
  1043.                     6th bit - write by group?        (no)
  1044.                      7th bit - execute by group?      (no)
  1045.                       8th bit - read by everyone?      (yes, by everyone)
  1046.                        9th bit - write by everyone?     (no)
  1047.                         10th bit - execute by everyone?  (no)
  1048.  
  1049.  
  1050.  
  1051.  
  1052.   The following lines are examples of the minimum set of the permissions
  1053.   that are required to perform the access described.  You may want to
  1054.   give more permission than what's listed, but this should describe what
  1055.   these minimum permissions on files do:
  1056.  
  1057.        -r--------  Allow read access to the file by owner
  1058.        --w-------  Allows the owner to modify or delete the file
  1059.        ---x------  The owner can execute this program, but not shell scripts,
  1060.                     which still need read permission
  1061.        ---s------  Will execute with effective user ID = owner
  1062.        -------s--  Will execute with effective user ID = group
  1063.        -rw------T  No update of "last modified time".  Usually used for swap
  1064.                     files
  1065.        ---t------  No effect.  (formerly sticky bit)
  1066.  
  1067.  
  1068.  
  1069.  
  1070.   Directory Example:
  1071.  
  1072.  
  1073.  
  1074.                drwxr-xr-x  3 kevin  users         512 Sep 19 13:47 .public_html/
  1075.                1st bit - directory?             (yes, it contains many files)
  1076.                 2nd bit - read by owner?         (yes, by kevin)
  1077.                  3rd bit - write by owner?        (yes, by kevin)
  1078.                   4th bit - execute by owner?      (yes, by kevin)
  1079.                    5th bit - read by group?         (yes, by users
  1080.                     6th bit - write by group?        (no)
  1081.                      7th bit - execute by group?      (yes, by users)
  1082.                       8th bit - read by everyone?      (yes, by everyone)
  1083.                        9th bit - write by everyone?     (no)
  1084.                         10th bit - execute by everyone?  (yes, by everyone)
  1085.  
  1086.  
  1087.  
  1088.  
  1089.   The following lines are examples of the minimum set of the permissions
  1090.   that are required to perform the access described.  You may want to
  1091.   give more permission than what's listed, but this should describe what
  1092.   these minimum permissions on directories do:
  1093.  
  1094.  
  1095.  
  1096.  
  1097.        dr--------  The contents can be listed, but file attributes can't be read
  1098.        d--x------  The directory can be entered, and used in full execution
  1099.                     paths
  1100.        dr-x------  File attributes can now be read by owner
  1101.        d-wx------  Files can now be created/deleted, even if the directory
  1102.                     isn't the current one
  1103.        d------x-t  Prevents files from deletion by others with write
  1104.                     access. Used on /tmp
  1105.        d---s--s--  No effect
  1106.  
  1107.  
  1108.  
  1109.  
  1110.   System configuration files (usually in /etc) are usually mode 640
  1111.   (-rw-r-----), and owned by root. Depending on your sites security
  1112.   requirements, you might adjust this. Never leave any system files
  1113.   writable by a group or everyone.  Some configuration files, including
  1114.   /etc/shadow, should only be readable by root, and directories in /etc
  1115.   should at least not be accessible by others.
  1116.  
  1117.  
  1118.      SUID Shell Scripts
  1119.         SUID shell scripts are a serious security risk, and for this
  1120.         reason the kernel will not honor them.  Regardless of how secure
  1121.         you think the shell script is, it can be exploited to give the
  1122.         cracker a root shell.
  1123.   5.3.  Integrity Checking with Tripwire
  1124.  
  1125.   Another very good way to detect local (and also network) attacks on
  1126.   your system is to run an integrity checker like Tripwire. Tripwire
  1127.   runs a number of checksums on all your important binaries and config
  1128.   files and compares them against a database of former, known-good
  1129.   values as a reference. Thus, any changes in the files will be flagged.
  1130.  
  1131.   It's a good idea to install tripwire onto a floppy, and then
  1132.   physically set the write protect on the floppy. This way intruders
  1133.   can't tamper with tripwire itself or change the database. Once you
  1134.   have tripwire setup, it's a good idea to run it as part of your normal
  1135.   security administration duties to see if anything has changed.
  1136.  
  1137.   You can even add a crontab entry to run tripwire from your floppy
  1138.   every night and mail you the results in the morning. Something like:
  1139.  
  1140.  
  1141.                        # set mailto
  1142.                        MAILTO=kevin
  1143.                        # run tripwire
  1144.                        15 05 * * * root /usr/local/adm/tcheck/tripwire
  1145.  
  1146.  
  1147.  
  1148.  
  1149.   will mail you a report each morning at 5:15am.
  1150.  
  1151.   Tripwire can be a godsend to detecting intruders before you would
  1152.   otherwise notice them. Since a lot of files change on the average
  1153.   system, you have to be careful what is cracker activity and what is
  1154.   your own doing.
  1155.  
  1156.  
  1157.   5.4.  Trojan Horses
  1158.  
  1159.   A Trojan Horse is named after the fabled ploy in Homers great literary
  1160.   work. The idea is that you put up a program or binary that sounds
  1161.   great, and get other people to download it and run it as root. Then,
  1162.   you can compromise their system while they are not paying attention.
  1163.   While they think the binary they just pulled down does one thing (and
  1164.   it might very well), it also compromises their security.
  1165.  
  1166.   You should take care of what programs you install on your machine.
  1167.   redhat provides MD5 checksums, and PGP signs, RPM files so you can
  1168.   verify you are installing the real thing. Other distributions have
  1169.   similar methods. You should never run any binary you don't have the
  1170.   source for or a well known binary as root! Few attackers are willing
  1171.   to release source code to public scrutiny.
  1172.  
  1173.   Although it can be complex, make sure you are getting the source for
  1174.   some program from it's real distribution site. If the program is going
  1175.   to run as root make sure either you or someone you trust has looked
  1176.   over the source and verified it.
  1177.  
  1178.  
  1179.   6.  Password Security & Encryption
  1180.  
  1181.   One of the most important security features used today are passwords.
  1182.   It is important for both you and all your users to have secure,
  1183.   unguessable passwords. Most of the more recent Linux distributions
  1184.   include 'passwd' programs that do not allow you to set a easily
  1185.   guessable password. Make sure your passwd program is up to date and
  1186.   has these features.
  1187.  
  1188.  
  1189.   In depth discussion of encryption is beyond the scope of this
  1190.   document, but a introduction is in order. Encryption is very useful,
  1191.   possibly even nessessary in this day and age. There are all sorts of
  1192.   methods of encrypting data, each with their own set of
  1193.   characteristics.
  1194.  
  1195.   Most unicies (and Linux is no exception) primarily use a one-way
  1196.   encryption algorithm, called DES (Data Encryption Standard) to encrypt
  1197.   your passwords. This encrypted password is then stored in (typically)
  1198.   /etc/passwd (or less commonly) /etc/shadow. When you attempt to login,
  1199.   whatever you type in is encrypted again and compared with the entry in
  1200.   the file that stores your passwords. If they match, it must be the
  1201.   same password, and you are allowed access. Although DES is a two-way
  1202.   encryption algorithm (you can code and then decode a message, given
  1203.   the right keys), the variant that most unices use is one-way. This
  1204.   means that it should not be possible to reverse the encryption to get
  1205.   the password from the contents of /etc/passwd (or /etc/shadow).
  1206.  
  1207.   Brute force attacks, such as "Crack" or "John the Ripper" (see below)
  1208.   can often guess passwords unless your password is sufficently random.
  1209.   PAM modules (see below) allow you to use a different encryption
  1210.   routine with your passwords (MD5 or the like).
  1211.  
  1212.   You can go to http://consult.cern.ch/writeup/security/security_3.html
  1213.   for information on how to choose a good password.
  1214.  
  1215.  
  1216.   6.1.  PGP and Public Key Cryptography
  1217.  
  1218.  
  1219.   Public Key Cryptography, such as that which is used for PGP, involves
  1220.   cryptography that uses one key for encryption, and one key for
  1221.   decryption.  Traditionally, cryptography involves using the same key
  1222.   for encryption that is used for decryption.  This "private key" must
  1223.   be known to both parties, and somehow transferred from one another
  1224.   securely.
  1225.  
  1226.   Public key encryption alleviates the need to securely transmit the key
  1227.   that is used for encryption by using two seperate keys, a public key
  1228.   and a private key.  Each person's public key is available by anyone to
  1229.   do the encryption, while at the same time each person keeps his or her
  1230.   private key to decrypt messages encrypted with the correct public key.
  1231.  
  1232.   There are advantages to both public key and private key cryptography,
  1233.   and you can read about those differences in the RSA Cryptography FAQ,
  1234.   listed at the end of this section.
  1235.  
  1236.   PGP (Pretty Good Privacy) is well supported on Linux. Versions 2.6.2
  1237.   and 5.0 are known to work well. For a good primer on PGP and how to
  1238.   use it, take a look a the PGP FAQ.
  1239.   http://www.pgp.com/service/export/faq/55faq.cgi Be sure to use the
  1240.   version that is applicable to your country, as due to export
  1241.   restrictions by the US Government, strong-encryption is considered a
  1242.   military weapon, and prohibited from being transferred in electronic
  1243.   form outside the country.
  1244.  
  1245.   There is also a step-by-step guide for configuring PGP on Linux
  1246.   available at
  1247.   http://mercury.chem.pitt.edu/~angel/LinuxFocus/English/November1997/article7.html
  1248.   It was written for the International version of PGP, but is easily
  1249.   adaptable to the United States version.  You may also need a patch for
  1250.   some of the latest versions of Linux, which is available at
  1251.   ftp://sunsite.unc.edu/pub/Linux/apps/crypto.
  1252.  
  1253.   More information on cryptography can be found in the RSA cryptography
  1254.   FAQ, available at http://www.rsa.com/rsalabs/newfaq/.  Here you will
  1255.   find information on such terms as "Diffie-Hellman", "public-key
  1256.   cryptography", "Digital Certificates", etc.
  1257.  
  1258.  
  1259.   6.2.  SSL, S-HTTP, HTTPS and S/MIME
  1260.  
  1261.   Often times users ask about the differences between the various
  1262.   security and encryption protocols, and how to use them.  While this
  1263.   isn't an encryption document, it is a good idea to explain briefly
  1264.   what each are, and where to find more information.
  1265.  
  1266.   o  SSL: - SSL, or Secure Sockets Layer, is an encryption method
  1267.      developed by Netscape to provide security over the Internet.  It
  1268.      supports several different encryption protocols, and provides
  1269.      client and server authentication.  SSL operates at the transport
  1270.      layer, creates a secure encrypted channel of data, and thus can
  1271.      seamlessly encrypt data of many types.  This is most commonly seen
  1272.      when going to a secure site to view a secure online document with
  1273.      Communicator, and serves as the basis for secure communications
  1274.      with Communicator, as well as many other Netscape Communications
  1275.      data encryption.  More information can be found at
  1276.      http://www.consensus.com/security/ssl-talk-faq.html.  Information
  1277.      on Netscape's other security implementations, and a good starting
  1278.      point for these protocols is available at
  1279.      http://home.netscape.com/info/security-doc.html.
  1280.  
  1281.  
  1282.   o  S-HTTP: - S-HTTP is another protocol that provides security
  1283.      services across the Internet.  It was designed to provide
  1284.      confidentiality, authenticity, integrity, and non-repudiability
  1285.      [cannot be mistaken for someone else ] while supporting multiple
  1286.      key management mechanisms and cryptographic algorithms via option
  1287.      negotiation between the parties involved in each transaction. S-
  1288.      HTTP is limited to the specific software that is implementing it,
  1289.      and encrypts each message individually.  [ From RSA Cryptography
  1290.      FAQ, page 138]
  1291.  
  1292.  
  1293.   o  S/MIME: - S/MIME, or Secure Multipurpose Internet Mail Extension,
  1294.      is an encryption standard used to encrypt electronic mail, or other
  1295.      types of messages on the Internet.  It is an open standard
  1296.      developed by RSA, so it is hopefully likely we will see it on Linux
  1297.      one day soon.  More information on S/MIME can be found at
  1298.      http://home.netscape.com/assist/security/smime/overview.html.
  1299.  
  1300.  
  1301.   6.3.  Linux x-kernel IPSEC Implementation
  1302.  
  1303.   Along with CIPE, and other forms of data encryption, there is also an
  1304.   implemention of IPSEC for Linux.  IPSEC is an effort by the IETF to
  1305.   create cryptographically secure communications at the IP network
  1306.   level, which also provides authentication, integrity, access control,
  1307.   and confidentiality.  Information on IPSEC and Internet draft can be
  1308.   found at http://www.ietf.org/html.charters/ipsec-charter.html. You can
  1309.   also find links to other protocols involving key management, and an
  1310.   IPSEC mailing list and archives.
  1311.  
  1312.   The Linux implementation, which is being developed at the University
  1313.   of Arizona, uses an object-based framework for implementing network
  1314.   protocols called x-kernel, and can be found at
  1315.   http://www.cs.arizona.edu/xkernel/hpcc-blue/linux.html.  Most simply,
  1316.   the x-kernel is a method of passing messages at the kernel level,
  1317.   which makes for an easier implementation.
  1318.  
  1319.   As with other forms of cryptography, it is not distributed with the
  1320.   kernel by default due to export restrictions.
  1321.   6.4.  SSH (Secure Shell), stelnet
  1322.  
  1323.   SSH and stelnet are programs that allow you to login to remote systems
  1324.   and have a encrypted connection.
  1325.  
  1326.   SSH is a suite of programs used as a secure replacement for rlogin,
  1327.   rsh and rcp.  It uses public-key cryptography to encrypt
  1328.   communications between two hosts, as well as for user authentication.
  1329.   This can be used to securely login to a remote host or copy data
  1330.   between hosts, while preventing man-in-the-middle attacks (session
  1331.   hijacking) and DNS spoofing.  It will perform data compression on your
  1332.   connections, and secure X11 communications between hosts.  The SSH
  1333.   home page can be found at http://www.cs.hut.fi/ssh/
  1334.  
  1335.   You can also use SSH from your Windows workstation to your Linux SSH
  1336.   server.  There are several freely available Windows client
  1337.   implementations, including the one at
  1338.   http://guardian.htu.tuwien.ac.at/therapy/ssh/ as well as a commercial
  1339.   implementation from DataFellows, at http://www.datafellows.com.
  1340.  
  1341.   SSLeay is a free implmentation of Netscape's Secure Sockets Layer
  1342.   protocol, including several applications, such as Secure telnet, a
  1343.   module for Apache, several databases, as well as several algorithms
  1344.   including DES, IDEA and Blowfish.
  1345.  
  1346.   Using this library, a secure telnet replacement has been created that
  1347.   does encryption over a telnet connection.  Unlike SSH, stelnet uses
  1348.   SSL, the Secure Sockets Layer protocol developed by Netscape.  You can
  1349.   find Secure telnet and Secure FTP by starting with the SSLeay FAQ,
  1350.   available at http://www.psy.uq.oz.au/~ftp/Crypto/
  1351.  
  1352.  
  1353.   6.5.  PAM - Pluggable Authentication Modules
  1354.  
  1355.   Newer versions of the Red Hat Linux distribution ship with a unified
  1356.   authentication scheme called "PAM". PAM allows you to change on the
  1357.   fly your authentication methods, requirements, and encapsulate all
  1358.   local authentication methods without re-compiling any of your
  1359.   binaries.  Configuration of PAM is beyond the scope of this document,
  1360.   but be suer to take a look at the PAM web site for more information.
  1361.   http://www.kernel.org/pub/linux/libs/pam/index.html
  1362.  
  1363.   Just a few of the things you can do with PAM:
  1364.  
  1365.  
  1366.   o  Use a non DES encryption for your passwords. (Making them harder to
  1367.      brute force decode)
  1368.  
  1369.   o  Set resource limits on all your users so they can't perform denial
  1370.      of service attacks (number of processes, amount of memory, etc)
  1371.  
  1372.   o  Enable shadow passwords (see below) on the fly
  1373.  
  1374.   o  allow specific users to login only at specific times from specific
  1375.      places
  1376.  
  1377.   Within a few hours of installing and configuring your system, you can
  1378.   prevent many attacks before they even occur.  For example, use PAM to
  1379.   disable the system-wide usage of dot-rhosts files in user's home
  1380.   directories by adding these lines to /etc/pam.d/login:
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.                   #
  1388.                   # Disable rsh/rlogin/rexec for users
  1389.                   #
  1390.                   login auth required pam_rhosts_auth.so no_rhosts
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396.   6.6.  Cryptographic IP Encapsulation (CIPE)
  1397.  
  1398.   The primary goal of this software is to provide a facility for secure
  1399.   (against eavesdropping, including traffic analysis, and faked message
  1400.   injection) subnetwork interconnection across an insecure packet
  1401.   network such as the Internet.
  1402.  
  1403.   CIPE encrypts the data at the network level.  Packets travelling
  1404.   between hosts on the network are encrypted.  The encryption engine is
  1405.   placed near the driver which sends and receives packets.
  1406.  
  1407.   This is unlike SSH, which encrypts the data by connection, at the
  1408.   socket level.  A logical connection between programs running on
  1409.   different hosts is encrypted.
  1410.  
  1411.   CIPE can be used in tunnelling, in order to create a Virtual Private
  1412.   Network.  Low-level encryption has the advantage that it can be made
  1413.   to work transparently between the two networks connected in the VPN,
  1414.   without any change to application software.
  1415.  
  1416.   Summarized from the CIPE documentation:
  1417.  
  1418.   The IPSEC standards define a set of protocols which can be used (among
  1419.   other things) to build encrypted VPNs.  However, IPSEC is a rather
  1420.   heavyweight and complicated protocol set with a lot of options,
  1421.   implementations of the full protocol set are still rarely used and
  1422.   some issues (such as key management) are still not fully resolved.
  1423.   CIPE uses a simpler approach, in which many things which can be
  1424.   parameterized (such as the choice of the actual encryption algorithm
  1425.   used) are an install-time fixed choice.  This limits flexibility, but
  1426.   allows for a simple (and therefore efficient, easy to debug...)
  1427.   implementation.
  1428.  
  1429.   Further information can be found at
  1430.   http://www.inka.de/~bigred/devel/cipe.html
  1431.  
  1432.   As with other forms of cryptography, it is not distributed with the
  1433.   kernel by default due to export restrictions.
  1434.  
  1435.  
  1436.  
  1437.   6.7.  Kerberos
  1438.  
  1439.   Kerberos is an authentication system developed by the Athena Project
  1440.   at MIT. When a user logs in, Kerberos authenticates that user (using a
  1441.   password), and provides the user with a way to prove her identity to
  1442.   other servers and hosts scattered around the network.
  1443.  
  1444.   This authentication is then used by programs such as rlogin to allow
  1445.   the user to login to other hosts without a password (in place of the
  1446.   .rhosts file).  The authentication is also used by the mail system in
  1447.   order to guarantee that mail is delivered to the correct person, as
  1448.   well as to guarantee that the sender is who he claims to be.
  1449.  
  1450.   The overall effect of installing Kerberos and the numerous other
  1451.   programs that go with it is to virtually eliminate the ability of
  1452.   users to "spoof" the system into believing they are someone else.
  1453.   Unfortunately, installing Kerberos is very intrusive, requiring the
  1454.   modification or replacement of numerous stanard programs.
  1455.  
  1456.   You can find more information on kerberos at
  1457.   http://www.veritas.com/common/f/97042301.htm and the code can be found
  1458.   at http://nii.isi.edu/info/kerberos/
  1459.  
  1460.   [From: Stein, Jennifer G., Clifford Neuman, and Jeffrey L. Schiller.
  1461.   "Kerberos: An Authentication Service for Open Network Systems." USENIX
  1462.   Conference Proceedings, Dallas, Texas, Winter 1998.]
  1463.  
  1464.  
  1465.   6.8.  Shadow Passwords.
  1466.  
  1467.   Shadow passwords are a means of keeping your encrypted password
  1468.   information secret from normal users. Normally this encrypted password
  1469.   is stored in your /etc/passwd file for all to read. They can then run
  1470.   password guesser programs on it and attempt to determine what it is.
  1471.   Shadow passwords save this information to a /etc/shadow file that only
  1472.   privileged users can read. In order to run shadow passwords you need
  1473.   to make sure all your utilities that need access to password
  1474.   information are recompiled to support it. PAM (above) also allows you
  1475.   to just plug in a shadow module and doesn't require re-compilation of
  1476.   executables.  You can refer to the Shadow-Password HOWTO for further
  1477.   information if necessary.  It is available at
  1478.   http://sunsite.unc.edu/LDP/HOWTO/Shadow-Password-HOWTO.html It is
  1479.   rather dated now, and will not be required for distributions
  1480.   supporting PAM.
  1481.  
  1482.  
  1483.   6.9.  Crack and John the Ripper
  1484.  
  1485.   If for some reason your passwd program is not enforcing non easily
  1486.   guessable passwords, you might want to run a password cracking program
  1487.   and make sure your users passwords are secure.
  1488.  
  1489.   Password cracking programs work on a simple idea. They try every word
  1490.   in the dictionary, and then variations on those words. They encrypt
  1491.   each one and check it against your encrypted password. If they get a
  1492.   match they are in.
  1493.  
  1494.   There are a number of programs out there...the two most notable of
  1495.   which are "Crack" and "John the Ripper"
  1496.   http://www.false.com/security/john/index.html . They will take up a
  1497.   lot of your cpu time, but you should be able to tell if an attacker
  1498.   could get in using them by running them first yourself and notifying
  1499.   users with weak passwords. Note that an attacker would have to use
  1500.   some other hole first in order to get your passwd (unix /etc/passwd)
  1501.   file, but these are more common than you might think.
  1502.  
  1503.  
  1504.   6.10.  CFS - Cryptographic File System and TCFS - transparent crypto-
  1505.   graphic File System
  1506.  
  1507.   CFS is a way of encrypting an entire file system and allow users to
  1508.   store encrypted files on them. It uses a NFS server running on the
  1509.   local machine. rpms are avail at http://www.replay.com/redhat/ and
  1510.   more information on how it all works is at:
  1511.   ftp://ftp.research.att.com/dist/mab/
  1512.  
  1513.   TCFS improves on CFS, adding more integration with the file system, so
  1514.   that it's transparent to any users using the file system that it's
  1515.   encrypted. more information at: http://edu-gw.dia.unisa.it/tcfs/
  1516.  
  1517.  
  1518.  
  1519.   6.11.  X11, SVGA and display security
  1520.  
  1521.  
  1522.   6.11.1.  X11
  1523.  
  1524.   It's important for you to secure your graphical display to prevent
  1525.   attackers from doing things like: grabbing your passwords as you type
  1526.   them without you knowing it, reading documents or information you are
  1527.   reading on your screen, or even using a hole to gain superuser access.
  1528.   Running remote X applications over a network also can be fraught with
  1529.   peril, allowing sniffers to see all your interaction with the remote
  1530.   system.
  1531.  
  1532.   X has a number of access control mechanisms. The simplest of them is
  1533.   host based. You can use xhost to specify what hosts are allowed access
  1534.   to your display. This is not very secure at all. If someone has access
  1535.   to your machine they can xhost + their machine and get in easily.
  1536.   Also, if you have to allow access from an untrusted machine, anyone
  1537.   there can compromise your display.
  1538.  
  1539.   When using xdm (x display manager) to login, you get a much better
  1540.   access method: MIT-MAGIC-COOKIE-1. A 128bit cookie is generated and
  1541.   stored in your .Xauthorty file. If you need to allow a remote machine
  1542.   access to your display, you can use the xauth command and the
  1543.   information in your .Xauthority file to provide only that connection
  1544.   access.  See the Remote-X-Apps mini-howto, available at
  1545.   http://sunsite.unc.edu/LDP/HOWTO/mini/Remote-X-Apps.html.
  1546.  
  1547.   You can also use ssh (see ssh, above) to allow secure X connections.
  1548.   This has the advantage of also being transparent to the end user, and
  1549.   means that no un-encrypted data flows across the network.
  1550.  
  1551.   Take a look at the Xsecurity man page for more information on X
  1552.   security. The safe bet is to use xdm to login to your console and then
  1553.   use ssh to go to remote sites you wish to run X programs off of.
  1554.  
  1555.  
  1556.   6.11.2.  SVGA
  1557.  
  1558.   SVGAlib programs are typically SUID-root in order to access all your
  1559.   Linux machines video hardware. This makes them very dangerous. If they
  1560.   crash, you typically need to reboot your machine to get a usable
  1561.   console back. Make sure any SVGA programs you are running are
  1562.   authentic, and can at least be somewhat trusted. Even better, don't
  1563.   run them at all.
  1564.  
  1565.  
  1566.   6.11.3.  GGI (Generic Graphics Interface project)
  1567.  
  1568.   The Linux GGI project is trying to solve several of the problems with
  1569.   video interfaces on Linux. GGI will move a small piece of the video
  1570.   code into the Linux kernel, and then control access to the video
  1571.   system. This means GGI will be able to restore your console at any
  1572.   time to a known good state. They will also allow a secure attention
  1573.   key, so you can be sure that there is no Trojan horse login program
  1574.   running on your console. http://synergy.caltech.edu/~ggi/
  1575.  
  1576.  
  1577.   7.  Kernel Security
  1578.  
  1579.   This is a description of the kernel configuration options that relate
  1580.   to security, and an explanation of what they do, and how to use them.
  1581.  
  1582.   As the kernel controls your computer's networking, it is important
  1583.   that the kernel is very secure, and the kernel itself won't be
  1584.   compromised. To prevent some of the latest networkworking attacks, you
  1585.   should try and keep your kernel version current. You can find new
  1586.   kernels at ftp://ftp.kernel.org.
  1587.  
  1588.  
  1589.   7.1.  Kernel Compile Options
  1590.  
  1591.  
  1592.   o  IP: Drop source routed frames (CONFIG_IP_NOSR)
  1593.  
  1594.      This option should be enabled.  Source routed frames contain the
  1595.      entire path to their destination inside of the packet.  This means
  1596.      that routers the packet goes thru does not need to inspect the
  1597.      packet, and just forwards it on. This could lead to data entering
  1598.      your system that may be a potential exploit.
  1599.  
  1600.  
  1601.   o  IP: Firewalling (CONFIG_IP_FIREWALL)
  1602.  
  1603.      This option is necessary if you are going to configure your machine
  1604.      as a firewall, do masquerading, or wish to protect your dial-up
  1605.      workstation from someone entering via your PPP dial-up interface.
  1606.  
  1607.  
  1608.   o  IP: forwarding/gatewaying (CONFIG_IP_FORWARD)
  1609.  
  1610.      If you enable IP forwarding, your Linux box essentially becomes a
  1611.      router.  If your machine is on a network, you could be forwarding
  1612.      data from one network to another, and perhaps subverting a firewall
  1613.      that was put there to prevent this from happening.  Normal dial-up
  1614.      users will want to disable this, and other users should concentrate
  1615.      on the security implications of doing this.  Firewall machines will
  1616.      want this enabled, and used in conjunction with firewall software.
  1617.  
  1618.      You can enable and disable IP forwarding dynamically using the
  1619.      following command:
  1620.  
  1621.  
  1622.  
  1623.                root#  echo 1 > /proc/sys/net/ipv4/ip_forward
  1624.  
  1625.  
  1626.  
  1627.  
  1628.   and disable it with the command:
  1629.  
  1630.  
  1631.                root#  echo 0 > /proc/sys/net/ipv4/ip_forward
  1632.  
  1633.  
  1634.  
  1635.  
  1636.   This file (and many other files in /proc) will always appear to be
  1637.   zero length, but in fact aren't.  This is a newly introduced kernel
  1638.   feature, so be sure your using a kernel 2.0.33 or later.
  1639.  
  1640.  
  1641.   o  IP: firewall packet logging (CONFIG_IP_FIREWALL_VERBOSE)
  1642.  
  1643.      This option gives you information about packets your firewall
  1644.      received, like sender, receipient, port, etc.
  1645.  
  1646.  
  1647.   o  IP: always defragment (CONFIG_IP_ALWAYS_DEFRAG)
  1648.  
  1649.      Generally this option is disabled, but if you are building a
  1650.      firewall or a masquerading host, you will want to enable it.  When
  1651.      data is sent from one host to another, it does not always get sent
  1652.      as a single packet of data, but rather it is fragmented into
  1653.      several pieces.  The problem with this is that the port numbers are
  1654.      only stored in the first fragment.  This means that someone can
  1655.      insert information into the remaining packets for your connection
  1656.      that aren't supposed to be there.
  1657.  
  1658.  
  1659.   o  IP: syn cookies (CONFIG_SYN_COOKIES)
  1660.  
  1661.      SYN Attack is a denial of service (DoS) attack that consumes all
  1662.      the resources on your machine, forcing you to reboot.  We can't
  1663.      think of a reason you wouldn't normally enable this.
  1664.  
  1665.  
  1666.   o  Packet Signatures (CONFIG_NCPFS_PACKET_SIGNING)
  1667.  
  1668.      This is an option that is available in the 2.1 kernel series that
  1669.      will sign NCP packets for stronger security.  Normally you can
  1670.      leave it off, but it is there if you do need it.
  1671.  
  1672.  
  1673.   o  IP: Firewall packet netlink device (CONFIG_IP_FIREWALL_NETLINK)
  1674.  
  1675.      This is a really neat option that allows you to analyze the first
  1676.      128 bytes of the packets in a userspace program, to determine if
  1677.      you would like to accept or deny the packet, based on its validity.
  1678.  
  1679.  
  1680.   7.2.  Kernel Devices
  1681.  
  1682.   There are a few block and character devices available on Linux that
  1683.   will also help you with security.
  1684.  
  1685.   The two devices /dev/random and /dev/urandom are provided by the
  1686.   kernel to retrieve random data at any time.
  1687.  
  1688.   Both /dev/random and /dev/urandom should be secure enough to use in
  1689.   generating PGP keys, SSH challenges, and other applications where
  1690.   secure random numbers are requisite.  Attackers should be unable to
  1691.   predict the next number given any initial sequence of numbers from
  1692.   these sources.  There has been a lot of effort put in to ensuring that
  1693.   the numbers you get from these sources are random in every sense of
  1694.   the word random.
  1695.  
  1696.   The only difference is that /dev/random runs out of random bytes and
  1697.   it makes you wait for more to be accumulated.  Note that on some
  1698.   systems, it can block for a long time waiting for new user-generated
  1699.   entry to be entered into the system.  So you have to use care before
  1700.   using /dev/random.  (Perhaps the best thing to do is to use it when
  1701.   you're generating sensitive keying information, and you tell the user
  1702.   to pound on the keyboard repeatedly until you print out "OK, enough".)
  1703.  
  1704.   /dev/random is high quality entropy, generated from measuring the
  1705.   inter-interrupt times etc. It blocks until enough bits of random data
  1706.   are available.
  1707.  
  1708.   /dev/urandom is similar, but when the store of entropy is running low,
  1709.   it'll return a cryptographically strong hash of what there is. This
  1710.   isn't as secure, but it's enough for most applications.
  1711.  
  1712.   You might read from the devices using something like:
  1713.  
  1714.  
  1715.  
  1716.  
  1717.           root#  head -c 6 /dev/urandom | uuencode -
  1718.  
  1719.  
  1720.  
  1721.  
  1722.   This will print six random characters on the console, suitable for
  1723.   password generation.
  1724.  
  1725.   See /usr/src/linux/drivers/char/random.c for a description of the
  1726.   algorithm.
  1727.  
  1728.   Thanks to Theodore Y. Ts'o, Jon Lewis, and others from Linux-kernel
  1729.   for helping me (Dave) with this.
  1730.  
  1731.  
  1732.   8.  Network Security
  1733.  
  1734.   Network security is becoming more and more important as people spend
  1735.   more and more time connected. Compromising network security is often
  1736.   much easier than physical or local, and is much more common.
  1737.  
  1738.   There are a number of good tools to assist with network security, and
  1739.   more and more of them are shipping with Linux distributions.
  1740.  
  1741.  
  1742.   8.1.  Packet Sniffers
  1743.  
  1744.   One of the most common ways intruders gain access to more systems on
  1745.   your network is by employing a packet sniffer on a already compromised
  1746.   host. This "sniffer" just listens on the Ethernet port for things like
  1747.   "Password" and "Login" and "su" in the packet stream and then logs the
  1748.   traffic after that. This way, attackers gain passwords for systems
  1749.   they are not even attempting to break into. Clear text passwords are
  1750.   very vulnerable to this attack.
  1751.  
  1752.   EXAMPLE: host A has been compromised. Attacker installs a sniffer.
  1753.   Sniffer picks up admin logging into host B from Host C. It gets the
  1754.   admins personal password as they login to B. Then, the admin does a
  1755.   'su' to fix a problem. They now have the root password for Host B.
  1756.   Later the admin lets someone telnet from his account to host Z on
  1757.   another site. Now the attacker has a password/login on host Z.
  1758.  
  1759.   In this day and age, the attacker doesn't even need to compromise a
  1760.   system to do this, they could also bring a laptop or pc into a
  1761.   building and tap into your net.
  1762.  
  1763.   Using ssh or other encrypted password methods thwarts this attack.
  1764.   Things like APOP for pop accounts also prevents this attack. (Normal
  1765.   pop logins are very vulnerable to this, as is anything that sends
  1766.   clear text passwords over the wire.)
  1767.  
  1768.  
  1769.   8.2.  System services and tcp_wrappers
  1770.  
  1771.   As soon as you put your Linux system on ANY network the first thing to
  1772.   look at is what services you need to offer. Services that you do not
  1773.   need to offer should be disabled so that you have one less thing to
  1774.   worry about and attackers have one less place to look for a hole.
  1775.  
  1776.   There are a number of ways to disable services under Linux. You can
  1777.   look at your /etc/inetd.conf file and see what services are being
  1778.   offered by your inetd. Disable any that you do not need by commenting
  1779.   them out (# at the beginning of the line), and then sending your inetd
  1780.   process a SIGHUP.
  1781.  
  1782.  
  1783.   You can also remove (or comment out) services in your /etc/services
  1784.   file. This will mean that local clients will also be unable to find
  1785.   the service (ie, if you remove ftp, and try and ftp to a remote site
  1786.   from that machine it will fail with an unknown service message). It's
  1787.   usually not worth the trouble to remove services, since it provides no
  1788.   additional security. If a local person wanted to use ftp even tho you
  1789.   had commented it out, they would make their own client that use the
  1790.   common ftp port and would still work fine.
  1791.  
  1792.   Some of the services you will want to leave enabled are:
  1793.  
  1794.  
  1795.   o  ftp
  1796.  
  1797.   o  telnet
  1798.  
  1799.   o  mail, such as pop-3 or imap
  1800.  
  1801.   o  identd
  1802.  
  1803.   o  time
  1804.  
  1805.   If you know you are not going to use some particular package, you can
  1806.   also delete it entirely. rpm -e under the Red Hat distribution will
  1807.   erase an entire package. Under debian dpkg likely does the same thing.
  1808.  
  1809.   Additionally, you really want to disable the rsh/rlogin/rcp utilities,
  1810.   including login (used by rlogin), shell (used by rcp), and exec (used
  1811.   by rsh) from being started in /etc/inetd.conf.  These protocols are
  1812.   extremely insecure and have been the cause of exploits in the past.
  1813.  
  1814.   You should check your /etc/rc.d/rcN.d, where N is your systems run
  1815.   level and see if any of the servers started in that directory are not
  1816.   needed. The files in /etc/rc.d/rcN.d are actually symbolic links to
  1817.   the directory /etc/rc.d/init.d. Renaming the files in the init.d
  1818.   directory has the effect of disabling all the symbolic links in
  1819.   /etc/rc.d/rcN.d.  If you only wish to disable a service for a
  1820.   particular runlevel, rename the appropriate file with a lower-case
  1821.  
  1822.   If you have BSD style rc files, you will want to check /etc/rc* for
  1823.   programs you don't need.
  1824.  
  1825.   Most Linux distributions ship with tcp_wrappers "wrapping" all your
  1826.   tcp services. A tcp_wrapper (tcpd) is invoked from inetd instead of
  1827.   the real server. tcpd then checks the host that is requesting the
  1828.   service and either executes the real server or denies access from that
  1829.   host. tcpd allows you to restrict access to your tcp services. You
  1830.   should make a /etc/hosts.allow and add in only those hosts that need
  1831.   to have access to your machines services.
  1832.  
  1833.   If you are a home dialup user, we suggest you deny ALL. tcpd also logs
  1834.   failed attempts to access services, so this can give you an idea that
  1835.   you are under attack. If you add new services, you should be sure to
  1836.   configure it to use tcp_wrappers TCP based.  For example, a normal
  1837.   dial-up user can prevent outsiders from connecting to your machine,
  1838.   yet still have the ability to retrieve mail, and make network
  1839.   connections to the Internet.  To do this, you might add the following
  1840.   to your /etc/hosts.allow:
  1841.  
  1842.   ALL: 127.
  1843.  
  1844.   And of course /etc/hosts.deny would contain:
  1845.  
  1846.   ALL: ALL
  1847.  
  1848.  
  1849.   which will prevent external connections to your machine, yet still
  1850.   allow you from the inside to connect to servers on the Internet.
  1851.  
  1852.  
  1853.   8.3.  Verify Your DNS Information
  1854.  
  1855.   Keeping up-to-date DNS information about all hosts on your network can
  1856.   help to increase security.  In the event of an unauthorized host
  1857.   becomes connected to your network, you can recognize it by its lack of
  1858.   a DNS entry.  Many services can be configured to not accept
  1859.   connections from hosts that do not have valid DNS entries.
  1860.  
  1861.  
  1862.   8.4.  identd
  1863.  
  1864.   identd is a small program that typically runs out of your inetd. It
  1865.   keeps track of what user is running what tcp service, and then reports
  1866.   this to whoever requests it.
  1867.  
  1868.   Many people misunderstand the usefulness of identd, and so disable it
  1869.   or block all off site requests for it. identd is not there to help out
  1870.   remote sites. There is no way of knowing if the data you get from the
  1871.   remote identd is correct or not. There is no authentication in identd
  1872.   requests.
  1873.  
  1874.   Why would you want to run it then? Because it helps _you_ out, and is
  1875.   another data-point in tracking. If your identd is un compromised, then
  1876.   you know it's telling remote sites the user-name or uid of people
  1877.   using tcp services. If the admin at a remote site comes back to you
  1878.   and tells you user so and so was trying to hack into their site, you
  1879.   can easily take action against that user. If you are not running
  1880.   identd, you will have to look at lots and lots of logs, figure out who
  1881.   was on at the time, and in general take a lot more time to track down
  1882.   the user.
  1883.  
  1884.   The identd that ships with most distributions is more configurable
  1885.   than many people think. You can disable identd for specific users
  1886.   (they can make a .noident file), you can log all identd requests (I
  1887.   recommend it), you can even have identd return a uid instead of a user
  1888.   name or even NO-USER.
  1889.  
  1890.  
  1891.   8.5.  SATAN , ISS, and Other Network Scanners
  1892.  
  1893.   There are a number of different software packages out there that do
  1894.   port and service based scanning of machines or networks. SATAN and ISS
  1895.   are two of the more well known ones. This software connects to the
  1896.   target machine (or all the target machines on a network) on all the
  1897.   ports it can, and tries to determine what service is running there.
  1898.   Based on this information, you could find out the machine is
  1899.   vulnerable to a specific exploit on that server.
  1900.  
  1901.   SATAN (Security Administrators Tool for Analyzing Networks) is a port
  1902.   scanner with a web interface. It can be configured to do light,
  1903.   medium, or strong checks on a machine or a network of machines. It's a
  1904.   good idea to get SATAN and scan your machine or network, and fix the
  1905.   problems it finds. Make sure you get the copy of SATAN from sun-site
  1906.   or a reputable FTP or web site. There was a Trojan copy of SATAN that
  1907.   was distributed out on the net.
  1908.   http://www.trouble.org/~zen/satan/satan.html
  1909.  
  1910.   ISS (Internet Security Scanner) is another port based scanner. It is
  1911.   faster than Satan, and thus might be better for large networks.
  1912.   However, SATAN tends to provide more information.
  1913.  
  1914.  
  1915.   Abacus-Sentry is a commercial port scanner from www.psionic.com. Look
  1916.   at it's home page on the web for more information.
  1917.   http://www.psionic.com
  1918.  
  1919.   Detecting Port scans.
  1920.  
  1921.   There are some tools designed to alert you to probes by Satan and ISS
  1922.   and other scanning software, However liberal use of tcp_wrappers and
  1923.   making sure to look over your log files regularly, you should be able
  1924.   to notice such probes. Even on the lowest setting, Satan still leaves
  1925.   traces in the logs on a stock Red Hat system.
  1926.  
  1927.  
  1928.   8.6.  Sendmail, qmail and MTA's.
  1929.  
  1930.   One of the most important services you can provide is a mail server.
  1931.   Unfortunately, it is also one of the most vulnerable to attack, simply
  1932.   due to the number of tasks it must perform and the privileges it
  1933.   typically needs.
  1934.  
  1935.   If you are using sendmail it is very important to keep up on current
  1936.   versions. Sendmail has a long long history of security exploits.
  1937.   Always make sure you are running the most recent version.
  1938.   http://www.sendmail.org
  1939.  
  1940.   If you are tired of upgrading your version of sendmail every week, you
  1941.   might consider switching over to qmail. qmail was designed with
  1942.   security in mind from the ground up. It's fast and stable and secure.
  1943.   http://www.qmail.org
  1944.  
  1945.  
  1946.   8.7.  Denial of Service Attacks
  1947.  
  1948.   A Denial of service attack is one where the attacker tries to make
  1949.   some resource too busy to answer legitimate requests, or to deny
  1950.   legitimate users access to your machine.
  1951.  
  1952.   Denial of service attacks have increased greatly in recent years. Some
  1953.   of the more popular and recent ones are listed below. Note that new
  1954.   ones show up all the time, so this is just a few examples. Read the
  1955.   Linux security lists and the bugtraq list and archives for more
  1956.   current information.
  1957.  
  1958.  
  1959.   o  SYN Flooding - SYN flooding is a network denial of service attack.
  1960.      It takes advantage of a "loophole" in the way TCP connections are
  1961.      created. The newer Linux kernels (2.0.30 and up) have several
  1962.      configurable options to prevent SYN flood attacks from denying
  1963.      people access to your machine or services. See the section on
  1964.      kernel security for proper kernel protection options.
  1965.  
  1966.  
  1967.   o  Pentium "F00F" Bug - It was recently discovered that a series of
  1968.      assembly codes send to a genuine Intel Pentium processor would
  1969.      reboot the machine.  This affects every machine with a Pentium
  1970.      processor (not clones, not Pentium Pro or PII), no matter what
  1971.      operating system it's running. Linux kernel 2.0.32 and up contain a
  1972.      work around for this bug, preventing it from locking your machine.
  1973.      Kernel 2.0.33 has an improved version of the kernel fix, and is
  1974.      suggested over 2.0.32.  If you are running on a Pentium, you should
  1975.      upgrade now!
  1976.  
  1977.  
  1978.   o  Ping Flooding - Ping flooding is a simple brute force denial of
  1979.      service attack. The attacker sends a "flood" of ICMP packets to
  1980.      your machine. If they are doing this from a host with better
  1981.      bandwidth than yours, your machine will be unable to send anything
  1982.      on the network. A variation on this attack, called "smurfing",
  1983.      sends ICMP packets to a host with _your_ machines return IP,
  1984.      allowing them to flood you less detectably.  You can find more
  1985.      information about the "smurf" attack at
  1986.      http://www.quadrunner.com/~chuegen/smurf.txt
  1987.  
  1988.      If you are ever under a ping flood attack, use a tool like tcpdump
  1989.      to determine where the packets are coming from (or appear to be
  1990.      coming from), then contact your provider with this information.
  1991.      Ping floods can most easily be stopped at the router level or by
  1992.      using a firewall.
  1993.  
  1994.  
  1995.   o  Ping o' Death - The Ping o' Death attack is a result of incoming
  1996.      ICMP ECHO REQUEST packets being larger than the kernel data
  1997.      structures that store this information can hold.  Because sending a
  1998.      single, large (65,510 bytes) "ping" packet to many systems will
  1999.      cause them to hang or even crash, this problem was quickly dubbed
  2000.      the "Ping o' Death."  This one has long been fixed, and is no
  2001.      longer anything to worry about.
  2002.  
  2003.  
  2004.   o  Teardrop / New Tear - One of the most recent exploits involves a
  2005.      bug present in the IP fragmentation code on Linux and Windows
  2006.      platforms.  It is fixed in kernel version 2.0.33, and does not
  2007.      require selecting any kernel compile-time options to utilize the
  2008.      fix.  Linux is apparently not vulnerable to the 'newtear' exploit.
  2009.  
  2010.  
  2011.      You can find most exploit code, and a more in-depth description of
  2012.      how they work at http://www.rootshell.com using their search
  2013.      engine.
  2014.  
  2015.  
  2016.   8.8.  NFS (Network File System) Security.
  2017.  
  2018.   NFS is a very widely used file sharing protocol. It allows servers
  2019.   running nfsd and mountd to "export" entire filesystems to other
  2020.   machines with nfs filesystem support builtin to their kernels (or some
  2021.   other client support if they are non Linux machines). Mountd keeps
  2022.   track of mounted filesystems in /etc/mtab, and can display them with
  2023.  
  2024.   Many sites use NFS to serve home directories to users, so that no
  2025.   matter what machine in the cluster they login to, they will have all
  2026.   their home files.
  2027.  
  2028.   There is some small amount of "security" allowed in exporting
  2029.   filesystems. You can make your nfsd map the remote root user (uid=0)
  2030.   to the nobody user, denying them total access to the files exported.
  2031.   However, since individual users have access to their own (or at least
  2032.   the same uid) files, the remote superuser can login or su to their
  2033.   account and have total access to their files. This is only a small
  2034.   hindrance to an attacker that has access to mount your remote
  2035.   filesystems.
  2036.  
  2037.   If you must use NFS, make sure you export to only those machines that
  2038.   you really need to export only. Never export your entire root
  2039.   directory, export only directories you need to export.
  2040.  
  2041.   See the NFS HOWTO for more information on NFS: NFS HOWTO
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.   8.9.  NIS (Network Information Service) (formerly YP).
  2048.  
  2049.   Network Information service (formerly YP) is a means of distributing
  2050.   information to a group of machines. The NIS master holds the
  2051.   information tables and converts them into NIS map files. These maps
  2052.   are then served over the network, allowing NIS client machines to get
  2053.   login, password, home directory and shell information (all the
  2054.   information in a standard /etc/passwd file). This allows users to
  2055.   change their password once and have it take affect on all the machines
  2056.   in the NIS domain.
  2057.  
  2058.   NIS is not at all secure. It was never meant to be. It was meant to be
  2059.   handy and usefull. Anyone that can guess the name of your NIS domain
  2060.   (anywhere on the net) can get a copy of your passwd file, and use
  2061.   crack and john the ripper against your users passwords. Also, it is
  2062.   possible to spoof NIS and do all sorts of nasty tricks. If you must
  2063.   use NIS, make sure you are aware of the dangers.
  2064.  
  2065.   There is a much more secure replacement for NIS, called NIS+.  Check
  2066.   out the NIS HOWTO for more information:
  2067.   http://sunsite.unc.edu/mdw/HOWTO/NIS-HOWTO.html
  2068.  
  2069.  
  2070.   8.10.  Firewalls
  2071.  
  2072.   Firewalls are a means of restricting what information is allowed into
  2073.   and out of your local network. Typically the firewall host is
  2074.   connected to the Internet and your local lan, and the only access from
  2075.   your lan to the Internet is through the firewall. This way the
  2076.   firewall can control what passes back and forth from the Internet and
  2077.   your lan.
  2078.  
  2079.   There are a number of types and methods of setting up firewalls. Linux
  2080.   machines make pretty good low cost firewalls. Firewall code can be
  2081.   built right into 2.0 and higher kernels. The ipfwadm user space tool
  2082.   allows you to change what types of network traffic you allow on the
  2083.   fly. You can also log particular types of network traffic.
  2084.  
  2085.   Firewalls are a very usefull and important technique in securing your
  2086.   network. It is important to realize that you should never think that
  2087.   because you have a firewall, you don't need to secure the machines
  2088.   behind it. This is a fatal mistake. Check out the very good Firewall-
  2089.   HOWTO at your latest sunsite archive for more information on firewalls
  2090.   and Linux. http://sunsite.unc.edu/mdw/HOWTO/Firewall-HOWTO.html
  2091.  
  2092.   More information can also be found in the IP-Masquerade mini-howto:
  2093.   http://sunsite.unc.edu/mdw/HOWTO/mini/IP-Masquerade.html
  2094.  
  2095.   More information on ipfwadm (The tool that lets you change settings on
  2096.   your firewall, can be found at it's home page:
  2097.   http://www.xos.nl/linux/ipfwadm/
  2098.  
  2099.  
  2100.   9.  Security Preparation (before you go on-line)
  2101.  
  2102.   Ok, so you have checked over your system, and determined its as secure
  2103.   as feasible, and are ready to put it online.  There are a few things
  2104.   you should now do in order to be prepared in case an intrusion
  2105.   actually does happen, so you can quickly disable the intruder, and get
  2106.   back up and running.
  2107.  
  2108.  
  2109.   9.1.  Make a Full Backup of Your Machine
  2110.  
  2111.   Discussion of backup methods and storage is beyond the scope of this
  2112.   document, but a few words relating to backups and security:
  2113.   If you have less than 650mb of data to store on a partition, a CD-R
  2114.   copy of your data is a good way to go (as it's hard to tamper with
  2115.   later, and if stored properly can last a long time). Tapes and other
  2116.   re-writable media should be write protected as soon as your backup is
  2117.   complete and verified to prevent tampering. Make sure you store your
  2118.   backups in a secure off line area. A good backup will ensure that you
  2119.   have a known good point to restore your system from.
  2120.  
  2121.  
  2122.   9.2.  Choosing a Good Backup Schedule
  2123.  
  2124.   A six-tape cycle is an easy one to maintain.  This includes four tapes
  2125.   for during the week, one tape for even Friday's, and one tape for odd
  2126.   Friday's.  Perform an incremental backup every day, and a full backup
  2127.   on the appropriate Friday tape. If you make some particular important
  2128.   changes or add some important data to your system, a backup might well
  2129.   be in order.
  2130.  
  2131.  
  2132.   9.3.  Backup Your RPM or Debian File Database
  2133.  
  2134.   In the event of an intrusion, you can use your RPM database like you
  2135.   would use tripwire, but only if you can be sure it too hasn't been
  2136.   modified.  You should copy the RPM database to a floppy, and keep this
  2137.   copy off-line at all times. The Debian distribution likely has
  2138.   something similar.
  2139.  
  2140.   Specifically, the files /var/lib/rpm/fileindex.rpm and
  2141.   /var/lib/rpm/packages.rpm most likely won't fit on a single floppy.
  2142.   Compressed, each should fit on a seperate floppy.
  2143.  
  2144.   Now, when your system is compromised, you can use the command:
  2145.  
  2146.  
  2147.  
  2148.                                root#  rpm -Va
  2149.  
  2150.  
  2151.  
  2152.  
  2153.   to verify each file on the system.  See the RPM man page, as there are
  2154.   a few other options that can be included to make it less verbose.
  2155.  
  2156.   This means that every time a new RPM is added to the system, the RPM
  2157.   database will need to be rearchived.  You will have to decide the
  2158.   advantages versus drawbacks.
  2159.  
  2160.  
  2161.   9.4.  Keep Track of Your System Accounting Data
  2162.  
  2163.   It is very important that the information that comes from syslog has
  2164.   not been compromised.  Making the files in /var/log readable and
  2165.   writable by a limited number of users is a good start.
  2166.  
  2167.   Be sure to keep an eye on what gets written there, especially under
  2168.   the `auth' facility.  Multiple login failures, for example, can
  2169.   indicate an attempted break-in.
  2170.  
  2171.   Where to look for your log file will depend on your distribution. In a
  2172.   Linux system that conforms to the "Linux Filesystem Standard", such as
  2173.   Red Hat, you will want to look in /var/log and check messages,
  2174.   mail.log, and others.
  2175.  
  2176.   You can find out where your distribution is logging to by looking at
  2177.   your /etc/syslog.conf file. This is the file that tells syslogd (the
  2178.   system logging daemon) where to log various messages.
  2179.   You might also want to configure your log-rotating script or daemon to
  2180.   keep logs around longer so you have time to examine them. Take a look
  2181.   at the 'logrotate' package un recent Red Hat distributions. Other
  2182.   distributions likely have a similar process.
  2183.  
  2184.   If your log files have been tampered with, see if you can determine
  2185.   when the tampering started, and what sort of things they appeared to
  2186.   tamper with. Are there large periods of time that cannot be accounted
  2187.   for?  Checking backup tapes (if you have any) for untampered log files
  2188.   is a good idea.
  2189.  
  2190.   Log files are typically modified by the intruder in order to cover his
  2191.   tracks, but they should still be checked for strange happenings. You
  2192.   may notice the intruder attempting to gain entrance, or exploit a
  2193.   program in order to obtain the root account. You might see log entries
  2194.   before the intruder has time to modify them.
  2195.  
  2196.   You should also be sure to seperate the `auth' facility from other log
  2197.   data, including attempts to switch users using `su', login attempts,
  2198.   and other user accounting information.
  2199.  
  2200.   If possible, configure syslog to send a copy of the most important
  2201.   data to a secure system.  This will prevent an intruder from covering
  2202.   his tracks by deleting his login/su/ftp/etc attempts.  See the
  2203.   syslog.conf man page, and refer to the `@' option.
  2204.  
  2205.   Finally, log files are much less useful when no one is reading them.
  2206.   Take some time out every once in a while to look over your log files,
  2207.   and get a feeling for what the look like on a normal day. Knowing this
  2208.   can help make unusual things stand out.
  2209.  
  2210.  
  2211.   9.5.  Apply All New System Updates.
  2212.  
  2213.   Most Linux users install from a CDROM. Due to the fast paced nature of
  2214.   security fixes, new (fixed) programs are always being released. Before
  2215.   you connect your machine to the network, it's a good idea to check
  2216.   with your distribution's ftp site (ftp.redhat.com for example) and get
  2217.   all the updated packages since you received your distribution CDROM.
  2218.   Many times these packages contain important security fixes, so it's a
  2219.   good idea to get them installed.
  2220.  
  2221.  
  2222.   10.  What To Do During and After a Breakin
  2223.  
  2224.   So you have followed some of the advice here (or elsewhere) and have
  2225.   detected a breakin? The first thing to do is to remain calm. Hasty
  2226.   actions can cause more harm than the attacker would have.
  2227.  
  2228.  
  2229.  
  2230.   10.1.  Security Compromise under way.
  2231.  
  2232.   Spotting a security compromise under way can be a tense undertaking.
  2233.   How you react can have large consequences.
  2234.  
  2235.   If the compromise you are seeing is a physical one, odds are you have
  2236.   spotted someone who has broken into your home, office or lab. You
  2237.   should notify your local authorities. In a lab setting you might have
  2238.   spotted someone trying to open a case or reboot a machine. Depending
  2239.   on your authority and procedures, you might ask them to stop, or
  2240.   contact your local security people.
  2241.  
  2242.   If you have detected a local user trying to compromise your security,
  2243.   the first thing to do is confirm they are in fact who you think they
  2244.   are. Check the site they are logging in from. Is it the site they are
  2245.   normally in from? no? Then use a non electronic means of getting in
  2246.   touch. For instance, call them on the phone or walk over to their
  2247.   office/house and talk to them. If they agree that they are on, you can
  2248.   ask them to explain what they were doing or tell them to cease doing
  2249.   it. If they are not on, and have no idea what you are talking about,
  2250.   odds are this incident requires further investigation. Look into such
  2251.   incidents , and have lots of information before making any
  2252.   accusations.
  2253.  
  2254.   If you have detected a network compromise, the first thing to do (if
  2255.   you are able) is to disconnect your network. If they are connected via
  2256.   modem, unplug the modem cable, if they are connected via ethernet,
  2257.   unplug the ethernet cable. This will prevent them from doing any
  2258.   further damage, and they will probably see it as a network problem
  2259.   rather than detection.
  2260.  
  2261.   If you are unable to disconnect the network (if you have a busy site,
  2262.   or you do not have physical control of your machines), the next best
  2263.   step is to use something like tcp_wrappers or ipfwadm to deny access
  2264.   from the intruders site.
  2265.  
  2266.   If you can't deny all people from the same site as the intruder,
  2267.   locking the users account will have to do. Note that locking an
  2268.   account is not an easy thing. You have to keep in mind .rhosts files,
  2269.   FTP access, and a host of backdoors).
  2270.  
  2271.   After you have done one of the above (disconnected network, denied
  2272.   access from their site, and/or disabled their account), you need to
  2273.   kill all their user processes and log them off.
  2274.  
  2275.   You should monitor your site well for the next few minutes, as the
  2276.   attacker will try and get back in. Perhaps using a different account,
  2277.   and/or from a different network address.
  2278.  
  2279.  
  2280.   10.2.  Security Compromise has already happened
  2281.  
  2282.   So you have either detected a compromise that has already happened or
  2283.   you have detected it and locked (hopefully) the offending attacker out
  2284.   of your system. Now what?
  2285.  
  2286.  
  2287.   10.2.1.  Closing the Hole
  2288.  
  2289.   If you are able to determine what means the attacker used to get into
  2290.   your system, you should try and close that hole. For instance, perhaps
  2291.   you see several FTP entries just before the user logged in. Disable
  2292.   the FTP service and check and see if there is an updated version or
  2293.   any of the lists know of a fix.
  2294.  
  2295.   Check all your log files, and make a visit to your security lists and
  2296.   pages and see if there are any new common exploits you can fix.  You
  2297.   can find Caldera security fixes here http://www.caldera.com/tech-
  2298.   ref/security/. Red Hat has not yet seperated their security fixes from
  2299.   bugfixes, but their distribution errata is available at
  2300.   http://www.redhat.com/errata  It is very likely that if one vendor has
  2301.   released a security update, that most other Linux vendors will as
  2302.   well.
  2303.  
  2304.   If you don't lock the attacker out, they will likely be back. Not just
  2305.   back on your machine, but back somewhere on your network. If they were
  2306.   running a packet sniffer, odds are good they have access to other
  2307.   local machines.
  2308.  
  2309.  
  2310.  
  2311.   10.2.2.  Assessing the Damage
  2312.  
  2313.   The first thing is to assess the damage. What has been compromised?
  2314.   If you are running an Integrity Checker like Tripwire you can make a
  2315.   tripwire run and it should tell you. If not, you will have to look
  2316.   around at all your important data.
  2317.  
  2318.   Since Linux systems are getting easier and easier to install, you
  2319.   might consider saving your config files and then wiping your disk(s)
  2320.   and reinstalling, then restoring your user files from backups and your
  2321.   config files. This will insure that you have a new clean system.  If
  2322.   you have to backup files from the compromised system, be especially
  2323.   cautious of any binaries that you restore as they may be trojan horses
  2324.   placed there by the intruder.
  2325.  
  2326.  
  2327.   10.2.3.  Backups, Backups, Backups!
  2328.  
  2329.   Having regular backups is a godsend for security matters. If your
  2330.   system is compromised, you can restore the data you need from backups.
  2331.   Of course some data is valuable to the attacker to, and they will not
  2332.   only destroy it, they will steal it and have their own copies, but at
  2333.   least you will still have the data.
  2334.  
  2335.   You should check several backups back into the past before restoring a
  2336.   file that has been tampered with. The intruder could have compromised
  2337.   your files long ago, and you could have made many successful backups
  2338.   of the compromised file!!!
  2339.  
  2340.   Of course, there are also a raft of security concerns with backups.
  2341.   Make sure you are storing them in a secure place. Know who has access
  2342.   to them. (If an attacker can get your backups, they can have access to
  2343.   all your data without you ever knowing it.)
  2344.  
  2345.  
  2346.   10.2.4.  Tracking Down the Intruder.
  2347.  
  2348.   Ok, you have locked the intruder out, and recovered your system, but
  2349.   you're not quite done yet. While it is unlikely that most intruders
  2350.   will ever be caught, you should report the attack.
  2351.  
  2352.   You should report the attack to the admin contact at the site where
  2353.   the attacker attacked your system. You can look up this contact with
  2354.   "whois" or the internic database. You might send them an email with
  2355.   all applicable log entries and dates and times. If you spotted
  2356.   anything else distinctive about your intruder, you might mention that
  2357.   too. After sending the email, you should (if you are so inclined)
  2358.   follow up with a phone call. If that admin in turn spots your
  2359.   attacker, they might be able to talk to the admin of the site where
  2360.   they are coming from and so on.
  2361.  
  2362.   Good hackers often use many intermediate systems. Some (or many) of
  2363.   which may not even know they have been compromised. Trying to track a
  2364.   cracker back to their home system can be difficult. Being polite to
  2365.   the admins you talk to can go a long way to getting help from them.
  2366.  
  2367.   You should also notify any security organizations you are a part of
  2368.   (CERT or similar).
  2369.  
  2370.  
  2371.   11.  Security Sources
  2372.  
  2373.   There are a LOT of good sites out there for UNIX security in general
  2374.   and Linux security specifically. It's very important to subscribe to
  2375.   one (or more) of the security mailing lists and keep current on
  2376.   security fixes. Most of these lists are very low volume, and very
  2377.   informative.
  2378.  
  2379.  
  2380.   11.1.  FTP sites
  2381.  
  2382.   CERT is the Computer Emergency Response Team. They often send out
  2383.   alerts of current attacks and fixes. cert.org
  2384.  
  2385.   Replay has archives of many security programs. Since they are outside
  2386.   the US, they don't need to obey US crypto restrictions.  replay.com
  2387.  
  2388.   Matt Blaze is the author of CFS and a great security advocate.  Matt
  2389.   Blaze's stuff
  2390.  
  2391.   tue.nl is a great security ftp site in the Netherlands.
  2392.   ftp.win.tue.nl
  2393.  
  2394.  
  2395.   11.2.  Web Sites
  2396.  
  2397.   The Hacker FAQ is a FAQ about hackers: The Hacker FAQ
  2398.  
  2399.   The COAST archive has a large number of unix security programs and
  2400.   information: COAST
  2401.  
  2402.   Rootshell.com is a great site for seeing what exploits are currently
  2403.   being used by crackers: rootshell.com exploits
  2404.  
  2405.   BUGTRAQ puts out advisories on security issues: BUGTRAQ archives
  2406.  
  2407.   CERT, the Computer Emergency Response Team, puts out advisories on
  2408.   common attacks on unix platforms: CERT home
  2409.  
  2410.   Dan Farmer is the author of SATAN and many other security tools, his
  2411.   home site has some interesting security survey information as well as
  2412.   security tools: Dan Farmers trouble.org
  2413.  
  2414.   The Linux security WWW is a good site for Linux security information:
  2415.   Linux Security WWW
  2416.  
  2417.   Reptile has lots of good Linux security information on his site:
  2418.   Reptiles Linux Security Page
  2419.  
  2420.   Infilsec has a vulnerability engine that can tell you what
  2421.   vunerabilities affect a specific platform: Infilsec vunerability
  2422.   engine
  2423.  
  2424.   CIAC sends out periodic security bulitins on common exploits: CIAC
  2425.   bulitins
  2426.  
  2427.   A good starting point for Linux Pluggable Authentication modules can
  2428.   be found at http://www.kernel.org/pub/linux/libs/pam/.
  2429.  
  2430.  
  2431.  
  2432.   11.3.  Mailing Lists
  2433.  
  2434.   Bugtraq:  To subscribe to bugtraq, send mail to listserv@netspace.org
  2435.   containing the message body subscribe bugtraq. (see links above for
  2436.   archives).
  2437.  
  2438.   CIAC: Send e-mail to: majordomo@tholia.llnl.gov In the BODY (not
  2439.   subject) of the message put (either or both): subscribe ciac-bulletin
  2440.  
  2441.  
  2442.  
  2443.   11.4.  Books - Printed Reading Material.
  2444.  
  2445.   There are a number of good security books out there. This section
  2446.   lists a few of them. In addition to the security specify books,
  2447.   security is covered in a number of other books on system
  2448.   administration.
  2449.  
  2450.   Building Internet Firewalls By D. Brent Chapman & Elizabeth D. Zwicky
  2451.  
  2452.   1st Edition September 1995
  2453.  
  2454.   ISBN: 1-56592-124-0
  2455.  
  2456.   Practical UNIX & Internet Security, 2nd Edition By Simson Garfinkel &
  2457.   Gene Spafford
  2458.  
  2459.   2nd Edition April 1996
  2460.  
  2461.   ISBN: 1-56592-148-8
  2462.  
  2463.   Computer Security Basics By Deborah Russell & G.T. Gangemi, Sr.
  2464.  
  2465.   1st Edition July 1991
  2466.  
  2467.   ISBN: 0-937175-71-4
  2468.  
  2469.   Linux Network Administrator's Guide By Olaf Kirch
  2470.  
  2471.   1st Edition January 1995
  2472.  
  2473.   ISBN: 1-56592-087-2
  2474.  
  2475.   PGP: Pretty Good Privacy By Simson Garfinkel
  2476.  
  2477.   1st Edition December 1994
  2478.  
  2479.   ISBN: 1-56592-098-8
  2480.  
  2481.   Computer Crime A Crimefighter's Handbook By David Icove, Karl Seger &
  2482.   William VonStorch (Consulting Editor Eugene H. Spafford)
  2483.  
  2484.   1st Edition August 1995
  2485.  
  2486.   ISBN: 1-56592-086-4
  2487.  
  2488.  
  2489.   12.  Glossary
  2490.  
  2491.  
  2492.   o  Host: A computer system attached to a network
  2493.  
  2494.  
  2495.   o  Firewall: A component or set of components that restricts access
  2496.      between a protected network and the Internet, or between other sets
  2497.      of networks.
  2498.  
  2499.  
  2500.   o  Bastion Host: A computer system that must be highly secured because
  2501.      it is vulnerable to attack, usually because it is exposed to the
  2502.      Internet and is a main point of contact for users of internal
  2503.      networks.  It gets its name from the highly fortified projects on
  2504.      the outer walls of medieval castles.  Bastions overlook critical
  2505.      areas of defense, usually having strongs walls, room for extra
  2506.      troops, and the occasional useful tub of boiling hot oil for
  2507.      discouraging attackers.
  2508.  
  2509.   o  Dual-homed Host: A general-purpose computer system that has at
  2510.      least two network interfaces.
  2511.  
  2512.  
  2513.   o  Packet: The fundamental unit of communication on the Internet.
  2514.  
  2515.  
  2516.   o  Packet Filtering: The action a device takes to selectively control
  2517.      the flow of data to and from a network.  Packet filters allow or
  2518.      block packets, usually while routing them from one network to
  2519.      another (most often from the Internet to an internal network, and
  2520.      vice-versa).  accomplish packet filtering, you set up a set of
  2521.      rules that specifiy what types of packets (those to or from a
  2522.      particular IP address or port) are to be allowed and what types are
  2523.      to be blocked.
  2524.  
  2525.  
  2526.   o  Perimeter network: A network added between a protected network and
  2527.      an external network, in order to provide an additional layer of
  2528.      security.  A perimeter network is sometimes called a DMZ.
  2529.  
  2530.  
  2531.   o  Proxy server: A program that deals with external servers on behalf
  2532.      of internal clients.  Proxy clients talk to proxy servers, which
  2533.      relay approved client requests on to real servers, and relay
  2534.      answers back to clients.
  2535.  
  2536.  
  2537.   o  Denial of Service: A denial of service attack is when an attacker
  2538.      consumes the resources on your computer for things it was not
  2539.      intended to be doing, thus preventing normal use of your network
  2540.      resources to legimite purposes.
  2541.  
  2542.  
  2543.   o  Buffer Overflow: Common coding style is never to allocate buffers
  2544.      "large enough" and not checking for overflows.  When such buffers
  2545.      are overflows, the executing program (daemon or set-uid program)
  2546.      can be tricked in doing some other things.  Generally this works by
  2547.      overwriting a function's return address on the stack to point to
  2548.      another location.
  2549.  
  2550.  
  2551.   o  IP Spoofing: IP-Spoofing is a complex technical attack that is made
  2552.      up of several components.  It is a security exploit that works by
  2553.      tricking computers in a trust-relationship that you are someone
  2554.      that you really aren't.  There is an extensive paper written by
  2555.      daemon9, route, and infinity in the Volume Seven, Issue Fourty-
  2556.      Eight issue of Phrack Magazine.
  2557.  
  2558.  
  2559.   o  Authentication: The property of knowing that the data received is
  2560.      the same as the data that was sent and that the claimed sender is
  2561.      in fact the actual sender.
  2562.  
  2563.  
  2564.   o  Non-repudiation: The property of a receiver being able to prove
  2565.      that the sender of some data did in fact send the data even though
  2566.      the sender might later desire to deny ever having sent that data.
  2567.  
  2568.  
  2569.   13.  Frequently Asked Questions
  2570.  
  2571.  
  2572.   1. Is it more secure to compile driver support directly into the
  2573.      kernel, instead of making it a module?
  2574.  
  2575.      Answer: Some people think it is better to disable the ability to
  2576.      load device drivers using modules, because an intruder could load a
  2577.      trojan module or himself load a module that could affect system
  2578.      security.
  2579.  
  2580.      However, in order to load modules, you must be root.  The module
  2581.      object files are also only writable by root.  This means the
  2582.      intruder would need root access to insert a module.  If the
  2583.      intruder gains root access, there are more serious things to worry
  2584.      about than whether he will load a module.
  2585.  
  2586.      Modules are for dynamically loading support for a particular device
  2587.      that may be infrequently used.  On server machines, or firewalls
  2588.      for instance, this is very unlikely to happen.  For this reason, it
  2589.      would make more sense to compile support directly into the kernel
  2590.      for machines acting as a server.  Modules are also slower than
  2591.      support compiled directly in the kernel.
  2592.  
  2593.  
  2594.   2. Logging in as root from a remote machine always fails.
  2595.  
  2596.      Answer: See the section on Root security.  This is done
  2597.      intentionally to prevent remote users from attempting to connect
  2598.      via telnet to your machine as root, which is a serious security
  2599.      vulnerability.  Don't forget, potential intruders have time on
  2600.      their side, and can run automated programs to find your password.
  2601.  
  2602.  
  2603.   3. How do I enable shadow passwords on my Red Hat 4.2 or 5.0 Linux
  2604.      box?
  2605.  
  2606.      Answer: Shadow passwords is a mechanism for storing your password
  2607.      in a file other than the normal /etc/passwd file.  This has several
  2608.      advantages.  The first one is that the shadow file, /etc/shadow, is
  2609.      only readable by root, unlike /etc/passwd, which must remain
  2610.      readable by everyone.  The other advantage is that as the
  2611.      administrator, you can enable or disable accounts without everyone
  2612.      knowing the status of other users accounts.
  2613.  
  2614.      The /etc/passwd file is then used to store user and group names,
  2615.      used by programs like `/bin/ls' to map the user ID to the proper
  2616.      username in a directory listing.
  2617.  
  2618.      The /etc/shadow file then only contains the username and his/her
  2619.      password, and perhaps accounting information, like when the account
  2620.      expires, etc.
  2621.  
  2622.      To enable shadow passwords, run 'pwconv' as root, and /etc/shadow
  2623.      should now exist, and be used by applications.  Since you are using
  2624.      RH 4.2 or above, the PAM modules will automatically adapt to the
  2625.      change from using normal /etc/passwd to shadow passwords without
  2626.      any other change.
  2627.  
  2628.      Since your interested in securing your passwords, perhaps you would
  2629.      also be interested in generating good passwords to begin with.  For
  2630.      this you can use the `pam_cracklib' module, which is part of PAM.
  2631.      It runs your password against the Crack libraries to help you
  2632.      decide if it is too easily guessable by password cracking programs.
  2633.  
  2634.  
  2635.   4. How can I enable the Apache SSL extensions?
  2636.  
  2637.      Answer:
  2638.  
  2639.      1.Get SSLeay 0.8.0 or later from
  2640.      ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL
  2641.      2.Build and test and install it!
  2642.  
  2643.      3.Get Apache 1.2.5 source
  2644.  
  2645.      4.Get Apache SSLeay extensions from here
  2646.      <ftp://ftp.ox.ac.uk/pub/crypto/SSL/apache_1.2.5+ssl_1.13.tar.gz>
  2647.  
  2648.      5.Unpack it in the apache-1.2.5 source directory and patch Apache
  2649.      as per the README.
  2650.  
  2651.      6.Configure and build it.
  2652.  
  2653.  
  2654.      You might also try Replay Associates which has many pre-built
  2655.      packages, and is located outside of the United States.
  2656.  
  2657.  
  2658.   5. How can I manipulate user accounts, and still retain security?
  2659.  
  2660.      Answer:  The Red Hat distribution, especially RH5.0, contains a
  2661.      great number of tools to change the properties of user accounts.
  2662.  
  2663.  
  2664.   o  The pwconv and unpwconv programs can be used to convert back and
  2665.      forth between shadow and non-shadowed passwords
  2666.  
  2667.   o  The pwck and grpck programs can be used to verify proper
  2668.      organization of the passwd and group files.
  2669.  
  2670.   o  The programs useradd, usermod, and userdel can be used to add,
  2671.      delete and modify user accounts.  The programs groupadd, groupmod,
  2672.      and groupdel will do the same for groups.
  2673.  
  2674.   o  Group passwords can be created using gpasswd.
  2675.  
  2676.      All these programs are 'shadow-aware' -- that is; if you enable
  2677.      shadow it will use /etc/shadow for password information, otherwise
  2678.      it won't.
  2679.  
  2680.      See the respective man pages for further information.
  2681.  
  2682.  
  2683.   6. How can I password protect specific HTML documents using Apache?
  2684.  
  2685.      I bet you didn't know about http://www.apacheweek.org did you?
  2686.  
  2687.      You can find information on User Authentication at
  2688.      http://www.apacheweek.com/features/userauth as well as other web
  2689.      server security tips from
  2690.      http://www.apache.org/docs/misc/security_tips.html
  2691.  
  2692.   14.  Conclusion
  2693.  
  2694.   By subscribing to the security alert mailing lists, and keeping
  2695.   current, you can do a lot towards securing your machine. If you pay
  2696.   attention to your log files and run something like tripwire regularly,
  2697.   you can do even more.
  2698.  
  2699.   A reasonable level of computer security is not difficult to maintain
  2700.   on a home machine. More effort is required on business machines, but
  2701.   Linux can indeed be a secure platform. Due to the nature of Linux
  2702.   development, security fixes often come out much faster than they do on
  2703.   commercial operating systems, making Linux an ideal platform when
  2704.   security is a requirement.
  2705.  
  2706.  
  2707.   15.  Thanks to
  2708.  
  2709.   Information here is collected from many sources. Thanks to the
  2710.   following that either indirectly or directly have contributed:
  2711.  
  2712.  
  2713.        Rob Riggs <rob@DevilsThumb.com>
  2714.        S. Coffin <scoffin@netcom.com>
  2715.        Viktor Przebinda <viktor@CRYSTAL.MATH.ou.edu>
  2716.        Roelof Osinga <roelof@eboa.com>
  2717.        Kyle Hasselbacher <kyle@carefree.quux.soltec.net>
  2718.        "David S. Jackson" <dsj@dsj.net>
  2719.        "Todd G. Ruskell" <ruskell@boulder.nist.gov>
  2720.        Rogier Wolff <R.E.Wolff@BitWizard.nl>
  2721.  
  2722.  
  2723.  
  2724.  
  2725.  
  2726.  
  2727.  
  2728.  
  2729.  
  2730.  
  2731.  
  2732.  
  2733.  
  2734.  
  2735.  
  2736.  
  2737.  
  2738.  
  2739.  
  2740.  
  2741.  
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.