diff --git a/nselib/creds.lua b/nselib/creds.lua index 7d8d4b5e1..c56f08ccf 100644 --- a/nselib/creds.lua +++ b/nselib/creds.lua @@ -114,7 +114,6 @@ -- scripts -- -local bit = require "bit" local coroutine = require "coroutine" local io = require "io" local ipOps = require "ipOps" @@ -248,7 +247,7 @@ RegStorage = { coroutine.yield(v) end elseif ( ( host and ( h == host or h == host.ip ) ) and port.number == v.port ) then - if ( not(self.filter.state) or ( v.state == bit.band(self.filter.state, v.state) ) ) then + if ( not(self.filter.state) or ( v.state == (self.filter.state & v.state) ) ) then coroutine.yield(v) end end @@ -395,7 +394,7 @@ Credentials = { end end - if ( state and State.PARAM == bit.band(state, State.PARAM) ) then + if ( state and State.PARAM == (state & State.PARAM) ) then local creds_global = stdnse.get_script_args('creds.global') local creds_service local creds_params diff --git a/nselib/dhcp6.lua b/nselib/dhcp6.lua index a3343572a..71b77671c 100644 --- a/nselib/dhcp6.lua +++ b/nselib/dhcp6.lua @@ -22,7 +22,6 @@ -- local bin = require "bin" -local bit = require "bit" local datetime = require "datetime" local ipOps = require "ipOps" local math = require "math" @@ -453,7 +452,7 @@ DHCP6.Request = { -- Converts option to a string -- @return str string containing the class instance as string __tostring = function(self) - local tmp = bit.lshift(self.type, 24) + self.xid + local tmp = (self.type << 24) + self.xid local data = "" for _, opt in ipairs(self.opts) do @@ -488,9 +487,9 @@ DHCP6.Response = { local resp = DHCP6.Response:new() local pos, tmp = bin.unpack(">I", data) - resp.msgtype = bit.band(tmp, 0xFF000000) - resp.msgtype = bit.rshift(resp.msgtype, 24) - resp.xid = bit.band(tmp, 0x00FFFFFF) + resp.msgtype = (tmp & 0xFF000000) + resp.msgtype = (resp.msgtype >> 24) + resp.xid = (tmp & 0x00FFFFFF) while( pos < #data ) do local opt = {} pos, opt.type, opt.data = bin.unpack(">SP", data, pos) diff --git a/nselib/dns.lua b/nselib/dns.lua index 5caac382a..bb9e2024e 100644 --- a/nselib/dns.lua +++ b/nselib/dns.lua @@ -31,7 +31,6 @@ local bin = require "bin" -local bit = require "bit" local coroutine = require "coroutine" local ipOps = require "ipOps" local nmap = require "nmap" @@ -1053,11 +1052,11 @@ local function bit_iter(bits) local mask = 0x80 while mask > 0 do - if bit.band(n, mask) ~= 0 then + if (n & mask) ~= 0 then coroutine.yield((i - 1) * 8 + j) end j = j + 1 - mask = bit.rshift(mask, 1) + mask = (mask >> 1) end end end) diff --git a/nselib/dnsbl.lua b/nselib/dnsbl.lua index 885ed6506..3d6ecba78 100644 --- a/nselib/dnsbl.lua +++ b/nselib/dnsbl.lua @@ -18,7 +18,6 @@ -- @author Patrik Karlsson -- -local bit = require "bit" local coroutine = require "coroutine" local dns = require "dns" local ipOps = require "ipOps" @@ -214,7 +213,7 @@ SERVICES = { local result = {} for k, v in pairs(responses) do - if ( bit.band( code, k ) == k ) then + if ( ( code & k ) == k ) then table.insert(result, v) end end @@ -397,17 +396,17 @@ SERVICES = { local activity = {} activity['name'] = "Activity" -- Suspicious activity - if ( bit.band(octet4, 1) == 1) then + if ( (octet4 & 1) == 1) then table.insert(activity, "Suspicious") end -- Harvester - if ( bit.band(octet4, 2) == 2) then + if ( (octet4 & 2) == 2) then table.insert(activity, "Harvester") end -- Comment spammer - if ( bit.band(octet4, 4) == 4) then + if ( (octet4 & 4) == 4) then table.insert(activity, "Comment spammer") end diff --git a/nselib/drda.lua b/nselib/drda.lua index 36cef563f..caf3321be 100644 --- a/nselib/drda.lua +++ b/nselib/drda.lua @@ -59,7 +59,6 @@ -- x IBM Informix Dynamic Server local bin = require "bin" -local bit = require "bit" local match = require "match" local nmap = require "nmap" local stdnse = require "stdnse" @@ -404,7 +403,7 @@ DDM = { -- -- @return true if the DRDA is to be chained, false if it's the last one isChained = function( self ) - if ( bit.band( self.Format, DDM.Formats.CHAINED ) == DDM.Formats.CHAINED ) then + if ( (self.Format & DDM.Formats.CHAINED) == DDM.Formats.CHAINED ) then return true end return false @@ -415,9 +414,9 @@ DDM = { -- @param chained boolean true if more DRDA's are following setChained = function( self, chained ) if ( self:isChained() ) then - self.Format = bit.bxor( self.Format, self.Formats.CHAINED ) + self.Format = ( self.Format ~ self.Formats.CHAINED ) else - self.Format = bit.bor( self.Format, self.Formats.CHAINED ) + self.Format = ( self.Format | self.Formats.CHAINED ) end end, diff --git a/nselib/http.lua b/nselib/http.lua index 637adae5b..af6130b39 100644 --- a/nselib/http.lua +++ b/nselib/http.lua @@ -113,7 +113,6 @@ local base64 = require "base64" local bin = require "bin" -local bit = require "bit" local comm = require "comm" local coroutine = require "coroutine" local nmap = require "nmap" @@ -1375,8 +1374,8 @@ function generic_request(host, port, method, path, options) return end - local is_unicode = (bit.band(flags_received, 0x00000001) == 0x00000001) -- 0x00000001 UNICODE Flag - local is_extended = (bit.band(flags_received, 0x00080000) == 0x00080000) -- 0x00080000 Extended Security Flag + local is_unicode = ((flags_received & 0x00000001) == 0x00000001) -- 0x00000001 UNICODE Flag + local is_extended = ((flags_received & 0x00080000) == 0x00080000) -- 0x00080000 Extended Security Flag local type_3_flags = 0xa2888206 -- flags 56, 128, Version, Target Info, Extended Security, Always Sign, NTLM Key, OEM local lanman, ntlm diff --git a/nselib/iax2.lua b/nselib/iax2.lua index 185032890..9ab96c3c1 100644 --- a/nselib/iax2.lua +++ b/nselib/iax2.lua @@ -6,7 +6,6 @@ -- local bin = require "bin" -local bit = require "bit" local math = require "math" local nmap = require "nmap" local os = require "os" @@ -74,22 +73,22 @@ IAX2 = { parse = function(data) local header = IAX2.Header:new() local pos, frame_type = bin.unpack("C", data) - if ( bit.band(frame_type, 0x80) == 0 ) then + if ( (frame_type & 0x80) == 0 ) then print("frame_type", stdnse.tohex(frame_type)) stdnse.debug2("Frametype not supported") return end header.type = IAX2.PacketType.FULL pos, header.src_call = bin.unpack(">S", data) - header.src_call = bit.band(header.src_call, 0x7FFF) + header.src_call = (header.src_call & 0x7FFF) local retrans pos, retrans = bin.unpack("C", data, pos) - if ( bit.band(retrans, 0x80) == 8 ) then + if ( (retrans & 0x80) == 8 ) then header.retrans = true end pos, header.dst_call = bin.unpack(">S", data, pos - 1) - header.dst_call = bit.band(header.dst_call, 0x7FFF) + header.dst_call = (header.dst_call & 0x7FFF) pos, header.timestamp, header.oseqno, header.iseqno, header.frametype, header.subclass = bin.unpack(">ICCCC", data, pos) diff --git a/nselib/msrpcperformance.lua b/nselib/msrpcperformance.lua index 4f0987e36..0ee8116f1 100644 --- a/nselib/msrpcperformance.lua +++ b/nselib/msrpcperformance.lua @@ -18,7 +18,6 @@ ----------------------------------------------------------------------- local bin = require "bin" -local bit = require "bit" local msrpc = require "msrpc" local msrpctypes = require "msrpctypes" local stdnse = require "stdnse" @@ -536,7 +535,7 @@ function get_performance_data(host, objects) pos = object_start + object_type['DefinitionLength'] -- Check if we have any instances (sometimes we don't -- if we don't, the value returned is a negative) - if(bit.band(object_type['NumInstances'], 0x80000000) == 0) then + if (object_type['NumInstances'] & 0x80000000) == 0 then -- Parse the object instances and counters for j = 1, object_type['NumInstances'], 1 do local instance_start = pos diff --git a/nselib/msrpctypes.lua b/nselib/msrpctypes.lua index 441a2dad7..34c6be13a 100644 --- a/nselib/msrpctypes.lua +++ b/nselib/msrpctypes.lua @@ -104,7 +104,6 @@ -- * GUIDs are stored as tables of values; however, I might change this to a string representation at some point local bin = require "bin" -local bit = require "bit" local os = require "os" local stdnse = require "stdnse" local string = require "string" @@ -1294,7 +1293,7 @@ local function marshall_Enum32(val, table) local i for i = 1, #vals, 1 do - result = bit.bor(result, table[vals[i]]) + result = result | table[vals[i]] end result = marshall_int32(result) @@ -1380,7 +1379,7 @@ local function marshall_Enum8(val, table, pad) local i for i = 1, #vals, 1 do - result = bit.bor(result, table[vals[i]]) + result = result | table[vals[i]] end result = marshall_int8(result, pad) @@ -1407,7 +1406,7 @@ local function unmarshall_Enum32_array(data, pos, table) pos, val = unmarshall_int32(data, pos) for i, v in pairs(table) do - if(bit.band(v, val) ~= 0) then + if (v & val) ~= 0 then array[#array + 1] = i end end @@ -1552,7 +1551,7 @@ function unmarshall_dom_sid2(data, pos) if(sid['authority_low'] == nil) then stdnse.debug1("MSRPC: ERROR: Ran off the end of a packet in unmarshall_dom_sid2(). Please report!") end - sid['authority'] = bit.bor(bit.lshift(sid['authority_high'], 32), sid['authority_low']) + sid['authority'] = (sid['authority_high'] << 32) | sid['authority_low'] sid['sub_auths'] = {} for i = 1, sid['num_auths'], 1 do @@ -1614,8 +1613,8 @@ function marshall_dom_sid2(sid) pos = pos_next + 1 pos_next = string.find(sid, "-", pos) - sid_array['authority_high'] = bit.rshift(string.sub(sid, pos, pos_next - 1), 32) - sid_array['authority_low'] = bit.band(string.sub(sid, pos, pos_next - 1), 0xFFFFFFFF) + sid_array['authority_high'] = string.sub(sid, pos, pos_next - 1) >> 32 + sid_array['authority_low'] = string.sub(sid, pos, pos_next - 1) & 0xFFFFFFFF sid_array['sub_auths'] = {} i = 1 diff --git a/nselib/mssql.lua b/nselib/mssql.lua index dc1c809b7..a0748faed 100644 --- a/nselib/mssql.lua +++ b/nselib/mssql.lua @@ -104,7 +104,6 @@ -- will not be stored for use by other ms-sql-* scripts. local bin = require "bin" -local bit = require "bit" local math = require "math" local match = require "match" local nmap = require "nmap" @@ -2280,7 +2279,7 @@ TDSStream = { -- Check the status flags in the TDS packet to see if the message is -- continued in another TDS packet. - tdsPacketAvailable = (bit.band( messageStatus, TDSStream.MESSAGE_STATUS_FLAGS.EndOfMessage) ~= + tdsPacketAvailable = (( messageStatus & TDSStream.MESSAGE_STATUS_FLAGS.EndOfMessage) ~= TDSStream.MESSAGE_STATUS_FLAGS.EndOfMessage) end @@ -3111,10 +3110,10 @@ Auth = { local xormask = 0x5a5a return password:gsub(".", function(i) - local c = bit.bxor( string.byte( i ), xormask ) - local m1= bit.band( bit.rshift( c, 4 ), 0x0F0F ) - local m2= bit.band( bit.lshift( c, 4 ), 0xF0F0 ) - return bin.pack("> 4 ) & 0x0F0F + local m2= ( c << 4 ) & 0xF0F0 + return bin.pack(" local bin = require "bin" -local bit = require "bit" local nmap = require "nmap" local stdnse = require "stdnse" local string = require "string" @@ -93,8 +92,8 @@ local function decodeHeader( data, pos ) local pos, tmp = pos or 1, 0 pos, tmp = bin.unpack( "I", data, pos ) - response.len = bit.band( tmp,255 ) - response.number = bit.rshift( tmp, 24 ) + response.len = ( tmp & 255 ) + response.number = ( tmp >> 24 ) return pos, response end @@ -193,7 +192,7 @@ local function createLoginHash(pass, salt) _, b1 = bin.unpack( "C", hash_stage1, pos ) _, b2 = bin.unpack( "C", hash_stage3, pos ) - reply[pos] = string.char( bit.bxor( b2, b1 ) ) + reply[pos] = string.char( b2 ~ b1 ) end return table.concat(reply) @@ -255,7 +254,7 @@ function loginRequest( socket, params, username, password, salt ) hash ) - local tmp = packet:len() + bit.lshift( packetno, 24 ) + local tmp = packet:len() + ( packetno << 24 ) packet = bin.pack( "I", tmp ) .. packet diff --git a/nselib/ncp.lua b/nselib/ncp.lua index 0061e3d9a..88a84f1d3 100644 --- a/nselib/ncp.lua +++ b/nselib/ncp.lua @@ -51,7 +51,6 @@ -- Created 24/04/2011 - v0.1 - created by Patrik Karlsson local bin = require "bin" -local bit = require "bit" local ipOps = require "ipOps" local match = require "match" local nmap = require "nmap" @@ -473,7 +472,7 @@ ResponseParser = { "RelDN", "DN" } local bits = 1 for _, field in ipairs(fields) do - self[field] = ( bit.band(self.val, bits) == bits ) + self[field] = ((self.val & bits) == bits) bits = bits * 2 end end diff --git a/nselib/ndmp.lua b/nselib/ndmp.lua index 5d7c84343..b1a17bac8 100644 --- a/nselib/ndmp.lua +++ b/nselib/ndmp.lua @@ -5,7 +5,6 @@ -- local bin = require "bin" -local bit = require "bit" local match = require "match" local nmap = require "nmap" local os = require "os" @@ -52,8 +51,8 @@ NDMP = { parse = function(data) local fh = NDMP.FragmentHeader:new() local _, tmp = bin.unpack(">I", data) - fh.length = bit.band(tmp, 0x7fffffff) - fh.last= bit.rshift(tmp, 31) + fh.length = (tmp & 0x7fffffff) + fh.last= (tmp >> 31) return fh end, diff --git a/nselib/pppoe.lua b/nselib/pppoe.lua index a124c8277..da40c35d0 100644 --- a/nselib/pppoe.lua +++ b/nselib/pppoe.lua @@ -22,7 +22,6 @@ -- local bin = require "bin" -local bit = require "bit" local math = require "math" local nmap = require "nmap" local packet = require "packet" @@ -396,15 +395,15 @@ PPPoE = { local pos, vertyp local header = PPPoE.Header:new() pos, vertyp, header.code, header.session, header.length = bin.unpack(">CCSS", data) - header.version = bit.rshift(vertyp,4) - header.type = bit.band(vertyp, 0x0F) + header.version = (vertyp >> 4) + header.type = (vertyp & 0x0F) return header end, -- Converts the instance to string -- @return string containing the raw config option __tostring = function(self) - local vertype = bit.lshift(self.version, 4) + self.type + local vertype = (self.version << 4) + self.type return bin.pack(">CCSS", vertype, self.code, self.session, self.length) end, diff --git a/nselib/rmi.lua b/nselib/rmi.lua index 35bb38367..df8bdd140 100644 --- a/nselib/rmi.lua +++ b/nselib/rmi.lua @@ -43,7 +43,6 @@ -- Fixed more documentation - v0.2 Martin Holst Swende local bin = require "bin" -local bit = require "bit" local nmap = require "nmap" local stdnse = require "stdnse" local string = require "string" @@ -419,7 +418,7 @@ JavaClass = { isExternalizable = function(self) if self._binaryFlags == nil then return false end - return bit.band(self._binaryflags, RMIUtils.SC_EXTERNALIZABLE) + return (self._binaryflags & RMIUtils.SC_EXTERNALIZABLE) end, addField = function( self, field ) @@ -1510,19 +1509,19 @@ RMIUtils = { flagsToString = function(flags) local retval = '' - if ( bit.band(flags, RMIUtils.SC_WRITE_METHOD) ~= 0) then + if ( (flags & RMIUtils.SC_WRITE_METHOD) ~= 0) then retval = retval .. " WRITE_METHOD" end - if ( bit.band(flags, RMIUtils.SC_BLOCK_DATA) ~= 0) then + if ( (flags & RMIUtils.SC_BLOCK_DATA) ~= 0) then retval = retval .. " BLOCK_DATA" end - if ( bit.band(flags, RMIUtils.SC_EXTERNALIZABLE) ~= 0) then + if ( (flags & RMIUtils.SC_EXTERNALIZABLE) ~= 0) then retval = retval .. " EXTERNALIZABLE" end - if ( bit.band(flags, RMIUtils.SC_SERIALIZABLE) ~= 0) then + if ( (flags & RMIUtils.SC_SERIALIZABLE) ~= 0) then retval = retval .. " SC_SERIALIZABLE" end - if ( bit.band(flags, RMIUtils.SC_ENUM) ~= 0) then + if ( (flags & RMIUtils.SC_ENUM) ~= 0) then retval = retval .. " SC_ENUM" end return retval diff --git a/nselib/sasl.lua b/nselib/sasl.lua index a73ac3ad0..c5cc74fdc 100644 --- a/nselib/sasl.lua +++ b/nselib/sasl.lua @@ -42,7 +42,6 @@ local bin = require "bin" -local bit = require "bit" local smbauth = require "smbauth" local stdnse = require "stdnse" local string = require "string" @@ -206,8 +205,8 @@ if HAVE_SSL then error("NTLM parseChallenge expected message type: 0x02") end - self.is_extended = ( bit.band(self.flags, NTLM_NegotiateExtendedSecurity) == NTLM_NegotiateExtendedSecurity ) - local is_unicode = ( bit.band(self.flags, NTLM_NegotiateUnicode) == NTLM_NegotiateUnicode ) + self.is_extended = ( (self.flags & NTLM_NegotiateExtendedSecurity) == NTLM_NegotiateExtendedSecurity ) + local is_unicode = ( (self.flags & NTLM_NegotiateUnicode) == NTLM_NegotiateUnicode ) self.workstation = "NMAP-HOST" self.domain = self.username:match("^(.-)\\(.*)$") or "DOMAIN"