Improvements in log details v10

This commit is contained in:
fbsanchez 2020-05-13 16:43:20 +02:00
parent 6bbb9d5d9b
commit bd6b57e8c3
2 changed files with 69 additions and 63 deletions

View File

@ -409,8 +409,8 @@ sub exec_recon_script ($$$) {
################################################################################ ################################################################################
# Guess the OS using xprobe2 or nmap. # Guess the OS using xprobe2 or nmap.
################################################################################ ################################################################################
sub PandoraFMS::Recon::Base::guess_os($$) { sub PandoraFMS::Recon::Base::guess_os($$;$) {
my ($self, $device) = @_; my ($self, $device, $string_flag) = @_;
return $self->{'os_id'}{$device} if defined($self->{'os_id'}{$device}); return $self->{'os_id'}{$device} if defined($self->{'os_id'}{$device});
@ -432,7 +432,9 @@ sub PandoraFMS::Recon::Base::guess_os($$) {
my $return = `"$self->{pa_config}->{xprobe2}" $device 2>$DEVNULL`; my $return = `"$self->{pa_config}->{xprobe2}" $device 2>$DEVNULL`;
if ($? == 0) { if ($? == 0) {
if($return =~ /Running OS:(.*)/) { if($return =~ /Running OS:(.*)/) {
return pandora_get_os($self->{'dbh'}, $1); my $str_os = $1;
return $str_os if is_enabled($string_flag);
return pandora_get_os($self->{'dbh'}, $str_os);
} }
} }
} }
@ -443,7 +445,9 @@ sub PandoraFMS::Recon::Base::guess_os($$) {
return OS_OTHER if ($? != 0); return OS_OTHER if ($? != 0);
if ($return =~ /Aggressive OS guesses:\s*(.*)/) { if ($return =~ /Aggressive OS guesses:\s*(.*)/) {
return pandora_get_os($self->{'dbh'}, $1); my $str_os = $1;
return $str_os if is_enabled($string_flag);
return pandora_get_os($self->{'dbh'}, $str_os);
} }
} }

View File

@ -438,11 +438,11 @@ sub are_connected($$$$$) {
sub icmp_discovery($$) { sub icmp_discovery($$) {
my ($self, $addr) = @_; my ($self, $addr) = @_;
# Create an agent for the device and add it to the list of known hosts. # Create an agent for the device and add it to the list of known hosts.
push(@{$self->{'hosts'}}, $addr); push(@{$self->{'hosts'}}, $addr);
# Create an agent for the device and add it to the list of known hosts. # Create an agent for the device and add it to the list of known hosts.
$self->add_agent($addr); $self->add_agent($addr);
$self->add_module($addr, $self->add_module($addr,
{ {
@ -1355,11 +1355,11 @@ sub prepare_agent($$) {
my $main_address = $self->get_main_address($addr); my $main_address = $self->get_main_address($addr);
return unless is_empty($main_address); return unless is_empty($main_address);
# Resolve hostnames. # Resolve hostnames.
my $host_name = (($self->{'resolve_names'} == 1) ? gethostbyaddr(inet_aton($addr), AF_INET) : $addr); my $host_name = (($self->{'resolve_names'} == 1) ? gethostbyaddr(inet_aton($addr), AF_INET) : $addr);
# Fallback to device IP if host name could not be resolved. # Fallback to device IP if host name could not be resolved.
$host_name = $addr if (!defined($host_name) || $host_name eq ''); $host_name = $addr if (!defined($host_name) || $host_name eq '');
$self->{'agents_found'} = {} if ref($self->{'agents_found'}) ne 'HASH'; $self->{'agents_found'} = {} if ref($self->{'agents_found'}) ne 'HASH';
@ -1978,10 +1978,10 @@ sub scan($) {
} }
} }
# Apply monitoring templates # Apply monitoring templates
$self->call('message', "[5/6] Applying monitoring.", 3); $self->call('message', "[5/6] Applying monitoring.", 3);
$self->{'step'} = STEP_MONITORING; $self->{'step'} = STEP_MONITORING;
$self->call('apply_monitoring', $self); $self->call('apply_monitoring', $self);
# Print debug information on found devices. # Print debug information on found devices.
$self->call('message', "[Summary]", 3); $self->call('message', "[Summary]", 3);
@ -1999,8 +1999,8 @@ sub scan($) {
$self->call('message', $dev_info, 3); $self->call('message', $dev_info, 3);
} }
# Apply monitoring templates # Apply monitoring templates
$self->call('message', "[6/6] Processing results.", 3); $self->call('message', "[6/6] Processing results.", 3);
$self->{'step'} = STEP_PROCESSING; $self->{'step'} = STEP_PROCESSING;
# Send agent information to Database (Discovery) or XML (satellite.). # Send agent information to Database (Discovery) or XML (satellite.).
$self->call('report_scanned_agents'); $self->call('report_scanned_agents');
@ -2226,8 +2226,8 @@ sub wmi_credentials {
# undef if it does not respond to WMI. # undef if it does not respond to WMI.
################################################################################ ################################################################################
sub wmi_credentials_key { sub wmi_credentials_key {
my ($self, $target) = @_; my ($self, $target) = @_;
return $self->{'wmi_auth_key'}{$target}; return $self->{'wmi_auth_key'}{$target};
} }
################################################################################ ################################################################################
@ -2299,8 +2299,8 @@ sub rcmd_credentials {
# undef if it does not respond to WMI. # undef if it does not respond to WMI.
################################################################################ ################################################################################
sub rcmd_credentials_key { sub rcmd_credentials_key {
my ($self, $target) = @_; my ($self, $target) = @_;
return $self->{'rcmd_auth_key'}{$target}; return $self->{'rcmd_auth_key'}{$target};
} }
################################################################################ ################################################################################
@ -2311,7 +2311,7 @@ sub rcmd_credentials_calculation {
my ($self, $target) = @_; my ($self, $target) = @_;
my $rcmd = PandoraFMS::Recon::Util::enterprise_new( my $rcmd = PandoraFMS::Recon::Util::enterprise_new(
'PandoraFMS::RemoteCmd',[{ 'PandoraFMS::RemoteCmd',[{
'psexec' => $self->{'parent'}->{'pa_config'}->{'psexec'}, 'psexec' => $self->{'parent'}->{'pa_config'}->{'psexec'},
'winexe' => $self->{'parent'}->{'pa_config'}->{'winexe'}, 'winexe' => $self->{'parent'}->{'pa_config'}->{'winexe'},
'plink' => $self->{'parent'}->{'pa_config'}->{'plink'} 'plink' => $self->{'parent'}->{'pa_config'}->{'plink'}
@ -2324,50 +2324,50 @@ sub rcmd_credentials_calculation {
return undef; return undef;
} }
my $id_os = $self->call('guess_os', $target); my $id_os = $self->call('guess_os', $target, 1);
$rcmd->set_host($target); $rcmd->set_host($target);
$rcmd->set_os($id_os); $rcmd->set_os($id_os);
# Test all credentials selected. # Test all credentials selected.
foreach my $key_index (@{$self->{'auth_strings_array'}}) { foreach my $key_index (@{$self->{'auth_strings_array'}}) {
my $cred = $self->call('get_credentials', $key_index); my $cred = $self->call('get_credentials', $key_index);
next if ref($cred) ne 'HASH'; next if ref($cred) ne 'HASH';
$rcmd->clean_ssh_lib(); $rcmd->clean_ssh_lib();
my $username; my $username;
my $domain; my $domain;
if($cred->{'username'} =~ /^(.*?)\\(.*)$/) { if($cred->{'username'} =~ /^(.*?)\\(.*)$/) {
$domain = $1; $domain = $1;
$username = $2; $username = $2;
} else { } else {
$username = $cred->{'username'}; $username = $cred->{'username'};
} }
$rcmd->set_credentials( $rcmd->set_credentials(
{ {
'user' => $username, 'user' => $username,
'pass' => $cred->{'password'}, 'pass' => $cred->{'password'},
'domain' => $domain 'domain' => $domain
} }
); );
$rcmd->set_timeout( $rcmd->set_timeout(
$self->{'rcmd_timeout_bin'}, $self->{'rcmd_timeout_bin'},
$self->{'rcmd_timeout'} $self->{'rcmd_timeout'}
); );
my $result; my $result;
eval { eval {
$result = $rcmd->rcmd('echo 1'); $result = $rcmd->rcmd('echo 1');
chomp($result); chomp($result);
my $out = ''; my $out = '';
$out = $result if !is_empty($result); $out = $result if !is_empty($result);
$self->call('message', "Trying [".$key_index."] in [". $target."] [".$id_os."]: [$out]", 10); $self->call('message', "Trying [".$key_index."] in [". $target."] [".$id_os."]: [$out]", 10);
}; };
if ($@) { if ($@) {
$self->call('message', "Failed while trying [".$key_index."] in [". $target."] [".$id_os."]:" . @_, 10); $self->call('message', "Failed while trying [".$key_index."] in [". $target."] [".$id_os."]:" . @_, 10);
} }
if (!is_empty($result) && $result == "1") { if (!is_empty($result) && $result == "1") {
$self->{'rcmd_auth'}{$target} = $cred; $self->{'rcmd_auth'}{$target} = $cred;
@ -2376,12 +2376,14 @@ sub rcmd_credentials_calculation {
$self->{'summary'}->{'RCMD'} += 1; $self->{'summary'}->{'RCMD'} += 1;
$self->call('message', "RCMD available for $target", 10); $self->call('message', "RCMD available for $target", 10);
return 1; return 1;
} else {
$self->call('message', "Last error ($target|$id_os|$result) was [".$rcmd->get_last_error()."]", 10);
} }
} }
# Not found. # Not found.
return 0; return 0;
} }
################################################################################ ################################################################################
@ -2402,13 +2404,13 @@ sub wmi_discovery {
# Tests credentials against addr. # Tests credentials against addr.
################################################################################ ################################################################################
sub rcmd_discovery { sub rcmd_discovery {
my ($self, $addr) = @_; my ($self, $addr) = @_;
# Initialization. # Initialization.
$self->{'rcmd'} = {} unless ref($self->{'rcmd'}) eq 'HASH'; $self->{'rcmd'} = {} unless ref($self->{'rcmd'}) eq 'HASH';
# Calculate credentials. # Calculate credentials.
$self->rcmd_credentials_calculation($addr); $self->rcmd_credentials_calculation($addr);
} }
@ -2496,18 +2498,18 @@ sub wmi_get_command {
# Checks if target is reachable using wmi. # Checks if target is reachable using wmi.
################################################################################ ################################################################################
sub wmi_responds { sub wmi_responds {
my ($self, $target) = @_; my ($self, $target) = @_;
return 1 if is_enabled($self->{'wmi'}{$target}); return 1 if is_enabled($self->{'wmi'}{$target});
return 0; return 0;
} }
################################################################################ ################################################################################
# Checks if target is reachable using rcmd. # Checks if target is reachable using rcmd.
################################################################################ ################################################################################
sub rcmd_responds { sub rcmd_responds {
my ($self, $target) = @_; my ($self, $target) = @_;
return 1 if is_enabled($self->{'rcmd'}{$target}); return 1 if is_enabled($self->{'rcmd'}{$target});
return 0; return 0;
} }
################################################################################ ################################################################################