App-DubiousHTTP
view release on metacpan or search on metacpan
lib/App/DubiousHTTP/Tests.pm view on Meta::CPAN
VALID it is expected that loading succeeds, on INVALID requests it is expected
that they fail. In other words: anything turning red is bad and more so if it is
for INVALID requests. Because in this case the browser executes the payload even
if the HTTP response was invalid which might often be used to bypass firewalls
which behave differently.
</p>
HTML
$page =~s{href="(/[^"]+)"}{ 'href="'. garble_url($1). '"' }eg;
for( grep { $_->TESTS } @cat ) {
$page .= "<h3>".html_escape($_->SHORT_DESC)."</h3>";
$page .= $_->LONG_DESC_HTML;
$page .= "<p class=runtest><a href=/".$_->ID.">Run Test</a></p>\n";
}
$page .= "</body></html>";
return "HTTP/1.0 200 ok\r\n".
"Content-type: text/html\r\n".
"Content-length: ".length($page)."\r\n".
"\r\n".
$page;
}
lib/App/DubiousHTTP/Tests.pm view on Meta::CPAN
$html .= "checks.push({ num:0, harmless:'". garble_url("/clen/$good_page/close,clen,content").
"', desc:'sanity check', valid:2, log_header:1, file: '$good_page' });\n";
}
my $limit;
for(@cat) {
next if $cat ne 'all' && $_->ID ne $cat;
for my $t ($_->TESTS) {
last if defined $limit && --$limit <= 0;
if (!@bad_pages) {
$html .= sprintf("checks.push({ num:%s, harmless:'%s', desc:'%s', valid:%d, file:'%s' });\n",
$t->NUM_ID, url_encode($t->url($good_page)), quotemeta(html_escape($t->DESCRIPTION)), $t->VALID,$good_page)
} else {
my $bad_urls = "[".join(",", map { "'".url_encode($t->url($_))."'" } @bad_pages)."]";
$html .= sprintf("checks.push({ num:%s, bad:%s, harmless: '%s', desc:'%s', valid:%d });\n",
$t->NUM_ID, $bad_urls, url_encode($t->url($good_page)), quotemeta(html_escape($t->DESCRIPTION)), $t->VALID)
}
}
}
$html .= sprintf("reference='%x' + Math.floor(time()/1000).toString(16);\n", rand(2**32));
$html .= "runtests();\n</script>\n";
return "HTTP/1.0 200 ok\r\n".
"Content-type: text/html\r\n".
"Content-length: ".length($html)."\r\n".
"ETag: ".App::DubiousHTTP->VERSION."\r\n".
"\r\n".
lib/App/DubiousHTTP/Tests.pm view on Meta::CPAN
my ($cat,$title,$page,$mkhtml) = @_;
my $jsglob = '';
$jsglob .= sprintf("reference='%x' + Math.floor(time()/1000).toString(16);\n", rand(2**32));
$jsglob .= "fast_feedback = 16384;\n" if $FAST_FEEDBACK;
my $rand = rand();
for(@cat) {
next if $cat ne 'all' && $_->ID ne $cat;
for($_->TESTS) {
my $num = $_->NUM_ID;
my $xid = quotemeta(html_escape($_->LONG_ID));
my $url = url_encode($_->url($page));
my $html = $mkhtml->("$url?rand=$rand",$xid);
$jsglob .= "checks.push({ "
. "num: $num, page: '$url', xid: '$xid', "
. 'desc: "'.quotemeta(html_escape($_->DESCRIPTION)) .'",'
. 'valid: '.$_->VALID .','
. 'html: '.($html =~m{^function} ? $html : '"'.quotemeta($html).'"')
."});\n";
}
}
$jsglob .= "div_title.innerHTML = '<h1>".html_escape($title)."</h1>';";
$jsglob .= "runtests()\n";
my $html = _auto_static_html()."<script>$jsglob</script>\n";
return "HTTP/1.0 200 ok\r\n".
"Content-type: text/html\r\n".
"Content-length: ".length($html)."\r\n".
"ETag: ".App::DubiousHTTP->VERSION."\r\n".
"\r\n".
$html;
}
lib/App/DubiousHTTP/Tests.pm view on Meta::CPAN
function add_debug(m,test) {
if (test) {
m = "[" + test['num'] + "] " + m;
}
div_debug.innerHTML = div_debug.innerHTML + m + (test ?
" <a class=trylink target=_blank download='" + test['file'] + "' href=" + test['page'] + ">try</a>" +
" <a class=srclink target=_blank href=/src" + test['page'] + ">src</a>"
: "" ) + "<br>";
}
function escapeAttribute(attr) {
return attr
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function _log(m) {
try { console.log(m) }
lib/App/DubiousHTTP/Tests/Common.pm view on Meta::CPAN
use strict;
use warnings;
package App::DubiousHTTP::Tests::Common;
use Compress::Raw::Zlib;
use MIME::Base64 'decode_base64';
use Exporter 'import';
our @EXPORT = qw(
MUSTBE_VALID SHOULDBE_VALID VALID INVALID UNCOMMON_VALID UNCOMMON_INVALID COMMON_INVALID
SETUP content html_escape url_encode garble_url ungarble_url bro_compress zlib_compress
$NOGARBLE $CLIENTIP $TRACKHDR $FAST_FEEDBACK
);
use Scalar::Util 'blessed';
our $CLIENTIP = undef;
our $NOGARBLE = 0;
our $FAST_FEEDBACK = 0;
use constant {
SHOULDBE_VALID => 3, # simple chunked, gzip.. - note if blocked
MUSTBE_VALID => 2, # no browser should fail on this
lib/App/DubiousHTTP/Tests/Common.pm view on Meta::CPAN
$cache{$page} = [ $hdr,$data,$bad ];
return ($hdr,$data,$bad);
}
if ( my $builtin = $builtin{$page} ) {
$builtin = $builtin->($spec,"/$page") if ref($builtin) eq 'CODE';
return @$builtin;
}
return;
}
sub html_escape {
local $_ = shift;
s{\&}{&}g;
s{<}{<}g;
s{>}{>}g;
return $_
}
sub url_encode {
local $_ = shift;
s{([^\w\-&/?=!$~.,;])}{ sprintf("%%%02X",ord($1)) }esg;
lib/App/DubiousHTTP/Tests/Common.pm view on Meta::CPAN
$body .= '<table style="width: 100%; border-style: none; border-spacing: 0px;">';
for my $test (@tests) {
if (!blessed($test)) {
$body .= "<tr><td colspan=6><h2>$test->[0]</h2></td></tr>";
next;
}
my $valid = $test->VALID;
my $base = $valid>0 ? 'ok' : $valid<0 ? 'warn' : 'bad';
my $bg = $valid>0 ? '#e30e2c' : $valid<0 ? '#d0cfd1' : '#00e800';
$body .= "<tr>";
$body .= "<td>". html_escape($test->DESCRIPTION) ."</td>";
$body .= "<td><div style='height: 2em; border-style: solid; border-width: 1px; width: 6em; text-align: center; background: $bg url(\"".$test->url("$base.png"). "\");'><span style='vertical-align: middle;'>IMAGE</span></div></td>";
$body .= "<td><div id='".$test->LONG_ID."' style='height: 2em; border-style: solid; border-width: 1px; width: 6em; text-align: center; background: $bg'><span style='vertical-align: middle;'>SCRIPT</span></div></td>";
$body .= "<td><iframe seamless=seamless scrolling=no style='border-style: solid; border-width: 1px; width: 6em; height: 2em; overflow: hidden;' src=". $test->url("$base.html"). "></iframe></td>";
$body .= "<td> <a class=button download='eicar.com' href=". $test->url('eicar.txt').">load EICAR</a> </td>";
$body .= "<td> <a class=button download='eicar.zip' href=". $test->url('eicar.zip').">load eicar.zip</a> </td>";
$body .= "</tr>";
$body .= "<script src=".$test->url("$base.js")."></script>";
$body .= "<tr><td colspan=5><hr></td></tr>";
}
$body .= "</table>";
( run in 0.589 second using v1.01-cache-2.11-cpan-c21f80fb71c )