Session Hijacking
Session Hijacking
This means that an attacker can repeatedly attempt to log in with incorrect session IDs
without facing any restrictions. This can lead to brute-force attacks where an attacker can try
different combinations of session IDs until they find the correct one.
This means that sessions can remain active for an indefinite period, even after the user has
stopped using the system. This can increase the risk of unauthorized access, as an attacker
could potentially take over a session that has not been properly timed out.
This means that the session IDs are easy to guess or predict. This can make it easier for
attackers to hijack sessions or impersonate users.
This means that most computers connected to the internet are susceptible to attacks that
exploit vulnerabilities in session management. This is because TCP/IP is the protocol used for
most internet communication.
This means that session IDs are not properly protected, which can make them vulnerable to
interception or tampering. This can allow attackers to steal session IDs and use them to
access the system as the legitimate user.
This means that many of the countermeasures used to protect session IDs are ineffective
unless they are used in conjunction with encryption. Encryption helps to protect session IDs
from being intercepted and tampered with.
Types of Session hijacking:
1. Passive: Here an attacker hijacks a session but sits back, watches, and records all the traffic in
that session.
2. Active: Here an attacker finds an active session and seizes control of it.
Spoofing vs Hijacking:
1. Use Strong Cryptography: Generate session tokens using secure random number
generators (e.g., crypto.randomBytes()), and ensure tokens are long and complex.
2. Regenerate Tokens After Login: Always regenerate session IDs after a successful login to
prevent session fixation.
3. Use Secure Cookies: Store session tokens in cookies with HttpOnly, Secure, and SameSite
flags to protect them from being accessed by client-side scripts or stolen over non-HTTPS
connections.
4. Limit Session Lifespan: Set an expiration time for session tokens to reduce the window
of opportunity for attackers.
5. Implement Multi-Factor Authentication (MFA): Adding MFA ensures that even if an
attacker guesses the session token, they cannot access the account without the second
factor.
Ethical Reminder:
Only attempt to predict or test session token vulnerabilities in authorized environments (e.g.,
Capture the Flag challenges, penetration testing with permission). Unauthorized testing is illegal and
unethical.
In Man-in-the-Middle (MitM) attacks, the attacker positions themselves between the client and
server to intercept or modify data. They can also use session fixation to set a known session ID
before login, allowing them to hijack the session. To prevent such attacks, use HTTPS, implement
session expiration, secure Wi-Fi, and enable secure cookie flags (HttpOnly, Secure).
It includes:
i. Blind Hijacking
ii. RST hijacking
iii. UDP hijacking
iv. TCP/IP hijacking
v. IP spoofing
TCP/IP hijacking:
TCP/IP hijacking occurs when an attacker intercepts and takes control of an active TCP session
between two devices. By predicting or stealing sequence numbers, the attacker can inject malicious
packets into the communication, gaining unauthorized access to the session.
IP spoofing:
IP spoofing is a technique where an attacker falsifies the source IP address of a packet to appear as
though it’s coming from a trusted or legitimate source. This is often used in attacks like Denial of
Service (DoS) or Man-in-the-Middle to bypass security measures and gain unauthorized access.
RST hijacking:
RST hijacking involves an attacker sending a TCP Reset (RST) packet to one or both parties in an
active connection. By spoofing the sequence numbers, the attacker disrupts the connection, causing
the session to terminate. This technique can be used to intercept, block, or manipulate
communication between two devices.
Blind Hijacking:
An attacker can inject malicious data or commands into the intercepted communications in
the TCP session even if the source-routing is disabled.
The attacker can send the data or commands but has no access to see the response.
UDP Hijacking:
A network-level session hijacking where the attacker sends a forged server reply to a victim's
UDP request before the intended server replies to it.
The attacker uses a man-in-the-middle attack to intercept the server's response to the client
and sends a forged reply.
Session hijacking tools:
i. OWASP ZAP
ii. Burp suite
iii. Netool toolkit
iv. Sslstrip
v. Wireshark
IPsec:
IPsec is a protocol suite developed by the IETF for securing IP communications by authenticating and
encrypting each IP packet of a communication session.
Hijacking a session using ZAP:
Intercept HTTP traffic using bettercap:
Detect session hijacking using wireshark: