CEH: Web Applications and Data Servers: Understand Session Hijacking Pen Testing
Session hijacking is about compromising the trust of two hosts, services, or accounts. Countermeasures are put in place to counteract the effects of eavesdropping (sniffing) login credentials. If the attacker can wait until trust is established and then impersonate one of the parties, the blind system would have no idea it is giving or receiving data whose integrity has been breached.
Session hijacking can occur in multiple ways. There are web based hijacks, wireless AP hijacks (evil-twin), and TCP session based hijacks. In all cases the principle is to attack lower on the OSI model that the actual session that is being taken. For example in a TCP attack, the idea is to let layer 5-7 establish trust and then take the layer 4 socket, knowing the higher layers do not care and might not even notice the change.
The Differences Between Spoofing, MiTM, and Hijacking
Spoofing, a technique that is useful in social engineering is the basic act of pretending to be something else. People are not always the essential parties. The problem with some authentication controls is they are based on hardware or protocol constructs and have nothing to do with user accounts or actual identities.
The inherent problem with spoofing is that the receiving host will reply to the party that seemed to have sent the data. Either the masquerading party has to become that party, or she must eavesdrop in. An additional problem could occur if the receiving host doesn’t get the reply it expects after sending the data; it may try to send more data assuming an error has occurred. If the masqueraded victim receives these messages, he might get confused and create additional confusion through asking more questions.
Although spoofing has its place, it is often more of a component in an attack rather than the only technique.
An MiTM attack also involves social engineering. The attacker is able to transparently accept and send traffic to the true endpoints of communication. Much like sending important documents via a courier, the data is handed off, stored, and forwarded to the receiver. The transparent part is the trick. If the client sending the data knows it is using a proxy service, it is agreeing to this type of exchange. If not, the middle man must exploit a service at a lower level of the OSI model.
Application services, such as surfing the web, usually involve client/server interactions. If the client knows about a proxy server, it sends the data there and gets the response back from the proxy without worry. In this case, the client must be “proxified” in that it is fully aware of the man in the middle transaction. The human being user, however, might not be. Clients can be pointed to proxies without their user knowing or caring in the slightest, and this is the best MiTM attack vector. These proxies can be anywhere on the Internet, and this is a common technique of the malware exploits discussed in previous chapters.
If the attacker has to utilize lower layers of the network model, meaning that protocols must be manipulated to hijack traffic, greater skill and positioning is required. Earlier we discussed the ARP poison attack as an example of this. The victim is totally unaware of the attack, and therefore the attacker is considered transparent.
Pure session hijacking is the ultimate example of combining techniques to completely take over an established session after the authentication phase has completed.
We can illustrate this by using a TCP session hijack as an example and following the sequence of events takes place:
1. Tracking the connection
2. Desynchronizing the connection
3. Injecting the attacker’s packet
Tracking the connection
The attackers must identify the targets and observe the characteristics of their connections. Predicting sequence numbers and windows sizes will allow the attacker to construct packets in advance of the attack. These packets will be injected at exactly the right time.
Desynchronizing the connection
If a server is presently communicating with an authenticated client, it is the client that needs to be knocked offline (assuming the attacker wants to impersonate the client). If this step does not happen correctly, the server will see echoes, traffic from both the real client and the attacker. The server will get confused and possibly drop the connection.
The client must be convinced it is no longer speaking to the server while leaving the server still expecting data. This can be accomplished using a variety of means.
Sending NULL data to the server spoofing the client’s IP address as the source will cause it to expect traffic the real client is not prepared to send. Other techniques involving SYN/ACK and FIN fags can be used. The idea is to make the server think it is at a different place in the conversation, a place the attacker knows but the client doesn’t.
The client is the DoS’d (Denial of Serviced) to keep it from attempting to recover. The attacker is spoofing the client address, so he needs to be able to sniff the traffic that comes from the server, since he is not really the destination of the traffic.
Injecting the attacker’s packet
Packets can be injected at this point onto the network in the form of disruptive data that will be trusted or commands that continue the conversation.
Types of Session Hijacking
The official CEH courseware lists several types of hijacking, though some of them are arguably completely different forms of attack. This is one of those points where the precision of the terms is less important than the point behind them. Be very familiar with the vocabulary, however:
TCP hijacking
UDP hijacking
RST hijacking
Session tokens
TCP hijacking
This form of attack involves having an accurate understanding of the current state of synchronization between two hosts. The handshake must be observed, and sequence numbers must be set in the injected packets to be accepted inside of the current window.
Since this form of attack was discovered, RFC 1948 was written to suggest that ISN (Initial Sequence Numbers) are not incremented every four microseconds as suggested by RFC 792, but should instead involve a PRNG (Pseudo Random Number Generator). The quality of the randomness of the ISN greatly impacts the difficulty of predicting the number.
RST hijacking
This is a form of DoS attack. Packets are injected into an established TCP stream that convinces one side that the other is confused and wants to call it quits. All it takes is to set the RST flag, set the ACK number so it is in the window and, and spoof one side of the conversation. Ettercap is a tool that makes this easy as long as the initial synchronization was observed.
UDP hijacking
The UDP protocol does not involve the complexity of TCP. There are no flags or SEQ/ACK numbers to keep track of sessions. MiTM attacks and DoS attacks are much easier. The UDP protocol does not require the receiving host to respond at all, or acknowledge that there is even a source port to which a response can be given. All communication is handled at the application layer.
Session tokens
Whether or not an application uses the UDP or the TCP protocol, if the application layer requires an authentication or session token, it may be possible for the attacker to capture this token from the network or from a MiTM attack and replay the token to the server.
In stateless environments such as HTTP, session hijacking based on HTTP session tokens and CSRF (Cross-site Request Forgery Attacks) are examples of hijacking. The applications try to create a sense of “state” using unique strings that will be volleyed back and forth. Trust is established and then abused either by replaying a challenge or issuing commands that are trusted. The attacker can capture this information through a proxy server, or cookie stealing.
Countermeasures to Session Hijacking
Since the advent of the session hijacking attack, the TCP protocol specification has been modified to make sequence number prediction extremely difficult. Since it is a 32 bit field, there are about 4.3 billion possible values that can be chosen for the ISN. The attacker would have to sniff enough connections from a host to predict what an ISN would be in the future, even a PRNG (Pseudo-Random Number Generator) is sufficient to make this extremely challenging.
Circuit level gateway firewalls take this a step further by translating the ISN at the same time the network address and ports are translated when a host initiates an outbound connection. This in effect makes it a Layer 4 proxy server; the circuit level gateway is a man-in-the-middle but does not interfere with Layer 7 data.
IPSec (Internet Protocol Security) incorporates an integrity check that will not accept forged packets. Between all of these countermeasures, session hijacking threats are well mitigated, but the presence of the idea is important both from an academic standpoint, and to illustrate the importance of maintaining such countermeasures.
Other forms of session hijacking are more difficult to prevent. Session hijacks based on http session IDs must not be sniffed, guessed or predicted. This involves the proper use of SSL and random number generation for the token. Wireless evil-twin attacks are best prevented with the use of WPA-Enterprise or just plain physical situational awareness.
|