[go: nahoru, domu]

Skip to content

Commit

Permalink
Report multiple addresses found when resolving a name sullo#488.
Browse files Browse the repository at this point in the history
Also adds functionality to create $mark->{'messages'} (as an array) to print things in the target info output
  • Loading branch information
sullo committed Mar 10, 2019
1 parent 6490538 commit 7b77c70
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
10 changes: 8 additions & 2 deletions program/nikto.pl
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,17 @@

# Now check each target is real and remove duplicates/fill in extra information
foreach my $mark (@MARKS) {
$mark->{'messages'} = ();
$mark->{'test'} = 1;
$mark->{'failures'} = 0;

# Try to resolve the host
($mark->{'hostname'}, $mark->{'ip'}, $mark->{'display_name'}) = resolve($mark->{'ident'});
my $msgs;
($mark->{'hostname'}, $mark->{'ip'}, $mark->{'display_name'}, $msgs) = resolve($mark->{'ident'});
if ($msgs ne "") {
push(@{ $mark->{'messages'} }, $msgs);
#push ($mark->{'messages'}, $msgs);
}

# Skip if we can't resolve the host - we'll error later
if (!defined $mark->{'ip'}) {
Expand Down Expand Up @@ -269,7 +275,7 @@ sub config_init {
###############################################################################
sub load_modules {
my $errors=0;
my @modules = qw/Getopt::Long Time::Local IO::Socket/;
my @modules = qw/Getopt::Long Time::Local IO::Socket Net::hostent/;
push(@modules,"List::Util qw(sum)");
foreach my $mod (@modules) {
eval "use $mod";
Expand Down
46 changes: 31 additions & 15 deletions program/plugins/nikto_core.plugin
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ sub dump_target_info {
}
}
}

if (defined $mark->{'messages'}) {
my @msgs = @{ $mark->{'messages'} };
foreach my $m (@msgs) {
nprint("+ Message: $m");
}
}

my $time = date_disp($mark->{start_time});
nprint("+ Start Time: $time (GMT$VARIABLES{'GMTOFFSET'})");
nprint($VARIABLES{'DIV'});
Expand Down Expand Up @@ -1025,8 +1033,9 @@ sub readkey {

###############################################################################
sub resolve {
my $ident = $_[0] || return;
my ($name, $ip) = "";
my $ident = $_[0] or return;
my ($ip, $name, $ipcache) = "";
my @addresses;

if (($CONFIGFILE{'PROXYHOST'} ne '') && $CLI{'useproxy'}) {
return $ident, $ident, $ident;
Expand All @@ -1039,21 +1048,28 @@ sub resolve {
exit;
}

$ip = gethostbyname($ident);
if ($ip eq "") {
nprint("+ ERROR: Cannot resolve hostname '$ident'\n");
return;
}
if ($hent = gethostbyname($ident)) {
# my $name = $hent->name; ## Future--report multiple names
my $addr_ref = $hent->addr_list;
@addresses = map { inet_ntoa($_) } @$addr_ref;
}

# inet_ntoa will throw errors if something is wrong
$ip = inet_ntoa($ip);
if ($ip !~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
nprint("+ ERROR: Invalid IP: $ip\n\n");
exit;
}
$ip = $addresses[0];
if ($addresses[1] != "") {
$ipcache = "Multiple IP addresses found: $ip, ";
for (my $i=1; $i<=$#addresses; $i++) {
$ipcache .= "$addresses[$i], ";
}
$ipcache =~ s/, $//;
}

if ($ip !~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
nprint("+ ERROR: Invalid IP: $ip\n\n");
exit;
}
$name = $ident;
}
else # ident is IP
else # ident is IP
{
if ($ident !~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
nprint("+ ERROR: Invalid IP: $ident\n\n");
Expand All @@ -1064,7 +1080,7 @@ sub resolve {
}

my $displayname = ($name) ? $name : $ip;
return $name, $ip, $displayname;
return $name, $ip, $displayname, $ipcache;
}

###############################################################################
Expand Down

0 comments on commit 7b77c70

Please sign in to comment.