#VERSION,2.07
###############################################################################
#  Copyright (C) 2006 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:
# Determine if the web site is an embedded device
###############################################################################
sub nikto_embedded_init {
    my $id = { name        => "embedded",
               full_name   => "Embedded Detection",
               author      => "Tautology",
               description => "Checks to see whether the host is an embedded server.",
               hooks       => { scan => { method => \&nikto_embedded, }, 
                                start => { method => \&nikto_embedded_load, },
                              },
               copyright   => "2009 Chris Sullo"
               };
    use vars qw/$EMBEDDEDDB/;
    return $id;
}

sub nikto_embedded_load {
    # load up the database here so we don't redo it each time
    $EMBEDDEDDB = init_db("db_embedded");
}

sub nikto_embedded {
    return if $mark->{'terminate'};
    my ($mark) = @_;

    foreach my $item (@$EMBEDDEDDB) {
        return if $mark->{'terminate'};
        my ($res, $content, $request, $response) = nfetch($mark, $item->{'uri'}, "GET", "", "", "", "embedded detection");
        if ($res eq "200") {
            $item->{'match'} = validate_and_fix_regex($item->{'match'});
            foreach my $line (split(/\n/, $content)) {

                # Check for the matches and pull out information
                if ($line =~ /$item->{'match'}/) {

                    # Now pull out the make
                    my $model = $line;
                    $model =~ s/$item->{'match'}/$item->{'model'}/ee;
                    $model =~ s/\+/ /g;

                    if ($model ne "") {
                        add_vulnerability($mark, "$item->{'message'} $model", $item->{'nikto_id'}, 0, "GET", $item->{'uri'}, $request, $response);
                    }
                }
            }
        }
    }

}

1;
