mirror of
https://github.com/nmap/nmap.git
synced 2025-12-10 09:49:05 +00:00
Reindent the last of the NSE libraries.
https://secwiki.org/w/Nmap/Code_Standards
This commit is contained in:
@@ -302,9 +302,9 @@ bdecode = function(buf)
|
||||
|
||||
-- next(stack) is never gonna be nil because we're always in the main list
|
||||
-- next(stack, next(stack)) should be nil if we're in the main list
|
||||
-- if next(stack, next(stack)) then
|
||||
-- return false, "Probably file incorrect format"
|
||||
-- end
|
||||
-- if next(stack, next(stack)) then
|
||||
-- return false, "Probably file incorrect format"
|
||||
-- end
|
||||
|
||||
return true, t
|
||||
end
|
||||
|
||||
@@ -1141,7 +1141,7 @@ local function decDomain(entry, data, pos)
|
||||
local np = pos - #entry.data
|
||||
local _
|
||||
_, entry.domain = decStr(data, np)
|
||||
end
|
||||
end
|
||||
|
||||
-- Decodes CNAME records.
|
||||
-- Puts result in <code>entry.domain</code>.
|
||||
@@ -1178,7 +1178,7 @@ decoder[types.PTR] = decDomain
|
||||
-- @param data Complete encoded DNS packet.
|
||||
-- @param pos Position in packet after RR.
|
||||
decoder[types.TXT] =
|
||||
function (entry, data, pos)
|
||||
function (entry, data, pos)
|
||||
|
||||
local len = entry.data:len()
|
||||
local np = pos - #entry.data
|
||||
@@ -1197,7 +1197,7 @@ decoder[types.TXT] =
|
||||
table.insert( entry.TXT.text, txt )
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
---
|
||||
-- Decodes OPT record, puts it in <code>entry.OPT</code>.
|
||||
@@ -1209,13 +1209,13 @@ decoder[types.TXT] =
|
||||
-- @param data Complete encoded DNS packet.
|
||||
-- @param pos Position in packet after RR.
|
||||
decoder[types.OPT] =
|
||||
function(entry, data, pos)
|
||||
function(entry, data, pos)
|
||||
local np = pos - #entry.data - 6
|
||||
local opt = { bufsize = entry.class }
|
||||
np, opt.rcode, opt.version, opt.zflags, opt.rdlen = bin.unpack(">CCSS", data, np)
|
||||
np, opt.data = bin.unpack("A" .. opt.rdlen, data, np)
|
||||
entry.OPT = opt
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Decodes MX record, puts it in <code>entry.MX</code>.
|
||||
@@ -1226,13 +1226,13 @@ decoder[types.OPT] =
|
||||
-- @param data Complete encoded DNS packet.
|
||||
-- @param pos Position in packet after RR.
|
||||
decoder[types.MX] =
|
||||
function(entry, data, pos)
|
||||
function(entry, data, pos)
|
||||
local np = pos - #entry.data + 2
|
||||
local _
|
||||
entry.MX = {}
|
||||
_, entry.MX.pref = bin.unpack(">S", entry.data)
|
||||
_, entry.MX.server = decStr(data, np)
|
||||
end
|
||||
end
|
||||
|
||||
-- Decodes SRV record, puts it in <code>entry.SRV</code>.
|
||||
--
|
||||
@@ -1243,13 +1243,13 @@ decoder[types.MX] =
|
||||
-- @param data Complete encoded DNS packet.
|
||||
-- @param pos Position in packet after RR.
|
||||
decoder[types.SRV] =
|
||||
function(entry, data, pos)
|
||||
function(entry, data, pos)
|
||||
local np = pos - #entry.data
|
||||
local _
|
||||
entry.SRV = {}
|
||||
np, entry.SRV.prio, entry.SRV.weight, entry.SRV.port = bin.unpack(">S>S>S", data, np)
|
||||
np, entry.SRV.target = decStr(data, np)
|
||||
end
|
||||
end
|
||||
|
||||
-- Decodes returned resource records (answer, authority, or additional part).
|
||||
-- @param data Complete encoded DNS packet.
|
||||
|
||||
@@ -557,7 +557,7 @@ SERVICES = {
|
||||
end
|
||||
end,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -414,21 +414,21 @@ local function generate_aggressive(port, protocol, id, diffie)
|
||||
|
||||
return bin.pack(">SHHSSHSHCHHH",
|
||||
-- Key Exchange
|
||||
0x0a00 , -- Next payload (Nonce)
|
||||
string.format("%04X", key_length+4) , -- Length (132-bit)
|
||||
generate_random(key_length) , -- Random key data
|
||||
0x0a00, -- Next payload (Nonce)
|
||||
string.format("%04X", key_length+4), -- Length (132-bit)
|
||||
generate_random(key_length), -- Random key data
|
||||
|
||||
-- Nonce
|
||||
0x0500 , -- Next payload (Identification)
|
||||
0x0018 , -- Length (24)
|
||||
generate_random(20) , -- Nonce data
|
||||
0x0500, -- Next payload (Identification)
|
||||
0x0018, -- Length (24)
|
||||
generate_random(20), -- Nonce data
|
||||
|
||||
-- Identification
|
||||
0x0000 , -- Next Payload (None)
|
||||
id_len , -- Payload length (id + 8)
|
||||
0x03 , -- ID Type (USER_FQDN)
|
||||
hex_prot , -- Protocol ID (UDP)
|
||||
hex_port , -- Port (500)
|
||||
0x0000, -- Next Payload (None)
|
||||
id_len, -- Payload length (id + 8)
|
||||
0x03, -- ID Type (USER_FQDN)
|
||||
hex_prot, -- Protocol ID (UDP)
|
||||
hex_port, -- Port (500)
|
||||
convert_to_hex(id) -- Id Data (as hex)
|
||||
)
|
||||
end
|
||||
@@ -464,14 +464,14 @@ local function generate_transform(auth, encryption, hash, group, number, total)
|
||||
payload_number = string.format("%.2X", number)
|
||||
|
||||
local trans = bin.pack(">SSHCSIIII",
|
||||
next_payload , -- Next payload
|
||||
trans_length , -- Transform length
|
||||
payload_number , -- Transform number
|
||||
0x01 , -- Transform ID (IKE)
|
||||
0x0000 , -- spacers ?
|
||||
enc , -- Encryption algorithm
|
||||
HASH_ALGORITHM[hash] , -- Hash algorithm
|
||||
AUTH_TYPES[auth] , -- Authentication method
|
||||
next_payload, -- Next payload
|
||||
trans_length, -- Transform length
|
||||
payload_number, -- Transform number
|
||||
0x01, -- Transform ID (IKE)
|
||||
0x0000, -- spacers ?
|
||||
enc, -- Encryption algorithm
|
||||
HASH_ALGORITHM[hash], -- Hash algorithm
|
||||
AUTH_TYPES[auth], -- Authentication method
|
||||
GROUP_DESCRIPTION[group] -- Group Description
|
||||
)
|
||||
|
||||
@@ -480,7 +480,7 @@ local function generate_transform(auth, encryption, hash, group, number, total)
|
||||
end
|
||||
|
||||
trans = trans .. bin.pack(">IL",
|
||||
0x800b0001 , -- Life type (seconds)
|
||||
0x800b0001, -- Life type (seconds)
|
||||
0x000c000400007080 -- Life duration (28800)
|
||||
)
|
||||
|
||||
@@ -530,28 +530,28 @@ function request(port, proto, mode, transforms, diffie, id)
|
||||
|
||||
-- Build the packet
|
||||
local packet = bin.pack(">HLCCCCIHSHIISHCCCH",
|
||||
generate_random(8) , -- Initiator cookie
|
||||
0x0000000000000000 , -- Responder cookie
|
||||
0x01 , -- Next payload (SA)
|
||||
0x10 , -- Version
|
||||
EXCHANGE_MODE[mode] , -- Exchange type
|
||||
0x00 , -- Flags
|
||||
0x00000000 , -- Message id
|
||||
l , -- packet length
|
||||
generate_random(8), -- Initiator cookie
|
||||
0x0000000000000000, -- Responder cookie
|
||||
0x01, -- Next payload (SA)
|
||||
0x10, -- Version
|
||||
EXCHANGE_MODE[mode], -- Exchange type
|
||||
0x00, -- Flags
|
||||
0x00000000, -- Message id
|
||||
l, -- packet length
|
||||
|
||||
|
||||
-- Security Association
|
||||
payload_after_sa , -- Next payload (Key exchange, if aggressive mode)
|
||||
l_sa , -- Length
|
||||
0x00000001 , -- IPSEC
|
||||
0x00000001 , -- Situation
|
||||
payload_after_sa, -- Next payload (Key exchange, if aggressive mode)
|
||||
l_sa, -- Length
|
||||
0x00000001, -- IPSEC
|
||||
0x00000001, -- Situation
|
||||
|
||||
--## Proposal
|
||||
0x0000 , -- Next payload (None)
|
||||
l_pro , -- Payload length
|
||||
0x01 , -- Proposal number
|
||||
0x01 , -- Protocol ID (ISAKMP)
|
||||
0x00 , -- SPI Size
|
||||
0x0000, -- Next payload (None)
|
||||
l_pro, -- Payload length
|
||||
0x01, -- Proposal number
|
||||
0x01, -- Protocol ID (ISAKMP)
|
||||
0x00, -- SPI Size
|
||||
number_transforms -- Proposal transforms
|
||||
)
|
||||
|
||||
|
||||
@@ -241,8 +241,8 @@ function receive_all(socket)
|
||||
return true, data -- if somethign is wrong,return partial data
|
||||
end
|
||||
data = data .. result
|
||||
end
|
||||
return true,data
|
||||
end
|
||||
return true,data
|
||||
end
|
||||
|
||||
--- Helper function to extract ascii string from UTF-8
|
||||
|
||||
@@ -365,7 +365,7 @@ MongoData ={
|
||||
MSG = 1000,
|
||||
UPDATE = 2001,
|
||||
INSERT = 2002,
|
||||
GET_BY_IOD =2003,
|
||||
GET_BY_IOD = 2003,
|
||||
QUERY = 2004,
|
||||
GET_MORE = 2005,
|
||||
DELETE = 2006,
|
||||
@@ -397,7 +397,7 @@ end
|
||||
--@return status : true if ok, false if error occurred
|
||||
--@return Error message if error occurred
|
||||
function MongoData:addBSON(dict)
|
||||
-- status, res = bson.toBson(dict)
|
||||
-- status, res = bson.toBson(dict)
|
||||
local status, res = toBson(dict)
|
||||
if not status then
|
||||
dbg(res)
|
||||
@@ -588,7 +588,7 @@ function query(socket, data)
|
||||
return false, "No Bson data returned"
|
||||
end
|
||||
|
||||
-- result, data, err_msg = bson.fromBson(bsonData)
|
||||
-- result, data, err_msg = bson.fromBson(bsonData)
|
||||
result, data, err_msg = fromBson(bsonData)
|
||||
|
||||
if err_msg then
|
||||
|
||||
770
nselib/msrpc.lua
770
nselib/msrpc.lua
File diff suppressed because it is too large
Load Diff
@@ -234,9 +234,9 @@ local function parse_perf_object_type(data, pos)
|
||||
pos, result['DefaultCounter'] = msrpctypes.unmarshall_int32(data, pos)
|
||||
pos, result['NumInstances'] = msrpctypes.unmarshall_int32(data, pos) -- Numer of object instances for which counters are being returned
|
||||
pos, result['CodePage'] = msrpctypes.unmarshall_int32(data, pos) -- 0 if strings are in UNICODE, otherwise the Code Page
|
||||
-- if(result['CodePage'] ~= 0) then
|
||||
-- return false, string.format("Unknown Code Page for data: %d\n", result['CodePage'])
|
||||
-- end
|
||||
-- if(result['CodePage'] ~= 0) then
|
||||
-- return false, string.format("Unknown Code Page for data: %d\n", result['CodePage'])
|
||||
-- end
|
||||
pos, result['PerfTime'] = msrpctypes.unmarshall_int64(data, pos) -- Sample time in "Object" units
|
||||
pos, result['PerfFreq'] = msrpctypes.unmarshall_int64(data, pos) -- Frequency of "Object" units in counts/second
|
||||
|
||||
@@ -327,7 +327,7 @@ local function parse_perf_counter(data, pos, counter_definition)
|
||||
pos, result = msrpctypes.unmarshall_int32(data, pos)
|
||||
elseif(counter_definition['CounterSize'] == 8) then
|
||||
pos, result = msrpctypes.unmarshall_int64(data, pos)
|
||||
-- pos, result = bin.unpack("<d", data, pos)
|
||||
-- pos, result = bin.unpack("<d", data, pos)
|
||||
else
|
||||
pos, result = msrpctypes.unmarshall_raw(data, pos, counter_definition['CounterSize'])
|
||||
end
|
||||
@@ -505,14 +505,14 @@ function get_performance_data(host, objects)
|
||||
end
|
||||
|
||||
-- Start setting up the result object
|
||||
--stdnse.print_debug("Index = %d\n", object_type['ObjectNameTitleIndex'])
|
||||
--stdnse.print_debug("Index = %d\n", object_type['ObjectNameTitleIndex'])
|
||||
local object_name = result['title_database'][object_type['ObjectNameTitleIndex']]
|
||||
result[object_name] = {}
|
||||
|
||||
--stdnse.print_debug("\n\nOBJECT: %s\n", object_name)
|
||||
--stdnse.print_debug(" Counters: %d\n", object_type['NumCounters'])
|
||||
--stdnse.print_debug(" Instances: %d\n", object_type['NumInstances'])
|
||||
--stdnse.print_debug("-----------------\n")
|
||||
--stdnse.print_debug("\n\nOBJECT: %s\n", object_name)
|
||||
--stdnse.print_debug(" Counters: %d\n", object_type['NumCounters'])
|
||||
--stdnse.print_debug(" Instances: %d\n", object_type['NumInstances'])
|
||||
--stdnse.print_debug("-----------------\n")
|
||||
|
||||
-- Bring the position to the beginning of the counter definitions
|
||||
pos = object_start + object_type['HeaderLength']
|
||||
@@ -524,7 +524,7 @@ function get_performance_data(host, objects)
|
||||
msrpc.stop_smb(smbstate)
|
||||
return false, pos
|
||||
end
|
||||
--stdnse.print_debug(" Counter definition #%2d: [%d bytes] %s\n", j, counter_definitions[j]['CounterSize'], result['title_database'][counter_definitions[j]['CounterNameTitleIndex']])
|
||||
--stdnse.print_debug(" Counter definition #%2d: [%d bytes] %s\n", j, counter_definitions[j]['CounterSize'], result['title_database'][counter_definitions[j]['CounterNameTitleIndex']])
|
||||
end
|
||||
|
||||
-- Bring the position to the beginning of the instances (or counters)
|
||||
@@ -551,11 +551,11 @@ function get_performance_data(host, objects)
|
||||
-- Bring the pos to the start of the counter block
|
||||
pos = instance_start + object_instances[j]['ByteLength']
|
||||
|
||||
--stdnse.print_debug("\n INSTANCE: %s\n", instance_name)
|
||||
--stdnse.print_debug(" Length: %d\n", object_instances[j]['ByteLength'])
|
||||
--stdnse.print_debug(" NameOffset: %d\n", object_instances[j]['NameOffset'])
|
||||
--stdnse.print_debug(" NameLength: %d\n", object_instances[j]['NameLength'])
|
||||
--stdnse.print_debug(" --------------\n")
|
||||
--stdnse.print_debug("\n INSTANCE: %s\n", instance_name)
|
||||
--stdnse.print_debug(" Length: %d\n", object_instances[j]['ByteLength'])
|
||||
--stdnse.print_debug(" NameOffset: %d\n", object_instances[j]['NameOffset'])
|
||||
--stdnse.print_debug(" NameLength: %d\n", object_instances[j]['NameLength'])
|
||||
--stdnse.print_debug(" --------------\n")
|
||||
|
||||
-- The counter block
|
||||
local status, counter_block
|
||||
@@ -575,7 +575,7 @@ function get_performance_data(host, objects)
|
||||
end
|
||||
|
||||
local counter_name = result['title_database'][counter_definitions[k]['CounterNameTitleIndex']]
|
||||
--stdnse.print_debug(" %s: %s\n", counter_name, counter_result)
|
||||
--stdnse.print_debug(" %s: %s\n", counter_name, counter_result)
|
||||
|
||||
-- Save it in the result
|
||||
result[object_name][instance_name][counter_name] = counter_result
|
||||
@@ -595,7 +595,7 @@ function get_performance_data(host, objects)
|
||||
end
|
||||
|
||||
local counter_name = result['title_database'][counter_definitions[k]['CounterNameTitleIndex']]
|
||||
--stdnse.print_debug(" %s: %s\n", counter_name, counter_result)
|
||||
--stdnse.print_debug(" %s: %s\n", counter_name, counter_result)
|
||||
|
||||
-- Save it in the result
|
||||
result[object_name][counter_name] = counter_result
|
||||
|
||||
@@ -1771,9 +1771,9 @@ function marshall_lsa_String_array2(strings)
|
||||
result = result .. marshall_int32(0) -- Offset
|
||||
result = result .. marshall_array(array)
|
||||
|
||||
--require 'nsedebug'
|
||||
--nsedebug.print_hex(result)
|
||||
--os.exit()
|
||||
--require 'nsedebug'
|
||||
--nsedebug.print_hex(result)
|
||||
--os.exit()
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ LCP = {
|
||||
MRU = 1,
|
||||
AUTH_PROTO = 3,
|
||||
QUAL_PROTO = 4,
|
||||
MAGIC_NUMBER= 5,
|
||||
MAGIC_NUMBER = 5,
|
||||
PROTO_COMPR = 7,
|
||||
ACFC = 8,
|
||||
|
||||
@@ -634,7 +634,7 @@ PPPoE = {
|
||||
PPPoE.TagDecoder = {}
|
||||
PPPoE.TagDecoder.decodeHex = function(data, pos, len) return pos + len, stdnse.tohex(data:sub(pos, pos+len)) end
|
||||
PPPoE.TagDecoder.decodeStr = function(data, pos, len) return pos + len, data:sub(pos, pos + len - 1) end
|
||||
PPPoE.TagDecoder[PPPoE.TagType.SERVICE_NAME]= PPPoE.TagDecoder.decodeStr
|
||||
PPPoE.TagDecoder[PPPoE.TagType.SERVICE_NAME] = PPPoE.TagDecoder.decodeStr
|
||||
PPPoE.TagDecoder[PPPoE.TagType.AC_NAME] = PPPoE.TagDecoder.decodeStr
|
||||
PPPoE.TagDecoder[PPPoE.TagType.AC_COOKIE] = PPPoE.TagDecoder.decodeHex
|
||||
PPPoE.TagDecoder[PPPoE.TagType.HOST_UNIQUE] = PPPoE.TagDecoder.decodeHex
|
||||
|
||||
@@ -708,7 +708,7 @@ function RmiDataStream:connect(host, port)
|
||||
local socket = nmap.new_socket()
|
||||
socket:set_timeout(5000)
|
||||
|
||||
-- local bsocket = BufferedSocket:new()
|
||||
-- local bsocket = BufferedSocket:new()
|
||||
socket:connect(host,port, "tcp")
|
||||
|
||||
-- Output and input
|
||||
@@ -1360,11 +1360,11 @@ function readFieldDesc(dis)
|
||||
|
||||
j_field:setType(fieldType)
|
||||
j_field:setName(name)
|
||||
-- setType = function( self, typ ) self.type = typ end,
|
||||
-- setSignature = function( self, sig ) self.signature = sig end,
|
||||
-- setName = function( self, name ) self.name = name end,
|
||||
-- setObjectType = function( self, ot ) self.object_type = ot end,
|
||||
-- setReference = function( self, ref ) self.ref = ref end,
|
||||
-- setType = function( self, typ ) self.type = typ end,
|
||||
-- setSignature = function( self, sig ) self.signature = sig end,
|
||||
-- setName = function( self, name ) self.name = name end,
|
||||
-- setObjectType = function( self, ot ) self.object_type = ot end,
|
||||
-- setReference = function( self, ref ) self.ref = ref end,
|
||||
|
||||
dbg("Created java field:".. tostring(j_field))
|
||||
|
||||
@@ -1407,7 +1407,7 @@ Registry ={
|
||||
setmetatable(o, self)
|
||||
self.__index = self -- DIY inheritance
|
||||
-- Hash code for sun.rmi.registry.RegistryImpl_Stub, which we are invoking :
|
||||
-- hex: 0x44154dc9d4e63bdf , dec: 4905912898345647071
|
||||
-- hex: 0x44154dc9d4e63bdf, dec: 4905912898345647071
|
||||
self.hash = '44154dc9d4e63bdf'
|
||||
-- RmiRegistry object id is 0
|
||||
self.objId = 0
|
||||
|
||||
@@ -1083,9 +1083,9 @@ function negotiate_protocol(smb, overrides)
|
||||
smb['server'] = ""
|
||||
|
||||
pos, ch, dummy = bin.unpack("<CC", data, pos)
|
||||
-- if(dummy == nil) then
|
||||
-- return false, "SMB: ERROR: Server returned less data than it was supposed to (one or more fields are missing); aborting [13]"
|
||||
-- end
|
||||
--if(dummy == nil) then
|
||||
-- return false, "SMB: ERROR: Server returned less data than it was supposed to (one or more fields are missing); aborting [13]"
|
||||
--end
|
||||
while ch ~= nil and ch ~= 0 do
|
||||
smb['domain'] = smb['domain'] .. string.char(ch)
|
||||
pos, ch, dummy = bin.unpack("<CC", data, pos)
|
||||
|
||||
@@ -149,16 +149,16 @@ end
|
||||
--@param is_admin [optional] Set to 'true' the account is known to be an administrator.
|
||||
function add_account(host, username, domain, password, password_hash, hash_type, is_admin)
|
||||
-- Save the username in a global list -- TODO: restore this
|
||||
-- if(nmap.registry.usernames == nil) then
|
||||
-- nmap.registry.usernames = {}
|
||||
-- end
|
||||
-- nmap.registry.usernames[username] = true
|
||||
--
|
||||
-- -- Save the username/password pair in a global list
|
||||
-- if(nmap.registry.smbaccounts == nil) then
|
||||
-- nmap.registry.smbaccounts = {}
|
||||
-- end
|
||||
-- nmap.registry.smbaccounts[username] = password
|
||||
-- if(nmap.registry.usernames == nil) then
|
||||
-- nmap.registry.usernames = {}
|
||||
-- end
|
||||
-- nmap.registry.usernames[username] = true
|
||||
--
|
||||
-- -- Save the username/password pair in a global list
|
||||
-- if(nmap.registry.smbaccounts == nil) then
|
||||
-- nmap.registry.smbaccounts = {}
|
||||
-- end
|
||||
-- nmap.registry.smbaccounts[username] = password
|
||||
|
||||
-- Check if we've already recorded this account
|
||||
if(account_exists(host, username, domain)) then
|
||||
@@ -212,7 +212,7 @@ function add_account(host, username, domain, password, password_hash, hash_type,
|
||||
-- Reset the credentials
|
||||
next_account(host, 1)
|
||||
|
||||
-- io.write("\n\n" .. nsedebug.tostr(host.registry['smbaccounts']) .. "\n\n")
|
||||
-- io.write("\n\n" .. nsedebug.tostr(host.registry['smbaccounts']) .. "\n\n")
|
||||
end
|
||||
|
||||
---Retrieve the current set of credentials set in the registry. If these fail, <code>next_credentials</code> should be
|
||||
|
||||
Reference in New Issue
Block a user