A year ago, I attended a 4 day Linux Security class. The following are a list of notes that I compiled after I had returned from the class.
There are obviously many more things that can be done to safeguard your system but most of these items are a good starting point.
As the instructor repeatedly stated: "It's not a question of IF you're system is going to be hacked, it is a question of WHEN."
Remember: A FIREWALL WILL NOT KEEP CRACKERS OUT, ITS PURPOSE IS TO BUY YOU TIME TO REACT BEFORE THEY (script kiddies, et. al.) CAN DO SERIOUS DAMAGE. The only secure box is turned off and locked in the back room -- but it's also not much use to anyone.
The following services provide some useful service to remote users, yet do not provide login access:
Interactive user services - The following services allow
users to login or connect and directly access your
system:
Which services are used? Check /var/log/syslog to see if there are any instances of a sevice being used. If none, remove the service or remove it anyway until you find you need it. It is better to lock down the box and slowly re-enable services than to leave everything open.
After making the changes to/etc/inetd.conf, restart inetd using:
Other services can be 'wrapped' if they aren't already. This means using a package called "tcp_wrappers". When wrappers are used, all requests for the wrapped service are tested against /etc/hosts.allow and /etc/hosts.deny thus either authorizing the access or denying it. (see the man pages for "tcpd" for more information)<find the pid number for inetd>
ps aux | grep inetd<tell inetd to do a restart>
kill -HUP <pid for inetd>To verify a service is wrapped, look at the entry in /etc/inetd.conf. The TCP_wrapper checks any incoming request for service against an Access Control List (ACL).
Unwrapped service:
| echo | stream | tcp | nowait | root | internal |
Wrapped service:
| telnet | stream | tcp | nowait | root | /usr/sbin/tcpd | in.telnetd |
Some network tools are started from /etc/rc.d/rc<runlevel>.d (Example: /etc/rc.d/rc5.d) The files in these directories can be renamed to eliminate the associated startup.Another method for eliminating startup of daemons is to change the files in /etc/sysconfig/daemons. Edit the files there and change the parameter ONBOOT="yes" to "no".
Get a copy of nmap (www.insecure.org/nmap) and run it to determine what ports are open.
FTP access is controlled by the /etc/ftpaccessfile. Below are two entries; the first allows a single domain to have access and the second denies all access to everyone:
class all real most-trusted.comdeny * /etc/ftpdeny
(use this statement to block all ftp access but also comment out ftpd in /etc/inetd.conf)
The ftpdeny file can contain a message: "*** FTP ACCESS DENIED ***"
Here's an example of a logcheck scan of the log files. An attack was reported and prevented by portsentry:
Active System Attack
Alerts
=-=-=-=-=-=-=-=-=-=-=-=-=-=
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: SYN/Normal scan from host:
194.74.16.5/194.74.16.5 to TCP port: 81
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: Host 194.74.16.5 has been
blocked via wrappers with string: "ALL: 194.74.16.5" (an
entry is placed in /etc/hosts.deny to block the
attacker)
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: SYN/Normal scan from host:
194.74.16.5/194.74.16.5 to TCP port: 81
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: Host:
194.74.16.5/194.74.16.5 is already blocked
Ignoring
Security Violations
=-=-=-=-=-=-=-=-=-=
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: SYN/Normal scan from host:
194.74.16.5/194.74.16.5 to TCP port: 81
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: Host 194.74.16.5 has been
blocked via wrappers with string: "ALL:
194.74.16.5"
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: SYN/Normal scan from host:
194.74.16.5/194.74.16.5 to TCP port: 81
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: Host:
194.74.16.5/194.74.16.5 is already blocked
Ignoring
Unusual System Events
=-=-=-=-=-=-=-=-=-=-=
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: SYN/Normal scan from host:
194.74.16.5/194.74.16.5 to TCP port: 81
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: Host 194.74.16.5 has been
blocked via wrappers with string: "ALL:
194.74.16.5"
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: SYN/Normal scan from host:
194.74.16.5/194.74.16.5 to TCP port: 81
May 1 22:12:16 bmarsh
portsentry[6728]: attackalert: Host:
194.74.16.5/194.74.16.5 is already blocked
Ignoring
Knowing the version of your sendmail can help a hacker if there is an exploit for it. The 'configuration version' is kept in your /etc/sendmail.cf file. (Search for "Configuration version number") Change the version to anything you like. The sendmail greeting message can be changed in a similar manner.
# Configuration version number
DZ8.9.1Change to:
DZ8.7.2 (or anything)O SmtpGreetingMessage=$j Sendmail $v/$Z; $b
Change to:
# SMTP initial login message (old $e macro)
O SmtpGreetingMessage=$j UpChuck 1.01/1.nospam; $bThere are many other options and parameters that can be changed in sendmail.cf to improve security.
| -rwsr-xr-x | 1 | root | root | 21384 | Apr | 3 | 1999 | sliplogin |
To find such programs, use the command:find /<blank>\( -perm -4000 -o -perm -2000 \) >> /tmp/remove_suidswhich will create the /tmp/remove_suids file containing the names.Once you have found all the files, make a script to change all the SUID/SGID' Edit the /tmp/remove_suids file to first remove those programs that need the permission:
find / \( -perm -4000 -o -perm -2000 \) >> /tmp/remove_suids
cd /tmp
vi remove_suids
< remove sendmail, su, ping, traceroute, write, passwd, Xwrapper, cgi-bin files and possibly others>
<esc>
:g/^/s//chmod -s /
<move to top line and add the following line:>
#!/bin/sh
:wq!<the script: remove_suids has been created. Now we make it executable>
chmod 700 remove_suids<now execute the completed script file>
./remove_suids
chmod o-rw /bin
chmod o+t /tmp <=== turn on the sticky bit
chattr +a /var/log/syslog
lsattr /var/log/syslog
#
/etc/syslog.conf
# For info about the format of
this file, see "man syslog.conf" (the BSD
man
# page), and
/usr/doc/sysklogd/README.linux.
#
# NOTE: YOU HAVE TO USE TABS
HERE - NOT SPACES.
# I don't know
why.
#
*.=info;*.=notice;*.warn;mail.none<2
tab>/var/log/messages
*.=debug<5
tab>/var/log/debug
*.warn;*.crit;*.emerg<4
tab>/var/log/syslog
auth. *<6
tab>/var/log/log.auth
cron.*<6
tab>/var/log/log.cron
daemon.*<5
tab>/var/log/log.daemon
kern.*<6
tab>/var/log/log.kern
mail.*<6
tab>/var/log/log.mail
mark.*<6
tab>/var/log/log.mark
syslog.*<5
tab>/var/log/log.syslog
user.*<6
tab>/var/log/log.user
#uucp.*<6
tab>/var/log/log.uucp
#lpr.*<6
tab>/var/log/log.lpr
#news.*<6
tab>/var/log/log.news
|
|
|