Implemented clean host delete in VS

This commit is contained in:
Luca Deri 2023-08-17 18:52:06 +02:00
parent b98a100871
commit 75ccb84b31
2 changed files with 22 additions and 10 deletions

View file

@ -56,13 +56,6 @@ function vs_module:scan_host(host_ip, ports)
local result = handle:read("*a")
handle:close()
if(true) then
io.write("-------------------------\n")
tprint(scan_command)
tprint(result)
io.write("-------------------------\n")
end
local duration = os.time() - begin_epoch
local scan_ok = true
local num_open_ports
@ -70,7 +63,7 @@ function vs_module:scan_host(host_ip, ports)
local cve
result, num_open_ports, num_vulnerabilities_found, cve = vs_utils.cleanup_nmap_result(result, self.name)
tprint(num_open_ports)
return result, duration, scan_ok, num_open_ports, num_vulnerabilities_found, cve
end

View file

@ -38,8 +38,8 @@ package.path = dirs.installdir .. "/scripts/lua/modules/vulnerability_scan/?.lua
require "lua_utils" -- used by tprint (debug)
local host_to_scan_key = "ntopng.prefs.host_to_scan"
local host_scan_queue_key = "ntopng.vs_scan_queue"
local host_to_scan_key = "ntopng.prefs.host_to_scan"
local host_scan_queue_key = "ntopng.vs_scan_queue"
local scanned_hosts_changes_key = "ntopng.alerts.scanned_hosts_changes"
local json = require("dkjson")
@ -426,6 +426,25 @@ function vs_utils.delete_host_to_scan(host, scan_type, all)
local path_to_s_result = get_report_path(scan_type, host, false)
os.remove(path_to_s_result)
ntop.delHashCache(host_to_scan_key, host_hash_key)
-- Remove this host from active schedules
local elems = {}
while(true) do
local e = ntop.lpopCache(host_scan_queue_key)
if(e == nil) then
break
else
local r = json.decode(e)
if(not((r.scan_type == "cve") and (r.host == "127.0.0.1"))) then
table.insert(elems, e)
end
end
end
for _,i in pairs(elems) do
ntop.lpushCache(host_scan_queue_key, i)
end
end
return true