From: <Microsoft Internet Explorer 5¡Æ¢® AuAa>
Subject: Beginner's guide to armoring Linux
Date: Sun, 17 Jun 2001 12:27:20 +0900
MIME-Version: 1.0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.enteract.com/~lspitz/linux.html
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.3018.1300

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Beginner's guide to armoring Linux</TITLE>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"Published article on how to armor Linux." =
name=3Ddescription>
<META=20
content=3D"hacking,linux,Linux,armoring,hardening,logging,inetd,syslog,TC=
P Wrappers"=20
name=3Dkeywords>
<STYLE type=3Dtext/css>A:active {
	TEXT-DECORATION: none
}
A:hover {
	TEXT-DECORATION: none
}
A:link {
	TEXT-DECORATION: none
}
A:visited {
	TEXT-DECORATION: none
}
</STYLE>

<META content=3D"MSHTML 5.00.3018.900" name=3DGENERATOR></HEAD>
<BODY link=3D#0000ff vLink=3D#800080>
<CENTER><I><FONT face=3D"Helvetica-Narrow,Arial Narrow"><FONT =
size=3D+1>Preparing=20
your linux box for the Internet</FONT></FONT></I> <BR><B><FONT=20
face=3D"Helvetica-Narrow,Arial Narrow"><FONT size=3D+4>Armoring=20
Linux</FONT></FONT></B>=20
<P><B><FONT size=3D-1><A=20
href=3D"mailto:lance@honeynet.org?Subject=3DArmoring Linux">Lance=20
Spitzner</A></B></FONT> <BR><A=20
href=3D"http://www.enteract.com/~lspitz">http://www.enteract.com/~lspitz<=
/A>=20
</FONT><BR>Last Modified: 19 September, 2000 </CENTER>
<P><B>Organizations throughout the world are adopting Linux as their =
production=20
platform.&nbsp;&nbsp; By connecting to the Internet to provide critical=20
services, they also become targets of opportunity.&nbsp; To help protect =
these=20
Linux systems, this article covers the basics of securing a Linux =
box.&nbsp; The=20
examples provided here are based on Red Hat 6.0, but should apply to =
most Linux=20
distributions.</B>=20
<P><B><FONT face=3D"Helvetica-Narrow,Arial Narrow"><FONT=20
size=3D+2>Installation</FONT></FONT></B> <BR>The best place to start in =
armoring=20
your system is at the beginning, OS installation. Since this is a =
production=20
system, you cannot trust any previous installations. You want to start =
with a=20
clean installation, where you can guarantee the system integrity. Place =
your=20
system in an isolated network. At no time do you want to connect this =
box to an=20
active network nor the Internet, exposing the system to a possible =
compromise. I=20
personally witnessed a system hacked by a <A=20
href=3D"http://www.enteract.com/~lspitz/enemy.html">script kiddie</A> =
within 15=20
minutes of connecting to the Internet.&nbsp; To get critical files and =
patches=20
later, you will need a second box that acts as a go between. This second =
box=20
will download files from the Internet, then connect to your isolated,=20
configuration "network" to transfer critical files or burn the patches =
to a=20
CDROM.=20
<P>Once you have placed your future Linux box in an isolated network, =
you are=20
ready to begin. The first step is selecting what OS package to load. As =
of RH=20
6.0, you have three options, Workstation, Server, and Custom =
(default).&nbsp; I=20
highly recommend Custom, as this allows you to choose what services are =
added=20
and how the system is partitioned.&nbsp; The idea is to load the minimum =

packages, while maintaining maximum efficiency.&nbsp;&nbsp; The less =
software=20
that resides on the box, the fewer potential security exploits or =
holes.&nbsp;=20
This means if you do not need a News or Real Audio Server, don't install =

