Web Application Security
Web Application Security
Web Application Security
Gábor Molnár
HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 60
Connection: close
<html>
<head><title>Example</title></head>
<body>
<img src="photo.jpg">
…
name=joe&newsletter=on
------6335469
Content-Disposition: form-data; name="document";
filename="cv.pdf"
Content-Type: application/octet-stream
%PDF-1.4 ...
------6335469--
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 100
Set-Cookie: PHPSESSID=asdfghjkl1234567890
…
Network Communication
HTTP
server
<?php
$n = $_GET["name"];
$p = $_GET["password"];
$q = "SELECT * FROM users WHERE name=$n AND password=$p";
$result = mysql_query($q);
$authenticated_user = mysql_fetch_row($result);
?>
2. Prepared statements
– Superior to input sanitization
– Clear control channel vs. data channel separation
– Step 1: Prepare (parse, etc.) the query with input placeholders
– Step 2: Execute the query with concrete input data
– Supported in most languages (PHP, ASP.NET, etc.)
<?php
$page = $_GET['page'];
include($page + '.php')
?>
<!DOCTYPE my_own_type [
<!ENTITY my_simple_entity "1234567890" >
<!ENTITY my_external_entity SYSTEM "file.xml">
]>
<x>
<!--Parser injects 1234567890 here:-->
<a>&my_simple_entity;</a>
<!--Parser injects the contents of file.xml:-->
<b>&my_external_entity;</b>
</x>
Active
– Can eavesdrop the network traffic
– Can change the network traffic
– Goal: steal user data, change the information seen by the user
2. Reflected XSS
– Attack JS passed as GET/POST parameter
– Server code "reflects" the parameter in the returned HTML
– Trigger: user visits malicious site → site redirects to/frames vuln. URL
HTTP request DB request
Server side script DB
HTTP response DB data
Web Application Security
| 55/65
Cross Site Scripting Types
3. DOM based XSS
– The injection does not occur on the server side
– HTML is created on the client side
– x.innerHTML = attacker_controlled_variable;
– Special case: Client side template based XSS
» Client side JS interprets the template
» Server generates it dynamically
» Attacker controlled variable is inserted HTML encoded
» In some cases, it is possible to achieve JS execution
» Example: AngularJS template sandbox bypasses