#VERSION,2.08
# $Id: nikto_favicon.plugin 632 2011-02-19 02:49:31Z sullo $
###############################################################################
#  Copyright (C) 2007 CIRT, Inc.
#
#  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 the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
###############################################################################
# PURPOSE:
# Get a favicon.ico file & MD5 fingerprint
###############################################################################
sub nikto_favicon_init {
    my $id = { name        => "favicon",
               full_name   => "Favicon",
               author      => "Sullo",
               description => "Checks the web server's favicon against known favicons.",
               copyright   => "2008 CIRT Inc.",
               hooks       => { scan => { method => \&nikto_favicon, }, },
               };
    return $id;
}

sub nikto_favicon {
    return if $mark->{'terminate'};
    my ($mark) = @_;
    my ($RES, $CONTENT) = nfetch($mark, "/favicon.ico", "GET", "", "", "", "favicon");
    my $dbarray = init_db("db_favicon");

    if ($RES eq "200" && $CONTENT ne "") {
        my $hash = LW2::md5($CONTENT);
        $hash =~ s/^.*://;
        nprint("Got favicon.ico hash:$hash", "d", "");

        foreach my $item (@$dbarray) {
            if ($item->{'md5hash'} eq $hash) {
                add_vulnerability($mark,
                              "/favicon.ico file identifies this server as: $item->{'description'}",
                              $item->{'nikto_id'}, 39272);
            }
        }
    }
}

1;