it.&nbsp; The nice thing about Linux is, if you change your mind, it is =
easy to=20
add packages later.&nbsp; Regardless of which installation you choose, I =
would=20
add the manual pages and HOWTO docs.&nbsp; I find the on-line man pages =
and docs=20
to be a critical resource that add little risk to your system.=20
<P>If you selected Custom, you will be asked to partition your =
system.&nbsp; I=20
always like to make root as big as possible and just throw everything in =
there,=20
then you do not run out of room in the future.&nbsp; However, we do need =
several=20
partitions to protect the root drive.&nbsp; If we were to fill the root=20
partition with data, such as logging or email, we would cause a denial =
of=20
service, potentially crashing the system.=20
<P>Therefore, I always recommend a separate partition for /var, this is =
where=20
all the system logging and email goes.&nbsp; By isolating the /var =
partition,=20
you protect your root partition from overfilling.&nbsp;&nbsp; I've found =
400 MB=20
to be more then enough for /var (increase this if your system will have =
alot of=20
mail) .&nbsp; You may also consider making a separate partition for =
specific=20
application purposes, especially applications that store extensive =
logging. If=20
you are going to have users on your system you do not trust, you may =
also want=20
to create a seperate /home directory, so malicious users cannot fille =
the /=20
partition. For a standalone server, your partitions may look as follows: =

<P><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1>/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - everything=20
else</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1>/var&nbsp;&nbsp;&nbsp;&nbsp; - 400 MB</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT =
size=3D-1>swap&nbsp;&nbsp;&nbsp;&nbsp; - (I=20
normally go with 256 MB)</FONT></FONT> <BR>&nbsp;=20
<P>Once the system has rebooted after the installation, be sure to =
install the=20
recommend security patches. For Red Hat, you can find these security =
patches at=20
<A href=3D"http://www.redhat.com/apps/support/updates.html">Red Hat's =
errata=20
support site</A>.&nbsp; Patches are critical to armoring a system and =
should=20
always be updated.&nbsp; <A=20
href=3D"http://securityfocus.com/forums/bugtraq/faq.html#0.3.1">bugtraq@s=
ecurityfocus.com</A>=20
or <A=20
href=3D"http://www.redhat.com/corp/support/errata/">redhat-watch-list-req=
uest@redhat.com</A>=20
are excellent sources for following bugs and system patches.&nbsp; =
Without these=20
patches, your system can be easily compromised.&nbsp; Be sure to use =
your go=20
between box to get the patches, the Linux box should always remain on an =

isolated network. . For Red Hat, once you download the rpm, you can =
easily=20
update your system using the following syntax.&nbsp; An excellent =
example of=20
this is the security update for wu-ftpd=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>rpm -Uvh=20
wu-ftpd-2.6.0-14.6x.i386.rpm</FONT></FONT>=20
<P>For systems that are already on-line, you can ftp the rpm and install =
it at=20
the same time, using the following syntax.=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>rpm -Uvh=20
ftp://updates.redhat.com/6.1/i386/wu-ftpd-2.6.0-14.6x.i386.rpm</FONT></FO=
NT>=20
<P>To maintain your patches, I highly recommend the utility <A=20
href=3D"http://www.kaybee.org/~kirk">autorpm</A>. This command line =
utility=20
determines which .rpm's need to be updated, gets those rpm's from Red =
Hats's web=20
site, and then downloads and installs the updated files (if you so =
desire). This=20
tool is highly customizable and easy to use. The best thing is it can =
run out of=20
cron, so your file system gets checked every night, then emails you the =
next day=20
that you should update your system.=20
<P><B><FONT face=3D"Helvetica-Narrow,Arial Narrow"><FONT =
size=3D+2>Eliminating=20
Services</FONT></FONT></B> <BR>Once you have loaded the installation =
package,=20
patches, and rebooted, we are now ready to armor the operating system. =
Armoring=20
consists mainly of turning off services, adding logging, tweaking =
several files,=20
and configuring TCP Wrappers. First we will begin with turning off =
services.=20
<P>By default, Linux is a powerful operating system that executes many =
useful=20
services. However, most of these services are unneeded and pose a =
potential=20
security risk. The first place to start is /etc/inetd.conf. This file =
specifies=20
which services the /usr/sbin/inetd daemon will listen for. By default,=20
/etc/inetd.conf is configured for a variety of services, you most likely =
only=20
need two, ftp and telnet. You eliminate the remaining unnecessary =
services by=20
commenting them out (<A=20
href=3D"http://www.enteract.com/~lspitz/lx_example.html#A">example =
A</A>).&nbsp;=20
This is critical, as many of the services run by inetd pose serious =
security=20
threats, such as popd, imapd, and rsh.&nbsp; Confirm what you have =
commented out=20
with the following command (this will show you all the services that =
were left=20
uncommented)=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>&nbsp;grep -v "^#" =

