2006-08-17 23:36:35 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-19 17:53:59 +00:00
|
|
|
require_once('common.php');
|
2006-08-17 23:36:35 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
function formatCode($string)
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
return
|
2006-11-08 01:31:38 +00:00
|
|
|
str_replace(
|
|
|
|
array("\t", '»', '\0(null)'),
|
|
|
|
array('<strong>\t</strong>', '<span class="linebreak">»</span>', '<strong>\0</strong>'),
|
|
|
|
escapeHTML(
|
|
|
|
str_replace("\0", '\0(null)',
|
|
|
|
wordwrap($string, 28, " »\n", true)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-12-06 07:28:20 +00:00
|
|
|
?><!DOCTYPE html
|
2006-08-14 03:40:51 +00:00
|
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html>
|
|
|
|
<head>
|
2006-11-24 06:26:02 +00:00
|
|
|
<title>HTML Purifier XSS Attacks Smoketest</title>
|
2006-08-17 23:36:35 +00:00
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
2006-11-08 01:31:38 +00:00
|
|
|
<style type="text/css">
|
|
|
|
.scroll {overflow:auto; width:100%;}
|
|
|
|
.even {background:#EAEAEA;}
|
|
|
|
thead th {border-bottom:1px solid #000;}
|
|
|
|
pre strong {color:#00C;}
|
|
|
|
pre .linebreak {color:#AAA;font-weight:100;}
|
|
|
|
</style>
|
2006-08-14 03:40:51 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2006-11-24 06:26:02 +00:00
|
|
|
<h1>HTML Purifier XSS Attacks Smoketest</h1>
|
2006-08-15 12:59:41 +00:00
|
|
|
<p>XSS attacks are from
|
|
|
|
<a href="http://ha.ckers.org/xss.html">http://ha.ckers.org/xss.html</a>.</p>
|
2006-11-08 01:31:38 +00:00
|
|
|
<p><strong>Caveats:</strong>
|
2006-11-26 23:14:12 +00:00
|
|
|
<tt>Google.com</tt> has been programatically disallowed, but as you can
|
|
|
|
see, there are ways of getting around that, so coverage in this area
|
|
|
|
is not complete. Most XSS broadcasts its presence by spawning an alert dialogue.
|
2006-11-08 01:31:38 +00:00
|
|
|
The displayed code is not strictly correct, as linebreaks have been forced for
|
|
|
|
readability. Linewraps have been marked with <tt>»</tt>. Some tests are
|
|
|
|
omitted for your convenience. Not all control characters are displayed.</p>
|
|
|
|
|
2006-08-17 23:36:35 +00:00
|
|
|
<h2>Test</h2>
|
2006-08-14 03:40:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (version_compare(PHP_VERSION, '5', '<')) exit('<p>Requires PHP 5.</p>');
|
|
|
|
|
|
|
|
$xml = simplexml_load_file('xssAttacks.xml');
|
2006-11-26 23:14:12 +00:00
|
|
|
|
|
|
|
// programatically disallow google.com for URI evasion tests
|
|
|
|
// not complete
|
|
|
|
$config = HTMLPurifier_Config::createDefault();
|
2009-02-20 00:17:49 +00:00
|
|
|
$config->set('URI.HostBlacklist', array('google.com'));
|
2006-11-26 23:14:12 +00:00
|
|
|
$purifier = new HTMLPurifier($config);
|
2006-08-14 03:40:51 +00:00
|
|
|
|
|
|
|
?>
|
2006-11-08 01:31:38 +00:00
|
|
|
<table cellspacing="0" cellpadding="2">
|
2006-08-14 03:40:51 +00:00
|
|
|
<thead><tr><th>Name</th><th width="30%">Raw</th><th>Output</th><th>Render</th></tr></thead>
|
|
|
|
<tbody>
|
|
|
|
<?php
|
|
|
|
|
2006-11-08 01:31:38 +00:00
|
|
|
$i = 0;
|
2006-08-14 03:40:51 +00:00
|
|
|
foreach ($xml->attack as $attack) {
|
2006-08-15 22:03:04 +00:00
|
|
|
$code = $attack->code;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-08 01:31:38 +00:00
|
|
|
// custom code for null byte injection tests
|
|
|
|
if (substr($code, 0, 7) == 'perl -e') {
|
|
|
|
$code = substr($code, $i=strpos($code, '"')+1, strrpos($code, '"') - $i);
|
|
|
|
$code = str_replace('\0', "\0", $code);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-08 01:31:38 +00:00
|
|
|
// disable vectors we cannot test in any meaningful way
|
|
|
|
if ($code == 'See Below') continue; // event handlers, whitelist defeats
|
|
|
|
if ($attack->name == 'OBJECT w/Flash 2') continue; // requires ActionScript
|
|
|
|
if ($attack->name == 'IMG Embedded commands 2') continue; // is an HTTP response
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-15 22:03:04 +00:00
|
|
|
// custom code for US-ASCII, which couldn't be expressed in XML without encoding
|
|
|
|
if ($attack->name == 'US-ASCII encoding') $code = urldecode($code);
|
2006-08-14 03:40:51 +00:00
|
|
|
?>
|
2006-11-08 01:31:38 +00:00
|
|
|
<tr<?php if ($i++ % 2) {echo ' class="even"';} ?>>
|
2006-08-19 17:53:59 +00:00
|
|
|
<td><?php echo escapeHTML($attack->name); ?></td>
|
2006-11-08 01:31:38 +00:00
|
|
|
<td><pre><?php echo formatCode($code); ?></pre></td>
|
2006-08-15 22:03:04 +00:00
|
|
|
<?php $pure_html = $purifier->purify($code); ?>
|
2006-11-08 01:31:38 +00:00
|
|
|
<td><pre><?php echo formatCode($pure_html); ?></pre></td>
|
|
|
|
<td><div class="scroll"><?php echo $pure_html ?></div></td>
|
2006-08-14 03:40:51 +00:00
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</body>
|
2007-06-27 13:58:32 +00:00
|
|
|
</html>
|
2008-12-06 09:24:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// vim: et sw=4 sts=4
|