mirror of
https://github.com/nmap/nmap.git
synced 2025-12-10 06:31:30 +00:00
Load http default accounts fingerprints only once
This commit is contained in:
@@ -169,6 +169,13 @@ local function validate_fingerprints(fingerprints)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- simplify unlocking the mutex, ensuring we don't try to parse again, and returning an error.
|
||||||
|
local function bad_prints(mutex, err)
|
||||||
|
nmap.registry.http_default_accounts_fingerprints = err
|
||||||
|
mutex "done"
|
||||||
|
return false, err
|
||||||
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
-- load_fingerprints(filename, category)
|
-- load_fingerprints(filename, category)
|
||||||
-- Loads data from file and returns table of fingerprints if sanity checks are passed
|
-- Loads data from file and returns table of fingerprints if sanity checks are passed
|
||||||
@@ -181,9 +188,16 @@ local function load_fingerprints(filename, cat)
|
|||||||
local file, filename_full, fingerprints
|
local file, filename_full, fingerprints
|
||||||
|
|
||||||
-- Check if fingerprints are cached
|
-- Check if fingerprints are cached
|
||||||
if(nmap.registry.http_default_accounts_fingerprints ~= nil) then
|
local mutex = nmap.mutex("http_default_accounts_fingerprints")
|
||||||
stdnse.debug(1, "Loading cached fingerprints")
|
mutex "lock"
|
||||||
return nmap.registry.http_default_accounts_fingerprints
|
if nmap.registry.http_default_accounts_fingerprints then
|
||||||
|
if type(nmap.registry.http_fingerprints) == "table" then
|
||||||
|
stdnse.debug(1, "Loading cached fingerprints")
|
||||||
|
mutex "done"
|
||||||
|
return true, nmap.registry.http_default_accounts_fingerprints
|
||||||
|
else
|
||||||
|
return bad_prints(mutex, nmap.registry.http_default_accounts_fingerprints)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Try and find the file
|
-- Try and find the file
|
||||||
@@ -199,7 +213,7 @@ local function load_fingerprints(filename, cat)
|
|||||||
file = loadfile(filename_full, "t", env)
|
file = loadfile(filename_full, "t", env)
|
||||||
if( not(file) ) then
|
if( not(file) ) then
|
||||||
stdnse.debug(1, "Couldn't load the file: %s", filename_full)
|
stdnse.debug(1, "Couldn't load the file: %s", filename_full)
|
||||||
return false, "Couldn't load fingerprint file: " .. filename_full
|
return bad_prints(mutex, "Couldn't load fingerprint file: " .. filename_full)
|
||||||
end
|
end
|
||||||
file()
|
file()
|
||||||
fingerprints = env.fingerprints
|
fingerprints = env.fingerprints
|
||||||
@@ -207,7 +221,7 @@ local function load_fingerprints(filename, cat)
|
|||||||
-- Validate fingerprints
|
-- Validate fingerprints
|
||||||
local valid_flag = validate_fingerprints(fingerprints)
|
local valid_flag = validate_fingerprints(fingerprints)
|
||||||
if type(valid_flag) == "string" then
|
if type(valid_flag) == "string" then
|
||||||
return false, valid_flag
|
return bad_prints(mutex, valid_flag)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Category filter
|
-- Category filter
|
||||||
@@ -223,9 +237,12 @@ local function load_fingerprints(filename, cat)
|
|||||||
|
|
||||||
-- Check there are fingerprints to use
|
-- Check there are fingerprints to use
|
||||||
if(#fingerprints == 0 ) then
|
if(#fingerprints == 0 ) then
|
||||||
return false, "No fingerprints were loaded after processing ".. filename
|
return bad_prints(mutex, "No fingerprints were loaded after processing ".. filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Cache the fingerprints for other scripts, so we aren't reading the files every time
|
||||||
|
nmap.registry.http_default_accounts_fingerprints = fingerprints
|
||||||
|
mutex "done"
|
||||||
return true, fingerprints
|
return true, fingerprints
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user