Implemented support for slow scan

This commit is contained in:
Luca Deri 2023-11-09 11:56:23 +01:00
parent 102034711a
commit 9ef85cb798

View file

@ -72,6 +72,8 @@ local verbose = false
local vs_utils = {}
local use_slow_scan;
-- **********************************************************
function vs_utils.get_host_hash_key(host, scan_type)
@ -102,10 +104,10 @@ function vs_utils.get_nmap_path()
"/usr/local/bin/nmap",
"/opt/homebrew/bin/nmap"
}
for _,p in pairs(path) do
if(ntop.exists(p)) then
return(p)
return(p..use_slow_scan)
end
end
@ -121,7 +123,7 @@ function vs_utils.is_nmap_installed()
"/usr/local/share/nmap/scripts/vulscan",
}
local path = vs_utils.get_nmap_path()
if(path ~= nil) then
for _,m in pairs(module_path) do
if(ntop.exists(m)) then
@ -129,7 +131,7 @@ function vs_utils.is_nmap_installed()
end
end
end
return false
end
@ -310,8 +312,8 @@ end
-- and return a table containing those differences
local function check_differences(host, host_name, scan_type, old_data, new_data)
local rsp = {}
-- security checks
-- security checks
if host == nil or scan_type == nil then
return nil
end
@ -493,15 +495,15 @@ function vs_utils.cleanup_nmap_result(scan_result, scan_type)
l = l:gsub(">", ">")
if(string.sub(l, 1, 2) == " [") then
local c = string.split(string.sub(l,3), "]")
local c = string.split(string.sub(l,3), "]")
local url = cve_utils.getDocURL(c[1], scan_type)
if(scan_type == "cve") then
l = '[<A HREF="'..url..'">'..c[1]..'</A>]'..c[2]
elseif(scan_type == "openvas") then
l = '[<A HREF="'..url..'">'..c[1]..'</A>]'..c[2]
end
table.insert(cve, c[1])
num_vulnerabilities = num_vulnerabilities + 1
end
@ -756,7 +758,7 @@ function vs_utils.restore_config_backup(vs_backup)
local item_to_restore = item
ntop.setHashCache(host_to_scan_key, host_hash_key, json.encode(item_to_restore))
ntop.setHashCache(prefs_host_values_key, host_hash_key, json.encode(item_to_restore))
end
end
@ -803,7 +805,7 @@ function vs_utils.add_host_pref(scan_type, host, ports, scan_frequency)
--saved_hosts[#saved_hosts+1] = new_item
ntop.setHashCache(prefs_host_values_key, host_hash_key, json.encode(new_item))
return result
end
@ -962,7 +964,7 @@ function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time
-- edit case
ntop.setHashCache(host_to_scan_key, host_hash_key, json.encode(new_item))
local counts = vs_utils.update_ts_counters()
if (new_item.is_periodicity) then
@ -1133,7 +1135,7 @@ function vs_utils.notify_scan_results(is_periodic, periodicity)
duration = duration_label,
start_date = start_date_formatted,
end_date = end_date_formatted,
})
end
@ -1260,7 +1262,7 @@ function vs_utils.retrieve_host(host)
if (k ~= 'is_ok_last_scan') then
hash_value[k] = value
end
end
end
end
return hash_value
@ -1291,9 +1293,9 @@ function vs_utils.retrieve_hosts_to_scan()
if (key ~= 'is_ok_last_scan') then
hash_value[key] = value
end
end
end
else
-- hash value not found
-- hash value not found
ntop.setHashCache(host_to_scan_key, k, hash_prefs_string)
end
@ -2005,7 +2007,7 @@ function vs_utils.migrate_keys()
scan_frequency = old_hash_value.scan_frequency,
ports = old_hash_value.ports,
}
ntop.setHashCache(prefs_host_values_key, key,json.encode(new_hash_value))
end
end
@ -2015,7 +2017,7 @@ function vs_utils.migrate_keys()
local hosts = ntop.getHashKeysCache(host_to_scan_key) or {}
local from_key = "tcp_openports"
local to_key = "tcp_portscan"
for key, _ in pairs(hosts) do
if(string.contains(key, from_key)) then
value = ntop.getHashCache(host_to_scan_key, key)
@ -2024,10 +2026,18 @@ function vs_utils.migrate_keys()
new_value = value:gsub(from_key, to_key)
ntop.setHashCache(host_to_scan_key, new_key, new_value)
ntop.delHashCache(host_to_scan_key, key)
ntop.delHashCache(host_to_scan_key, key)
end
end
end
-- **********************************************************
-- init once
if(ntop.getCache("ntopng.prefs.vs.vs_slow_scan") == "1") then
use_slow_scan = " -T polite --max-parallelism 1"
else
use_slow_scan = ""
end
-- **********************************************************