#VERSION,2.04
###############################################################################
#  Copyright (C) 2008 Chris Sullo
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; version 2
#  of the License only.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to 
#  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
###############################################################################
# PURPOSE:
# Test Apache's expect header XSS
###############################################################################
sub nikto_apache_expect_xss_init {
    my $id = {
        name      => "apache_expect_xss",
        full_name => "Apache Expect XSS",
        author    => "Sullo",
        description =>
          "Checks whether the web servers has a cross-site scripting vulnerability through the Expect: HTTP header",
        hooks     => { scan => { method => \&nikto_apache_expect_xss, }, },
        copyright => "2008 Chris Sullo"
        };
    return $id;
}

sub nikto_apache_expect_xss {
    return if $mark->{'terminate'};
    my ($mark) = @_;
    my %headers = ('Expect', '<script>alert(xss)</script>');
    my ($code, $content, $errors, $request, $response) = nfetch($mark, "/", "GET", "", \%headers, "", "apache_expect_xss");

    if ($content =~ /<script>alert\(xss\)<\/script>/) {
	 add_vulnerability($mark, "Apache is vulnerable to XSS via the Expect header", 999974, 27487, "GET", "/", $request, $response);
    }
}

1;
