diff --git a/scripts/allseeingeye-info.nse b/scripts/allseeingeye-info.nse index 70509f8a0..f49eaa3ba 100644 --- a/scripts/allseeingeye-info.nse +++ b/scripts/allseeingeye-info.nse @@ -3,7 +3,6 @@ local nmap = require "nmap" local shortport = require "shortport" local string = require "string" local bin = require "bin" -local bit = require "bit" local stdnse = require "stdnse" description = [[ @@ -181,22 +180,22 @@ action = function(host, port) pos = pos + 1 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) end - if bit.band(flags, 2) ~= 0 then + if (flags & 2) ~= 0 then pos, player.team = bin.unpack("p", data, pos) end - if bit.band(flags, 4) ~= 0 then + if (flags & 4) ~= 0 then pos, player.skin = bin.unpack("p", data, pos) end - if bit.band(flags, 8) ~= 0 then + if (flags & 8) ~= 0 then pos, player.score = bin.unpack("p", data, pos) end - if bit.band(flags, 16) ~= 0 then + if (flags & 16) ~= 0 then pos, player.ping = bin.unpack("p", data, pos) end - if bit.band(flags, 32) ~= 0 then + if (flags & 32) ~= 0 then pos, player.time = bin.unpack("p", data, pos) end diff --git a/scripts/backorifice-brute.nse b/scripts/backorifice-brute.nse index 80f74e19d..9b2fc6dda 100644 --- a/scripts/backorifice-brute.nse +++ b/scripts/backorifice-brute.nse @@ -1,5 +1,5 @@ -local bin = require "bin" local bit = require "bit" +local bin = require "bin" local brute = require "brute" local creds = require "creds" local nmap = require "nmap" @@ -175,7 +175,7 @@ local backorifice = -- @return seed number containing next seed gen_next_seed = function(self, seed) seed = seed*214013 + 2531011 - seed = bit.band(seed,0xffffff) + seed = seed & 0xffffff return seed end, @@ -198,9 +198,9 @@ local backorifice = --calculate next seed seed = self:gen_next_seed(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) --ARGSIZE limitation from BackOrifice server if i == 256 then break end diff --git a/scripts/backorifice-info.nse b/scripts/backorifice-info.nse index 83b2735bd..7d4d5932b 100644 --- a/scripts/backorifice-info.nse +++ b/scripts/backorifice-info.nse @@ -1,5 +1,5 @@ -local bin = require "bin" local bit = require "bit" +local bin = require "bin" local nmap = require "nmap" local shortport = require "shortport" local stdnse = require "stdnse" @@ -149,7 +149,7 @@ local cmds = { local function gen_next_seed(seed) seed = seed*214013 + 2531011 - seed = bit.band(seed,0xffffff) + seed = seed & 0xffffff return seed end @@ -202,9 +202,9 @@ local function BOcrypt(data, password, initial_seed ) --calculate next seed seed = gen_next_seed(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) if i == 256 then break end --ARGSIZE limitation end @@ -302,16 +302,16 @@ action = function( host, port ) end --singular - if bit.band(p_type,TYPE.PARTIAL_PACKET)==0x00 - and bit.band(p_type,TYPE.CONTINUED_PACKET)==0x00 then break end + if (p_type & TYPE.PARTIAL_PACKET)==0x00 + and (p_type & TYPE.CONTINUED_PACKET)==0x00 then break end --first - if bit.band(p_type,TYPE.CONTINUED_PACKET)==0x00 then + if (p_type & TYPE.CONTINUED_PACKET)==0x00 then multi_flag = true end --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 diff --git a/scripts/broadcast-ataoe-discover.nse b/scripts/broadcast-ataoe-discover.nse index 43fa0c92d..5a4644826 100644 --- a/scripts/broadcast-ataoe-discover.nse +++ b/scripts/broadcast-ataoe-discover.nse @@ -1,5 +1,4 @@ local bin = require "bin" -local bit = require "bit" local math = require "math" local nmap = require "nmap" local packet = require "packet" @@ -67,15 +66,15 @@ ATAoE = { pos, verflags, header.error, header.major, header.minor, header.cmd, header.tag = bin.unpack(">CCSCCI", data) - header.version = bit.rshift(verflags, 4) - header.flags = bit.band(verflags, 0x0F) + header.version = verflags >> 4 + header.flags = verflags & 0x0F return header end, -- return configuration info request as string __tostring = function(self) 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) end, }, diff --git a/scripts/broadcast-netbios-master-browser.nse b/scripts/broadcast-netbios-master-browser.nse index 63ca3f581..8bf600670 100644 --- a/scripts/broadcast-netbios-master-browser.nse +++ b/scripts/broadcast-netbios-master-browser.nse @@ -1,4 +1,3 @@ -local bit = require "bit" local netbios = require "netbios" local nmap = require "nmap" local stdnse = require "stdnse" @@ -28,7 +27,7 @@ categories = {"broadcast", "safe"} 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() diff --git a/scripts/broadcast-sybase-asa-discover.nse b/scripts/broadcast-sybase-asa-discover.nse index 110f507ed..277816764 100644 --- a/scripts/broadcast-sybase-asa-discover.nse +++ b/scripts/broadcast-sybase-asa-discover.nse @@ -1,5 +1,4 @@ local bin = require "bin" -local bit = require "bit" local nmap = require "nmap" local os = require "os" local stdnse = require "stdnse" @@ -70,7 +69,7 @@ Ping = { parse = function(self) -- do a very basic length check local pos, len = bin.unpack(">I", self.data) - len = bit.band(len, 0x0000FFFF) + len = len & 0x0000FFFF if ( len ~= #self.data ) then stdnse.debug2("The packet length was reported as %d, expected %d", len, #self.data) diff --git a/scripts/dns-random-srcport.nse b/scripts/dns-random-srcport.nse index df5bd5a89..b2fa016e7 100644 --- a/scripts/dns-random-srcport.nse +++ b/scripts/dns-random-srcport.nse @@ -1,4 +1,3 @@ -local bit = require "bit" local comm = require "comm" local nmap = require "nmap" local shortport = require "shortport" @@ -98,13 +97,13 @@ action = function(host, port) end -- Check response flag and recursion - if not (bit.band(string.byte(result, 3), 0x80) == 0x80 - and bit.band(string.byte(result, 4), 0x80) == 0x80) then + if not ((string.byte(result, 3) & 0x80) == 0x80 + and (string.byte(result, 4) & 0x80) == 0x80) then return fail("Server refused recursion") end -- 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") end diff --git a/scripts/dns-random-txid.nse b/scripts/dns-random-txid.nse index f91a8f01d..1f32d7ab3 100644 --- a/scripts/dns-random-txid.nse +++ b/scripts/dns-random-txid.nse @@ -1,4 +1,3 @@ -local bit = require "bit" local comm = require "comm" local nmap = require "nmap" local shortport = require "shortport" @@ -98,13 +97,13 @@ action = function(host, port) end -- Check response flag and recursion - if not (bit.band(string.byte(result, 3), 0x80) == 0x80 - and bit.band(string.byte(result, 4), 0x80) == 0x80) then + if not ((string.byte(result, 3) & 0x80) == 0x80 + and (string.byte(result, 4) & 0x80) == 0x80) then return fail("Server refused recursion") end -- 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") end diff --git a/scripts/dns-zone-transfer.nse b/scripts/dns-zone-transfer.nse index dbdfbafe5..42fa791a7 100644 --- a/scripts/dns-zone-transfer.nse +++ b/scripts/dns-zone-transfer.nse @@ -1,5 +1,4 @@ local bin = require "bin" -local bit = require "bit" local dns = require "dns" local ipOps = require "ipOps" local listop = require "listop" @@ -295,7 +294,7 @@ local RD = { for i=0, len-1 do local n = string.byte(data, offset + i) 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 end end @@ -368,11 +367,11 @@ local RD = { return offset, '' end 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 = bit.rshift(hp,4) * 10 ^ bit.band(hp, 0x0f) / 100 + hp = (hp >> 4) * 10 ^ (hp & 0x0f) / 100 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, lat, lon, alt = bin.unpack(">III", data, offset) lat = (lat-2^31)/3600000 --degrees @@ -420,7 +419,7 @@ local RD = { A6 = function(data, offset) -- obsoleted by AAAA local prefix, addr, name 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)) offset, name = parse_domain(data, offset + 17 - pbytes) return offset, string.format("%d %s %s", prefix, addr, name) @@ -761,7 +760,7 @@ action = function(host, port) -- check server response code 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 end diff --git a/scripts/firewall-bypass.nse b/scripts/firewall-bypass.nse index f4286eaf0..8c7b37ff7 100644 --- a/scripts/firewall-bypass.nse +++ b/scripts/firewall-bypass.nse @@ -1,6 +1,5 @@ local nmap = require "nmap" local stdnse = require "stdnse" -local bit = require "bit" local string = require "string" local packet = require "packet" @@ -75,8 +74,8 @@ ftp_helper = { -- IPv4 payload payload = "227 Entering Passive Mode (" .. string.gsub(host.ip,"%.",",") .. "," .. - bit.band(bit.rshift(targetport, 8), 0xff) .. - "," .. bit.band(targetport, 0xff) .. + ((targetport >> 8) & 0xff) .. + "," .. (targetport & 0xff) .. ")\r\n" ethertype = "\x08\0" -- Ethernet Type: IPv4 diff --git a/scripts/http-exif-spider.nse b/scripts/http-exif-spider.nse index d5e265d40..e19c5b4e4 100644 --- a/scripts/http-exif-spider.nse +++ b/scripts/http-exif-spider.nse @@ -31,7 +31,6 @@ local stdnse = require 'stdnse' local httpspider = require 'httpspider' local string = require 'string' local bin = require 'bin' -local bit = require 'bit' local table = require 'table' -- 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 elseif(tag == GPS_TAG_LATITUDEREF) then -- 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 -- 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 diff --git a/scripts/http-vuln-cve2014-3704.nse b/scripts/http-vuln-cve2014-3704.nse index 44e5616de..84812b40b 100644 --- a/scripts/http-vuln-cve2014-3704.nse +++ b/scripts/http-vuln-cve2014-3704.nse @@ -1,4 +1,3 @@ -local bit = require "bit" local http = require "http" local shortport = require "shortport" local stdnse = require "stdnse" @@ -131,12 +130,12 @@ local function phpass_encode64(input) while cur < count do local value = string.byte(input, cur) cur = cur + 1 - table.insert(out, itoa64(bit.band(value, 0x3f))) + table.insert(out, itoa64(value & 0x3f)) if cur < count then - value = bit.bor(value, bit.lshift(string.byte(input, cur), 8)) + value = value | (string.byte(input, cur) << 8) end - table.insert(out, itoa64(bit.band(bit.rshift(value, 6), 0x3f))) + table.insert(out, itoa64((value >> 6) & 0x3f)) if cur >= count then break @@ -144,16 +143,16 @@ local function phpass_encode64(input) cur = cur + 1 if cur < count then - value = bit.bor(value, bit.lshift(string.byte(input, cur), 16)) + value = value | (string.byte(input, cur) << 16) end - table.insert(out, itoa64(bit.band(bit.rshift(value, 12), 0x3f))) + table.insert(out, itoa64((value >> 12) & 0x3f)) if cur >= count then break end cur = cur + 1 - table.insert(out, itoa64(bit.band(bit.rshift(value, 18), 0x3f))) + table.insert(out, itoa64((value >> 18) & 0x3f)) end return table.concat(out) diff --git a/scripts/ip-geolocation-maxmind.nse b/scripts/ip-geolocation-maxmind.nse index ef9c30290..7290624e8 100644 --- a/scripts/ip-geolocation-maxmind.nse +++ b/scripts/ip-geolocation-maxmind.nse @@ -1,4 +1,3 @@ -local bit = require "bit" local geoip = require "geoip" local io = require "io" local ipOps = require "ipOps" @@ -474,7 +473,7 @@ local GeoIP = { -- the original representation in the MaxMind API is ANSI C integer -- which should not overflow the greatest value Lua can offer ;) 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 if o._databaseType == MaxmindDef.ORG_EDITION or o._databaseType == MaxmindDef.ISP_EDITION then @@ -548,16 +547,16 @@ local GeoIP = { start_pos = end_pos + 1 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 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 if self._databaseType == MaxmindDef.CITY_EDITION_REV1 and record.country_code=='US' then 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.area_code = dmaarea_combo % 1000 else @@ -585,11 +584,11 @@ local GeoIP = { for i=0,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 -- 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 return x[1] end diff --git a/scripts/knx-gateway-discover.nse b/scripts/knx-gateway-discover.nse index 49a3ba930..ddf8ce427 100644 --- a/scripts/knx-gateway-discover.nse +++ b/scripts/knx-gateway-discover.nse @@ -3,7 +3,6 @@ local coroutine = require "coroutine" local stdnse = require "stdnse" local table = require "table" local bin = require "bin" -local bit = require "bit" local packet = require "packet" local ipOps = require "ipOps" local string = require "string" @@ -120,9 +119,9 @@ end -- Parse a KNX address from raw bytes -- @param addr Unpacked 2 bytes local parseKnxAddress = function(addr) - local a = bit.rshift(bit.band(addr, 0xf000),12) - local b = bit.rshift(bit.band(addr, 0x0f00), 8) - local c = bit.band(addr, 0xff) + local a = (addr & 0xf000) >> 12 + local b = (addr & 0x0f00) >> 8 + local c = addr & 0xff return a..'.'..b..'.'..c end diff --git a/scripts/llmnr-resolve.nse b/scripts/llmnr-resolve.nse index 7a06c7870..a8e9a0240 100644 --- a/scripts/llmnr-resolve.nse +++ b/scripts/llmnr-resolve.nse @@ -2,7 +2,6 @@ local nmap = require "nmap" local stdnse = require "stdnse" local table = require "table" local bin = require "bin" -local bit = require "bit" local packet = require "packet" local ipOps = require "ipOps" local target = require "target" @@ -111,7 +110,7 @@ local llmnrListen = function(interface, timeout, result) -- Make verifications -- Message == Response bit -- 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) -- Skip header's 12 bytes -- extract host length diff --git a/scripts/ntp-monlist.nse b/scripts/ntp-monlist.nse index 19b258136..0d908ee9a 100644 --- a/scripts/ntp-monlist.nse +++ b/scripts/ntp-monlist.nse @@ -1,5 +1,4 @@ local bin = require "bin" -local bit = require "bit" local ipOps = require "ipOps" local math = require "math" local nmap = require "nmap" @@ -320,14 +319,14 @@ function check(status, response, track) end -- response bit set - if bit.rshift(pkt:u8(off), 7) ~= 1 then + if (pkt:u8(off) >> 7) ~= 1 then track.errcond = true track.evil_pkts = track.evil_pkts+1 stdnse.debug1('Bad response from %s - did not have response bit set.', track.target) return nil end -- 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 track.errcond = true track.evil_pkts = track.evil_pkts+1 @@ -335,7 +334,7 @@ function check(status, response, track) return nil end -- mode is as expected - val = bit.band(pkt:u8(off), 0x07) + val = pkt:u8(off) & 0x07 if val ~= track.m then track.errcond = true track.evil_pkts = track.evil_pkts+1 @@ -360,7 +359,7 @@ function check(status, response, track) end -- NTP error conditions - defined codes are not evil (bogus codes are). 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 -- NoOp elseif err == 1 then @@ -397,9 +396,9 @@ function check(status, response, track) -- implementation and request type. -- 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 - local isize = bit.band(pkt:u16(off+6), 0xFFF) + local isize = pkt:u16(off+6) & 0xFFF if icount < 1 then track.errcond = true track.evil_pkts = track.evil_pkts+1 @@ -436,7 +435,7 @@ function check(status, response, track) end -- 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 track.hseq = track.hseq+1 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 -- 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 track.rcv_again = true elseif track.mseq:len() > 1 then @@ -554,8 +553,8 @@ end function parse_monlist_1(pkt, recs) local off = pkt.udp_offset + 8 -- beginning of NTP - local icount = bit.band(pkt:u16(off+4), 0xFFF) - local isize = bit.band(pkt:u16(off+6), 0xFFF) + local icount = pkt:u16(off+4) & 0xFFF + local isize = pkt:u16(off+6) & 0xFFF local remaining = icount 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? if t.flags > 0xFFFFFF then -- only concerned with the high order byte - t.flags = bit.rshift(t.flags, 24) + t.flags = t.flags >> 24 end t.mode = pkt:u8(pos+30) t.version = pkt:u8(pos+31) @@ -622,8 +621,8 @@ end function parse_peerlist(pkt, recs) local off = pkt.udp_offset + 8 -- beginning of NTP - local icount = bit.band(pkt:u16(off+4), 0xFFF) - local isize = bit.band(pkt:u16(off+6), 0xFFF) + local icount = pkt:u16(off+4) & 0xFFF + local isize = pkt:u16(off+6) & 0xFFF local remaining = icount off = off+8 -- beginning of data section @@ -814,7 +813,7 @@ function interpret(recs, targetip) -- busy the server is. if t.have_peerlist then 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 if peer.saddr:match('^127') then -- always IPv4, never IPv6! t.sync = t.sync .. ' (reference clock)' diff --git a/scripts/pcanywhere-brute.nse b/scripts/pcanywhere-brute.nse index f8daeb6d8..1a824dba8 100644 --- a/scripts/pcanywhere-brute.nse +++ b/scripts/pcanywhere-brute.nse @@ -4,7 +4,6 @@ local nmap = require "nmap" local shortport = require "shortport" local stdnse = require "stdnse" local string = require "string" -local bit = require "bit" local bin = require "bin" local table = require "table" description = [[ @@ -48,9 +47,9 @@ local function encrypt(data) local xor_key = 0xab local k = 0 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 - 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 return string.char(table.unpack(result)) diff --git a/scripts/smb-brute.nse b/scripts/smb-brute.nse index a8e7c525c..e538cff8b 100644 --- a/scripts/smb-brute.nse +++ b/scripts/smb-brute.nse @@ -1,4 +1,3 @@ -local bit = require "bit" local msrpc = require "msrpc" local nmap = require "nmap" local smb = require "smb" @@ -405,10 +404,10 @@ local function count_ones(num) local count = 0 while num ~= 0 do - if(bit.band(num, 1) == 1) then + if((num & 1) == 1) then count = count + 1 end - num = bit.rshift(num, 1) + num = num >> 1 end return count @@ -431,7 +430,7 @@ local function convert_case(str, num) while(num ~= 0) do -- 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 if(pos == #str and pos == 1) then str = string.upper(string.sub(str, pos, pos)) @@ -444,7 +443,7 @@ local function convert_case(str, num) end end - num = bit.rshift(num, 1) + num = num >> 1 pos = pos - 1 end diff --git a/scripts/smb-ls.nse b/scripts/smb-ls.nse index 609900340..7b8a3cf66 100644 --- a/scripts/smb-ls.nse +++ b/scripts/smb-ls.nse @@ -1,4 +1,3 @@ -local bit = require 'bit' local smb = require 'smb' local string = require 'string' local stdnse = require 'stdnse' @@ -124,7 +123,7 @@ end -- checks whether the file entry is a directory local function is_dir(fe) - return ( bit.band(fe.attrs, 16) == 16 ) + return ( (fe.attrs & 16) == 16 ) end local function list_files(host, share, smbstate, path, options, output, maxdepth, basedir) diff --git a/scripts/smb-mbenum.nse b/scripts/smb-mbenum.nse index 04673afd3..f8e6dbc28 100644 --- a/scripts/smb-mbenum.nse +++ b/scripts/smb-mbenum.nse @@ -1,4 +1,3 @@ -local bit = require "bit" local msrpc = require "msrpc" local smb = require "smb" local stdnse = require "stdnse" @@ -203,7 +202,7 @@ action = function(host, port) local results, output = {}, {} for k, _ in pairs(ServerTypes) 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 {} if ( format == OutputFormat.BY_TYPE_V_DETAILED ) then table.insert(results[TypeNames[k].long], server) diff --git a/scripts/smb-psexec.nse b/scripts/smb-psexec.nse index 87c450881..ad7b0ec18 100644 --- a/scripts/smb-psexec.nse +++ b/scripts/smb-psexec.nse @@ -1,5 +1,4 @@ local _G = require "_G" -local bit = require "bit" local io = require "io" local math = require "math" local msrpc = require "msrpc" @@ -1047,7 +1046,7 @@ local function cipher(str, config) for i = 1, #str, 1 do 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 % #config.key @@ -1066,7 +1065,7 @@ local function get_overrides() -- 0x00000800 = Compressed file -- 0x00000002 = Hidden 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 if(stdnse.get_script_args( "nohide" )) then