aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Inject.pm25
-rw-r--r--Inject/Handler.pm40
2 files changed, 65 insertions, 0 deletions
diff --git a/Inject.pm b/Inject.pm
new file mode 100644
index 0000000..5b6df8d
--- /dev/null
+++ b/Inject.pm
@@ -0,0 +1,25 @@
+package Apache::Inject;
+
+use strict;
+use warnings;
+
+use Apache2::CmdParms ();
+use Apache2::Module ();
+use Apache2::Const qw/OR_LIMIT TAKE12/;
+
+my @directives = (
+ { name => 'Inject',
+ func => __PACKAGE__.'::Inject',
+ req_override => OR_LIMIT,
+ args_how => TAKE12,
+ errmsg => 'Inject HeadFile[!] FootFile[!]' }
+);
+Apache2::Module::add(__PACKAGE__, \@directives);
+
+sub Inject {
+ my ($self, $parms, @args) = @_;
+ $parms->add_config(['SetHandler perl-script',
+ 'PerlHandler Apache::Inject::Handler']);
+}
+
+1;
diff --git a/Inject/Handler.pm b/Inject/Handler.pm
new file mode 100644
index 0000000..adeec57
--- /dev/null
+++ b/Inject/Handler.pm
@@ -0,0 +1,40 @@
+package Apache::Inject::Handler;
+
+use strict;
+use warnings;
+
+use Apache2::RequestRec ();
+use Apache2::RequestUtil ();
+use Apache2::Const qw/OK DECLINED/;
+
+my $doc = qr{
+ (?<head> <head[^>*]>.*?</head>
+ |
+ ( <title[^>]*>.*?</title>
+ | <base[^>]*>
+ | <meta[^>]*>
+ | <link[^>]*>
+ | <object[^>]*>.*?</object>
+ | <style[^>]*>.*?</style> # n.b.
+ | <script[^>]*>.*?</script> # n.b.
+ | <noscript[^>]*>.*?</noscript> # n.b.!
+ )+ )
+ (?<body> .* )
+}xms;
+
+sub handler {
+ my $r = shift;
+
+ return DECLINED if not $r->content_type eq 'text/html';
+
+ my $content = ${$r->slurp_filename};
+ return DECLINED if not $content =~ /$doc/;
+ print $+{head};
+ print "Injection 1\n";
+ print $+{body};
+ print "Injection 2\n";
+
+ return OK;
+}
+
+1;