Static Detection of Second-Order Vulnerabilities in Web Applications
Johannes Dahse and Thorsten Holz
Ruhr-University Bochum
USENIX Security ’14, 20-22 August 2014, San Diego, CA, USA
Static Detection of Second-Order Vulnerabilities in Web Applications - - PowerPoint PPT Presentation
Static Detection of Second-Order Vulnerabilities in Web Applications Johannes Dahse and Thorsten Holz Ruhr-University Bochum USENIX Security 14, 20-22 August 2014, San Diego, CA, USA 1. Introduction 2. Implementation 3. Evaluation 4.
Johannes Dahse and Thorsten Holz
Ruhr-University Bochum
USENIX Security ’14, 20-22 August 2014, San Diego, CA, USA
2
<?php $name = $_POST['name']; // ', 1), (version(), 1)-- - $sql = “INSERT INTO users VALUES ('$name', '$pwd')“; mysql_query($sql); ?>
user input
application
send
!“*$()&/'\
3
<?php $name = mysql_real_escape_string($_POST['name']); $sql = “INSERT INTO users VALUES ('$name', '$pwd')“; mysql_query($sql); ?>
user input
application
send
!“*$()&/'\
4
<?php $name = mysql_real_escape_string($_POST['name']); $sql = “INSERT INTO users VALUES ('$name', '$pwd')“; mysql_query($sql); ?>
user input
application database
send write
5
user input
application database
send write
<?php $result = mysql_query('SELECT * FROM users'); $row = mysql_fetch_assoc($result); echo $row['name']; ?>
read
6
database
<?php $name = $_POST['name']; // ', 'payload')-- - $sql = “INSERT INTO users VALUES ('$name', '$pwd')“; mysql_query($sql); ?>
user input
application
send
!“*$()&/'\
7
database
write
<?php $name = $_POST['name']; // ', 'payload')-- - $sql = “INSERT INTO users VALUES ('$name', '$pwd')“; mysql_query($sql); ?>
user input
application
send
8
database
read
application
request
<?php $result = mysql_query('SELECT * FROM users'); $row = mysql_fetch_assoc($result); system('htpasswd -b .htpasswd Admin '.$row['pwd']); ?>
9
...
...
... User input Persistent Data Store (PDS) Sensitive Sink 1. 2.
10
...
...
... User input Sensitive Sink 1. 2. Persistent Data Store (PDS)
11
12
Source: http://rewalls.com
(Overview)
13
mysql_query('insert into users values(null, '$name', '$pwd');
$name = $_POST['name'];
14
mysql_query('insert into users values(null, '$name', '$pwd');
$name = $_POST['name'];
15
mysql_query('insert into users values(null, '$name', '$pwd');
$name = $_POST['name'];
16
mysql_query('insert into users values(null, '$name', '$pwd');
$name = $_POST['name'];
Vulnerability Report POST[name] SQLi
17
mysql_query('insert into users values(null, '$name', '$pwd');
$name = escape($_POST['name']);
id name pass
users
18
mysql_query('insert into users values(null, '$name', '$pwd');
$name = $_POST['name'];
id name pass
users
Vulnerability Report POST[name] SQLi
19
echo('Hi ' . $res['name'] . ' !');
$res = mysql_query('select name
from users');
$row = mysql_fetch_assoc($res);
PDS *
20
echo('Hi ' . $res['name'] . ' !');
$res = mysql_query('select name
from users');
$row = mysql_fetch_assoc($res);
PDS *
21
echo('Hi ' . $res['name'] . ' !');
$res = mysql_query('select name
from users');
$row = mysql_fetch_assoc($res);
PDS *
22
echo('Hi ' . $res['name'] . ' !');
$res = mysql_query('select name
from users');
$row = mysql_fetch_assoc($res);
PDS *
Temporary Vulnerability Report users[name] XSS
23
PDS *
Temporary Vulnerability Report users[name] XSS
id name pass
PDS'
users
Reads Writes
connect
24
PDS *
Temporary Vulnerability Report users[name] XSS
id name pass
PDS'
users
tainted? Reads Writes
25
PDS *
Temporary Vulnerability Report users[name] XSS
id name pass
PDS'
users
sanitized? Reads Writes
26
PDS *
Temporary Vulnerability Report users[name] XSS
id name pass
PDS'
users
Second-Order Vulnerability Report XSS
Reads Writes
27
Source: http://rewalls.com
28
29 False Positive True Positive False Negative
Non-Taintable Taintable '"\<>
Manually counted PDS (841) Detected Taintable PDS
71%
6%
29%
77% 23%
PDS
30
97% persistent XSS (database)
Missed by previous work
Root cause: Path-sensitive sanitization
E.g., store only valid email
Failures in 1st step propagate to 2nd step
PDS
31
2 based on file upload
12 based on SQLi
Missed by previous work
False positive SQLi
PDS
32
$r = mysql_query("select setting, value from " . OCC_TABLE_CONFIG); while ($l = mysql_fetch_assoc($r)) { $config[$l['setting']] = $l['value']; } function printHeader($what, $function="0") { require $GLOBALS['pfx'] . $GLOBALS['config']['OC_headerFile']; }
PDS
33
$r = mysql_query("select setting, value from " . OCC_TABLE_CONFIG); while ($l = mysql_fetch_assoc($r)) { $config[$l['setting']] = $l['value']; } function printHeader($what, $function="0") { require $GLOBALS['pfx'] . $GLOBALS['config']['OC_headerFile']; }
PDS
34
$r = mysql_query("select setting, value from " . OCC_TABLE_CONFIG); while ($l = mysql_fetch_assoc($r)) { $config[$l['setting']] = $l['value']; } function printHeader($what, $function="0") { require $GLOBALS['pfx'] . $GLOBALS['config']['OC_headerFile']; } function updateConfigSetting($setting, $value) {
SET `value`=' " . safeSQLstr(trim($value)) . " ' WHERE `setting`='" . safeSQLstr($setting) . " ' "); } foreach (array_keys($_POST) as $p) { if (preg_match("/^OC_[\w-]+$/", $p)) { updateConfigSetting($p, $_POST[$p]); } }
PDS
PDS
35
/data/papers/1.pdf
OC_headerFile
SQLi or XSS
Remote Command Execution
All issues are fixed in version 5.31 and 6.01
File Upload Second-Order LFI
36
Source: http://rewalls.com
37
Analyze and collect reads/writes to PDS (database, file names, session data)
Determine sensitive data flow at the end of analysis
Leading to RCE in NewsPro, Scarf, OpenConf, osCommerce
Overlooked problem in practice, missed in previous work
Support prepared statements
Improve SQL parser
38
39
40