Chapter 12. Unix Attacks

Unix has long been a favorite target for all sorts of hackers, including the malicious and the simply curious. While the old mainframes running VMS and OS/390 had sophisticated security and auditing features, few of them were exposed to the direct wrath of modern Internet threats. Modern Unix is often attacked by (and falls victim to) new exploits, near-forgotten old exploits, and vulnerabilities resulting from misconfiguration. In this chapter, we delve into the vast realm of local, remote, and denial-of-service Unix attacks.

Local Attacks

In this section, we discuss what an attacker can do if he already has some level of access to your Unix machine. This might happen on a machine with legitimate public shell access (a rare happening nowadays, unless you are at a university) or if an attacker gains the ability to run commands via some network service such as web, email, or FTP servers. It might happen through a bug, a misconfigured server, or a bad design decision on the part of the server programmers (such as a poorly designed web application or CGI script). This section presumes that the attacker already has a foothold on your system and is able to run commands more or less freely.

As we know from Chapter 11, a well-hardened Unix system should effectively resist attackers. Similarly, the system should be configured so that it is even more difficult to gain root privileges if the attacker somehow manages to penetrate the network’s defenses and obtain nonprivileged access.

Physical Abuses

If an attacker has access to a machine itself but not to any account on it, physical attacks can be very effective. We classify these as local attacks, since they require local access to the machine console rather than access via a network protocol.

Trivial local attacks such as stealing a machine or a hard drive with sensitive information will not be considered. These are valid attacks, but most theft countermeasures involve administrative and legal policies, rather than technical measures. In addition, stealing the computer hardly qualifies as hacking.

Shoulder surfing is another trivial attack, one that can be lumped together with social engineering attacks. In this case, a malicious intruder glances over the shoulder of a typing user to obtain a login password combination or other secrets.

Boot Prompt Attacks

Suppose the intruder does not steal a machine, but rather tries to reboot it by power-cycling it or by pressing the Reset button. Although such a strategy is damaging to Unix machines, most nevertheless survive the hit and try to boot Unix again.

However, if the machine is set to boot off a floppy or a CD-ROM (as many Intel i386 computers are), we have our first attack scenario. By changing the boot media, a hacker can boot the machine into another operating system, such as DOS, that does not respect standard Unix file permissions. Utilities such as the ltools kit (for access to Linux disks from Windows) can be used to access the drives and compromise sensitive information. An attacker can then locate and steal a password file located on a disk, even if /etc/shadow is used and is only readable by a user account.

Similarly, if single-user mode is not secured or if the attacker possesses the Unix/Linux boot media, she can boot to single-user mode and snoop around unrestricted. Note that if a machine is not set to boot from a floppy or CD-ROM, the BIOS/PROM may also be reset to accomplish the same thing.

Fortunately for many Unix systems there is no second OS that can be used in this manner. Sun, SGI, and HP Unix hardware do not run DOS, and the above attack will fail. In the case of those platforms, however, a smart attacker might use another Unix OS (such as NetBSD, which supports most of the above hardware) and boot into her own Unix as root. Linux now supports SPARC hardware (Sun) and some other proprietary Unix-based platforms as well.

Boot Interrupt

Another potential attack during the initial boot process involves the system boot loader. For example, the Linux boot loader (LILO or GRUB) allows you to enter commands to control the boot—for example, in order to boot into single-user mode.

Interrupting the boot sequence also provides opportunities for hackers. Indeed, some Unix variants allow you to skip the startup of some daemons for debugging purposes. Skipping the startup of, say, a host-based firewall might be helpful for an attacker.

Screensaver Attacks

Upon noticing a machine locked by a screensaver, a skilled attacker still has options. While most tricks only apply to breaking Windows screensavers, Unix screensavers can sometime be bypassed as well. One well-known trick using a boot CD-ROM can sometimes be used for Unix as well as Windows, since some Unix machines can automount CD-ROMs and then autostart the specified application. If this application is a short shell script that runs killall xlock, the screensaver defense is easily pierced. In the worst case, if stealth of access is not a requirement, the machine can simply be rebooted and then attacked during the boot phase as described above.

Path Abuse

One of the easiest local attacks is path abuse. However, it only works on systems run by deeply inexperienced or truly careless administrators. If the root environment has a “.” (current directory) in the path, root can be tricked into running the malicious executable file. The chances of this working are slim; not all modern Unix systems have “.” in the path before other commands. In addition, most best practices guides for Unix security suggest avoiding “.” in the path altogether.

In any case, if you can convince your local root to run something with root privileges (i.e., “Please help me, my little program does not have permission to get to such and such system library. Maybe you can run it as root so that it compiles and then I can just use the binary for my purposes.”), the system security is toast.

Password Attacks

In this age of ubiquitous strong encryption, you might think that getting a hold of encrypted passwords wouldn’t help an attacker all that much. Nothing is further from the truth. Uneducated users commonly undermine the most sophisticated encryption schemes.

The computational complexity of classic password encryption algorithms, such as DES, and the power of modern computers allows for the brute forcing of the less effective passwords. Users choosing passwords such as “password”, “secret”, or their last names easily defeat higher security provided by MD5. Basic security best practices—such as not choosing a dictionary word for a password, or at least adding several nonalphabetic characters—are often neglected.

In almost all old Unix versions, encrypted passwords were stored in the file /etc/passwd. As we discussed earlier, they are not really encrypted passwords, but rather a blocks of data encrypted with the password used as a key (in the case of DES). A typical attack involves one of two methods. The attacker can get a dictionary, encrypt it, and then compare the result with the scrambled string obtained from /etc/passwd. Another approach is to try a random combination of ASCII characters likely to be seen in passwords, such as numbers or letters. More intelligent programs use a combination approach: take a dictionary word and then add a couple of random characters, such as numbers. This method will discover the passwords of those “smart” people who replaced “root” with “root1” and thought they were safe.

Even if you use several dictionaries, it takes much less time to crack a password using a dictionary set than using a random search. Many dictionaries are available online for most major languages and even for Klingon, which is useful for cracking Unix (since Unix and Star Trek are merely transformations of the same reality).

Obtaining passwords from password files became much more complicated when password shadowing became widespread. Password shadowing (described in Chapter 11) makes the files containing the encrypted passwords readable only by root. Thus, ordinary users cannot obtain passwords for cracking attempts. They can still try random combinations, though.

Here are some other methods for recovering user passwords (encrypted and unencrypted) on modern Unix systems. Passwords can be found in user files such as:

~/.netrc

This is used for “passwordless” logins via FTP and telnet. The file format is shown below:

machine ftpserv.example.edu login anton password r7w7/R12

You can clearly see the login and password for the machine ftpserv.example.edu.

~/.fetchmailrc

This is used for the mail transfer program fetchmail, which downloads email via POP3/IMAP from a mail server. Here’s the file format:

set nobouncemail
set daemon 100
defaults
            user anton is anton
poll mailserv.example.edu with protocol pop3 and port 110:
password r7w7/R12;

Just as with .netrc, the passwords are exposed.

Older versions of the popauth program (called APOP)

This is used to store passwords for secure POP3 in clear text. The program needs a clear-text password to generate the challenge response protocol and is not able to use an encrypted password from standard Unix /etc/passwd files.

Some proprietary software products

Products such as databases can also expose passwords. The attacker just needs to look for them in the user’s home directory (providing he has read access to those files, which is not always the case).

Finding encrypted passwords to crack may also be performed as follows. If an application refers to standard Unix password files for access control, the passwords can be recovered from an application crash dump. For example, users were able to crash the Solaris FTP daemon with a command (CWD ~) without being logged in (see the Bugtraq vulnerability database, bugtraq id 2601). This resulted in a core dump. If you were to investigate the resulting dump file, you would find the fragments of /etc/shadow (the Unix strings command is ideal for this).

