mirror of
https://github.com/nmap/nmap.git
synced 2025-12-21 15:09:02 +00:00
Replace bit.lua functions with bitwise operators
This commit is contained in:
@@ -188,7 +188,6 @@
|
||||
-- @copyright Same as Nmap--See https://nmap.org/book/man-legal.html
|
||||
|
||||
|
||||
local bit = require "bit"
|
||||
local ipOps = require "ipOps"
|
||||
local nmap = require "nmap"
|
||||
local stdnse = require "stdnse"
|
||||
@@ -398,8 +397,8 @@ STATE_MSG = {
|
||||
[STATE.VULN] = 'VULNERABLE',
|
||||
[STATE.DoS] = 'VULNERABLE (DoS)',
|
||||
[STATE.EXPLOIT] = 'VULNERABLE (Exploitable)',
|
||||
[bit.bor(STATE.DoS,STATE.VULN)] = 'VULNERABLE (DoS)',
|
||||
[bit.bor(STATE.EXPLOIT,STATE.VULN)] = 'VULNERABLE (Exploitable)',
|
||||
[STATE.DoS | STATE.VULN] = 'VULNERABLE (DoS)',
|
||||
[STATE.EXPLOIT | STATE.VULN] = 'VULNERABLE (Exploitable)',
|
||||
}
|
||||
|
||||
-- Scripts must provide the correct risk factor string.
|
||||
@@ -570,7 +569,7 @@ local normalize_vuln_info = function(vuln_table)
|
||||
-- the 'VULN' state.
|
||||
if vuln_table.state == STATE.DoS or
|
||||
vuln_table.state == STATE.EXPLOIT then
|
||||
vuln_table.state = bit.bor(vuln_table.state, STATE.VULN)
|
||||
vuln_table.state = vuln_table.state | STATE.VULN
|
||||
end
|
||||
|
||||
-- Convert the following string fields to tables.
|
||||
@@ -785,7 +784,7 @@ local l_push_vuln = function(vulndb, new_vuln)
|
||||
end
|
||||
|
||||
-- Save these fields only when the state is not 'NOT VULNERABLE'
|
||||
if bit.band(new_vuln.state, STATE.NOT_VULN) == 0 then
|
||||
if (new_vuln.state & STATE.NOT_VULN) == 0 then
|
||||
if new_vuln.risk_factor then
|
||||
vuln.risk_factor = new_vuln.risk_factor
|
||||
vuln.scores = tcopy(new_vuln.scores)
|
||||
@@ -801,7 +800,7 @@ local l_push_vuln = function(vulndb, new_vuln)
|
||||
-- string_format("Script %s checks:", new_vuln.script_name))
|
||||
--end
|
||||
|
||||
--if bit.band(vuln.state, STATE.EXPLOIT) ~= 0 then
|
||||
--if (vuln.state & STATE.EXPLOIT) ~= 0 then
|
||||
-- vuln.exploit_results = tcopy(new_vuln.exploit_results)
|
||||
-- if vuln.exploit_results then
|
||||
-- insert(vuln.exploit_results, 1,
|
||||
@@ -888,7 +887,7 @@ local l_update_vuln = function(vulndb, old_vuln, new_vuln)
|
||||
|
||||
-- Remove these fields if the state is NOT VULNERABLE
|
||||
-- Note: At this level the old_vuln.state was already updated.
|
||||
if bit.band(old_vuln.state, STATE.NOT_VULN) ~= 0 then
|
||||
if (old_vuln.state & STATE.NOT_VULN) ~= 0 then
|
||||
old_vuln.risk_factor = nil
|
||||
old_vuln.scores = nil
|
||||
old_vuln.description = nil
|
||||
@@ -921,7 +920,7 @@ local l_update_vuln = function(vulndb, old_vuln, new_vuln)
|
||||
--end
|
||||
|
||||
--if new_vuln.exploit_results and
|
||||
--bit.band(old_vuln.state, STATE.EXPLOIT) ~= 0 then
|
||||
--(old_vuln.state & STATE.EXPLOIT) ~= 0 then
|
||||
-- old_vuln.exploit_results = old_vuln.exploit_results or {}
|
||||
-- insert(old_vuln.exploit_results,
|
||||
-- string_format("Script %s exploits:", new_vuln.script_name))
|
||||
@@ -1178,7 +1177,7 @@ end
|
||||
-- otherwise False.
|
||||
local l_filter_vuln = function(vuln_table, filter)
|
||||
if filter and next(filter) then
|
||||
if filter.state and bit.band(vuln_table.state, filter.state) == 0 then
|
||||
if filter.state and (vuln_table.state & filter.state) == 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -1338,7 +1337,7 @@ local l_make_output = function(fid_table, entries, filter)
|
||||
"vulns.lua: Vulnerability '%s' (host: %s): FOUND",
|
||||
vuln_table.title, vuln_table.host.ip)
|
||||
|
||||
if bit.band(vuln_table.state, STATE.NOT_VULN) == 0 then
|
||||
if (vuln_table.state & STATE.NOT_VULN) == 0 then
|
||||
host_entries.vulns[#host_entries.vulns + 1] = vuln_table
|
||||
else
|
||||
save_not_vulns(host_entries.not_vulns, vuln_table)
|
||||
@@ -1355,7 +1354,7 @@ local l_make_output = function(fid_table, entries, filter)
|
||||
if check_vuln(vuln_table, fid_table, filter) then
|
||||
debug(5,
|
||||
"vulns.lua: Vulnerability '%s': FOUND", vuln_table.title)
|
||||
if bit.band(vuln_table.state, STATE.NOT_VULN) == 0 then
|
||||
if (vuln_table.state & STATE.NOT_VULN) == 0 then
|
||||
networks.vulns[#networks.vulns + 1] = vuln_table
|
||||
else
|
||||
save_not_vulns(networks.not_vulns, vuln_table)
|
||||
@@ -1807,7 +1806,7 @@ local format_vuln_base = function(vuln_table, showall)
|
||||
return nil
|
||||
end
|
||||
|
||||
if not showall and bit.band(vuln_table.state, STATE.NOT_VULN) ~= 0 then
|
||||
if not showall and (vuln_table.state & STATE.NOT_VULN) ~= 0 then
|
||||
debug(2, "vulns.lua: vulnerability '%s'%s: %s.",
|
||||
vuln_table.title,
|
||||
vuln_table.host and
|
||||
@@ -1848,7 +1847,7 @@ local format_vuln_base = function(vuln_table, showall)
|
||||
end
|
||||
|
||||
-- Show this information only if the program is vulnerable
|
||||
if bit.band(vuln_table.state, STATE.NOT_VULN) == 0 then
|
||||
if (vuln_table.state & STATE.NOT_VULN) == 0 then
|
||||
if vuln_table.risk_factor then
|
||||
local risk_str = ""
|
||||
|
||||
@@ -2084,7 +2083,7 @@ end
|
||||
--
|
||||
-- -- Save only vulnerabilities with the <code>VULNERABLE</code> state.
|
||||
-- local function save_only_vuln(vuln_table)
|
||||
-- if bit.band(vuln_table.state, vulns.STATE.VULN) ~= 0 then
|
||||
-- if (vuln_table.state & vulns.STATE.VULN) ~= 0 then
|
||||
-- return true
|
||||
-- end
|
||||
-- return false
|
||||
@@ -2212,7 +2211,7 @@ Report = {
|
||||
vuln_table.script_name = self.script_name
|
||||
vuln_table.host = self.host
|
||||
vuln_table.port = self.port
|
||||
if bit.band(vuln_table.state, STATE.NOT_VULN) ~= 0 then
|
||||
if (vuln_table.state & STATE.NOT_VULN) ~= 0 then
|
||||
insert(self.entries.not_vulns, vuln_table)
|
||||
else
|
||||
insert(self.entries.vulns, vuln_table)
|
||||
|
||||
Reference in New Issue
Block a user