Friday, March 14, 2014

[infosecinstitute] ICMP Attacks

ICMP stands for Internet Control Message Protocol and is the most used protocol in networking technology. A connectionless protocol, ICMP does not use any port number and works in the network layer. ICMP is commonly used for diagnostic purposes, error reporting or querying any server, and right now attackers are using ICMP to send payloads, which we will discuss here. The popular ping command will use ICMP. There are lot of security issues of ICMP messages that we really need to look at.

ICMP Packet Format
ICMP messages are transmitted within packets, as shown below.
Below shows the format of an ICMP message. There are different values for the type field, which identify the ICMP message. So a type of ICMP message will use different values of the code field to specify the condition. If you look at RFC you will get to know the different types and their descriptions. The first two columns will determine whether the ICMP is a query message or an error message. We need to know this as we will particularly deal with ICMP error messages.
ICMP error messages are not sent in response to an ICMP error. When an ICMP error is sent, it always sends the IP header and the datagram that caused the error. So the receiving unit gets to associate the error with the process. So infact when a type 0 (echo reply) is sent, the reply will no longer be a Type 8 (echo request).
The last field talks about the Checksum, which is used to check errors while transmitting data and is calculated from the ICMP header and data. Before an ICMP message is transmitted, the checksum is computed and is inserted in to the field. So at the receiving end the checksum is calculated again and verified against the checksum field. If any mismatch is found, then it confirms that an error or change has occurred.
There are 15 different types of ICMP messages and some are categorized as error reporting and query.
A few popular ICMP messages:
Error ReportingQuery
TypeMessageTypeMessage
3Destination Unreachable8/0Echo(request/reply)
4Source quench13/14Timestamp(req/Reply)
11Time exceeded18/18Address mask(req/rep)
12Parameter problem10-SepRouter advertisement
5Redirection
ICMP Attack Types
  • ICMP Tunnelling
ICMP tunnels are one form of covert channel that is created wherein the information flow is not controlled by any security mechanism. An ICMP tunnel establishes a channel between the client and server, forcing a firewall not to trigger an alarm if data are sent via ICMP. ICMP tunnelling is a covert connection between two endpoints using ICMP echo requests and reply packets. So by using ICMP tunnelling, one can inject arbitrary data into an echo packet and send to a remote computer. The remote computer injects an answer into another ICMP packet and sends it back. This type of communication traffic remains undetectable for a proxy-based firewall, as they are more focused on source and destination IP address.
These mechanisms can be used to bypass firewalls’ rules through obfuscation of the actual traffic. Application-based firewalls are only capable of detecting such a type of traffic, as they do a deep packet inspection on the entire packet. So the network administrator or security administrators will not be able to detect such encrypted communication unless deep packet inspection is carried out.
Now let’s showcase this scenario by using the Hping tool. Hping is a packet crafter tool used to conduct a test or attack on a device. For a normal ping message that we send using a command prompt, it sends four packets of data. So if we want to send a particular ICMP request with a particular type or code set then we can use Hping (we can do this in cmd prompt also, but changing code and type of ICMP in cmd is not possible). Now I am going to send data, “sending packets via tunnelling”, via ping message, by typing the below command.
If we sniff the destination then we can see the entire data as well.
In a normal ICMP echo request, the packet length will be 42 bytes, where the data length is 0, and if we append any data in to the ICMP data field then the size of the packet increases. In the above scenario, the total size is 72 bytes out of which 30 bytes is the data “sending packets via tunnelling”. So if we want to detect ICMP tunnelling via any IDS/IPS devices we need to write a rule stating that if any data is present in the data header of the ICMP, then fire an alert.
The most common ICMP tunnelling program is LOKI. It uses the ICMP echo response packet to carry its payload. By using LOKI, one can transmit data secretly by hiding the traffic so networking devices cannot detect the transmission. It can also be used to set a backdoor into a target system and execute commands on the machine with admin privileges, as well as leak information and start/stop critical services without users’ knowledge.
Organisations have adopted many ways to prevent ICMP tunnelling, like blocking all ICMP traffic, limiting the size of ICMP packets, etc. However, some methods listed above are not realistic for the real world environment. The use of IDS/IPS is an effective method and many IPS/IDS devices have a signature to detect the presence of LOKI.
  • Smurf Attack
    As we discussed earlier, whenever a type 8 is sent, a type 0 is sent back, or an ICMP echo reply is sent whenever an echo request is sent. In a smurf attack, an attacker will spoof the source address of the ICMP packet and send a broadcast to all computers on that network. If networking devices do not filter this traffic, then they will be broadcasted to all computers in the network. The victim’s network gets congested by this much traffic, which brings down the productivity of the entire network.
    Countermeasures for Smurf Attack
    • Put filters on routers and firewall to counteract address spoofing. An IP address should be assigned to a LAN segment, and if the IP address of the source machine is not in the range of IP address that is assigned to the segment, then the traffic should be dropped.
    • Put filters on L3 devices to not reply for broadcast address.
  • Fragile Attack
    Fragile attack is same as a Amurf attack but rather than ICMP, UDP protocol is used. The prevention of these attacks is almost identical to Fragile attack.
  • Information Gathering
    Under the information gathering attack, one can use different methods within the ICMP to find out live host, network topology, OS fingerprinting, ACL detection, and so on.
    A classic way to discover hosts on the network is to send an ICMP echo request (type 8) which should prompt target hosts to respond with ICMP echo reply messages.
  • Trace Route