Several methods may be used to defeat the attack. First, some applications (such as the Secure Shell daemon, sshd) disable core dumps completely, so that nothing may be recovered. Some Unix flavors apply restrictive permissions (only readable by root) to such files. System owners might also disable the generation of such files (system-wide or on a per-user basis), however helpful they might be for application debugging.

Crashing POP3/IMAP daemons, login programs, telnet, Secure Shell, and other networked programs has a good chance of resulting in a crash dump, with tasty bits of otherwise inaccessible /etc/shadow.

What are the chances of finding a valid Unix password in a system logfile? Imagine that the root user has made an error (say, by accidentally typing the password in the space for username). In this case, the password might end up in the logfile. The same mistake might cause passwords to appear in shell history files (such as .history for the bash shell).

Where else can passwords be found? If /etc/passwd is almost empty and the system is active, it might actually be using NIS (Network Information Services, formerly known as Yellow Pages by Sun Microsystems). If NIS is deployed, typing ypcat passwd produces a list of usernames together with encrypted passwords.

SUID Abuse

Set-user-ID abuses are a good way to elevate privileges on a Unix system. Many binaries are deployed SUID root, sometimes to get the needed system privileges and sometimes to cover mistakes in sloppy programming.

A nice example of SUID abuse is an efax vulnerability in which the program typically used to send and receive fax messages from a Unix machine is installed SUID root (in order to access the modem device /dev/modem, which is sometimes created with restricted permissions):

-rwsr-xr-x    1 root     root        96689 Aug 16 10:23 efax

Run the vulnerable version of the program (0.9a is shown as an example) as follows:

$efax -d /etc/shadow

The contents of the /etc/shadow file are revealed. The program simply produces an error message using the pieces of the misread file (in this case, /etc/shadow). The same program can also be used to obtain a root shell. The mitigation is simple: the program should not be SUID root; instead, the more relaxed permission on a modem device should be in place. Programming errors in SUID binaries produce the lion’s share of all such remote and local exploits.

/tmp and Symlink/Hardlink Abuse

Almost every Unix system has an area writable by all system users: /tmp. This area is used for storing temporary files from various applications. If people without a secure programming background write these applications, it is likely that some abuses will be possible. Let us examine the notorious /tmp symbolic link (symlink) abuse. If an attacker knows or can guess the filename of the temporary file created by the root application, she can create a symlink with the same name and point it to, say, /etc/shadow. When the root application starts up, the attacker might write some system information to the temporary file, effectively overwriting the Unix password file and creating a denial-of-service condition. No one can log in to the system if the password file is corrupted. More insidious attacks that overwrite the password file with custom content are also possible.

Breaking Out of chroot Jail

While other local attacks are covered extensively in other places, breaking out of chroot() on Unix has not received the attention it deserves. The chroot command and chroot system call might sound like a good security measure—you execute one command, and plain old Unix cd / no longer transports you to a root directory of the system. Instead, you are bound to the restricted part of the filesystem, surrounded only by files chosen by a paranoid system administrator. In fact, that is how it should be.

Is it possible to break out of chroot solitary confinement? Yes, if certain conditions are met. We’ll analyze what chroot is good for and also what it’s bad for.

First, how does chroot work? After you type /sbin/chroot directory_name on the Unix system command line, you can see that the new root is now “directory_name” (the /bin/ls / command produces the listing of files from “directory_name”, presuming you have an ls command located within your new root). The chroot shell command changes the root directory for a process, goes into this directory, and starts a shell or runs a user-specified command. If there is no shell binary within the new directory, and no user command is specified, the chroot command fails, as follows:

[root@anton anton]#chroot Test
chroot: cannot execute /bin/bash: No such file or directory

The chroot command uses a chroot( ) system call. The command and the system call have an important difference: unlike the shell command, the chroot( ) call does not change your working directory to the one inside a chrooted jail. The source of chroot.c (a shell command in the Linux part of the sh-utils package) shows the following sequence of system calls:

chroot (argv[1]);
chdir ("/");

As we will demonstrate, it allows for easy chroot jailbreaking.

chroot is often used as a security measure. If you have ever logged into an anonymous FTP server, you have used chroot. The FTP server chroots itself into a special directory upon the anonymous FTP login. The DNS daemon BIND is often chrooted as well. Some people also suggest chrooting telnet/SSH remote shell users into their corresponding home directories, so they can only update their own web pages. Web servers can be run chrooted as well. smap, the secure email wrapper from the FWTK firewall toolkit, runs chrooted to the mail spool directory. When chroot is implemented, programs running inside cannot access any system resources on the outside. Thus, all system libraries, configuration files, and even device files should be recreated within the chroot jail.

What daemons can be chrooted? If a daemon has to access files that are not easily collectible in one place, chrooting it will be difficult. For example, sendmail needs the mail spool (/var/spool/mail), other files in the spool (such as mqueue), user home directories (to check for .forward files) and system configuration files in /etc. There is no place on the filesystem where sendmail can effectively be confined. Of course, a makeshift solution is possible, but it’s not clear that such a thing adds to security. However, if sendmail functionality is separated into a spool daemon and mail transfer program (as done in FWTK’s smap and smapd), then chrooting is entirely possible.

chrooting shell users is possible if there is a business need to keep them in some particular directory. However, it involves copying multiple system libraries and files needed for the login and for the user-required functionality.

Many other network daemons—such as BIND (DNS), Apache (WWW), and Squid (web caching)—can be chrooted, but sometimes the benefits are unclear, especially for daemons that run as root. In this case, chroot only provides security by obscurity.

“What daemon should be chrooted?” is an entirely different question from “What daemons can be chrooted?” Before we cover this issue, let’s analyze how attackers break out of chroot.

First, the larger the number of software applications that are deployed within the chroot environment, the more dangerous things become, since it is difficult to keep track of all of the programs that the attacker can use to elevate permission and escape.

Second, there are a vast number of ways that a root user can break out of chroot. These methods range from the simple use of a chroot() call with no chdir( ) (see Example 12-1) to esoteric methods such as the creation of your own /dev/had (for hard drive) or /dev/kmem (for memory) devices, injection of code into the running kernel, using open directory handles outside chroot, or using chroot-breaking buffer overflow shell codes. While adjusting system capabilities or other tricks can be used to render many of these methods inoperable, new ones will likely be found by smart attackers, since root is simply too powerful on the Unix system.

Example 12-1. Sample code for breaking out of chroot

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

int main(void)
{
    int i;
    mkdir("breakout", 0700);
    chroot("breakout");

    for (i = 0; i < 255; i++)
      chdir("..") ;

    chroot(".");
    execl("/bin/sh", "/bin/sh",NULL);
}

Tip

Compile Example 12-1 statically (using gcc -static) and run it within the chrooted directory (after entering chroot or similar from the shell prompt) to escape.

If there is no root user defined within the chroot environment, there are no SUID binaries or devices, and the daemon itself has dropped root privileges right after calling chroot( ) (like in the code below), breaking out of chroot becomes very difficult, if not impossible. Most secure coding practices emphasize dropping all unneeded privileges, but unfortunately (for the defender) or fortunately (for the attacker) most programmers do not heed such advice.

In other words, if there is no way to gain a root shell or to perform root-level actions (i.e., create devices or access raw memory), breaking chroot will be difficult. Ideally, if the custom software uses chroot for security, the sequence of calls should be as follows:

chdir("/home/safedir");
chroot("/home/safedir");
setuid(500);

