Assignment#9
Assignment#9
In this task we have written a javascript code in the About me section of a user “Alice”, Once
these changes will be saved, It will display an error message “XSS”.
The same Error Message displays when we visit the profile of Alice from the attacker (Samy’s)
machine. This shows that the Cross Site Scripting XSS attack has been executed on the Victim
(Alice’s) Machine.
Now, In order to receive the Cookies of the victim user at our end we have logged in to Alice’s
Profile and visited the profile of Samy and we can see that we have received all the relevant
information related to the victim user at our end, which is our objective has been achieved.
So, now we know that since Charlie tried to add Samy as a friend, a request was made with the
friend value as 47, This value must be of Samy. To verify this we have used the source code of
this website using the Inspect option:
By observing the source code of the website we have verified that the value 47 is of Samy. Now
that we have seen the parameters of Add Friend works, we have created another Javascript
code. We will use the same request of Add Friend between Samy and Charlie and make
changes in the cookies and tokens that we had retrieved earlier. We will use the following URL
in our Javascript code:
http://www.xsslabelgg.com/action/friends/add?friend=47&elgg_token=value&elgg_ts=value
Now, we will add this code in the About me section of Samy and as a result of this execution of
code, Samy will be a friend of Alice.
This means that we were able to successfully execute the code and now Samy has become
Alice’s Friend, Since this code is using AJAX which means all these things are happening in the
background and that Alice won’t be able to identify it, Neither will she receive any notification
regarding that.
Question 1: Explain the purpose of Lines 1 and 2, why are they needed?
Answer: We have included this line in our code, In order to send the HTTP request to the
victim, For that purpose we need to have the secret token and the Timestamp value of that
website, Otherwise our request will be considered Illegitimate and we won’t be able to perform
the attack.So the Secret Token and the Timestamp values are stored are stored in the line 1 and
2.
Question 2: If the Elgg application only provides the Editor mode for the "About Me"
field, i.e., you cannot switch to the Text mode; can you still launch a successful attack?
Answer: We won’t be able to successfully Implement the attack in the Text mode, As the Text
mode encodes most of the special character and the attack would never execute like that, So
we can only launch the attack in the Visual Editor Mode and enter the Javascript code.
We see that it is a post request and the content length is that of 476. On looking at Params tab:
Here we can observe that the description parameter is present with the string we entered. The
access level for every field is 2, Which means that it is publically visible. So, in order to construct
such a POST request using JS in Samy’s profile, we enter the following code in his about me
section of Samy’s Profile and once another user visits Samy’s profile a message will appear on
it’s About me Section.
• Question 3: Why do we need Line ➀? Remove this line, and repeat your attack. Report
and explain your observation.
Answer: The Specified Line1 is used in the code, So that the code doesn’t execute on the
attacker’s profile if he visits his own profile for testing purposes, However, if a different user
visits the profile of the attacker, That message would appear in his profile. If we remove this line
from our code, If a user visits Samy’s profile, The message will be displayed on Samy’s about
me section.
This indicates that the code has self propagated itself on charlie’s profile, After he visited Boby’s
Profile.
Now, once we have logged in again to Charlie’s Profile we can observe that the whole code is
visible now, Which means that it has decoded the whole code as data.
Then we Logged in to Alice’s profile and observed that after the update, Alice’s Profile is no
more impacted from the XSS Attack,
Now, in order to demonstrate the difference between the two countermeasures, we perform a
different type of XSS attack.
1. First, we disable both the countermeasures implemented and do the following: 1. We
enter the following into Boby’s brief description field (because it is plain text and not rich
text {in order to see the effect of htmlspecialchars()}):
2. 2. As soon as we save this change, we see that Boby’s profile creates an alert:
3.Now, we log into Alice’s account and go on the profile page of Boby. We see that the alert
pops up, hence proving that the given code ran.
4.Now, we enable the HTMLawed plugin from the admin account again, and then log into Alice’s
account and go to Boby’s profile to see if the alert still pops up:
5. Now, we enable the htmlspecialchars() countermeasure just as before and perform the same
activity. We first log into Boby’s account and see the following:
There is no alert anymore but in fact the code that we entered is displayed on the profile. We log
into Alice’s account and go to Boby’s profile to see if the alert pops up:
Now if we try to execute the code again The code is no more executed, and it is treated as text.
This proves that the htmlspecialchars() encodes the HTML input from the user, avoiding any
XSS attack, This time the alert message will be treated as a normal string.