Now let’s see how trace route can be used to determine the network topology. The trace route command is used to discover the routes that packets actually take when traveling to their destination.
Windows uses ICMP trace routes, while Linux-based systems use a UDP trace route. So when running a trace route from a Windows computer, three ICMP echo messages with TTL set to 1 are sent out to the destination IP addresses. The response of the ping will be an ICMP Time Exceeded message (this means the host responding is not the destination) or an ICMP Destination Unreachable (this means the host responding doesn’t know how to get to the destination IP address in the trace route packets). When the ICMP reaches one hop, the TTL value is decremented by one, so when the TTL value becomes zero, an ICMP type 11 message is sent back to the origin point.
In the next phase, the TTL value is incremented by one and the above process is repeated until it finds the correct destination address specified in the trace route command. So this activity will record the source of each ICMP Time Exceeded Message to provide a trace of the path the packet took to reach the destination.
  • Port Scan
ICMP Error Messages (Protocol/Port Unreachable) can be used to find out the open ports to an IP address or a LAN segment. Different types of scanners are available in the market that use ICMP to check whether a port is open or not. Usually ICMP packets are sent without any payload to each specified protocol on the target machine. If an ICMP Protocol Unreachable error message is received, it means the protocol is not used.
  • OS fingerprinting
Fingerprinting is a technique to find out what kind of OS the server is running by looking at the response of the ICMP packet. Now two important concepts to remember via OS fingerprinting are if the ICMP reply contains a TTL value of 128 then it is a Windows machine, and if the ICMP reply contains a TTL value of 64 then it is a Linux-based machine.
Now in the above diagram we can confirm that 192.168.10.2 is a Linux-based system and 192.168.10.3 is a Windows-based system by looking at the TTL value. The method of fingerprinting is different for each Windows and Linux family. Let’s dive in deeper into the above scenario.
Right now we have identified the target as the Windows machine, now we are looking to find out the versions of Windows machine. In order to double check the above activity, we can also send ICMP packets by setting the code field, and by looking at the ICMP reply of the code field we can confirm the target as a Linux or Windows machine. So let’s send an ICMP message where the code field equals 77. If we get a response from the target with a code field = 0, then the target Is a Windows family, and if we get a response with the code field not equal to 0, then it is a Linux family.
Below we see that the code for echo reply is 0, so the target is confirmed as Windows.
Now let’s send a Timestamp request to the target server to rule out Windows 95 and Windows NT. If we get no reply then it means the target is Windows server or Windows NT, and if we get a reply it means the target machine is Windows 98, Windows 2000 or Windows ME.
If we dive in deeper then we can get to know the exact output. But ICMP is not feasible to use as a OS fingerprinting method. An effective fingerprinting can be done via SYN.
  • ICMP Router Discovery
    The ICMP router discovery protocol will discover the IP address of the neighbouring routers. The ICMP router discovery messages are called “Router Advertisements” or “Router Solicitations”. The router discovery message is not a routing protocol. It enables hosts to discover the existence of a neighbouring routers, but not which router is best to reach a particular destination. Router advertisement is an ICMP message (type 9, code 0) with an advertisement lifetime. The main challenge for ICMP router discovery protocol is it doesn’t have any forms of authentication, so it is impossible for end hosts to tell whether or not the information they receive is valid or not.
    Due to the above issue, an attacker can perform a man in the middle attack where in an attacker will act as middle man for all the communication from the source to the endpoint. Attackers can also spoof ICMP router discovery messages and remotely add bad route entries into a victim’s routing table. So the victim’s system would be forwarding the frames to the wrong address, and it would be unable to reach other networks. Such type of attacks can lead to Denial of Service attack and can become quite severe.
    A countermeasure that is used to prevent ICMP route discovery is to use digital signatures and to block all type 9 and type 10 ICMP packets.
  • Teardrop
When a teardrop attack is carried out on a machine, it will crash or reboot. Eventually it is sort of DOS attack that an attacker does using ICMP packets. Teardrop attacks exploit the overlapping IP fragments present in machines. IP packets are broken up into smaller fragments, with each fragment having the original IP packet’s header, and field that tells the TCP/IP stack what bytes it contains. The packet is fragmented and is sent from the source to destination. In the destination point, the fragments need to be put back together again. What happens with teardrop though is that the IP fragments will have overlapping fields. When the destination tries to reassemble them, it cannot do it, and if it does not know to combine these packet fragments out, it can quickly fail. This type of attack is more common on the Internet, and precautions need to be taken to counteract such attacks.
References
http://resources.infosecinstitute.com/icmp-attacks/

No comments:

Post a Comment