In some cases, attackers might not be able to break out (i.e., run processes outside of the chrooted directory), but instead will be able to have a partial affect on such processes. For example, if BIND is chrooted, several devices should be created. One of them is /dev/log, which is necessary for logging BIND messages into the regular system logs. By crafting a malicious log message and sending it into /dev/log from within the chrooted directory, the attacker influences the behavior of the syslog daemon running outside of the chroot jail. If there is a buffer overflow in syslog (which runs as root), the attacker can obtain additional privileges.

What daemons can be chrooted, yet provide no security benefit? chrooting programs that do not drop root privileges while running or programs that provide root shell access (i.e., sshd or telnet with a root account within a chrooted directory) does not provide extra security.

For the defensive side, chroot is a good way to increase the security of software, provided secure programming guidelines are followed and chroot( ) system call limitations are taken into account. Chrooting prevents an attacker from reading files outside the chroot jail and prevents many local Unix attacks (such as SUID abuse and /tmp race conditions). However, improperly implemented chroots (such as when privileges were dropped too late, so that the attack will still yield “root”) will help the attacker to gain access to the target machine.

Remote Attacks

This section covers remote network attacks on Unix systems. Due to the vast range of such attacks, we’ve correlated the attack data to TCP/UDP port numbers, for your convenience. While legends tell of hackers who penetrate machines with no open ports (such as via a bug in a sniffer or even in a TCP/IP stack itself), the vast majority of network attacks come through a TCP (more often) or UDP (less often) port of a known network service.

We’ll briefly describe the security relevance of the ports. If you are reading this book, we assume you already know how to use an advanced port scanner such as Nmap to discover open ports. By sending various packets to open ports, you can tell open (return ACK) ports from closed (return RST) or filtered (return nothing or RST) ports.

