1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Remove nearly all bit.lua use

This commit is contained in:
dmiller
2018-08-28 15:56:45 +00:00
parent e0af0179eb
commit 24c5ff63b2
21 changed files with 79 additions and 98 deletions

View File

@@ -3,7 +3,6 @@ local nmap = require "nmap"
local shortport = require "shortport" local shortport = require "shortport"
local string = require "string" local string = require "string"
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local stdnse = require "stdnse" local stdnse = require "stdnse"
description = [[ description = [[
@@ -181,22 +180,22 @@ action = function(host, port)
pos = pos + 1 pos = pos + 1
local player = stdnse.output_table() local player = stdnse.output_table()
if bit.band(flags, 1) ~= 0 then if (flags & 1) ~= 0 then
pos, player.name = bin.unpack("p", data, pos) pos, player.name = bin.unpack("p", data, pos)
end end
if bit.band(flags, 2) ~= 0 then if (flags & 2) ~= 0 then
pos, player.team = bin.unpack("p", data, pos) pos, player.team = bin.unpack("p", data, pos)
end end
if bit.band(flags, 4) ~= 0 then if (flags & 4) ~= 0 then
pos, player.skin = bin.unpack("p", data, pos) pos, player.skin = bin.unpack("p", data, pos)
end end
if bit.band(flags, 8) ~= 0 then if (flags & 8) ~= 0 then
pos, player.score = bin.unpack("p", data, pos) pos, player.score = bin.unpack("p", data, pos)
end end
if bit.band(flags, 16) ~= 0 then if (flags & 16) ~= 0 then
pos, player.ping = bin.unpack("p", data, pos) pos, player.ping = bin.unpack("p", data, pos)
end end
if bit.band(flags, 32) ~= 0 then if (flags & 32) ~= 0 then
pos, player.time = bin.unpack("p", data, pos) pos, player.time = bin.unpack("p", data, pos)
end end

View File

@@ -1,5 +1,5 @@
local bin = require "bin"
local bit = require "bit" local bit = require "bit"
local bin = require "bin"
local brute = require "brute" local brute = require "brute"
local creds = require "creds" local creds = require "creds"
local nmap = require "nmap" local nmap = require "nmap"
@@ -175,7 +175,7 @@ local backorifice =
-- @return seed number containing next seed -- @return seed number containing next seed
gen_next_seed = function(self, seed) gen_next_seed = function(self, seed)
seed = seed*214013 + 2531011 seed = seed*214013 + 2531011
seed = bit.band(seed,0xffffff) seed = seed & 0xffffff
return seed return seed
end, end,
@@ -198,9 +198,9 @@ local backorifice =
--calculate next seed --calculate next seed
seed = self:gen_next_seed(seed) seed = self:gen_next_seed(seed)
--calculate encryption key based on seed --calculate encryption key based on seed
local key = bit.band(bit.arshift(seed,16), 0xff) local key = bit.arshift(seed,16) & 0xff
crypto_byte = bit.bxor(data_byte,key) crypto_byte = data_byte ~ key
output = bin.pack("AC",output,crypto_byte) output = bin.pack("AC",output,crypto_byte)
--ARGSIZE limitation from BackOrifice server --ARGSIZE limitation from BackOrifice server
if i == 256 then break end if i == 256 then break end

View File

@@ -1,5 +1,5 @@
local bin = require "bin"
local bit = require "bit" local bit = require "bit"
local bin = require "bin"
local nmap = require "nmap" local nmap = require "nmap"
local shortport = require "shortport" local shortport = require "shortport"
local stdnse = require "stdnse" local stdnse = require "stdnse"
@@ -149,7 +149,7 @@ local cmds = {
local function gen_next_seed(seed) local function gen_next_seed(seed)
seed = seed*214013 + 2531011 seed = seed*214013 + 2531011
seed = bit.band(seed,0xffffff) seed = seed & 0xffffff
return seed return seed
end end
@@ -202,9 +202,9 @@ local function BOcrypt(data, password, initial_seed )
--calculate next seed --calculate next seed
seed = gen_next_seed(seed) seed = gen_next_seed(seed)
--calculate encryption key based on seed --calculate encryption key based on seed
local key = bit.band(bit.arshift(seed,16), 0xff) local key = bit.arshift(seed,16) & 0xff
crypto_byte = bit.bxor(data_byte,key) crypto_byte = data_byte ~ key
output = bin.pack("AC",output,crypto_byte) output = bin.pack("AC",output,crypto_byte)
if i == 256 then break end --ARGSIZE limitation if i == 256 then break end --ARGSIZE limitation
end end
@@ -302,16 +302,16 @@ action = function( host, port )
end end
--singular --singular
if bit.band(p_type,TYPE.PARTIAL_PACKET)==0x00 if (p_type & TYPE.PARTIAL_PACKET)==0x00
and bit.band(p_type,TYPE.CONTINUED_PACKET)==0x00 then break end and (p_type & TYPE.CONTINUED_PACKET)==0x00 then break end
--first --first
if bit.band(p_type,TYPE.CONTINUED_PACKET)==0x00 then if (p_type & TYPE.CONTINUED_PACKET)==0x00 then
multi_flag = true multi_flag = true
end end
--last --last
if bit.band(p_type,TYPE.PARTIAL_PACKET)==0x00 then break end if (p_type & TYPE.PARTIAL_PACKET)==0x00 then break end
end end
end end

View File

@@ -1,5 +1,4 @@
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local math = require "math" local math = require "math"
local nmap = require "nmap" local nmap = require "nmap"
local packet = require "packet" local packet = require "packet"
@@ -67,15 +66,15 @@ ATAoE = {
pos, verflags, header.error, pos, verflags, header.error,
header.major, header.minor, header.major, header.minor,
header.cmd, header.tag = bin.unpack(">CCSCCI", data) header.cmd, header.tag = bin.unpack(">CCSCCI", data)
header.version = bit.rshift(verflags, 4) header.version = verflags >> 4
header.flags = bit.band(verflags, 0x0F) header.flags = verflags & 0x0F
return header return header
end, end,
-- return configuration info request as string -- return configuration info request as string
__tostring = function(self) __tostring = function(self)
assert(self.tag, "No tag was specified in Config Info Request") assert(self.tag, "No tag was specified in Config Info Request")
local verflags = bit.lshift(self.version, 4) local verflags = self.version << 4
return bin.pack(">CCSCCI", verflags, self.error, self.major, self.minor, self.cmd, self.tag) return bin.pack(">CCSCCI", verflags, self.error, self.major, self.minor, self.cmd, self.tag)
end, end,
}, },

View File

@@ -1,4 +1,3 @@
local bit = require "bit"
local netbios = require "netbios" local netbios = require "netbios"
local nmap = require "nmap" local nmap = require "nmap"
local stdnse = require "stdnse" local stdnse = require "stdnse"
@@ -28,7 +27,7 @@ categories = {"broadcast", "safe"}
prerule = function() return true end prerule = function() return true end
local function isGroup(flags) return ( bit.band(flags, 0x8000) == 0x8000 ) end local function isGroup(flags) return ( (flags & 0x8000) == 0x8000 ) end
action = function() action = function()

View File

@@ -1,5 +1,4 @@
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local nmap = require "nmap" local nmap = require "nmap"
local os = require "os" local os = require "os"
local stdnse = require "stdnse" local stdnse = require "stdnse"
@@ -70,7 +69,7 @@ Ping = {
parse = function(self) parse = function(self)
-- do a very basic length check -- do a very basic length check
local pos, len = bin.unpack(">I", self.data) local pos, len = bin.unpack(">I", self.data)
len = bit.band(len, 0x0000FFFF) len = len & 0x0000FFFF
if ( len ~= #self.data ) then if ( len ~= #self.data ) then
stdnse.debug2("The packet length was reported as %d, expected %d", len, #self.data) stdnse.debug2("The packet length was reported as %d, expected %d", len, #self.data)

View File

@@ -1,4 +1,3 @@
local bit = require "bit"
local comm = require "comm" local comm = require "comm"
local nmap = require "nmap" local nmap = require "nmap"
local shortport = require "shortport" local shortport = require "shortport"
@@ -98,13 +97,13 @@ action = function(host, port)
end end
-- Check response flag and recursion -- Check response flag and recursion
if not (bit.band(string.byte(result, 3), 0x80) == 0x80 if not ((string.byte(result, 3) & 0x80) == 0x80
and bit.band(string.byte(result, 4), 0x80) == 0x80) then and (string.byte(result, 4) & 0x80) == 0x80) then
return fail("Server refused recursion") return fail("Server refused recursion")
end end
-- Check error flag -- Check error flag
if (bit.band(string.byte(result, 4), 0x0F) ~= 0x00) then if (string.byte(result, 4) & 0x0F) ~= 0x00 then
return fail("Server failure") return fail("Server failure")
end end

View File

@@ -1,4 +1,3 @@
local bit = require "bit"
local comm = require "comm" local comm = require "comm"
local nmap = require "nmap" local nmap = require "nmap"
local shortport = require "shortport" local shortport = require "shortport"
@@ -98,13 +97,13 @@ action = function(host, port)
end end
-- Check response flag and recursion -- Check response flag and recursion
if not (bit.band(string.byte(result, 3), 0x80) == 0x80 if not ((string.byte(result, 3) & 0x80) == 0x80
and bit.band(string.byte(result, 4), 0x80) == 0x80) then and (string.byte(result, 4) & 0x80) == 0x80) then
return fail("Server refused recursion") return fail("Server refused recursion")
end end
-- Check error flag -- Check error flag
if (bit.band(string.byte(result, 4), 0x0F) ~= 0x00) then if (string.byte(result, 4) & 0x0F) ~= 0x00 then
return fail("Server failure") return fail("Server failure")
end end

View File

@@ -1,5 +1,4 @@
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local dns = require "dns" local dns = require "dns"
local ipOps = require "ipOps" local ipOps = require "ipOps"
local listop = require "listop" local listop = require "listop"
@@ -295,7 +294,7 @@ local RD = {
for i=0, len-1 do for i=0, len-1 do
local n = string.byte(data, offset + i) local n = string.byte(data, offset + i)
for _, v in ipairs(bits) do for _, v in ipairs(bits) do
if bit.band(v, n) > 0 then table.insert(svcs, p) end if (v & n) > 0 then table.insert(svcs, p) end
p = p + 1 p = p + 1
end end
end end
@@ -368,11 +367,11 @@ local RD = {
return offset, '' return offset, ''
end end
siz = string.byte(data, offset+1) siz = string.byte(data, offset+1)
siz = bit.rshift(siz,4) * 10 ^ bit.band(siz, 0x0f) / 100 siz = (siz >> 4) * 10 ^ (siz & 0x0f) / 100
hp = string.byte(data, offset+2) hp = string.byte(data, offset+2)
hp = bit.rshift(hp,4) * 10 ^ bit.band(hp, 0x0f) / 100 hp = (hp >> 4) * 10 ^ (hp & 0x0f) / 100
vp = string.byte(data, offset+3) vp = string.byte(data, offset+3)
vp = bit.rshift(vp,4) * 10 ^ bit.band(vp, 0x0f) / 100 vp = (vp >> 4) * 10 ^ (vp & 0x0f) / 100
offset = offset + 4 offset = offset + 4
offset, lat, lon, alt = bin.unpack(">III", data, offset) offset, lat, lon, alt = bin.unpack(">III", data, offset)
lat = (lat-2^31)/3600000 --degrees lat = (lat-2^31)/3600000 --degrees
@@ -420,7 +419,7 @@ local RD = {
A6 = function(data, offset) -- obsoleted by AAAA A6 = function(data, offset) -- obsoleted by AAAA
local prefix, addr, name local prefix, addr, name
prefix = string.byte(data, offset) prefix = string.byte(data, offset)
local pbytes = bit.rshift(prefix,3) local pbytes = prefix >> 3
addr = ipOps.str_to_ip(string.rep("\000", pbytes) .. data:sub(offset+1, 16-pbytes)) addr = ipOps.str_to_ip(string.rep("\000", pbytes) .. data:sub(offset+1, 16-pbytes))
offset, name = parse_domain(data, offset + 17 - pbytes) offset, name = parse_domain(data, offset + 17 - pbytes)
return offset, string.format("%d %s %s", prefix, addr, name) return offset, string.format("%d %s %s", prefix, addr, name)
@@ -761,7 +760,7 @@ action = function(host, port)
-- check server response code -- check server response code
if length < 6 or if length < 6 or
not (bit.band(string.byte(response_str, 6), 15) == 0) then not ((string.byte(response_str, 6) & 15) == 0) then
return nil return nil
end end

View File

@@ -1,6 +1,5 @@
local nmap = require "nmap" local nmap = require "nmap"
local stdnse = require "stdnse" local stdnse = require "stdnse"
local bit = require "bit"
local string = require "string" local string = require "string"
local packet = require "packet" local packet = require "packet"
@@ -75,8 +74,8 @@ ftp_helper = {
-- IPv4 payload -- IPv4 payload
payload = "227 Entering Passive Mode (" .. payload = "227 Entering Passive Mode (" ..
string.gsub(host.ip,"%.",",") .. "," .. string.gsub(host.ip,"%.",",") .. "," ..
bit.band(bit.rshift(targetport, 8), 0xff) .. ((targetport >> 8) & 0xff) ..
"," .. bit.band(targetport, 0xff) .. "," .. (targetport & 0xff) ..
")\r\n" ")\r\n"
ethertype = "\x08\0" -- Ethernet Type: IPv4 ethertype = "\x08\0" -- Ethernet Type: IPv4

View File

@@ -31,7 +31,6 @@ local stdnse = require 'stdnse'
local httpspider = require 'httpspider' local httpspider = require 'httpspider'
local string = require 'string' local string = require 'string'
local bin = require 'bin' local bin = require 'bin'
local bit = require 'bit'
local table = require 'table' local table = require 'table'
-- These definitions are copied/pasted/reformatted from the jhead-2.96 sourcecode -- These definitions are copied/pasted/reformatted from the jhead-2.96 sourcecode
@@ -369,10 +368,10 @@ local function process_gps(data, pos, endian, result)
end end
elseif(tag == GPS_TAG_LATITUDEREF) then elseif(tag == GPS_TAG_LATITUDEREF) then
-- Get the first byte in the latitude reference as a character -- Get the first byte in the latitude reference as a character
latitude_ref = string.char(bit.rshift(value, 24)) latitude_ref = string.char(value >> 24)
elseif(tag == GPS_TAG_LONGITUDEREF) then elseif(tag == GPS_TAG_LONGITUDEREF) then
-- Get the first byte in the longitude reference as a character -- Get the first byte in the longitude reference as a character
longitude_ref = string.char(bit.rshift(value, 24)) longitude_ref = string.char(value >> 24)
end end
end end

View File

@@ -1,4 +1,3 @@
local bit = require "bit"
local http = require "http" local http = require "http"
local shortport = require "shortport" local shortport = require "shortport"
local stdnse = require "stdnse" local stdnse = require "stdnse"
@@ -131,12 +130,12 @@ local function phpass_encode64(input)
while cur < count do while cur < count do
local value = string.byte(input, cur) local value = string.byte(input, cur)
cur = cur + 1 cur = cur + 1
table.insert(out, itoa64(bit.band(value, 0x3f))) table.insert(out, itoa64(value & 0x3f))
if cur < count then if cur < count then
value = bit.bor(value, bit.lshift(string.byte(input, cur), 8)) value = value | (string.byte(input, cur) << 8)
end end
table.insert(out, itoa64(bit.band(bit.rshift(value, 6), 0x3f))) table.insert(out, itoa64((value >> 6) & 0x3f))
if cur >= count then if cur >= count then
break break
@@ -144,16 +143,16 @@ local function phpass_encode64(input)
cur = cur + 1 cur = cur + 1
if cur < count then if cur < count then
value = bit.bor(value, bit.lshift(string.byte(input, cur), 16)) value = value | (string.byte(input, cur) << 16)
end end
table.insert(out, itoa64(bit.band(bit.rshift(value, 12), 0x3f))) table.insert(out, itoa64((value >> 12) & 0x3f))
if cur >= count then if cur >= count then
break break
end end
cur = cur + 1 cur = cur + 1
table.insert(out, itoa64(bit.band(bit.rshift(value, 18), 0x3f))) table.insert(out, itoa64((value >> 18) & 0x3f))
end end
return table.concat(out) return table.concat(out)

View File

@@ -1,4 +1,3 @@
local bit = require "bit"
local geoip = require "geoip" local geoip = require "geoip"
local io = require "io" local io = require "io"
local ipOps = require "ipOps" local ipOps = require "ipOps"
@@ -474,7 +473,7 @@ local GeoIP = {
-- the original representation in the MaxMind API is ANSI C integer -- the original representation in the MaxMind API is ANSI C integer
-- which should not overflow the greatest value Lua can offer ;) -- which should not overflow the greatest value Lua can offer ;)
for j=0,(MaxmindDef.SEGMENT_RECORD_LENGTH-1) do for j=0,(MaxmindDef.SEGMENT_RECORD_LENGTH-1) do
o._databaseSegments = o._databaseSegments + bit.lshift( buf:byte(j+1), j*8) o._databaseSegments = o._databaseSegments + ( buf:byte(j+1) << j*8)
end end
if o._databaseType == MaxmindDef.ORG_EDITION or o._databaseType == MaxmindDef.ISP_EDITION then if o._databaseType == MaxmindDef.ORG_EDITION or o._databaseType == MaxmindDef.ISP_EDITION then
@@ -548,16 +547,16 @@ local GeoIP = {
start_pos = end_pos + 1 start_pos = end_pos + 1
local c1,c2,c3=record_buf:byte(start_pos,start_pos+3) local c1,c2,c3=record_buf:byte(start_pos,start_pos+3)
record.latitude = (( bit.lshift(c1,0*8) + bit.lshift(c2,1*8) + bit.lshift(c3,2*8) )/10000) - 180 record.latitude = (( (c1 << 0*8) + (c2 << 1*8) + (c3 << 2*8) )/10000) - 180
start_pos = start_pos +3 start_pos = start_pos +3
c1,c2,c3=record_buf:byte(start_pos,start_pos+3) c1,c2,c3=record_buf:byte(start_pos,start_pos+3)
record.longitude = (( bit.lshift(c1,0*8) + bit.lshift(c2,1*8) + bit.lshift(c3,2*8) )/10000) - 180 record.longitude = (( (c1 << 0*8) + (c2 << 1*8) + (c3 << 2*8) )/10000) - 180
start_pos = start_pos +3 start_pos = start_pos +3
if self._databaseType == MaxmindDef.CITY_EDITION_REV1 and record.country_code=='US' then if self._databaseType == MaxmindDef.CITY_EDITION_REV1 and record.country_code=='US' then
c1,c2,c3=record_buf:byte(start_pos,start_pos+3) c1,c2,c3=record_buf:byte(start_pos,start_pos+3)
local dmaarea_combo= bit.lshift(c1,0*8) + bit.lshift(c2,1*8) + bit.lshift(c3,2*8) local dmaarea_combo= (c1 << 0*8) + (c2 << 1*8) + (c3 << 2*8)
record.dma_code = math.floor(dmaarea_combo/1000) record.dma_code = math.floor(dmaarea_combo/1000)
record.area_code = dmaarea_combo % 1000 record.area_code = dmaarea_combo % 1000
else else
@@ -585,11 +584,11 @@ local GeoIP = {
for i=0,1 do for i=0,1 do
for j=0,(self._recordLength-1) do for j=0,(self._recordLength-1) do
x[i] = x[i] + bit.lshift(buf:byte((self._recordLength * i + j) +1 ), j*8) x[i] = x[i] + (buf:byte((self._recordLength * i + j) +1 ) << j*8)
end end
end end
-- Gotta test this out thoroughly because of the ipnum -- Gotta test this out thoroughly because of the ipnum
if bit.band(ipnum, bit.lshift(1,depth)) ~= 0 then if (ipnum & (1 << depth)) ~= 0 then
if x[1] >= self._databaseSegments then if x[1] >= self._databaseSegments then
return x[1] return x[1]
end end

View File

@@ -3,7 +3,6 @@ local coroutine = require "coroutine"
local stdnse = require "stdnse" local stdnse = require "stdnse"
local table = require "table" local table = require "table"
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local packet = require "packet" local packet = require "packet"
local ipOps = require "ipOps" local ipOps = require "ipOps"
local string = require "string" local string = require "string"
@@ -120,9 +119,9 @@ end
-- Parse a KNX address from raw bytes -- Parse a KNX address from raw bytes
-- @param addr Unpacked 2 bytes -- @param addr Unpacked 2 bytes
local parseKnxAddress = function(addr) local parseKnxAddress = function(addr)
local a = bit.rshift(bit.band(addr, 0xf000),12) local a = (addr & 0xf000) >> 12
local b = bit.rshift(bit.band(addr, 0x0f00), 8) local b = (addr & 0x0f00) >> 8
local c = bit.band(addr, 0xff) local c = addr & 0xff
return a..'.'..b..'.'..c return a..'.'..b..'.'..c
end end

View File

@@ -2,7 +2,6 @@ local nmap = require "nmap"
local stdnse = require "stdnse" local stdnse = require "stdnse"
local table = require "table" local table = require "table"
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local packet = require "packet" local packet = require "packet"
local ipOps = require "ipOps" local ipOps = require "ipOps"
local target = require "target" local target = require "target"
@@ -111,7 +110,7 @@ local llmnrListen = function(interface, timeout, result)
-- Make verifications -- Make verifications
-- Message == Response bit -- Message == Response bit
-- and 1 Question (hostname we requested) and -- and 1 Question (hostname we requested) and
if (bit.rshift(flags, 15) == 1) and questions == 0x01 then if ((flags >> 15) == 1) and questions == 0x01 then
stdnse.debug1("got response from %s", p.ip_src) stdnse.debug1("got response from %s", p.ip_src)
-- Skip header's 12 bytes -- Skip header's 12 bytes
-- extract host length -- extract host length

View File

@@ -1,5 +1,4 @@
local bin = require "bin" local bin = require "bin"
local bit = require "bit"
local ipOps = require "ipOps" local ipOps = require "ipOps"
local math = require "math" local math = require "math"
local nmap = require "nmap" local nmap = require "nmap"
@@ -320,14 +319,14 @@ function check(status, response, track)
end end
-- response bit set -- response bit set
if bit.rshift(pkt:u8(off), 7) ~= 1 then if (pkt:u8(off) >> 7) ~= 1 then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.debug1('Bad response from %s - did not have response bit set.', track.target) stdnse.debug1('Bad response from %s - did not have response bit set.', track.target)
return nil return nil
end end
-- version is as expected -- version is as expected
val = bit.band(bit.rshift(pkt:u8(off), 3), 0x07) val = (pkt:u8(off) >> 3) & 0x07
if val ~= track.v then if val ~= track.v then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
@@ -335,7 +334,7 @@ function check(status, response, track)
return nil return nil
end end
-- mode is as expected -- mode is as expected
val = bit.band(pkt:u8(off), 0x07) val = pkt:u8(off) & 0x07
if val ~= track.m then if val ~= track.m then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
@@ -360,7 +359,7 @@ function check(status, response, track)
end end
-- NTP error conditions - defined codes are not evil (bogus codes are). -- NTP error conditions - defined codes are not evil (bogus codes are).
local fail, msg = false local fail, msg = false
local err = bit.band(bit.rshift(pkt:u8(off+4), 4), 0x0f) local err = (pkt:u8(off+4) >> 4) & 0x0f
if err == 0 then if err == 0 then
-- NoOp -- NoOp
elseif err == 1 then elseif err == 1 then
@@ -397,9 +396,9 @@ function check(status, response, track)
-- implementation and request type. -- implementation and request type.
-- Err 4 bits, Number of Data Items 12 bits -- Err 4 bits, Number of Data Items 12 bits
local icount = bit.band(pkt:u16(off+4), 0xFFF) local icount = pkt:u16(off+4) & 0xFFF
-- MBZ 4 bits, Size of Data Items: 12 bits -- MBZ 4 bits, Size of Data Items: 12 bits
local isize = bit.band(pkt:u16(off+6), 0xFFF) local isize = pkt:u16(off+6) & 0xFFF
if icount < 1 then if icount < 1 then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
@@ -436,7 +435,7 @@ function check(status, response, track)
end end
-- is the response out of sequence, a duplicate or is it peachy -- is the response out of sequence, a duplicate or is it peachy
local seq = bit.band(pkt:u8(off+1), 0x7f) local seq = pkt:u8(off+1) & 0x7f
if seq == track.hseq+1 then -- all good if seq == track.hseq+1 then -- all good
track.hseq = track.hseq+1 track.hseq = track.hseq+1
elseif track.mseq:match(('|%d|'):format(seq)) then -- one of our missing seq# elseif track.mseq:match(('|%d|'):format(seq)) then -- one of our missing seq#
@@ -464,7 +463,7 @@ function check(status, response, track)
-- if the more bit is set or if we have missing sequence numbers then we'll -- if the more bit is set or if we have missing sequence numbers then we'll
-- want to receive more packets after parsing this one. -- want to receive more packets after parsing this one.
local more = bit.band(bit.rshift(pkt:u8(off), 6), 0x01) local more = (pkt:u8(off) >> 6) & 0x01
if more == 1 then if more == 1 then
track.rcv_again = true track.rcv_again = true
elseif track.mseq:len() > 1 then elseif track.mseq:len() > 1 then
@@ -554,8 +553,8 @@ end
function parse_monlist_1(pkt, recs) function parse_monlist_1(pkt, recs)
local off = pkt.udp_offset + 8 -- beginning of NTP local off = pkt.udp_offset + 8 -- beginning of NTP
local icount = bit.band(pkt:u16(off+4), 0xFFF) local icount = pkt:u16(off+4) & 0xFFF
local isize = bit.band(pkt:u16(off+6), 0xFFF) local isize = pkt:u16(off+6) & 0xFFF
local remaining = icount local remaining = icount
off = off+8 -- beginning of data section off = off+8 -- beginning of data section
@@ -593,7 +592,7 @@ function parse_monlist_1(pkt, recs)
-- Some implementations are not doing htonl for this field? -- Some implementations are not doing htonl for this field?
if t.flags > 0xFFFFFF then if t.flags > 0xFFFFFF then
-- only concerned with the high order byte -- only concerned with the high order byte
t.flags = bit.rshift(t.flags, 24) t.flags = t.flags >> 24
end end
t.mode = pkt:u8(pos+30) t.mode = pkt:u8(pos+30)
t.version = pkt:u8(pos+31) t.version = pkt:u8(pos+31)
@@ -622,8 +621,8 @@ end
function parse_peerlist(pkt, recs) function parse_peerlist(pkt, recs)
local off = pkt.udp_offset + 8 -- beginning of NTP local off = pkt.udp_offset + 8 -- beginning of NTP
local icount = bit.band(pkt:u16(off+4), 0xFFF) local icount = pkt:u16(off+4) & 0xFFF
local isize = bit.band(pkt:u16(off+6), 0xFFF) local isize = pkt:u16(off+6) & 0xFFF
local remaining = icount local remaining = icount
off = off+8 -- beginning of data section off = off+8 -- beginning of data section
@@ -814,7 +813,7 @@ function interpret(recs, targetip)
-- busy the server is. -- busy the server is.
if t.have_peerlist then if t.have_peerlist then
for _, peer in ipairs(recs.peerlist) do for _, peer in ipairs(recs.peerlist) do
if bit.band(peer.flags, 0x2) == 0x2 then if (peer.flags & 0x2) == 0x2 then
t.sync = peer.saddr t.sync = peer.saddr
if peer.saddr:match('^127') then -- always IPv4, never IPv6! if peer.saddr:match('^127') then -- always IPv4, never IPv6!
t.sync = t.sync .. ' (reference clock)' t.sync = t.sync .. ' (reference clock)'

View File

@@ -4,7 +4,6 @@ local nmap = require "nmap"
local shortport = require "shortport" local shortport = require "shortport"
local stdnse = require "stdnse" local stdnse = require "stdnse"
local string = require "string" local string = require "string"
local bit = require "bit"
local bin = require "bin" local bin = require "bin"
local table = require "table" local table = require "table"
description = [[ description = [[
@@ -48,9 +47,9 @@ local function encrypt(data)
local xor_key = 0xab local xor_key = 0xab
local k = 0 local k = 0
if data then if data then
result[1] = bit.bxor(string.byte(data),xor_key) result[1] = string.byte(data) ~ xor_key
for i = 2,string.len(data) do for i = 2,string.len(data) do
result[i] = bit.bxor(result[i-1],string.byte(data,i),i-2) result[i] = result[i-1] ~ string.byte(data,i) ~ i-2
end end
end end
return string.char(table.unpack(result)) return string.char(table.unpack(result))

View File

@@ -1,4 +1,3 @@
local bit = require "bit"
local msrpc = require "msrpc" local msrpc = require "msrpc"
local nmap = require "nmap" local nmap = require "nmap"
local smb = require "smb" local smb = require "smb"
@@ -405,10 +404,10 @@ local function count_ones(num)
local count = 0 local count = 0
while num ~= 0 do while num ~= 0 do
if(bit.band(num, 1) == 1) then if((num & 1) == 1) then
count = count + 1 count = count + 1
end end
num = bit.rshift(num, 1) num = num >> 1
end end
return count return count
@@ -431,7 +430,7 @@ local function convert_case(str, num)
while(num ~= 0) do while(num ~= 0) do
-- Check if the bit we're at is '1' -- Check if the bit we're at is '1'
if(bit.band(num, 1) == 1) then if((num & 1) == 1) then
-- Check if we're at the beginning or end (or both) of the string -- those are special cases -- Check if we're at the beginning or end (or both) of the string -- those are special cases
if(pos == #str and pos == 1) then if(pos == #str and pos == 1) then
str = string.upper(string.sub(str, pos, pos)) str = string.upper(string.sub(str, pos, pos))
@@ -444,7 +443,7 @@ local function convert_case(str, num)
end end
end end
num = bit.rshift(num, 1) num = num >> 1
pos = pos - 1 pos = pos - 1
end end

View File

@@ -1,4 +1,3 @@
local bit = require 'bit'
local smb = require 'smb' local smb = require 'smb'
local string = require 'string' local string = require 'string'
local stdnse = require 'stdnse' local stdnse = require 'stdnse'
@@ -124,7 +123,7 @@ end
-- checks whether the file entry is a directory -- checks whether the file entry is a directory
local function is_dir(fe) local function is_dir(fe)
return ( bit.band(fe.attrs, 16) == 16 ) return ( (fe.attrs & 16) == 16 )
end end
local function list_files(host, share, smbstate, path, options, output, maxdepth, basedir) local function list_files(host, share, smbstate, path, options, output, maxdepth, basedir)

View File

@@ -1,4 +1,3 @@
local bit = require "bit"
local msrpc = require "msrpc" local msrpc = require "msrpc"
local smb = require "smb" local smb = require "smb"
local stdnse = require "stdnse" local stdnse = require "stdnse"
@@ -203,7 +202,7 @@ action = function(host, port)
local results, output = {}, {} local results, output = {}, {}
for k, _ in pairs(ServerTypes) do for k, _ in pairs(ServerTypes) do
for _, server in ipairs(entries) do for _, server in ipairs(entries) do
if ( TypeNames[k] and bit.band(server.type,ServerTypes[k]) == ServerTypes[k] ) then if ( TypeNames[k] and (server.type & ServerTypes[k]) == ServerTypes[k] ) then
results[TypeNames[k].long] = results[TypeNames[k].long] or {} results[TypeNames[k].long] = results[TypeNames[k].long] or {}
if ( format == OutputFormat.BY_TYPE_V_DETAILED ) then if ( format == OutputFormat.BY_TYPE_V_DETAILED ) then
table.insert(results[TypeNames[k].long], server) table.insert(results[TypeNames[k].long], server)

View File

@@ -1,5 +1,4 @@
local _G = require "_G" local _G = require "_G"
local bit = require "bit"
local io = require "io" local io = require "io"
local math = require "math" local math = require "math"
local msrpc = require "msrpc" local msrpc = require "msrpc"
@@ -1047,7 +1046,7 @@ local function cipher(str, config)
for i = 1, #str, 1 do for i = 1, #str, 1 do
local c = string.byte(str, i) local c = string.byte(str, i)
c = string.char(bit.bxor(c, string.byte(config.key, config.key_index + 1))) c = string.char(c ~ string.byte(config.key, config.key_index + 1))
config.key_index = config.key_index + 1 config.key_index = config.key_index + 1
config.key_index = config.key_index % #config.key config.key_index = config.key_index % #config.key
@@ -1066,7 +1065,7 @@ local function get_overrides()
-- 0x00000800 = Compressed file -- 0x00000800 = Compressed file
-- 0x00000002 = Hidden file -- 0x00000002 = Hidden file
-- 0x00000004 = System file -- 0x00000004 = System file
local attr = bit.bor(0x00000004,0x00000002,0x00000800,0x00000100,0x00002000,0x00004000) local attr = 0x00000004 | 0x00000002 | 0x00000800 | 0x00000100 | 0x00002000 | 0x00004000
-- Let the user override this behaviour -- Let the user override this behaviour
if(stdnse.get_script_args( "nohide" )) then if(stdnse.get_script_args( "nohide" )) then