From eec2c371fea0a143d1494d792a5c35c9f03fa5fb Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Tue, 15 Jan 2019 14:56:57 -0500 Subject: [PATCH] fix: fix host_list overwriting with eChecklist --- classes/scan.inc | 16 +++++++------ exec/parse_excel_echecklist.php | 42 +++++++++++++++++---------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/classes/scan.inc b/classes/scan.inc index 1383ead..c1c7c63 100644 --- a/classes/scan.inc +++ b/classes/scan.inc @@ -625,13 +625,15 @@ class scan */ public function set_Host_Error($tgt_id, $is_error, $err_msg = null) { - foreach($this->host_list as $x => $h) { - /** @var host_list $h */ - if($h->getTargetId() == $tgt_id) { - $this->host_list[$x]->setScanError($is_error); - $this->host_list[$x]->setScanNotes($err_msg); - return true; - } + if(isset($this->host_list[$tgt_id])) { + $h = $this->host_list[$tgt_id]; + + $h->setScanError($is_error); + $h->setScanNotes($err_msg); + + $this->host_list[$tgt_id] = $h; + + return true; } return false; diff --git a/exec/parse_excel_echecklist.php b/exec/parse_excel_echecklist.php index e740d15..1c4731f 100644 --- a/exec/parse_excel_echecklist.php +++ b/exec/parse_excel_echecklist.php @@ -248,27 +248,29 @@ foreach ($objSS->getWorksheetIterator() as $wksht) { $tgts[] = $tgt; $log->debug("Adding new target to host list", ['row_count' => $row_count, 'tgt_id' => $tgt->get_ID(), 'tgt_name' => $tgt->get_Name()]); - $hl = new host_list(); - $hl->setFindingCount($row_count); - $hl->setTargetId($tgt->get_ID()); - $hl->setTargetName($tgt->get_Name()); - if ($ip) { - $hl->setTargetIp($ip); - } elseif (is_array($tgt->interfaces) && count($tgt->interfaces)) { - foreach ($tgt->interfaces as $int) { - if (!in_array($int->get_IPv4(), ['0.0.0.0', '127.0.0.1'])) { - $ip = $int->get_IPv4(); - break; - } - } - $hl->setTargetIp($ip); - } - if(!isset($scan->get_Host_List()[$tgt->get_ID()])) { + $hl = new host_list(); + $hl->setFindingCount($row_count); + $hl->setTargetId($tgt->get_ID()); + $hl->setTargetName($tgt->get_Name()); + if ($ip) { + $hl->setTargetIp($ip); + } elseif (is_array($tgt->interfaces) && count($tgt->interfaces)) { + foreach ($tgt->interfaces as $int) { + if (!in_array($int->get_IPv4(), ['0.0.0.0', '127.0.0.1'])) { + $ip = $int->get_IPv4(); + break; + } + } + $hl->setTargetIp($ip); + } + $scan->add_Target_to_Host_List($hl); } else { - $existingFindingCount = $scan->get_Host_List()[$tgt->get_ID()]->getFindingCount(); - $hl->addFindingCount($existingFindingCount); + $hl = $scan->get_Host_List()[$tgt->get_ID()]; + + $hl->addFindingCount($row_count); + $scan->add_Target_to_Host_List($hl); } } @@ -400,14 +402,14 @@ foreach ($objSS->getWorksheetIterator() as $wksht) { print "\r" . sprintf("%.2f%%", (($row->getRowIndex() - 10) / $highestRow) * 100); } } + + $db->update_Scan_Host_List($scan); if (!$db->add_Findings_By_Target($updated_findings, $new_findings)) { print "Error adding finding" . PHP_EOL; } } -$db->update_Scan_Host_List($scan); - unset($objSS); if (!isset($cmd['debug'])) { rename($cmd['f'], TMP . "/echecklist/$base_name");