/etc/inetd.conf</FONT></FONT>=20
<P>The next place to start are the .rc scripts, these scripts determine =
what=20
services are started by the init process. For Red Hat, you will find =
these=20
scripts in /etc/rc.d/rc3.d (or /etc/rc.d/rc5.d if you automatically boot =
to a=20
GUI, such as Gnome or KDE).&nbsp; To stop a script from starting, =
replace the=20
capital S with a small s. That way you can easily start the script again =
just by=20
replacing the small s with a capital S. Or, if you prefer, Red Hat comes =
with a=20
great utility for turning off these services.&nbsp; Just type "<FONT=20
face=3D"Courier New,Courier"><FONT =
size=3D-1>/usr/sbin/setup</FONT></FONT>" at the=20
command prompt, and select "<FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1>System Services</FONT></FONT>", from there you can select what =
scripts=20
are started during the boot up process.&nbsp; Another option is <FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1>chkconfig</FONT></FONT>, =
which you will=20
find on most distributions.&nbsp; The following startup scripts may be =
installed=20
by default but are not critical to system functioning.&nbsp; If you =
don't need=20
them, turn these scripts off.&nbsp; The numbers in the names determine =
the=20
sequence of initialization, they may vary based on your distribution and =

version.&nbsp; Scripts that start with a capital <B>K</B> instead of a =
captial=20
<B>S</B> are used to kill services that are already running.=20
<P><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S05apmd</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (You only =
need this=20
for laptops)</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S10xntpd&nbsp;&nbsp;&nbsp;&nbsp; </B>(Network time=20
protocol)</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S11portmap&nbsp;&nbsp; </B>(Required if you have any rpc =
services,=20
such as NIS or NFS)</FONT></FONT> <BR><FONT face=3D"Courier =
New,Courier"><FONT=20
size=3D-1><B>S15sound&nbsp;&nbsp;&nbsp;&nbsp; </B>(Saves sound cared=20
settings)</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S15netfs&nbsp;&nbsp;&nbsp;&nbsp; </B>(This is the nfs =
client, used=20
for mounting filesystems from a nfs server)</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT =
size=3D-1><B>S20rstatd&nbsp;&nbsp;&nbsp; </B>(Try=20
to avoid running any <B>r</B> services, they provide too much =
information to=20
remote users)</FONT></FONT> <BR><B><FONT face=3D"Courier =
New,Courier"><FONT=20
size=3D-1>S20rusersd</FONT></FONT></B> <BR><B><FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1>S20rwhod</FONT></FONT></B> =
<BR><B><FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1>S20rwalld</FONT></FONT></B> =
<BR><FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1><B>S20bootparamd </B>(Used =
for diskless=20
clients, you probably don't need this vulnerable =
service<B>)</B></FONT></FONT>=20
<BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S25squid&nbsp;&nbsp;&nbsp;&nbsp; </B>(Proxy =
server)</FONT></FONT>=20
<BR><FONT face=3D"Courier New,Courier"><FONT size=3D-1><B>S34yppasswdd =
</B>(Required=20
if you are a NIS server, this is an extremely vulnerable =
service)</FONT></FONT>=20
<BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S35ypserv&nbsp;&nbsp;&nbsp; </B>(Required if you are a NIS =
server,=20
this is an extremely vulnerable service)</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT =
size=3D-1><B>S35dhcpd&nbsp;&nbsp;&nbsp;&nbsp;=20
</B>(Starts dhcp server daemon)</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S40atd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </B>(Used for =
the at=20
service, similar to cron, by not required by the system)</FONT></FONT> =
<BR><FONT=20
face=3D"Courier New,Courier"><FONT =
size=3D-1><B>S45pcmcia&nbsp;&nbsp;&nbsp; </B>(You=20
only need this script for laptops)</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT =
size=3D-1><B>S50snmpd&nbsp;&nbsp;&nbsp;&nbsp;=20
</B>(SNMP daemon, can give remote users detailed information about your=20
system)</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S55named&nbsp;&nbsp;&nbsp;&nbsp; </B>(DNS server.&nbsp; If =
you are=20
setting up DNS, upgrade to the latest version of BIND,&nbsp; <A=20
href=3D"http://www.isc.org/bind.html">http://www.isc.org/bind.html</A>)</=
FONT></FONT>=20
<BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S55routed&nbsp;&nbsp;&nbsp; </B>(RIP, don't run this unless =
you=20
REALLY need it)</FONT></FONT> <BR><FONT face=3D"Courier =
New,Courier"><FONT=20
size=3D-1><B>S60lpd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </B>(Printing=20
services)</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S60mars-nwe</B>&nbsp;&nbsp; (Netware file and print=20
server)</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S60nfs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </B>(Use for NFS =
server,=20
do not run unless you absolutely have to).</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S72amd</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
(AutoMount=20
daemon, used to mount remote file systems)</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S75gated</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (used to run =
other routing=20
protocols, such as OSPF)</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1><B>S80sendmail&nbsp; =
</B>(You can still=20
send email if you turn this script off, you just will not be able to =
receive or=20
relay)</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S85httpd&nbsp;&nbsp;&nbsp;&nbsp; </B>(Apache webserver, I =
recommend=20
you upgrade to the latest version, <A=20
href=3D"http://www.apache.org/">http://www.apache.org/</A>)</FONT></FONT>=
=20
<BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S87ypbind&nbsp;</B>&nbsp;&nbsp;&nbsp; (Required if you are =
a NIS=20
client)</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S90xfs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </B>(X font=20
server)</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1><B>S95innd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </B>(News =
server)</FONT></FONT>=20
<BR><FONT face=3D"Courier New,Courier"><FONT =
size=3D-1><B>S99linuxconf</B>&nbsp;=20
(Used to remotely configure Linux systems via browser, every black-hat's =
dream=20
:)</FONT></FONT>=20
<P>To see how many services are running before you change the startup =
scripts,=20
type=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>ps aux | wc =
-l</FONT></FONT>=20
<P>Once you are done with the installation and have turned off the =
startup=20
scripts, type the command again and compare how the number of services =
have=20
decreased. The fewer services running, the better. Also, confirm which =
are left=20
running by executing the following command:=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>netstat -na --ip=20
</FONT></FONT>
<P><B><FONT face=3D"Helvetica-Narrow,Arial Narrow"><FONT =
size=3D+2>Logging and=20
Tweaking</FONT></FONT></B> <BR>Once you have eliminated as many services =
as=20
possible, we want to enable logging. All system logging occurs in=20
/var/log.&nbsp;&nbsp; By default, Linux has excellent logging, except =
for=20
ftp.&nbsp; You have two options for logging for ftp, configure =
/etc/ftpaccess=20
file or edit /etc/inetd.conf.&nbsp; I prefer to edit /etc/inetd.conf, as =
it is=20
simpler (i.e. harder to mess up :).&nbsp; Edit /etc/inetd.conf as =
follows to=20
ensure full logging of all FTP sessions.=20
<P><FONT face=3D"Courier New,Courier"><FONT =
size=3D-1>ftp&nbsp;&nbsp;&nbsp;&nbsp;=20
stream&nbsp; tcp&nbsp;&nbsp;&nbsp;&nbsp; nowait&nbsp; =
root&nbsp;&nbsp;&nbsp;=20
/usr/sbin/tcpd&nbsp; in.ftpd -l -L -i -o</FONT></FONT>=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>--- From the man =
pages=20
--</FONT></FONT>-=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>If the -l option =
is specified,=20
each ftp session is logged in the syslog</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1>If the -L flag is used, =
command logging=20
will be on by default as soon as the ftp server is invoked.&nbsp; This =
will=20
cause&nbsp; the&nbsp; server&nbsp; to log all USER commands, which if a =
user=20
accidentally enters a password for that command instead of the username, =
will=20
cause passwords to be logged via syslog.</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1>If the -i option is =
specified, files=20
received by the ftpd(8) server will be logged to the =
xferlog(5).</FONT></FONT>=20
<BR><FONT face=3D"Courier New,Courier"><FONT size=3D-1>If the -o option =
is=20
specified, files transmitted by the ftpd(8) server will be logged to the =

xferlog(5).</FONT></FONT>=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>--- snip snip=20
---</FONT></FONT>=20
<P>Next comes tweaking. This involves various file administration. The =
first=20
thing we want to do is secure our /etc/passwd file (this is the database =
file=20
that holds your user accounts and passwords).&nbsp; First, we want to =
ensure our=20
system is using /etc/shadow, this securely stores everyone's password as =
hashes=20
in a file only root can access.&nbsp; This protects your passwords from =
being=20
easily accessed and cracked (one of the first exploits a hacker looks=20
for).&nbsp; The use of shadow passwords is default as of RH 6.0, however =
it=20
never hurts to be sure. All you have to do is type the following command =
as=20
root.&nbsp; This automatically&nbsp; converts your passwords to the =
/etc/shadow=20
file. Of all the actions you can take to secure your system, I consider =
this to=20
be one of the most important.=20
<P><FONT face=3D"Courier New,Courier"><FONT =
size=3D-1>pwconv</FONT></FONT>=20
<P>The second step is to remove most of the default system accounts in=20
/etc/passwd.&nbsp; Linux provides these accounts for various system =
activities=20
which you may not need.&nbsp; If you do not need the accounts, remove=20
them.&nbsp; The more accounts you have, the easier it is to access your=20
system.&nbsp; An example is the "news" account.&nbsp; If you are not =
running=20
nntp, a news group server, you do not need the account (be sure to =
update=20
/etc/cron.hourly, as this looks for the user "news"). Also, make sure =
you remove=20
the "ftp" account, as this is the account used for anonymous ftp.&nbsp; =
From the=20
man pages.=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>man =
ftpd:</FONT></FONT>=20
<P><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ftpd authenticates users =
according=20
to four rules.</FONT></FONT>=20
<P><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
4)&nbsp;&nbsp;&nbsp;&nbsp; If&nbsp;=20
the&nbsp; user name is ``anonymous'' or ``ftp'', an anonymous ftp =
account must=20
be pre-sent in the password file (user ``ftp'').&nbsp; In this case the =
user is=20
allowed to log in by specifying any password (by convention this is =
given as the=20
client host's name).</FONT></FONT>=20
<P>For an example of my /etc/passwd file, check out <A=20
href=3D"http://www.enteract.com/~lspitz/lx_example.html#C">example =
C</A>.=20
<P>We also want to modify the file /etc/ftpusers (<A=20
href=3D"http://www.enteract.com/~lspitz/lx_example.html#D">example =
D</A>). Any=20
account listed in this file cannot ftp to the system. This restricts =
common=20
system accounts, such as root or bin, from attempting ftp sessions. =
Linux has=20
the file by default.&nbsp; Ensure that root stays in this file, you =
never want=20
root to be able to ftp to this system.&nbsp; Ensure that any accounts =
that need=20
to ftp to the box are NOT in the file /etc/ftpusers.=20
<P>Also, ensure that root cannot telnet to the system. This forces users =
to=20
login to the system as themselves and then su to root. The file =
/etc/securetty=20
lists what ttys root can connect to.&nbsp; List only tty1, tty2, etc in =
this=20
file, this restricts root logins to local access only.&nbsp; ttyp1, =
ttyp2, are=20
pseudo terminals, they allow root to telnet to the system remotely (<A=20
href=3D"http://www.enteract.com/~lspitz/lx_example.html#E">example =
E</A>).=20
<P>Last, create the file /etc/issue. This file is an ASCII text banner =
that=20
appears for all telnet logins (<A=20
href=3D"http://www.enteract.com/~lspitz/lx_example.html#B">example =
B</A>). This=20
legal warning will appear whenever someone attempts to login to your =
system. If=20
you want to continue using the same /etc/issue file, you will have to =
modify=20
/etc/rc.d/init.d/S99local.&nbsp; By default, Linux creates a new =
/etc/issue file=20
on every reboot. <BR>&nbsp;<B><FONT face=3D"Helvetica-Narrow,Arial =
Narrow"><FONT=20
size=3D+2></FONT></FONT></B>=20
<P><B><FONT face=3D"Helvetica-Narrow,Arial Narrow"><FONT =
size=3D+2>Connecting to=20
your server</FONT></FONT></B> <BR>For those of you who will be doing =
remote=20
administration, it is critical that you develop a secured, controlled =
way to=20
connect to the server.&nbsp; Often, you need remote access to your =
server for=20
administration or the uploading of files, these communications need to =
be=20
secured&nbsp; I will discuss two options here, ssh and TCP Wrappers.=20
<P>I prefer ssh, as it encrypts all communication between you and the=20
firewall.&nbsp; TCP Wrappers will NOT protect your network traffic from=20
sniffing.&nbsp; Users can still capture all of your <A=20
href=3D"http://www.enteract.com/~lspitz/keystrokes.txt">keystrokes</A>&nb=
sp;=20
(including passwords) on the network.&nbsp; If you are concerned about =
users=20
capturing communications to your firewall, I recommend you replace =
telnet/ftp=20
with ssh.&nbsp; ssh will encrypt all communications to your server, =
allowing you=20
both to upload files and administer the server in a secure manner.&nbsp; =
ssh is=20
similar to TCP wrappers in that it has its own layer of logging, and can =
limit=20
what systems can connect to it.&nbsp; For more information on ssh, you =
can find=20
<A href=3D"http://www.ssh.org/download.html">ssh here,</A> including =
source for=20
both ssh clients and server daemon.&nbsp; I recommend you use ssh =
version 1.2.x,=20
as version 2.x has a limiting license. Another ssh option is <A=20
href=3D"http://www.openssh.com/">Openssh</A>.=20
<P>TCP Wrappers, while it does not encrypt, it does log and control who =
can=20
access your system.&nbsp; It is a binary that wraps itself around inetd=20
services, such as telnet or ftp. With TCP Wrappers, the system launches =
the=20
wrapper for inetd connections, logs all attempts and then verifies the =
attempt=20
against a access control list. If the connection is permitted, TCP =
Wrappers=20
hands the connection to the proper binary, such as telnet. If the =
connection is=20
rejected by the access control list, then the connection is =
dropped.&nbsp;=20
Fortunately for us Linux users, TCP Wrappers is already installed, the =
only=20
thing left for us to do is edit the /etc/hosts.allow and /etc/hosts.deny =

file.&nbsp; These files determine who can and cannot access our =
systems.&nbsp;=20
Also, TCP Wrappers allows us to do fancy things, such as banners or =
spawn=20
additional programs, such as safe_finger.&nbsp; The syntax is relatively =

simple.&nbsp; Put the IP address or networks in /etc/hosts.allow that =
you want=20
to permit connections from.&nbsp; Put IP addresses or networks in=20
/etc/hosts.deny that you do not want to permit access.&nbsp; By default, =
Linux=20
allows connections from everyone, so you will need to modify these =
files.&nbsp;=20
2 recommendations when working with TCP Wrappers.=20
<OL>
  <LI>Use IP addresses instead of system or domain names.=20
  <LI>Set up /etc/hosts.deny to deny everything (ALL), then permit only =
specific=20
  sites with /etc/hosts.allow. </LI></OL>For examples on how to setup=20
/etc/hosts.allow and /etc/hosts.deny, see <A=20
href=3D"http://www.enteract.com/~lspitz/lx_example.html#F">example =
F</A>.&nbsp;=20
For more ideas on how to use TCPWrappers, check out <A=20
href=3D"http://www.enteract.com/~lspitz/ids.html">Intrusion =
Detection</A>.=20
<BR>&nbsp; <BR>&nbsp;=20
<P><B><FONT face=3D"Helvetica-Narrow,Arial Narrow"><FONT size=3D+2>For =
the Truly=20
Paranoid</FONT></FONT></B> <BR>I consider the measures discussed above=20
absolutely essential.&nbsp; By following these steps, you have greatly =
improved=20
your system's security, congratulations!&nbsp; Unfortunately, your =
system is not=20
100% secure, nor will it ever be.&nbsp; So, for the truly paranoid, I =
have added=20
some additional steps you can take.=20
<P>First we will create the wheel group.&nbsp; The wheel group is a =
group of=20
select individuals that can execute powerful commands, such as /bin/su. =
By=20
limiting the people that can access these commands, you enhance the =
system=20
security.&nbsp; To create the group, vi the file /etc/group, create the =
group=20
wheel, and add the system admins to the group.&nbsp; Then identify =
critical=20
system binaries, such as /bin/su.&nbsp; Change the group ownership to =
wheel, and=20
the permissions to owner and group executable only (be sure to maintain =
the suid=20
or guid bit for specific binaries).&nbsp; For /bin/su, the commands =
would be:=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>/bin/chgrp wheel=20
/bin/su</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1>/bin/chmod 4750 /bin/su</FONT></FONT>=20
<P>Second, we will lock down the files .rhosts, .netrc, and=20
/etc/hosts.equiv.&nbsp; The r commands use these files to access =
systems.&nbsp;=20
To lock them down, touch the files, then change the permissions to zero, =
locking=20
them down. This way no one can create or alter the files. For example,=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>/bin/touch =
/root/.rhosts=20
/root/.netrc /etc/hosts.equiv</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1>/bin/chmod 0 /root/.rhosts =
/root/.netrc=20
/etc/hosts.equiv</FONT></FONT>=20
<P>Third, we configure /etc/shadow to use <A=20
href=3D"http://www.enteract.com/~lspitz/md5.html">MD5 hashes</A> instead =
of the=20
crypt(3) function.&nbsp; This makes the encrypted password file far more =

difficult to crack.&nbsp; This is done by modifying the PAM =
modules.&nbsp; PAM=20
(Pluggable Authentication Modules) is a suite of shared libraries that =
enable=20
you to choose how applications authenticate users.&nbsp; To learn more =
about=20
PAM, check out <A=20
href=3D"ftp://ftp.us.kernel.org/pub/linux/libs/pam/Linux-PAM-html/pam.htm=
l">ftp://ftp.us.kernel.org/pub/linux/libs/pam/Linux-PAM-html/pam.html</A>=
=20

<P>In the old days, you had to manually modify the PAM modules to use =
MD5=20
hashes.&nbsp; However, with Red Hat 6.0 or greater, you can select MD5 =
hashes=20
with the setup utility.&nbsp; Just type "setup" at the command prompt, =
then=20
select "authentication configuration".&nbsp; From there, you can choose =
to use=20
MD5 hashes.&nbsp; However, the MD5 hashes will not take effect until the =
user=20
re-enters their password.&nbsp; For those of you who do not have the =
setup=20
utility (or have Red Hat 5.2 or earlier), you can still modify the PAM =
modules=20
manually (<A =
href=3D"http://www.enteract.com/~lspitz/lx_example.html#G">example=20
G</A>).=20
<P>For us bash users, I'm not a big fan of the .bash_history file.&nbsp; =
I do=20
not want people (including root) to know my command history.&nbsp; So, =
in my=20
.bash_profile, I export the following entry:=20
<P><FONT face=3D"Courier New,Courier"><FONT =
size=3D-1>HISTFILESIZE=3D0</FONT></FONT>=20
<P>This means that nothing will be logged to my .bash_history =
file.&nbsp; I will=20
still have keystroke history and recall, the HISTSIZE env variable, but =
command=20
history will not be written to the .bash_history file.=20
<P>Last thing we can do is protect our system from physical =
access.&nbsp; This=20
mainly consists of setting up a password for our BIOS.&nbsp; Also, you =
can=20
password protect your system during boot-up by configuring =
/etc/lilo.conf with a=20
password (<FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1>password=3Dxxx</FONT></FONT>)&nbsp; where xxx is your =
password.&nbsp;=20
However, keep in mind, once someone has physical access to your system, =
there is=20
no guaranteed way to protect it.=20
<P><B><FONT face=3D"Helvetica-Narrow,Arial Narrow"><FONT=20
size=3D+2>IPChains</FONT></FONT></B> <BR>No discussion about Linux =
security would=20
be complete without covering IPChains.&nbsp; IPChains is packet =
filtering=20
software that comes with the 2.2.x kernel and above. This means if you =
are=20
running Red Hat 6.0 or later, you have it as part of your Linux =
installation=20
kit.&nbsp; IPChains is similar to Cisco Access Control Lists, it can =
control=20
what packets can come in and out of your Linux box.&nbsp; Primarly used =
as a=20
firewall application, IPChains can also be used to armor your standalone =
Linux=20
box.&nbsp;&nbsp;&nbsp; To armor a standalone system, I configure =
IPChains to=20
allow only TCP connections I initiate.&nbsp; If anyone attempts to =
initate any=20
TCP connections to me, the connection is denied.&nbsp; Since IPChains is =
not=20
stateful, I do allow all UDP and ICMP connections.&nbsp; Last, I log all =
denied=20
connections, this lets me know if someone out there is being naughty =
:)&nbsp;=20
However, I drop but do not log all the broadcat/multicast traffic, as =
this would=20
quickly fill up the system logs. A simple IPChains configuration to =
armor a=20
standalone system would look something like this.=20
<P><FONT face=3D"Courier New,Courier"><FONT size=3D-1>bash# ipchains=20
-L</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT =
size=3D-1>Chain input=20
(policy DENY):</FONT></FONT> <BR><FONT face=3D"Courier =
New,Courier"><FONT=20
size=3D-1>target prot opt source destination ports</FONT></FONT> =
<BR><FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1>DENY all ------ 0.0.0.0 =
anywhere=20
n/a</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT =
size=3D-1>DENY all=20
------ anywhere 255.255.255.255 n/a</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1>DENY all ------ anywhere=20
BASE-ADDRESS.MCAST.NET/8 n/a</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1>ACCEPT tcp !y---- anywhere =
anywhere any=20
-&gt; any</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT=20
size=3D-1>ACCEPT udp ----l- anywhere anywhere any -&gt; =
any</FONT></FONT>=20
<BR><FONT face=3D"Courier New,Courier"><FONT size=3D-1>ACCEPT icmp =
----l- anywhere=20
anywhere any -&gt; any</FONT></FONT> <BR><FONT face=3D"Courier =
New,Courier"><FONT=20
size=3D-1>DENY all ----l- anywhere anywhere n/a</FONT></FONT> <BR><FONT=20
face=3D"Courier New,Courier"><FONT size=3D-1>Chain forward (policy=20
ACCEPT):</FONT></FONT> <BR><FONT face=3D"Courier New,Courier"><FONT =
size=3D-1>Chain=20
output (policy ACCEPT):</FONT></FONT>=20
<P>To see the config files for this, see <A=20
href=3D"http://www.enteract.com/~lspitz/lx_example.html#H">example =
H.</A> To learn=20
more about using IPChains as a firewall or for a standalone system, =
check out=20
the <A=20
href=3D"http://metalab.unc.edu/pub/Linux/docs/HOWTO/IPCHAINS-HOWTO">IPCha=
ins=20
HOWTO</A>.=20
<P><B><FONT face=3D"Helvetica-Narrow,Arial Narrow"><FONT=20
size=3D+2>Conclusion</FONT></FONT></B> <BR>We have covered some of the =
more basic=20
steps involved in armoring a Linux box (Red Hat distribution). The key =
to a=20
secure system is having the minimal software installed, with protection =
in=20
layers, such as TCP Wrappers, IPChains, and shadowed passwords. There =
are many=20
additional steps that can be taken, such as&nbsp; <A=20
href=3D"ftp://ftp.cerias.purdue.edu/pub/tools/unix/ids/tripwire/">tripwir=
e=20
</A>(monitor changes in system binaries) and <A=20
href=3D"http://www.enteract.com/~lspitz/swatch.html">swatch =
</A>(automated log=20
monitoring and alerts). I also recommend that new Linux users check out =
<A=20
href=3D"http://www.bastille-linux.org/">Bastille Linux,</A> a PERL =
script that can=20
automatically secure your new Linux system, step by step. Remember, no =
system is=20
truly 100% secure. However, with the steps outlined above, you greatly =
reduce=20
the security risks. <BR>
<P><B><I><FONT face=3D"Helvetica-Narrow,Arial Narrow">Author's =
bio</FONT></I></B>=20
<BR><I>Lance Spitzner is currently an active member of the <A=20
href=3D"http://project.honeynet.org/">Honeynet Project</A>. He enjoys =
learning by=20
blowing up systems in his home lab. Before this, he was a <A=20
href=3D"http://www.enteract.com/~lspitz/officer.html">tanker in the =
Rapid=20
Deployment Force,</A> where he blew up things of a different nature. You =
can=20
reach him at <A =
href=3D"mailto:lance@honeynet.org">lance@honeynet.org</A> .</I>=20
<BR>&nbsp; <BR>&nbsp;=20
<CENTER>
<TABLE border=3D5>
  <TBODY>
  <TR>
    <TD><I><FONT size=3D+2><A=20
      href=3D"http://www.enteract.com/~lspitz/pubs.html">Whitepapers</A> =

      =
</FONT></FONT></FONT></I></TD></TR></TBODY></TABLE></CENTER></BODY></HTML=
>

