11 - Section Hijacking Concepts
11 - Section Hijacking Concepts
HTTP communication uses many different TCP connections, the web server needs a
method to recognize every user’s connections.
The most useful method depends on a token that the Web Server sends to the client
browser after a successful client authentication.
A session token is normally composed of a string of variable width and it could be
used in different ways
For example:
In a URL, the token is a cookie included in the the header or body of an HTTP request
It could also be a JSON Web Token (JWT)
URLs with embedded Cookie
http://www.example.com/PHPSESSID=298zf09hf012fh2
http://www.example.com/userid=sup3r4n0m-us3r-1d3nt1f13r
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9
.
eyJzdWIiOiJ1c2Vycy9Uek1Vb2NNRjRwIiwibmFtZSI6IlJvYmVydCBUb2tlbiBNYW4iLCJz
Y29wZSI6InNlbGYgZ3JvdXBzL2FkbWlucyIsImV4cCI6IjEzMDA4MTkzODAifQ
.
1pVOLQduFWW3muii1LExVBt2TK1-MdRI4QjhKryaDwc
Lack of account lockout for invalid session IDs
Session expiration time is indefinite
Session IDs are small or the ID generation algorithm is weak
Vulnerability of most TCP/IP computers
Session IDs handled insecurely
Majority of countermeasures require encryption to work
Hijacking
Process of taking over active session
Needs legitimate user to make/authenticate connection
Spoofing
Process of initiating new session using stolen credentials
Attacker pretends to be a user/machine to gain access
11.2
COMPROMISING A
Cookie-based Authentication
Token-based Authentication
HEADER.PAYLOAD.SIGNATURE
{ { { 7WK5T79u5mIzjIXXi2oI9
"alg": "HS256", "sub": "123456789", Fglmgivv7RAJ7izyj9tUyQ
"typ": "JWT" "name": "Moo", }
} "admin": true
}
Whole thing is then serialized (put in one line) and typically Base64 encoded:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyAKCSJzdWIiOiAiMTIzNDU2Nzg5IiwgCgkibmFtZSI6ICJNb28iLCAKCSJhZG1pbiI6IHRydWUgCn0=.
7WK5T79u5mIzjIXXi2oI9Fglmgivv7RAJ7izyj9tUyQ
1. User enters their login credentials.
2. Server verifies the credentials are correct and returns a signed token.
3. This token is stored client-side:
most commonly in local storage.
but can be stored in session storage or a cookie as well.
5. The server decodes the JWT and if the token is valid processes the request.
6. Once a user logs out:
the token is destroyed client-side.
no interaction with the server is necessary.
Because HTTP communication uses many different TCP connections, the web
server needs a method to recognize every user’s connections
The most useful method depends on a token that the Web Server sends to the client
browser after a successful client authentication
The token is used in different ways:
In the URL
In the header of the http requisition as a cookie
In other parts of the header of the http request
In the body of the http requisition.
Guessing
Attacker looks at variable parts of session IDs to try to guess what they are
Brute Force
Attacker keeps trying different session IDs until the right one is found
Command Injection
Attacker injects malicious code into the target server
Session ID Prediction
Attacker takes over the session
Session Desynchronization
Attacker breaks the connection with target machine
Monitoring
Attacker watches the TCP segment flow and predicts the TCP sequence number
Sniffing
Attacker intercepts a token
Unlike server-side languages such as PHP, JavaScript code inside your browser
cannot impact the website for other visitors
It only performs actions within the user’s browser
While JavaScript is client-side and does not run on the server, it can be used to
interact with the server by performing background requests
The web page does not display the script to the user
It is executed silently in the background
An attacker exploits a vulnerability on the website’s software
They inject their own script which is executed by the victim’s browser
The script can steal the session cookie/token, entice the user with phishing, or
perform unwanted actions in the user’s name
Stored XSS
Reflected XSS
DOM XSS
Note: You will learn more about compromising web apps in the
CEH Module “Hacking Web Applications”
AKA Persistent XSS
Malicious code is stored permanently in a website database
Victims later unknowingly run that code
An attacker injects a malicious script onto the site that others will read
The attacker posts to a forum, product review, or some other feedback page
The “legitimate” posting contains a hidden malicious script (easy to do in HTML)
As visitors read the posting, their browser is also running the malicious script in the
background
JavaScript document.cookie property in the script is a common way to capture a cookie
Requires some social engineering to entice victims to read the attacker’s post
A vulnerable web app allows visitors to post a comment:
Malicious code is run in the victim’s browser in the context of their current session
with the website
If you want to steal the user’s cookie, you need them to first obtain a cookie
While they still have that session going, you need the same browser (in the same session)
to execute the malicious code
If you simply send them a malicious link, it will open another instance of the browser,
which will be in a different session
The injected script is reflected off the webserver as part of:
An error message
A search result
Any other server response
The attacker must search the web app for any place where user input directly
triggers a response
A search field is a very common choice
Once a vulnerable insertion point is found, the attacker can craft a link containing it
(and the malicious script) and send it to the victim
Requires some social engineering to entice the victim to click a pre-created malicious link
1. Some vulnerable web app has a search function
Users enter a word (search term) in a form
The form creates a URL containing the search term. For example:
https://www.example.com/search?term=chocolate
2. When the user presses enter, the web app searches for the term AND echoes the
user-supplied search term back :
<p>You searched for: chocolate</p>
3. The attacker creates a URL with malicious code in place of a normal search term:
https://www.example.com/search?term=<script>some+malicious+code</script>
4. The attacker puts this malicious URL in a phishing email, SMS, etc. and sends it to
the user
5. The user just has to click the link, thinking it will lead to something else
6. The vulnerable site will reflect the malicious code back to the victim’s browser
7. The browser executes the code (which could include stealing the user’s session
token)
AKA DOM-based Cross-Site Scripting
Abuses the Document Object Model
A standard way to represent HTML objects in a hierarchical manner
In a DOM XSS attack, the malicious JavaScript code is inserted directly into the
victim’s browser
Unlike the other XSS attacks which upload (or reflect) malicious code off the server
There are several HMTL objects that are particularly suited for DOM XSS:
window.location
document.url
document.location
document.referrer
DOM is a programming interface for HTML
and XML documents
DOM treats an HTML/XML document as a tree
structure,
Each node in the tree is an “object”
representing part of the document
The document itself is also considered an object
http://testhtml5.vulnweb.com/#/redir?url=javascript:alert(%22Hacked%20by%20Moo%22)
document.getElementById('csrf').submit();
The power of CSRF is that it's difficult to detect
The attack is carried out by the user’s browser as if user requested it
The user could enter same URL manually and get same result
It’s nearly impossible for the browser to distinguish CSRF from normal
activity
CSRF can be difficult for an attacker to execute
Requires finding a form that can permit malicious instructions
Requires knowing the right values that aren't obscured
Sites that check the referrer header will disallow requests from different
origins
Implement CSRF tokens
A unique, unpredictable secret value generated by the web app
The client must present the token for every request
ATTACKS
Attacker listens in on conversation between user and server
Attacker obtains user’s authentication token
Attacker replays request to server using obtained token and gains unauthorized
server access
AKA Session Donation Attack
Permits an attacker to hijack a valid user session
Exploits a limitation in the way a vulnerable web app manages the session ID
An attacker obtains legitimate web app session ID
Tricks the victim’s browser into using it
3. The web app now thinks anyone with the session ID is legitimate
4. The attacker uses the session ID to access the web application
Takes over the user session
Impersonates the victim
AKA Monkey-in-the-Middle
A general term for an attacker inserting themselves into an existing session to
intercept messages
Uses various techniques to split TCP connection into two sessions:
Victim-to-attacker
Attacker-to-server
Once inserted, the attacker can read/modify/insert fraudulent data into the
communication
You can capture a session cookie by reading the HTTP header
You can also change the amount of a money transaction inside the application
context
ARP spoofing
DNS poisoning
Modify records on the authoritative DNS server
Modify the cache of the local DNS server
Inject fake cached lookups into the victim machine
Modify the victim machine’s HOSTS file with fake name to IP mappings
ONLINE BANKING
ONLINE BANKING
Forbidden Attack
A type of MITM
Exploits the reuse of a cryptographic nonce during the TLS handshake
*SPDY is a Google protocol that manipulates HTTP traffic. It attempts to reduce page load
latency, thus speeding up web traffic
11.6 TCP Session Hijacking
ARP Spoofing
Attacker sends fake ARP replies re-mapping the server/router IP address to the attacker’s
MAC address
The client will put the attacker’s MAC in the destination field of the Ethernet or Wi-Fi
frame
This is your
.254
router
speaking.
Next time
send traffic .1
to 254
instead of
me.
UDP Hijacking can happen in one of two ways:
Attacker sends a forged server reply to the victim before the legitimate server can reply
Attacker intercepts server’s reply using man-in-the-middle attack
Connection Request
MITM
A type of MITM
The attacker does NOT create two sessions
Instead, the attacker poisons the DNS lookup so the client sends traffic destined
for the server to the attacker
The attacker also manipulates the source routing option in the IP headers of the
client’s traffic
Specifies that the traffic return path from the server passes back through the attacker
Performed if source routing is not possible
Attacker can only send data/commands – cannot see server’s response
OK if they can see the results of a command
11.7
SESSION Hijacking Tools
TOOLS
Ettercap, bettercap
ARP poisoning and MITM tools
sslstrip
force SSL downgrade to HTTP
Used in HTTPS MITM attacks
Hamster
cookie sidejacking tool - replaces your cookie with someone else’s
Ferret
the cookie sniffer used by Hamster
Note: You can use Ettercap, hamster, and ferret together to MITM, sniff, and sidejack cookies
Burp Suite, OWASP ZAP, Paros
localhost proxies for intercepting and manipulating web app traffic
Firesheep
Mozilla Firefox extension
Packet sniffer that hijacks browser sessions on unencrypted public Wi-Fi
Steals cookies from the user’s favorite sites such as Facebook, Twitter, etc.
CookieCadger
A Java app that automatically sidejacks and replays insecure HTTP GET requests
DroidSheep
Android app that listens for HTTP packets on wireless networks
Sidejacks the session and extracts the session ID
DroidSniff
Sniffer, MITM, automatic password capture of popular social media sites
dSploit
Pentesting suite that runs on Android
Wi-Fi scanning, network mapping, port scanning session hijacking, MITM
zANTI
ARP poisoning MITM
Sniff cookies
DroidSheep DroidSniff
zANTI
dSploit
11.8 SESSION
HIJACKING
Countermeasures
COUNTER-
MEASURES
Protect Session IDs:
Use unpredictable (randomized) Session IDs
Never use URLs with Sessions IDs
Don't Re-use Session IDs
REVIEW
INTRO TO
In session hijacking, the attacker attempts to take over the client’s session AFTER the user
has authenticated
ETHICAL
Cookies and Java Web Tokens (JWTs) are the most common type of session token
Session Sniffing (sidejacking) is where you passively sniff and capture the user’s token
HACKING
Session Prediction is where you can guess what the next token value would be
REVIEW Stored (persistent) XSS stores the malicious code on a page that
Cross-Site Scripting (XSS) is where the client trusts the server
The attacker injects malicious code which the client’s browser executes in the background
others will see
Reflected XSS uses a web app’s search or error functionality to
send the malicious command, along with a session token, back to
the user
DOM XSS injects the malicious script into the victim’s browser
directly, superimposing it on top of a downloaded page
INTRO TO
Cross-Site Request Forgery (CSRF) is where the server trusts the client (authenticated user)
ETHICAL
As the user does something else, the CSRF tricks the browser into sending unauthorized commands to
the website, which the website will accept and execute
HACKING
Session Replay is where the attacker passively sniffs the client’s session token and then uses it
REVIEW
Session Fixation is where the attacker obtains a legitimate session token and then tricks the
client into using it while authenticating
CRIME and BREACH take advantage of protocol vulnerabilities
MITM can be accomplished through ARP spoofing, ICMP redirect, DNS poisoning, and
malicious links
Source-routed hijacking uses the source routing field in an IP header to instruct
routers to send traffic through a different path (the attacker)
Blind hijacking is used when source routing is not possible
The attacker can relay requests to the server, but cannot see the responses
TCP session hijacking requires the attacker to predict the next TCP sequence number,
deauthenticate the client, and take the client’s place
UDP hijacking intercepts a server’s UDP response to a client, sending a fake response
in its stead