ajax.php - sort checklists

background_stigs.php - change to support adding sunset STIGs to update_db.php
parse_nessus.php/parse_nmap.php - disable post processing until the end of reading the file
update_db.php - Add sunset STIGs downloading and parsing
database.inc - Removed unnecessary variables ($key, etc), fixed typo (proc_ia_control v. proc_ia_controls), fix typo line 11072, added query_type to other queries in post_Processing method, call update_Target_Count method at the end of post_Processing, convert update_Target_Count to use queries instead of get_pdi_count and get_finding_count views (caused a performance hit), removed calling update_Target_Count from save_Target method to support previously mentioned changes
index.php - removed ajax timeout when bulk removing targets
This commit is contained in:
2018-09-18 19:53:19 -04:00
parent 78e584c1b9
commit 927ae69743
7 changed files with 181 additions and 76 deletions

View File

@ -83,7 +83,6 @@ if (isset($cmd['d']) && $cmd['d']) {
chdir($path);
$db = new db();
$stack = [];
$zip_files = glob("*.zip");
$zip = new ZipArchive();
@ -235,7 +234,7 @@ if (isset($cmd['delete'])) {
*/
function directory_crawl($files)
{
global $zip;
global $zip, $log;
foreach ($files as $file) {
if (preg_match('/\.zip/', $file)) {

View File

@ -582,7 +582,8 @@ class nessus_parser extends scan_xml_parser
$this->log->script_log("Skipping tcp6 ports because there are " . count($netstat_keys) . " listening", E_DEBUG);
}
$this->tgt->set_ID($this->db->save_Target($this->tgt));
$this->tgt->set_PP_Flag(true);
$this->tgt->set_ID($this->db->save_Target($this->tgt, false));
$dt = DateTime::createFromFormat("D M d H:i:s Y", $this->tag["HOST_START"]);
if ($dt < $this->scan->get_File_DateTime()) {
@ -1332,7 +1333,8 @@ class nessus_parser extends scan_xml_parser
{
$this->log->script_log("ReportHost_end-START: {$this->tgt->get_Name()}");
// save findings
$this->db->save_Target($this->tgt);
$this->tgt->set_PP_flag(true);
$this->db->save_Target($this->tgt, false);
$this->log->script_log("Added finding counts: " . count($this->new_findings) . " for target " . $this->tgt->get_Name());
$this->log->script_log("Updated finding counts: " . count($this->updated_findings) . " for target " . $this->tgt->get_Name());
@ -1363,6 +1365,8 @@ class nessus_parser extends scan_xml_parser
{
$this->log->script_log("Saving host list");
$this->db->update_Scan_Host_List($this->scan);
$this->db->post_Processing();
}
}

View File

@ -92,6 +92,7 @@ foreach ($lines as $line_num => $line) {
continue;
} # skip blank lines
$line = trim($line, "\t\n\r"); # chomp would be nice...
$matches = [];
if (!isset($filetype)) {
if (preg_match('/Starting|\-oN/', $line)) {
$filetype = "text";
@ -242,8 +243,6 @@ if ($filetype == "xml") {
$target[$ip]['description'] = $vendor;
# Iterate through ports
$ports = getValue($xml, "ports/port", $host, true);
$tcp_ports = [];
$udp_ports = [];
foreach ($ports as $portxml) {
$portid = $portxml->getAttribute("portid");
$proto = $portxml->getAttribute("protocol");
@ -284,6 +283,7 @@ if ($filetype == "xml") {
$db->update_Running_Scan($base_name, ['name' => 'host_count', 'value' => count($target)]);
$count = 0;
$tgt_ip = null;
foreach ($target as $ip => $tgt) {
# get target ID
$tgt_id = 0;
@ -302,6 +302,7 @@ foreach ($target as $ip => $tgt) {
$tgt_obj->set_STE_ID($conf['ste']);
//$tgt_obj->set_Notes("New target found by NMap");
$tgt_obj->set_OS_ID($sw->get_ID());
$tgt_obj->set_PP_Flag(true);
if ($sw->get_Shortened_SW_String()) {
$tgt_obj->set_OS_String($sw->get_Shortened_SW_String());
}
@ -344,10 +345,11 @@ foreach ($target as $ip => $tgt) {
}
}
$tgt_obj->set_ID($tgt_id = $db->save_Target($tgt_obj));
$tgt_obj->set_ID($tgt_id = $db->save_Target($tgt_obj, false));
}
else { #Update
$db_tgt = $db->get_Target_Details($conf['ste'], $tgt_id)[0];
$db_tgt->set_PP_Flag(true);
if (isset($tgt['tcp'])) {
foreach ($tgt['tcp'] as $port_num => $port) {
@ -388,7 +390,7 @@ foreach ($target as $ip => $tgt) {
}
}
$db->save_Target($db_tgt);
$db->save_Target($db_tgt, false);
}
$count++;
@ -406,6 +408,7 @@ foreach ($target as $ip => $tgt) {
$db->update_Running_Scan($base_name, ['name' => 'last_host', 'value' => $db_tgt->get_Name()]);
}
$db->post_Processing();
$db->update_Scan_Host_List($scan);
$db->update_Running_Scan($base_name, ['name' => 'perc_comp', 'value' => 100, 'complete' => 1]);
if (!isset($cmd['debug'])) {

View File

@ -48,7 +48,8 @@
* - Apr 29, 2018 - Added extract parameter to only extract nasl archive file, fixed a couple bugs
* - May 10, 2018 - Removed ping of cve.mitre.org, and added 'po' and 'do' parameters for NVD CVE
* - Jun 5, 2018 - Fixed a couple setting updates
*/
* - Sep 18, 2018 - Jeff - Added --sunset switch for Installing Sunset STIGs from https://iase.disa.mil/stigs/sunset/Pages/index.aspx
*/
include_once 'config.inc';
include_once 'helper.inc';
include_once 'error.inc';
@ -61,11 +62,10 @@ use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter;
$current_date = new DateTime();
$total_time = null;
$total_diff = 0;
$summary_stats = [];
$total_complete = 0;
$threads = [];
$cmd = getopt("h::u::p::", ['cpe::', 'cce::', 'cve::', 'nvd::', 'nasl::', 'stig::', 'do::', 'po::', 'help::', 'debug::', 'extract::', 'exclude::']);
$cmd = getopt("h::u::p::", ['cpe::', 'cce::', 'cve::', 'nvd::', 'nasl::', 'stig::', 'sunset::', 'do::', 'po::', 'help::', 'debug::', 'extract::', 'exclude::']);
$db = new db();
$diff = new DateTimeDiff();
@ -94,7 +94,7 @@ $log->pushHandler(new StreamHandler(LOG_PATH . "/update_db.log", $log_level));
$log->pushHandler($stream);
if (isset($cmd['h'], $cmd['help']) ||
(!isset($cmd['cpe']) && !isset($cmd['cve']) && !isset($cmd['nasl']) && !isset($cmd['stig']) && !isset($cmd['nvd']))) {
(!isset($cmd['cpe']) && !isset($cmd['cve']) && !isset($cmd['nasl']) && !isset($cmd['stig']) && !isset($cmd['sunset']) && !isset($cmd['nvd']))) {
die(usage());
}
@ -460,6 +460,7 @@ if (isset($cmd['nasl'])) {
'nasl-progress' => 0,
'nasl-count' => 0
]);
$count = 0;
// Capture start time for performance monitoring
$diff->resetClock();
@ -702,6 +703,75 @@ if (isset($cmd['stig'])) {
sleep(3);
}
/**
* Update Sunset STIG library from DISA content
*/
if (isset($cmd['sunset'])) {
$db->set_Setting_Array([
'stig-dl-progress' => 0,
'stig-progress' => 0,
'stig-count' => 0
]);
$path = TMP . "/stigs/zip";
check_path($path);
$sunset_array = [];
$diff->resetClock();
print "Started Sunset STIG ingestion ({$diff->getStartClockTime()})" . PHP_EOL;
$sunset_url="https://iase.disa.mil/stigs/Lists/Sunset%20Master%20List/FinalView.aspx";
if (ping("disa.mil") && !isset($cmd['po'])) {
$log->debug("Checking for $sunset_url");
if ($found = url_exists($sunset_url)) {
$contents=file_get_contents($sunset_url);
}
if (!$found) {
$log->debug("Unable to download $sunset_url, aborting Sunset");
die("Unable to open $sunset_url, aborting Sunset");
}
preg_match_all("/a href=\"([^ ]+zip\/U_[^ ]+STIG\.zip)/", $contents, $sunset_array);
foreach($sunset_array[1] as $url) {
$sunset_fname = basename($url);
download_file($url, "{$path}/$sunset_fname");
}
}
if (!isset($cmd['do']) || isset($cmd['po'])) {
$stig_files = array_merge(
glob("{$path}/*.zip"), glob("{$path}/*.xml"),
glob(TMP . "/*.zip"), glob(TMP . "/*.xml"), glob(TMP . "/stigs/xml/*.xml")
);
if (!count($stig_files)) {
die("Could not find any other zip files in " . realpath(TMP));
}
$script = realpath(defined('PHP_BIN') ? PHP_BIN : PHP) .
" -c " . realpath(PHP_CONF) .
" -f " . realpath(DOC_ROOT . "/exec/background_stigs.php") . " --" .
(isset($cmd['exclude']) && $cmd['exclude'] ? " --exclude=\"{$cmd['exclude']}\"" : "") .
" --delete";
$log->debug("Script to run $script");
passthru($script);
}
$db->help->select_count("sagacity.stigs");
$stig_count = $db->help->execute();
$db->set_Setting("stig-count", $stig_count);
$diff->stopClock();
print PHP_EOL . "Finished at {$diff->getEndClockTime()}" . PHP_EOL .
"Total Time: {$diff->getDiffString()}" . PHP_EOL;
sleep(3);
}
if (is_a($diff->getTotalDiff(), 'DateInterval')) {
print "Total Script Time: {$diff->getTotalDiffString()}" . PHP_EOL;
}
@ -723,6 +793,7 @@ Usage: php update_db.php [--cpe] [--cve] [--nvd] [--nasl] [--stig] [-u={URL}] [-
--nasl To download OpenVAS NVT library and update NASL files
You can also extract *.nasl files from the Nessus library to $tmp/nessus_plugins and it will include these in the update
--stig To download and update the STIG library
--sunset To download and update the STIG library with the STIGs DISA has archived
--do To download the files only...do not call the parsers will overwrite any existing files
--po To parse the downloaded files only, do not download