Deadly Sins Linux
Deadly Sins Linux
Deadly Sins Linux
he problem with security advice is that there is too much of it and that those responsible for security certainly have too little time to implement all of it. The challenge is to determine what the biggest risks are and to worry about those rst and about others as time permits. Presented here are the seven common problemsthe seven deadly sins of securitymost likely to allow major damage to occur to your system or bank account. If any
38 May-June 2007 ACM QUEUE
of these are a problem on any of your systems, you will want to take care of them immediately. These seven deadly sins are based on my research and experience, which includes too many people who wait until after their Linux or Unix systems have suffered security breaches before they take action to increase system security, and on forensics analysis and discussions with systems administrators. Most of these sins and their solurants: [email protected]
1 7 6 5 4
2 3
tions also apply to Macs, Windows, and other platforms. They are not ordered by risk level because committing any one of them will likely allow your system to be compromised if it is accessible from the Internet. Even if you are behind a rewall, if you receive any untrusted data from the Internet, such as Web pages, e-mail, or instant messages, your system is at great risk. Avoid these sins like the devil.
more queue: www.acmqueue.com
Without further ado, here are the seven deadly sins and what to do about them.
Consider how severe the consequences would be if one account or one system gets hacked. Can the hacker then get into other accounts or other systems? If so, change passwords, ssh usage, etc. so that the hacker cannot spread the damage to other accounts and systems. This illustrates the concept of containment. Accept that some account, possibly root, on some system will get compromised. Ensure that the compromise will not spread by doing careful failure analysis now, before you suffer a compromise.
TIP
rants: [email protected]
TIP
Protecting every account is critical because of local root vulnerabilities in various programs and the Linux kernel itself. These vulnerabilities allow a hacker who gets shell access as any user to make himself or herself root.
passwd password requisite /usr/lib/security/pam_cracklib.so retry=3 passwd password required /usr/lib/security/pam_pwdb.so use_authtok
FIG 1
Avoid default passwords as if your job depended on it. makes very simple tests, there are more sophisticated routines that include much of Cracks capability. One way to do this is to make use of the cracklib capability in the PAM (pluggable authentication modules) enhancements to the passwd program. The cracklib library analyzes passwords to determine if they can be easily cracked. PAM offers additional security for Linux and Unix systems. Edit the /etc/pam.d/passwd le to include the code in gure 1. This will cause the PAM-enabled passwd program to load these dynamically loadable program libraries. PAM now is standard with Red Hat. On some systems these are in /lib instead of /usr/lib. (Another good source for PAM information is http://www.sun.com/software/ solaris/pam/.) On Slackware this capability will be enabled if the following line is present in /etc/login.defs (and the dictionary is installed): CRACKLIB_DICTPATH /var/cache/cracklib/cracklib_dict Consider restricting which remote systems can ssh into your systems various accounts either through IP tables rewall rules or by editing your ssh servers conguration le, /etc/ssh/sshd_config, to limit which remote systems can ssh in and which accounts they can ssh into, or use both methods for additional security. Make this list very short for root (in sshd_config).
Linux distributions and Unix vendors install tons of software and services by default. They deliberately prefer easy over secure. Many of these are neither necessary nor wanted. Take the time to remove software and services you do not need. Better yet, do not install them to begin with. To nd out which services are being run, use the netstat -atuv command. Even a home system can have dozens of different ports open. A large Web server could have more. If there are services listed that you do not want to be provided by this box, disable them. Many distributions offer a control panel to do this easily, including Red Hat and Mandriva. You may want to remove the binaries from the disk or chmod them to 0, especially any that are set-UID or set-GID. NFS, nger, the shell, exec, login r* services (rsh, rexec, and rlogin), FTP, telnet, sendmail, DNS, and linuxconf are some of the more popular services that get installed by default on many Linux distributions; at least some of these should not be enabled for most systems. Most are controlled by the daemon xinetd; these can be disabled by editing the /etc/xinetd.d/* scripts. You do not need the FTP or telnet daemons to use the respective clients to connect to other systems. You do not need the sendmail daemon listening on port 25 to send mail out, to send mail to local users, or to download mail via POP or IMAP. (You do need to invoke sendmail periodically to de-spool delayed outgoing mail.) You need DNS (named, the name daemon) only if other systems will be querying yours for this data. Most programs running on your own system will be very happy to read /etc/resolv.conf and query the main DNS server of your ISP or organization instead of contacting a named process running on your system. Coincidentally, nameds ports are some of the most popular ports that crackers use to break into systems. If you do need to run named, use the recently added facilities that allow it to chroot itself and switch to a nonroot user. All of these services, except the normal installations of NFS,1 DNS, and sendmail, are started on demand by xinetd. They may be turned off by commenting out their entries under /etc/xinetd.d. Many distributions offer a control panel or Linuxconf to do this easily, including Red Hat and Mandriva. ACM QUEUE May-June 2007 41
TIP
TIP
The most careful sysadmins will reboot their systems several times after making changes to startup scripts, other conguration les, and the kernel, and after installing security patches to ensure correct and reliable startup and operation.
One of the advantages of Linux is that when a x is issued, it is very quick to install. Furthermore, unless it is in the kernel, your downtime for that service is on the order of seconds or minutes. Rarely, if ever, is a reboot necessary.
rewall or to any system with condential information unless all wireless trafc rst is encrypted with IPsec or equivalent. Do not rely on WEP (Wired Equivalent Privacy) or its successors. Web servers and CGI programs are the bane of Linux and Unix computer security. Simply speaking, a CGI program is one of the easiest ways that a hacker can get into your system. It is essentially a program that runs on your computer at the request of anyone and everyone without passwords and has the access to do powerful things (for example, shipping valuable merchandise, revealing condential data such as your customers credit card numbers, and moving money between accounts). A CGI allows anyone to access your Web site, good intentions or not. While other accepted servers such as sendmail and named also will talk with anyone, the scope of what a client may request is far smaller. Although these latter servers have had their share of serious security bugs, those that keep their security patches up to date have minimal risk. Here are a few hard and fast rules that will help make your Web site secure. Know your data (supplied by Web clients). Establish maximums and minimums for data-entry values and lengths of elds. Decide which characters are acceptable in each eld. Expect the malicious to send you control characters and non-ASCII bytes. Expect that crackers will use the % encoding or alternate character sets to generate these evil characters. Thus, you need to check for illegal characters both before and after % conversion and in different character sets. Double-check each entered value. A surprising number of shopping-cart packages put the price of items in the form and believe the price in the lled-out form sent by the user. All a user needs to do to give himself or herself a discount is to alter this form. If possible enumerate the allowed values instead of using ranges (except for listing ranges of letters and digits). Understand, too, that an evil Web client can send bytes back to your server. The hacker may copy and alter your Web form to change your xed elds, etc. Use a secure language. Client-supplied data never should be handed directly to a shell script; there are too many opportunities for a cracker to get a shell or to exploit a buffer overow vulnerability. For many that secure language will be C, C++, Perl, Java, or Python. If that language offers checking for tainted data, use ACM QUEUE May-June 2007 43
unrelated memory. The strncpy() function is an excellent alternative. A safe way to copy strings is: strncpy(dest_buf, source_buf, sizeof dest_buf); dest_buf[sizeof dest_buf - 1] = \0; To detect a problem, one possibility is: if (strlen(source_buf) >= sizeof dest_buf) error(); else strcpy(dest_buf, source_buf);
Check for escape sequences, the possibility of a client issuing Linux or Unix commands (by inserting spaces, quotes, or semicolons), binary data, calls to other programs, etc. Often it is safer to have a list of allowed characters rather than determining each unsafe character. The following C code may be used to process a eld in which the client should supply his or her name. In this example, the calling process supplies a NUL-terminated string; this routine returns 0 if the string is a legal name, and -1 otherwise. The second argument species the maximum legal string allowed, including the terminating NUL byte. Note that the calling routine must be careful to ensure that its buffer did not overow. I chose clear code over slightly more efcient code. #include <string.h> char okname[] = .-,abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ;
/* Return 0 on legal names, -1 otherwise. */ legal(char *name, int maxlen) { if (!name || !*name || strlen(name) >= maxlen) return -1; while (*name) if (!strchr(okname, *name++)) return -1; return 0; }
rants: [email protected]
Many system break-ins relating to Linux and Unix Web servers happen via insecure CGIs. Implement rings of security in CGIs. Try to design your application so that even if it nds a CGI vulnerability, the system is protected from major damage. One solution is to have CGIs just be front ends for a solidly written server running on a different machine. The more hurdles a hacker must jump to reach the goal, the more likely it is that he or she will stumble. Watch for bug reports in third-party CGIs and inspect their code. If you use third party-supplied CGI scripts (such as shopping carts), you should subscribe to the appropriate mailing lists and watch for security bulletins. If possible, get the source code and review it. If you do not know the language, then get someone who does to review it. Many CGIs, both commercial and open source, have severe security holes that are well known to the hacker community. Many locally written CGIs have security vulnerabilities because the programmers who write them typically have no training in writing secure code and such code is rarely audited. Avoid creating and using set-UID and set-GID programs to the maximum extent possible, especially programs setUID to root (and try real hard). Many system programs run as root. Frequently all these programs need to be set-UID to run as some user to gain access to data that should not be world accessible. Other programs need to be set-UID to root only when starting to open a low network port for listening or to change its privileges to that of a particular user. In this case, the program then should give up root privileges. Apache, named, and ftpd were enhanced several years ago to do this for better security. Different programs may need to be setUID to different users to protect them from each other. Do not keep clients condential data on the Web server. Avoid storing users privileged data (credit card numbers, nancial details, mailing addresses and phone numbers, etc.) on the same machine as the Web server. This separation will force a hacker to crack two systems instead of just one to get this data. Do not include users condential data (credit card numbers, nancial details, mailing addresses and phone numbers, session ID, etc.) in an URL or cookie.6 Frequently this is done (insecurely) as arguments to a CGI
more queue: www.acmqueue.com
program. Consider the following example: www.abroker.com/cgi-bin/address_change?account=666 ?passwd=secret&addr=1+Maple+St.&phone=301-688-6524 Some browsers may store this URL (containing condential data) in a history le. If someone is browsing from a public terminal, such as a school or library, you could be liable for careless handling of the data. Similar issues are present for cookies. Be very sure that the privileged data that a user supplies on a form does not show up as the default data for the next person to pull down that form and see. Yes, this has actually happened. Always protect the user who types in a password. Take the user to a secured area prior to this information being entered and ensure that the password or credit card number will be encrypted on the system (with https) before transmission to your server.
When a user will no longer be using the system, be sure to remove his or her account from the system quickly.
rants: [email protected]
TIP
your desk, but that beats a cot in your ofce so that you can work around the clock for a week recovering from a compromise. Sadly, I know of one company where they did bring in those cots for a number of engineers during a weeks-long recovery project following a breach. Worse, they procrastinated on deciding to build a rewall until after this event. Q ACKNOWLEDGMENTS This article is based on RealWorld Linux Security: Intrusion, Detection, Prevention, and Recovery, second edition, by Bob Toxen (Prentice Hall PTR, 2003, ISBN 0130464562); chapter 2, section 2, The Seven Most Deadly Sins. Thanks to Prentice Hall PTR for granting permission to use material from the book in this article. Thanks to Larry Gee, a very talented programmer, for co-authoring this section of the book. ReFerences 1. NFS consists of these daemons and a few more, including: rpc.nfsd, rpc.mountd, portmap, rpc.lockd, rpc. statd, rpc.rquotad, and automounter, scattered among a number of startup scripts. A cracker process can lie to portmap and masquerade as a legitimate server. NFS has had plenty of security bugs in the past, and
chmod 700 /etc/cron*/. A better solution is to write a kernelloadable module to prevent use of the prctl() system call by other than root. Of course, the only full solution is to upgrade your kernel. If the system is at a remote ofce or colocation facility where there are no experienced sysadmins, then good luck if the new kernel does not boot.
TIP
The Linux 2.6 kernel prior to 2.6.17.4 has a nasty local root vulnerability where anyone with a shell account, possibly via ssh or abusing a Web server CGI program, can make himself or herself root. See CVE-2006-2451. Are any of your systems vulnerable to this right now? I thought so. A partial x is to issue the command:
its design prevents it from being made secure in many congurations. 2. Most recent vulnerabilities are not directly exploitable remotely on most systems. This means that most systems are not at risk for remote attack from the Internet. Many of the vulnerabilities may be taken advantage of by someone with a regular shell account on the system. Others are in programs that most people do not use and that are not set-UID or set-GID and thus are not a threat. This is different from most Windows vulnerabilities where almost every client system or server using that major version of Windows is vulnerable to remote attack over the Internet and thus to complete control by crackers. We observe that most Windows vulnerabilities affect all Windows versions released in the past four years, including Vista. We have recently seen Vista included with past versions of Windows for several remote root vulnerabilities. 3. Subscribe to Bugtraq by sending e-mail to [email protected] with empty subject and content. Subscribe to X-Forces Alert by logging on to https://atla-mm1.iss.net/mailman/listinfo/alert. 4. If you are doing only anonymous FTP, your password is normally your e-mail address. Unless you are a government researcher at Groom Lake (Area 51) and you do not want to acknowledge the existence of such a facility, then generally you have nothing to worry about. 5. Most of the information on Perl presented here is from Kurt Seifrieds writings. 6. Fidelity Investments, which manages $900 billion of its customers money, did not follow this advice. In May 2002, it was reported that by changing the digits in the URL of the page displaying his statementa three-digit numbera client saw other clients statements. 7. A skunk-works project is one done in secret without management approval or knowledge. 8. Thanks, Galaxy Quest. LOVE IT, HATE IT? LET US KNOW [email protected] or www.acmqueue.com/forums BOB TOXEN is a computer and network security consultant with 33 years of Unix experience and 12 years of Linux experience. He was one of the 162 developers of Berkeley Unix and one of the four creators of Silicon Graphics Unix. He has been an advisor to the George. W. Bush administration on computer issues at the ve principal intelligence agencies.
2007 ACM 1542-7730/07/0500 $5.00