We will categorize the attacks on Unix systems into several classes. Our categorization is inspired by the ICAT (http://icat.nist.gov) attack classification.

So, what dangers might lurk on a port?

Weak authentication

If an attacker can guess the password and access the service running on this port, the risks are obvious. No authentication also presents a trivial example of weak authentication.

Plain-text service

Allows sniffing authentication credentials using tools such as tcpdump. Additionally, TCP session hijacking attacks (taking over a running session) and command injection (where the attacker inserts his own command in the running TCP session, bypassing the authentication stage) are possible. Tools are available for the above attacks.

Known vulnerabilities

A large realm of weaknesses exists, such as buffer overflows, heap overflows, format string attacks, user input validation errors, race conditions, and other software flaws. The most dangerous of these holes are "remote root”—i.e., they provide an attacker with a remote shell running with “root” privileges on a Unix system.

DoS threat

A service can be used to flood the network or crash the system. In this category we will also list the services that can be abused to degrade the performance of a service or the entire system.

Information leak

Using such a port, attackers may be able to learn information about the operating system, running software or other bits important for the attack.

Next, we will look at common ports and investigate how they may be (and have been) attacked. The information below was collected from various vulnerability databases (shown in the “References” section) and from our own security research.

TCP

This section covers attacks against popular Unix TCP services. This is not an exhaustive treatise on Unix network attacks, as they are too numerous to be covered here. Also, the attack landscape changes with blinding speed.

TCP port 1 (destination)

The TCP Port Service Multiplexer used this port (described in RFC 1078). Among Unix vendors, only SGI implemented it. The services presented a security risk described in CERT Incident Note IN-98.01. Using this service, attackers are able to identify SGI machines (which used to ship with default passwords on several accounts). Risks: information leak.

TCP port 2 (source)

Another CERT Incident Note, IN-99-01, describes a scanning tool called "sscan” that used to send a TCP packet (with the FIN flag set) from source port 2. Sscan is a port scanner and OS identifier. Risks: information leak.

TCP ports 3, 4,and 5 (source)

The sscan tool sends a packet with source port 3 (with FIN and ACK flags set) in order to identify the target operating system. Risks: information leak.

TCP port 7 (destination)

This is the famous Unix echo port. It can be used for the echo-chargen local denial-of-service attack. Today, it is mostly disabled (from inetd.conf) or blocked by firewalls. More details are provided in the vintage CERT advisory “UDP Port Denial-of-Service Attack” (http://www.cert.org/advisories/CA-1996-01.html). Risks: DoS.

TCP port 9 (destination)

This service has no security relevance. Everything sent to this port goes nowhere. These days it is mostly disabled (from inetd.conf).

TCP port 11 (destination)

The systat service provides information about running services over the network (historical). Today, it is mostly disabled (from inetd.conf), since this service is a large security risk (it leaks critical information). Risks: information leak.

TCP port 13 (destination)

The Unix daytime service provides the time of the day over the network (no surprises here). Red Hat Linux 6.2 had a denial-of-service vulnerability because of unclosed network sockets in the daytime service (Red Hat advisory RHSA-2001:006-03). This denial-of-service condition will crash all network services. Risks: DoS.

TCP port 17 (destination)

Unix quote-of-the-day. No security relevance; today, this is mostly disabled (from inetd.conf).

TCP port 19 (destination)

Chargen (character generator). Used to be used for local denial-of-service together with echo. Nowadays mostly disabled (from inetd.conf) or blocked by firewalls. Risks: DoS.

TCP ports 20 and 21 (destination)

This is the FTP data (port 20) and command channel (port 21). Risks: information leak, known vulnerabilities, weak authentication, plain text service, DoS. There are plenty of risks here:

Anonymous FTP servers with upload capability

Malicious parties can use these servers to store illegal software or media, thus incurring liability upon the owner.

Buggy FTP daemons

FTP network services (which first appeared in an RFC in the 1970s) have their share of bugs. Almost every implementation of an FTP server has had bugs. If you search for “FTP server bugs” in an online exploit database, hundreds of entries pop up. For example, exploits against WU-FTPD (by Washington University) have been rampant. Default installs of Red Hat Linux Versions 7.0, 7.1, and 7.2 with FTP enabled were wide open. To find all vulnerabilities for your FTP daemon, query the bugtraq database (currently hosted on SecurityFocus.com) or the NIST ICAT database.

Sniffers

FTP uses a plain-text protocol, thus transmitting usernames and passwords in the clear, which makes them vulnerable to sniffers.

Denial-of-service attacks

Using the FTP server, attackers can upload files and cause a denial-of-service condition. This risk is especially high if anonymous uploads are allowed. Depending upon how the Unix server is configured (disk partitioning), some systems might become unstable if system partitions fill up.

TCP port 22 (destination)

Secure Shell (SSH) was plagued by security problems in earlier versions. Both commercial (SSH) and free (OpenSSH) versions had critical remote vulnerabilities. You can still see scans for those versions performed by automated tools, configured to detect and exploit various old versions of Secure Shell. The bugs that were rampant in SSH code allowed anything from local denial-of-service attacks to a full-blown remote root compromise.

While invulnerable from sniffing, SSH can be used to brute force the authentication credentials (provided that password-based authentication is enabled). Secure Shell server software might also take steps to make password guessing more difficult (such as by increasing the delay between allowed attempts), but it still remains possible. Risks: known vulnerabilities, weak authentication.

TCP port 23 (destination)

The telnet protocol, which uses port 23, had its share of critical bugs. For example, “Multiple Vendor Telnetd Buffer Overflow Vulnerability” allowed attackers to take over a machine running the telnet server.

In addition, telnet presents risks of sniffing (unencrypted user and root passwords), brute forcing (remote password guessing), and unauthorized remote root logins.

telnet is a popular choice for login guessing attacks. While root logins are usually disallowed over telnet, one can still try to guess a regular user’s password by repeatedly trying various username and password combinations, using a dictionary. Some default system usernames (abundant on older Unix versions, such as SGI IRIX and HP-UX) can also be tried for access, in case the accounts have interactive login privileges.

In addition to the above, default telnet banners[1] as shipped with most Unix variants usually disclose the system version (for example, Linux 2.4.7-12) and local name. The latter might shed some insight on the possible system role, increasing its appeal to the attacker. Risks: information leak, known vulnerabilities, weak authentication, plain-text service.

TCP port 25 (destination)

The SMTP protocol server—most often a sendmail, qmail, or postfix email server—occupies this port.

The famous Morris worm of 1988 used a vulnerability in an early version of sendmail (the debug command) to get access to servers. Remote root bugs, while rare, have occurred in the history of various Unix mail programs, some more often than others.

Other attacks on port 25 include spamming and unauthorized mail relaying (sending email messages to third parties using somebody else’s email server). Spamming may be classified as a DoS attack of sorts, as it denies access to legitimate email to its recipients and may overload and crash the email server.

Denial-of-service attacks and unprivileged remote access attacks are also possible, provided the mail server is configured with mistakes. sendmail, for example, uses an extremely confusing configuration file, and dangerous mistakes are common. For example, some sites allow the unrestricted sending of messages to programs. This functionality can be abused to execute commands on a victim’s system.

SMTP is usually plain text and can be sniffed. However, it presents a smaller risk, since email is akin to public information anyway (transmitted in plain text end-to-end). Risks: information leak, known vulnerabilities, plain-text service, DoS.

TCP port 53 (destination)

While the Domain Name Service (DNS) usually runs on port 53 UDP, port 53 TCP is also reserved by it for zone transfers and other bandwidth-heavy DNS operations. Most of the known attacks against DNS have used the UDP component of the name resolution service.

DNS servers such as BIND used to be fraught with critical root-level vulnerabilities. In fact, exploiting holes in BIND DNS software was the most common attack on a Unix system in 1999-2000, due to some easy-to-use exploits against it. Critical bugs in BIND continue to be discovered, and some say that due to its complexity such behavior can be expected for the near future.

DNS queries also might disclose important information about the target network, such as via zone transfers (discussed in detail in Chapter 8).

As a plain-text service, DNS can be sniffed. However, this presents no risk, as DNS information is public.

DNS also presents unique risks for service abuse. DNS spoofing can be considered a known and inherent (unless future DNSSEC is implemented) weakness in the service. Risks: information leak, known vulnerabilities, plain-text service.

TCP port 69 (destination)

The Trivial File Transfer Protocol (TFTP) is a huge security risk even without bugs, as it allows for unauthenticated file transfers. Most sites do not run it or restrict it on the perimeter.

TFTP is an inherently risky service due to its lack of authentication. To add insult to injury, known vulnerabilities in TFTP implementations may lead to root compromise. TFTP is plain text and thus can be sniffed; and files transferred by TFTP can be captured by the attacker. Risks: information leak, known vulnerabilities, plain-text service, no authentication.

TCP port 79 (destination)

finger (as in “finger [email protected]”) is a classic Unix service to get information about users. At least, that was its design. Now attempts to “learn more about users” are classified as reconnaissance. Few sites run finger nowadays, due to various security concerns. The Morris worm used a remote root exploit in finger to spread back in 1988.

By definition, the finger service presents an information leak risk, revealing information about system’s users. finger is plain text and can be sniffed, which might not make sense (as the information is public), but is still available as an option.

Bugs in the finger service might lead to a root compromise since (at least on older Unix systems) the service is running as root. Risks: information leak, known vulnerabilities, plain-text service, no authentication.

TCP port 80 (destination)

Port 80—HTTP—is a world in itself. While talking of port 80 attacks, we could cover SQL injection attacks, web application attacks, CGI abuses, IIS worms, web server and add-on module bugs, webmail abuse, server misconfigurations, and attacks against other services available though port 80.

While Unix web server code has few critical remote bugs, server misconfigurations are still somewhat of an issue for security administrators. It’s unrealistic to try to cover attacks against all web applications in this summary chapter: it would require several volumes.

Certain resources on web servers might be password protected. This raises the opportunity for authentication guessing over the Web. Risks: information leak, known vulnerabilities, plain-text service, weak authentication.

TCP port 110 (destination)

Post Office Protocol Version 3 (POP3), which runs on TCP port 110, is a method to retrieve email from a remote server. Together with IMAP and webmail, POP3 is one of the more popular email solutions. Attacks against port 110 are still present in the Internet noise (as detected by our honeypot in Chapter 20). Several popular POP3 daemons (qpopper, wu-imapd, etc.) used to have remote root bugs and exploits circulated in the underground. Port 110 traffic can also be subjected to password guessing (attacks against email passwords) and sniffing attacks.

In addition to POP3, scans for POP2 (an older version of the mail protocol, unused since the 1980s) still occur on rare occasions. Risks: known vulnerabilities, plain-text service, weak authentication.

TCP port 111 (destination)

Portmapper (a Unix Remote Procedure Call service daemon) runs on port 111. Popular RPC portmapper implementations (such as those used by Linux and some Unix flavors) have a gaping security hole: remote root. Over the course of 2000-2001, this was a popular way to break into unsecured Linux servers.

RPC is another universe in itself. RPC portmapper is a gateway to a large number of Unix services running on a dynamically allocated ports managed by the portmapper. These include NIS, NFS, and others. Many of these run with root privileges and thus, if exploited, will yield an attacker root access to the target system. Other RPC services will disclose information about the target system. Risks: information leak, known vulnerabilities, weak authentication.

TCP port 113 (destination)

The authentication daemon (identd) was standard for older Unix systems and is still present (usually disabled) on newer machines. It does not present a traditional security hole, but rather allows a privacy leak. Attackers might be able to use it to determine the user IDs under which network services run. This task can be automated by tools such as Nmap (choose the -I option). Most versions of identd provide the information without any authentication or use only an address-based authentication.

Additionally, some versions of identd (such as the less common cidentd) had known remote holes, providing root access to attackers.

The service is plain text, but the information is public; thus, the sniffing risk is low. Risks: information leak, known vulnerabilities, weak authentication, DoS, plain-text service.

TCP port 119 (destination)

The Network News Transfer Protocol (NNTP) runs on port 119. Few sites run NNTP daemons and thus few people audit their source code. Attacks against port 119 are probably possible, but they are not widespread. However, an NNTP server might be running as root; thus, successfully exploiting the service can give root access.

NNTP servers (such as some older versions of INN NNTP server) with remote holes are not unknown. Some other services can be crashed remotely. The service is plain text, but the information is public; thus, the sniffing risk is low. Risks: known vulnerabilities, plain-text service, DoS.

TCP port 123 (destination)

The Network Time Protocol (NTP), while seemingly innocent, has nevertheless been used for serious network compromise in the past. CERT Vulnerability Note VU#970472 (http://www.kb.cert.org/vuls/id/970472) outlines a well-known remotely exploitable buffer overflow in the NTP daemon. This vulnerability can be exploited over port 123 UDP as well. In spite of this critical hole, there are few scans for port 123 detected in the wild. The reasons are unclear.

While breaking through buggy NTP servers is not as common as FTP and SSH attacks, some of the popular NTP server implementations contain remote root holes. Misconfigured NTP servers will disclose a system time to outside parties due to weak authentication, creating a minor information leak, while others can be crashed remotely. Risks: information leak, known vulnerabilities, weak authentication, DoS.

TCP ports 135-139 (destination)

While Windows file sharing and name resolution are not relevant for Unix, SMB network services (such as Linux’s SAMBA) are known to have bugs on older versions. However, the scans against ports 135-139 most likely target Windows machines. For example, the Blaster worm targeted port 135 on Windows machines.

While SAMBA’s track record is not as bad as some of the FTP servers, it’s had its share of remote root exploits and information leaks. Some versions of SAMBA servers can be crashed remotely. Additionally, nothing stops attackers from trying to guess a SAMBA’s server share credentials by brute force. Risks: information leak, known vulnerabilities, weak authentication, plain-text service, DoS.

TCP port 143 (destination)

IMAP is a remote mail access protocol that has more functionality than POP3. Crucial remote root class attacks were discovered in some versions of WU-IMAPD and other daemons. In addition, port 143 can be used to brute force a password if log monitoring is not performed. Also, some IMAP servers can be crashed remotely, causing denial-of-service conditions.

Like POP3, IMAP is a plain text service; thus, email contents and authentication credentials can be sniffed. IMAP (again, like POP) may be tunneled over SSL or SSH to prevent that. Risks: known vulnerabilities, weak authentication, plain text service, DoS.

TCP port 443 (destination)

HTTPS (secure HTTP) runs on port 443. All port 80 information readily applies to port 443. In addition, all port 80 attacks directed to port 443 will be undetectable by existing intrusion detection systems (a great advantage to an attacker) due to encryption. If the same services and web applications are provided over port 443 (SSL encrypted) as well as 80 (plain text), attackers can easily abuse them.

Several popular SSL implementations (such as OpenSSL) were the subject of attacks and even worm outbreaks. It was possible to exploit SSL bugs through the SSL-enabled web server running on port 443. Risks: information leak, known vulnerabilities, weak authentication, DoS.

TCP ports 512-514 (destination)

rlogin and rsh are outdated Unix remote access services. They used to be plagued with bugs and configuration weaknesses. However, they are almost never used today, so attacks such as the “rsh -froot bug” exploit and the “rlogin trust abuse via .rhosts” are largely things of the past. Risks: information leak, known vulnerabilities, plain-text service, weak authentication.

TCP port 515 (destination)

The printer daemon is a famous source of Unix security holes, and root level at that. Linux LPR (actually, all BSD-derived) implementations “boast” a root-level bug that earned its own CVE entry (CVE-2001-0670, http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2001-0670). In addition, submitting abusive print jobs and even crashing the print service (effectively a printer DoS attack) is possible for certain printer daemon implementations. We highly recommend that you firewall this port at the network perimeter.

Risks: known vulnerabilities, plain text service, DoS.

TCP port 1080 (destination)

The SOCKS proxy port is the subject of many network scans, although the SOCKS proxy itself does not have known security weaknesses. The reason is simple: misconfigured proxies allow for connection laundering or anonymous connectivity for attackers. Lists of open SOCKS proxies are posted on the Internet for all to use.

Proxies such as SOCKS are not a large risk by themselves. Due to their weak authentication, however, they can be used in attacks against third party sites. Risks: weak authentication.

TCP port 2049 (destination)

The Network File System (NFS) from Sun is configured to use this TCP (and also UDP) port. NFS is the subject of many attacks and abuses. An open NFS port is a likely indication that a system can be accessed to various degrees, but not necessary at root level.

NFS can be abused in a variety of ways. In addition to known vulnerabilities (yes, including root-level), NFS can be manipulated to overwrite files and cause server crashes. In addition, NFS runs in plain text and there are many tools exist to capture files transmitted over it. Risks: information leak, known vulnerabilities, weak authentication, plain-text service, DoS.

TCP port 3128 (destination)

This port is commonly used by the Squid web proxy (http://www.squid-cache.org). Similar to the SOCKS proxy port (TCP 1080), this is the subject of many network scans. The reason is simple: misconfigured Squid proxies allow for connection laundering, or anonymous connectivity to web and FTP servers for attackers. Lists of open web proxies are posted on the Internet for all to use.

Proxies such as Squid are not a large risk by themselves, but due to their weak authentication they can be used in attacks against third-party sites. The Squid proxy also has its share of bugs, including critical root level bugs and authentication bypass flaws. Risks: information leak, known vulnerabilities, weak authentication, DoS.

TCP port 3306 (destination)

The MySQL database server, the most popular free open source database solution, is commonly run on TCP port 3306. MySQL server (in addition to having remote root bugs and remote crash options in some versions) can be used to brute force authentication credentials (username and passwords). The service runs in clear text and thus can be sniffed (giving the attacker access to potentially sensitive database contents). Risks: known vulnerabilities, weak authentication, plain-text service, DoS.

TCP port 6000 (destination)

The X Window System (also known as X11, X, X Windows, etc.) uses this port for remote client-server communication. While no public exploits exist, many abuses are possible on misconfigured servers including remote application start, key press logging, and screen snooping. Also, several DoS attacks leading to application crashes can be accomplished via this port. Higher-numbered ports (6001, 6002, 6003, etc.) are also used by the X Window System, in case more displays are configured.

While no major root exploits were made public for the X Window System, many smaller-scale holes, DoS attacks and flaws were discovered. X authentication can also be bypassed to gain system privileges.

While not strictly a text service, X Windows traffic can be sniffed by attackers, possibly granting access to display contents and the input of the victim. Risks: information leak, known vulnerabilities, weak authentication, plain-text service, DoS.

TCP port 6667 (destination)

IRC is a can of security worms, including the possibility of remote penetration, worm and automated attack agents, piracy, copyright violations, and so on. Also, many Trojan programs are set to communicate with their masters via IRC. In fact, several common IRC clients have been Trojaned by attackers; the users’ machines are compromised if such a client is used. Another example was the ThreatKrew (TK) bot, which was first discoverd and traced back to its masters by Seth Fogie. Both IRC clients and servers have a history of remote holes actively exploited by attackers. Some servers can be crashed remotely as well. Risks: known vulnerabilities, DoS.

TCP port 7100 (destination)

The X font (xfs) server is used by the X Window System for displaying font configuration. Some remote attack bugs exist for the xfs, especially for Sun, IRIX, and Linux implementations. At the very least, several DoS attacks are possible. Risks: known vulnerabilities, DoS.

TCP port 8080 (destination)

WinGate and other web proxies often use this port, leading to many network scans. The reason is simple: misconfigured proxies allow for connection laundering, or anonymous connectivity for attackers. Lists of open proxies are posted on the Internet for all to use and abuse.

Proxies such as WinGate are not a large risk by themselves, but due to their weak authentication, they can be used in attacks against third party sites. Risks: weak authentication.

UDP

The section covers attacks against some of the Unix UDP services. Although it is not exhaustive, this list emphasizes some classic and recent attacks.

UDP port 53 (destination)

DNS running on this port (also TCP port 53) is the subject of a large number of remote exploits, mostly due to BIND DNS software (see http://www.isc.org/products/BIND/). Unfortunately, it is very difficult to protect against these exploits, since DNS servers must expose this port to the Internet. Here are some examples, spanning all versions of BIND (4.x and up): buffer overflow in DNS resolver functions, remote BIND denial-of-service, denial-of-service vulnerability in BIND 8 via maliciously formatted DNS messages, and malicious modification of DNS records.

DNS servers such as ISC BIND were fraught with critical root-level vulnerabilities. In fact, exploiting holes in BIND DNS software was the most common attack on a Unix system in 1999-2000, due to some easy-to-use exploits against it. Critical bugs in BIND continue to be discovered, and some say that due to its complexity such behavior can be expected for the near future.

DNS queries also might disclose important information about the target network, such as via zone transfers (discussed in detail in Chapter 8) .

As a plain-text service, DNS can be sniffed. However, this presents no risk, as DNS information is public. DNS does present unique risks for service abuse, though. DNS spoofing can be considered a known and inherent (unless future DNSSEC is implemented) weakness in the service. Risks: information leak, known vulnerabilities, plain-text service.

UDP port 123 (destination)

The Unix NTP daemon (ntpd) is used to synchronize time between networked machines and time servers, such as nist.time.gov. Several network attacks are known that can be used against misconfigured and/or vulnerable NTP daemons. Buffer overflows plague ntpd (CVE-2001-0414).

While breaking through buggy NNTP servers is not as common as FTP and SSH attacks, some of the popular NTP server implementations contain remote root holes. Misconfigured NTP servers will disclose the system time to outside parties due to weak authentication, creating a minor information leak, while others can be crashed remotely. Risks: information leak, known vulnerabilities, weak authentication, DoS.

UDP port 514 (destination)

Unix syslog uses UDP port 514 for network log transfers. While the classic BSD-derived syslog implementations have no publicly known security holes, several other implementations are plagued with holes.

Various syslog servers have remote bugs, allowing access to target systems. Additionally, some syslog-specific attacks such as log flooding (DoS) and message spoofing (injecting spurious data) are possible.

syslog messages are sent without authentication or (rarely) with weak address-based authentication. The messages are sent in plain text and can be sniffed to gain important system information such as usernames and (rarely) passwords.[2] Risks: information leak, known vulnerabilities, weak authentication, plain-text service, DoS.

UDP port 517 (destination)

Port 517 is used by various talk (host-to-host chat) daemons on Unix. Various talkd implementations have remotely exploitable holes and must run as root due to their low port assignments (below 1024). Fortunately, talk is not used very often nowadays.

Buffer overflows plague some of the talk daemons, leading to remote root compromises. Risks: information leak, known vulnerabilities, weak authentication, plain-text service, DoS.

UDP port 2049 (destination)

NFS is configured to use this UDP (and also TCP) port. NFS the is subject of many attacks and abuses. An open NFS port is a likely indication that a system can be accessed to various degrees, although not necessary at root level.

NFS can be abused in a variety of ways. In addition to known vulnerabilities (yes, including root-level), NFS can be manipulated to overwrite files and cause server crashes. In addition, NFS runs in plain text and there are many tools exist to capture files transmitted over it. Risks: information leak, known vulnerabilities, weak authentication, plain-text service, DoS.

Top Unix Vulnerabilities

The above lists describe some commonly attacked Unix ports. They are not exhaustive, though, and many other ports are being used by custom applications that are just as vulnerable.

How close to real life are the examples in the lists? What ports are being exploited (even as you read this) on the systems deployed on the Internet?

Let’s analyze some publicly reported data from SANS (SysAdmin, Audit, Network, Security) Institute (http://www.sans.org) from the last several years. SANS is a nonprofit security research and education organization that conducts conferences and training classes, administers popular security certifications (such as GCIA and GCIH), and also organizes members of the security community to work on various projects of value to everybody.

SANS now compiles a list of “The Twenty Most Critical Internet Security Vulnerabilities,” published once a year. SANS collects the most dangerous and commonly attacked vulnerabilities from a worldwide group of contributors (one of the authors of this book included) and then lets them vote on what are the 20 most critical. Nowadays, the list is split into two parts, for Unix and Windows. We will be focusing on a Unix list here. Here is how the recent “Top 20” lists looked.

The top vulnerabilities in Unix Systems in 2003 included:

  1. BIND/Domain Name System

  2. Remote Procedure Calls (RPC)

  3. Apache web server

  4. General Unix authentication (accounts with no passwords or weak passwords)

  5. Clear-text services

  6. sendmail

  7. Simple Network Management Protocol (SNMP)

  8. Secure Shell (SSH)

  9. Misconfiguration of enterprise services NIS/NFS

  10. Open Secure Sockets Layer (OpenSSL)

And the top vulnerabilities to Unix Systems in 2002 included:

  1. Remote Procedure Calls (RPC)

  2. Apache web server

  3. Secure Shell (SSH)

  4. Simple Network Management Protocol (SNMP)

  5. File Transfer Protocol (FTP)

  6. R-Services—trust relationships

  7. Line Printer Daemon (LPD)

  8. sendmail

  9. BIND/DNS

  10. General Unix authentication (accounts with no passwords or weak passwords)

In 2001, the list was called “Top 10” and combined Unix and Windows. Here are the Unix entries (we have cut out the WIndows entry, leaving only those that are Unix- related):

  1. BIND weaknesses: nxt, qinv and in.named allow immediate root compromise

  2. Vulnerable CGI programs and application extensions (e.g., ColdFusion) installed on web servers

  3. Remote Procedure Call (RPC) weaknesses in rpc.ttdbserverd (ToolTalk), rpc.cmsd (Calendar Manager), and rpc.statd that allow immediate root compromise

  4. sendmail and MIME buffer overflows as well as pipe attacks that allow immediate root compromise

  5. sadmind and mountd

  6. Unix NFS exports on port 2049, or Macintosh web sharing or AppleShare/IP on ports 80, 427, and 548

  7. User IDs, especially root/administrator with no passwords or weak passwords

  8. IMAP and POP buffer overflow vulnerabilities or incorrect configuration

  9. Default SNMP community strings set to “public” and “private”

Now, at this point, the reader might ask what this has to do with our discussion on Unix attacks categorized by port. The following table demonstrates the relation. Table 12-1 summarizes the entries from the SANS top attack lists by port to show the commonly attacked Unix ports. It will be obvious that some of the ports are true attackers’ favorites, while others become important or fade away as a target.

Table 12-1. Most-attacked Unix ports

Unix application

Protocol

Port

Year

Common attacks

BIND

TCP, UDP

53

2001, 2002, 2003

Known vulnerabilities, information leak

RPC

TCP

111+[3]

2001, 2002, 2003

Known vulnerabilities

Apache, CGI

TCP

80,443

2001, 2002, 2003

Known vulnerabilities, brute force, information leak

Unix authentication

TCP

21,22,23+[4]

2002, 2003

Brute force, information leak

Unix clear-text services

TCP

21,23,25,80, 110, 143, 161, 512,513,514+

2003

Sniffing, information leak

sendmail

TCP

25

2001, 2002, 2003

Known vulnerabilities

SNMP

TCP, UDP

161,162

2001, 2002, 2003

Known vulnerabilities,information leak

SSH

TCP

22

2002, 2003

Known vulnerabilities, brute force

NIS/NFS

TCP, UDP

2049

2001, 2003

Known vulnerabilities,information leak

SSL applications

TCP

25,995,443+[5]

2003

Known vulnerabilities

FTP

TCP

21,20

2002

Known vulnerabilities, brute force, sniffing, information leak

R-services[6] remote session

TCP

512,513,514

2002

Known vulnerabilities, brute force, sniffing, information leak

IMAP and POP mail retrieval

TCP

110,143

2001

Known vulnerabilities, brute force, sniffing, information leak

LPD

TCP

515

2002

Known vulnerabilities, DoS

[3] The plus sign indicates that other “ephemeral” ports are also used by this service.

[4] Various Unix services use remote password-based authentication—only common ones are shown.

[5] SSL may be used by many other services, such as SMTP, POP3, IMAP, HTTP, and custom applications.

[6] Remote login (rlogin), remote shell (rsh) and remote copy (rcp). Today largely historical

Table 12-1 shows the recently attacked Unix ports. Indeed, as indicated by the Unix honeynet research conducted by one of the authors, the observed attack activity closely matches the above table. For example, FTP attacks were subsiding in 2003, while RPC is as popular as ever (due to recent vulnerabilities in Linux systems).

To conclude, it is important to be aware of attacks on various ports on Unix systems—and some ports are more important for both attackers (better availability of attack tools) and defenders (more bang for the buck for the protection measures).

Unix Denial-of-Service Attacks

Denial-of-service (DoS) attacks are considered the least elegant form of hacking. The world of DoS, especially as related to Unix systems, is extremely broad. Denial-of-service conditions can be achieved by anything from smashing the computer system with a sledgehammer to sending sophisticated, custom TCP/IP packets in order to disable network connectivity.

Pedants in computer security sometimes define DoS attacks as the “prevention or delay of authorized access to IT resources.” However, many things can affect computers and networked systems; thus, a wide array of attacks is covered under denial-of-service.

This section covers local DoS attacks, relevant network attacks, and some distributed denial-of-service (DDos) attacks. While physically destroying computing resources constitutes a denial-of-service, we will not be covering those attacks since they do not require a computer. However, it is important to remember that cutting a wire is still the most reliable way to stop network connectivity, and incinerating a hard drive is the most reliable way to erase information. Physical security, while not covered here, is of paramount importance in network defense.

Standalone host DoS attacks can work through crashing applications or operating systems or through exhausting memory, disk, or CPU resources. They can be loosely categorized into resource exhausting (such as cat /dev/zero > /tmp/file) and resource destruction (such as rm /etc/passwd).

Network denial-of-service attacks attempt to incapacitate systems from the network via weaknesses of network protocols, networking code implementations, or other vulnerabilities. Sometimes, especially in the case of massive DDoS attacks, no vulnerability is required for the attack to work—all the attacker needs is better network connectivity.

DoS attacks are a nuisance. Sometimes, however, they can have a major effect on the target. DoS attacks are common on the Internet, and they comprise a growing part of hacker wars and hacktivism.

Local Attacks

This section covers local DoS attacks requiring the attacker’s presence at the system console or a working remote shell connection (via telnet, ssh, rlogin, etc.).

Destruction of resources

Destruction of resources on Unix be accomplished by removing or overwriting critical system files and by crashing server processes and other applications. In addition, it may be possible to harm system hardware under the right circumstances, especially in Unix systems running on i386 architecture (Linux, BSD). However, most of these attacks require system privileges. For example, only root users can erase the password file. Root access enables the attacker to do much more damage, such as removing or reformatting all data on the system. As long as attackers are unable to access resource, the risk of its destruction is low. Table 12-2 gives examples of some destruction-of-resources attacks.

Table 12-2. Local DoS resource attacks

Attack

Impact

Remove or corrupt critical file

Access denied, system crash, loss of data, etc.

Erase/format partition

System disabled

Shut off power

System temporarily disabled

Crash a service

Service functionality disabled

Overall, these attacks are easy to prevent. However, their power should not be underestimated—attackers who have gained root privileges can do whatever they want to the system, and the boring /bin/rm -rf / does much more damage than any kind of fancy network packet manipulation. Sometimes bugs in programs can give attackers the ability to cause damage without having root privileges. For example, a buffer overflow attack might crash the service, and abusing SUID binaries can corrupt root-owned files such as /etc/passwd or /etc/shadow. In the case of buffer overflows, if the shell code is incorrect or not used at all, the attack will crash the application without giving the attacker any additional access rights. Some of the resource starvation attacks covered later in this chapter, such as filling the /tmp partition, prevent applications from starting or cause Unix to crash. Also, sometimes bugs in systems (such as the well-known process-kill bug in Linux) allow users to kill the processes owned by others.

Buggy applications are known to crash without any malicious influence. However, with a little help from creative intruders, they do it much more willingly. Examples of this are plentiful; for example, using a device name (such as /dev/null) in certain contexts causes some versions of Netscape browsers to crash. Other applications, and even the entire system, can also be frozen. For example, cat /dev/urandom is reported to cause crashes.

Resource exhaustion

Rogue processes can consume the resources of a computer system. Using too much memory, disk space, and CPU cycles and filling kernel process tables and other data structures severely hinders the operation of a Unix system.

Classic resource attacks include the following examples:

Disk overflow

While Unix partitions often have 10% of emergency space available only to root, the attacker can cause the disk to overflow by making a root-owned process fill the disk for him. For instance, sending too many faked syslog messages makes syslog fill the /var partition. If Unix is installed in one partition (admittedly, not a recommended best practice, but the one often followed by novice users), the system can thus be rendered unusable.

In fact, it might not be necessary to fill the entire disk. Simply creating a large number of files exhausts all the inodes and renders the filesystem unusable. A famous attack script that creates recursive directories uses this principle. These directories occupy little space, but because there are so many of them, the partition fills.

Memory overflow

Simply making a user program allocate a generous chunk of memory can cause problems. While a well-configured Unix system will not crash because of this, other applications might run slowly, especially if both physical memory and swap space (virtual memory on a disk drive) are exhausted. This attack is sometimes referred to as a “malloc bomb,” due to the name of the system call that allocates memory.

CPU hogging

It is extremely difficult for a program to hog CPU resources because of the preemptive multitasking used by modern Unix-based operating systems. However, some of us are old enough to remember playing a game called Rogue (later usurped by Nethack) on university PDP-1170 and VAX systems running Berkeley distributions from the early 1980s. Rogue was a graphical Unix equivalent of the Dungeons and Dragons™ fantasy game, and it was highly addictive. Unfortunately, simply by playing Rogue, a nonprivileged user could thrash an entire university system by consuming 95% of processor time. We fondly remember the network administrator jumping up and down, cursing like a sailor and swearing to God that we had hacked his root—which of course we had not. So, excusing the pun, Rogue was the ultimate example of a rogue application.

Filling kernel data structures

Another way to attack a Unix system is to fill the kernel data structures. The famous “fork bomb” (which can be written in many languages, from C to shell script) is an example of this strategy. Example 12-2 shows the shortest fork bomb known (in bash shell script). It’s a fork bomb bash from http://www.voltronkru.com/library/fork.html. Recursive directory creation can be used to disable or slow down the system just as effectively. It uses up all available inodes (usually defined at kernel compile time).

Example 12-2. An elegant shell script fork bomb

:(  ){ :|:&};:
    int main(  )
{
while(1)
{
fork(  );
}
}
while : ;
mkdir .xxx
cd .xxx
done

Unix is often not configured by default to withstand resource starvation attacks. However, using resource limits (available in many Unix flavors), you can build an effective defense against users attempting to access all available resources. Disk quotas, memory limits, and file limits can go a long way toward preventing these attacks. It is worth noting, however, that these imposed limits most likely will not stop a resource allocation attack launched by root.

One last class of attack we’d like to mention here involves using the security measures of the system owners. While Unix is rarely configured with account expiration (unlike Windows NT), if such a feature is enabled it can be used to lock the user out of the system just by trying incorrect username/password combinations.

Network Attacks

The field of network DoS is extremely rich and varied, ranging from the now common SYN floods to sophisticated distributed denial-of-service attacks. Since examples of classic network DoS attacks are covered extensively elsewhere in the security literature, we concentrate on the mechanics of the attacks themselves.

Network attacks can be loosely categorized as application crashing or resource consumption . However, in the case of network attacks, the attacker can consume both host and network resources. SYN flooding is an example of the former, while UDP or ICMP flooding is an example of the latter.

Consuming network resources simply involves flooding the network pipe; i.e., sending the victim so much extra traffic that normal traffic cannot get through. Any kind of IP packet can be used to fill the pipe. In addition, the source addresses of the packets are often spoofed. Sometimes third parties also add to the flood—below, we consider reflexive DoS attacks in which the attacker sends traffic to some systems that in turn flood the victim (usually without violating any TCP/IP standards). The smurf or ICMP broadcast attack is the simplest example of a reflexive DoS attack.

Consuming host resources sometimes requires more ingenuity than just sending enough traffic. A SYN flood sent over a relatively slow line can bring the victim system to a crawl. Host resources can rapidly be consumed if the system has to perform an expensive operation for each connection or even for each arriving packet, i.e., an operation that requires a lot of CPU, memory, or some kernel data structure resources). SYN flooding, for instance, requires the system to keep a table entry for each arrived SYN packet, since it potentially indicates the beginning of a new connection. Unix OS vendors currently use various tricks to mitigate the effects of SYN floods, such as Linux’s SYN-cookies.

Reassembling packet fragments is another operation that puts a heavy load on the victim computer. If IP datagrams are sent in fragmented form, the system has to reassemble them before passing them on to higher levels in the stack (such as to the TCP or UDP layer). Another group of resource consumption attacks works due to a particular quirk in certain TCP/IP stack implementations. Some systems, especially those with substandard networking, have been known to crash or overload upon receiving abnormal network packets.

The majority of DoS attacks are in the category of remote OS or application crashing. Application-level network DoS attacks could involve mail bombing or web flooding. The former consists simply of sending many large email messages to the target email address, thus overloading email servers, storage, and network pipes. Web flooding is a relative newcomer to the DoS party. Recently, the World Economic Forum web site was brought down by hacktivists who simultaneously reloaded web pages using their browsers, running one version of a malicious applet. On the other side of the DoS spectrum, remotely sending spoofed syslog messages can cause a disk overflow and (for a badly configured systems) a subsequent crash.

In the rest of this section, we’ll briefly outline some of the popular network DoS attacks seen on the Internet.

Smurfing saturates the network connection of a victim by recruiting the help of multiple machines willing to respond to a broadcast. To successfully smurf, one has to find a network willing to amplify the attack through misconfiguration. However, similar attacks are possible via any network system that can send a response larger than a request (i.e., can work as an amplifier). Acting as an amplifier involves trusting the IP address of the sending party to send a request back—i.e., to be vulnerable to IP spoofing.

Even DNS queries are reported to cause denial-of-service conditions if the requests are spoofed with a victim’s address. The intermediate DNS server happily responds to the victim, thereby flooding it. If many DNS servers are queried, the result is a reflexive DoS attack, a relatively new breed that is extremely difficult to defend against. More information on those and other attacks are provided in the next section.

The land attack, which is only of historic interest, consists of sending a packet with an identical source and destination. It used to crash many TCP/IP stacks, especially in early Windows versions.

IP fragmentation abuse is represented by the teardrop attack. Fragments with a corrupted offset sent by the attacker are used to crash Linux and Windows machines. A variety of DoS attacks with names such as bonk, boink, and newtear also use improper fragmentation handling.

The ping of death is the granddaddy of many network DoS attacks. The ping of death is simply an oversized ping packet (65,536 bytes instead of the normal 28 bytes) that used to crash very old Unix TCP stack implementations. A buffer overflow in the stack source code was to blame for this once lethal attack.

Many other DoS tools exist, from plain TCP flooders to more exotic ones such as puke (which sends ICMP unreachable packets, thus attempting to reset connections of the target host) and jolt (which kills windows machines by sending deformed and fragmented packets). Even peaceful Internet Gateway Message Protocol (IGMP) packets have been recruited for network warfare; tools exist to send oversized IGMP packets that can crash Windows.

The ultimate creations of the point-to-point (i.e., nondistributed) DoS are the multiDoS kits such as spike, 7plagues, targa, or datapool. A kit combines various DoS attacks that can be launched against multiple addresses in random order. The datapool tool (with 106 attacks packaged together) actually remembers which attacks worked against a host and next time only runs those, saving some bandwidth for the attacker.

Network DoS attacks are by no means a thing of the past; there are still enough vulnerable machines deployed on the Internet for the attackers to have their share of “fun,” and new exploits arise every day.

Distributed Denial-of-Service Attacks

The road to fame for distributed denial-of-service (DDoS) attacks started in 1999, when the first rumors of massive “attack zombie” deployments appeared. However, it was not until February 2000 that DDoS became a household word. On February 6 and 7 of 2000, floods of packets from multiple sources hit many popular sites such as Yahoo!, eBay, Amazon, and CNN. The floods overloaded the sites and they either became unavailable or slowed to a crawl.

Dave Dittrich from Washington University has analyzed most of the DDoS tools that have surfaced so far. Here we present a short overview of DDoS toolkits seen in the “wide wild web.”

Trinoo is an early DDoS kit that consists of a set of zombies that are deployed on multiple machines, usually hacked via some exploit. A master program controlled by an attacker commands the zombies. The master sends commands to the zombies in order to start flooding the victim with (in the case of Trinoo) UDP packets. Trinoo did not used source spoofing; thus, the zombies are easy to find.

TFN (Tribal Flood Network) is a similar tool that can flood in UDP and TCP SYN (causing a SYN flood, which is more damaging to the victim than a UDP flood) or ICMP echo flood (also dangerous). Its ICMPs can also send to broadcast addresses, thus enhancing the attack with smurf amplification. The kit does have some bugs that limit its control functionality. However, the tools use spoofed source addresses. Thus, the zombies are relatively safe, since the UDP packets seem to originate elsewhere.

TFN2K (a newer version of TFN) sends all the above attacks at once, with spoofed sources. In this toolkit, the authors first implemented an encrypted control channel that uses TCP, UDP, or ICMP to give commands to the zombies. While the commands were found to have a unique signature that simplified detection, the encrypted communication is more stable than the plain-text one.

Stacheldraht (German for barbed wire) is another tool with features similar to TFN2K. Newer versions have added several more attacks, such as TCP ACK flood (only the ACK bit is set, so it might pass through a badly configured firewall), TCP NUL flag (no flags set), and improved ICMP flooding with smurf support. Also, the author has worked on quality control and the software has fewer bugs than its predecessors. It also uses spoofed packets in all protocols. However, by the time the tool appeared, the techniques to trace spoofed floods had been perfected and the zombies could be found quickly. Such tracing usually involves hop-by-hop tracing from ISP to higher-level ISP, until the source is found.

Several other tools have been found as well. Shaft , for example, can send a mix of UDP, TCP SYN, and ICMP floods. Mstream is designed to send an ACK flood with spoofed addresses. The reason that ACK floods are more effective than, say, UDP floods is that they elicit multiple responses, thus increasing bandwidth consumption and stress on the host resources.

Coordinated and reflexive denial-of-service attacks

In addition to “regular” distributed DoS, there are two DoS variations called coordinated denial of service and reflexive denial of service . Coordinated DoS simply involves a great many people simultaneously doing something otherwise considered nonmalicious, such as pressing the Refresh button on their browsers (as in the previously described attack on the WEF web site). This causes software to request the pages from the server. If many people do it at the same time, the server gets overloaded and might crash or slow down. The attack is virtually impossible to differentiate from normal traffic that has peaked for whatever benign reasons.

In a reflexive DoS attack, a mild DoS flood is sent toward an intermediate victim with the spoofed source address of the true victim. The responses go straight to the victim. If several (or as many as available) hosts start to respond to the victim via an otherwise harmless protocol, a flood occurs and eats up all of the victim’s available bandwidth. Reflexive Dos is difficult to trace. Basically, reflexive DoS attacks can be traced to its origin, in a manner similar to tracing a spoofed DDos attack. However, the search will lead not to a zombie, but to a machine that is simply doing its job by responding to requests.

Application-level denial-of-service attacks

Unix applications can be used for denial-of-service attacks as well. Mail bombing, which originated on Unix, is still a threat. If someone decided to send a number of multimegabyte attachments to your unfiltered server, it might block your email service, block other network services, or even cause the system to crash (especially if the same partition is used for /tmp, where the system often expects to see some free space, and /var, where the mail is stored). Coordinated DoS using a web browser is another example of a web application DoS.

References



[1] Messages shown to the user before a network login prompt.

[2] This can occur if a user mistypes the password in place of a username—it will be logged via syslog.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset