1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-10 17:59:04 +00:00

Reindent the last of the NSE libraries.

https://secwiki.org/w/Nmap/Code_Standards
This commit is contained in:
dmiller
2014-02-04 19:47:26 +00:00
parent d5746993e2
commit 69e343f0aa
34 changed files with 26811 additions and 26811 deletions

View File

@@ -302,9 +302,9 @@ bdecode = function(buf)
-- next(stack) is never gonna be nil because we're always in the main list -- 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 -- next(stack, next(stack)) should be nil if we're in the main list
-- if next(stack, next(stack)) then -- if next(stack, next(stack)) then
-- return false, "Probably file incorrect format" -- return false, "Probably file incorrect format"
-- end -- end
return true, t return true, t
end end

View File

@@ -1141,7 +1141,7 @@ local function decDomain(entry, data, pos)
local np = pos - #entry.data local np = pos - #entry.data
local _ local _
_, entry.domain = decStr(data, np) _, entry.domain = decStr(data, np)
end end
-- Decodes CNAME records. -- Decodes CNAME records.
-- Puts result in <code>entry.domain</code>. -- Puts result in <code>entry.domain</code>.
@@ -1178,7 +1178,7 @@ decoder[types.PTR] = decDomain
-- @param data Complete encoded DNS packet. -- @param data Complete encoded DNS packet.
-- @param pos Position in packet after RR. -- @param pos Position in packet after RR.
decoder[types.TXT] = decoder[types.TXT] =
function (entry, data, pos) function (entry, data, pos)
local len = entry.data:len() local len = entry.data:len()
local np = pos - #entry.data local np = pos - #entry.data
@@ -1197,7 +1197,7 @@ decoder[types.TXT] =
table.insert( entry.TXT.text, txt ) table.insert( entry.TXT.text, txt )
end end
end end
--- ---
-- Decodes OPT record, puts it in <code>entry.OPT</code>. -- Decodes OPT record, puts it in <code>entry.OPT</code>.
@@ -1209,13 +1209,13 @@ decoder[types.TXT] =
-- @param data Complete encoded DNS packet. -- @param data Complete encoded DNS packet.
-- @param pos Position in packet after RR. -- @param pos Position in packet after RR.
decoder[types.OPT] = decoder[types.OPT] =
function(entry, data, pos) function(entry, data, pos)
local np = pos - #entry.data - 6 local np = pos - #entry.data - 6
local opt = { bufsize = entry.class } local opt = { bufsize = entry.class }
np, opt.rcode, opt.version, opt.zflags, opt.rdlen = bin.unpack(">CCSS", data, np) np, opt.rcode, opt.version, opt.zflags, opt.rdlen = bin.unpack(">CCSS", data, np)
np, opt.data = bin.unpack("A" .. opt.rdlen, data, np) np, opt.data = bin.unpack("A" .. opt.rdlen, data, np)
entry.OPT = opt entry.OPT = opt
end end
-- Decodes MX record, puts it in <code>entry.MX</code>. -- Decodes MX record, puts it in <code>entry.MX</code>.
@@ -1226,13 +1226,13 @@ decoder[types.OPT] =
-- @param data Complete encoded DNS packet. -- @param data Complete encoded DNS packet.
-- @param pos Position in packet after RR. -- @param pos Position in packet after RR.
decoder[types.MX] = decoder[types.MX] =
function(entry, data, pos) function(entry, data, pos)
local np = pos - #entry.data + 2 local np = pos - #entry.data + 2
local _ local _
entry.MX = {} entry.MX = {}
_, entry.MX.pref = bin.unpack(">S", entry.data) _, entry.MX.pref = bin.unpack(">S", entry.data)
_, entry.MX.server = decStr(data, np) _, entry.MX.server = decStr(data, np)
end end
-- Decodes SRV record, puts it in <code>entry.SRV</code>. -- Decodes SRV record, puts it in <code>entry.SRV</code>.
-- --
@@ -1243,13 +1243,13 @@ decoder[types.MX] =
-- @param data Complete encoded DNS packet. -- @param data Complete encoded DNS packet.
-- @param pos Position in packet after RR. -- @param pos Position in packet after RR.
decoder[types.SRV] = decoder[types.SRV] =
function(entry, data, pos) function(entry, data, pos)
local np = pos - #entry.data local np = pos - #entry.data
local _ local _
entry.SRV = {} entry.SRV = {}
np, entry.SRV.prio, entry.SRV.weight, entry.SRV.port = bin.unpack(">S>S>S", data, np) np, entry.SRV.prio, entry.SRV.weight, entry.SRV.port = bin.unpack(">S>S>S", data, np)
np, entry.SRV.target = decStr(data, np) np, entry.SRV.target = decStr(data, np)
end end
-- Decodes returned resource records (answer, authority, or additional part). -- Decodes returned resource records (answer, authority, or additional part).
-- @param data Complete encoded DNS packet. -- @param data Complete encoded DNS packet.

View File

@@ -557,7 +557,7 @@ SERVICES = {
end end
end, end,
} }
}, },
} }

View File

@@ -414,21 +414,21 @@ local function generate_aggressive(port, protocol, id, diffie)
return bin.pack(">SHHSSHSHCHHH", return bin.pack(">SHHSSHSHCHHH",
-- Key Exchange -- Key Exchange
0x0a00 , -- Next payload (Nonce) 0x0a00, -- Next payload (Nonce)
string.format("%04X", key_length+4) , -- Length (132-bit) string.format("%04X", key_length+4), -- Length (132-bit)
generate_random(key_length) , -- Random key data generate_random(key_length), -- Random key data
-- Nonce -- Nonce
0x0500 , -- Next payload (Identification) 0x0500, -- Next payload (Identification)
0x0018 , -- Length (24) 0x0018, -- Length (24)
generate_random(20) , -- Nonce data generate_random(20), -- Nonce data
-- Identification -- Identification
0x0000 , -- Next Payload (None) 0x0000, -- Next Payload (None)
id_len , -- Payload length (id + 8) id_len, -- Payload length (id + 8)
0x03 , -- ID Type (USER_FQDN) 0x03, -- ID Type (USER_FQDN)
hex_prot , -- Protocol ID (UDP) hex_prot, -- Protocol ID (UDP)
hex_port , -- Port (500) hex_port, -- Port (500)
convert_to_hex(id) -- Id Data (as hex) convert_to_hex(id) -- Id Data (as hex)
) )
end end
@@ -464,14 +464,14 @@ local function generate_transform(auth, encryption, hash, group, number, total)
payload_number = string.format("%.2X", number) payload_number = string.format("%.2X", number)
local trans = bin.pack(">SSHCSIIII", local trans = bin.pack(">SSHCSIIII",
next_payload , -- Next payload next_payload, -- Next payload
trans_length , -- Transform length trans_length, -- Transform length
payload_number , -- Transform number payload_number, -- Transform number
0x01 , -- Transform ID (IKE) 0x01, -- Transform ID (IKE)
0x0000 , -- spacers ? 0x0000, -- spacers ?
enc , -- Encryption algorithm enc, -- Encryption algorithm
HASH_ALGORITHM[hash] , -- Hash algorithm HASH_ALGORITHM[hash], -- Hash algorithm
AUTH_TYPES[auth] , -- Authentication method AUTH_TYPES[auth], -- Authentication method
GROUP_DESCRIPTION[group] -- Group Description GROUP_DESCRIPTION[group] -- Group Description
) )
@@ -480,7 +480,7 @@ local function generate_transform(auth, encryption, hash, group, number, total)
end end
trans = trans .. bin.pack(">IL", trans = trans .. bin.pack(">IL",
0x800b0001 , -- Life type (seconds) 0x800b0001, -- Life type (seconds)
0x000c000400007080 -- Life duration (28800) 0x000c000400007080 -- Life duration (28800)
) )
@@ -530,28 +530,28 @@ function request(port, proto, mode, transforms, diffie, id)
-- Build the packet -- Build the packet
local packet = bin.pack(">HLCCCCIHSHIISHCCCH", local packet = bin.pack(">HLCCCCIHSHIISHCCCH",
generate_random(8) , -- Initiator cookie generate_random(8), -- Initiator cookie
0x0000000000000000 , -- Responder cookie 0x0000000000000000, -- Responder cookie
0x01 , -- Next payload (SA) 0x01, -- Next payload (SA)
0x10 , -- Version 0x10, -- Version
EXCHANGE_MODE[mode] , -- Exchange type EXCHANGE_MODE[mode], -- Exchange type
0x00 , -- Flags 0x00, -- Flags
0x00000000 , -- Message id 0x00000000, -- Message id
l , -- packet length l, -- packet length
-- Security Association -- Security Association
payload_after_sa , -- Next payload (Key exchange, if aggressive mode) payload_after_sa, -- Next payload (Key exchange, if aggressive mode)
l_sa , -- Length l_sa, -- Length
0x00000001 , -- IPSEC 0x00000001, -- IPSEC
0x00000001 , -- Situation 0x00000001, -- Situation
--## Proposal --## Proposal
0x0000 , -- Next payload (None) 0x0000, -- Next payload (None)
l_pro , -- Payload length l_pro, -- Payload length
0x01 , -- Proposal number 0x01, -- Proposal number
0x01 , -- Protocol ID (ISAKMP) 0x01, -- Protocol ID (ISAKMP)
0x00 , -- SPI Size 0x00, -- SPI Size
number_transforms -- Proposal transforms number_transforms -- Proposal transforms
) )

View File

@@ -241,8 +241,8 @@ function receive_all(socket)
return true, data -- if somethign is wrong,return partial data return true, data -- if somethign is wrong,return partial data
end end
data = data .. result data = data .. result
end end
return true,data return true,data
end end
--- Helper function to extract ascii string from UTF-8 --- Helper function to extract ascii string from UTF-8

View File

@@ -365,7 +365,7 @@ MongoData ={
MSG = 1000, MSG = 1000,
UPDATE = 2001, UPDATE = 2001,
INSERT = 2002, INSERT = 2002,
GET_BY_IOD =2003, GET_BY_IOD = 2003,
QUERY = 2004, QUERY = 2004,
GET_MORE = 2005, GET_MORE = 2005,
DELETE = 2006, DELETE = 2006,
@@ -397,7 +397,7 @@ end
--@return status : true if ok, false if error occurred --@return status : true if ok, false if error occurred
--@return Error message if error occurred --@return Error message if error occurred
function MongoData:addBSON(dict) function MongoData:addBSON(dict)
-- status, res = bson.toBson(dict) -- status, res = bson.toBson(dict)
local status, res = toBson(dict) local status, res = toBson(dict)
if not status then if not status then
dbg(res) dbg(res)
@@ -588,7 +588,7 @@ function query(socket, data)
return false, "No Bson data returned" return false, "No Bson data returned"
end end
-- result, data, err_msg = bson.fromBson(bsonData) -- result, data, err_msg = bson.fromBson(bsonData)
result, data, err_msg = fromBson(bsonData) result, data, err_msg = fromBson(bsonData)
if err_msg then if err_msg then

File diff suppressed because it is too large Load Diff

View File

@@ -234,9 +234,9 @@ local function parse_perf_object_type(data, pos)
pos, result['DefaultCounter'] = msrpctypes.unmarshall_int32(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['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 pos, result['CodePage'] = msrpctypes.unmarshall_int32(data, pos) -- 0 if strings are in UNICODE, otherwise the Code Page
-- if(result['CodePage'] ~= 0) then -- if(result['CodePage'] ~= 0) then
-- return false, string.format("Unknown Code Page for data: %d\n", result['CodePage']) -- return false, string.format("Unknown Code Page for data: %d\n", result['CodePage'])
-- end -- end
pos, result['PerfTime'] = msrpctypes.unmarshall_int64(data, pos) -- Sample time in "Object" units 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 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) pos, result = msrpctypes.unmarshall_int32(data, pos)
elseif(counter_definition['CounterSize'] == 8) then elseif(counter_definition['CounterSize'] == 8) then
pos, result = msrpctypes.unmarshall_int64(data, pos) pos, result = msrpctypes.unmarshall_int64(data, pos)
-- pos, result = bin.unpack("<d", data, pos) -- pos, result = bin.unpack("<d", data, pos)
else else
pos, result = msrpctypes.unmarshall_raw(data, pos, counter_definition['CounterSize']) pos, result = msrpctypes.unmarshall_raw(data, pos, counter_definition['CounterSize'])
end end
@@ -505,14 +505,14 @@ function get_performance_data(host, objects)
end end
-- Start setting up the result object -- 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']] local object_name = result['title_database'][object_type['ObjectNameTitleIndex']]
result[object_name] = {} result[object_name] = {}
--stdnse.print_debug("\n\nOBJECT: %s\n", object_name) --stdnse.print_debug("\n\nOBJECT: %s\n", object_name)
--stdnse.print_debug(" Counters: %d\n", object_type['NumCounters']) --stdnse.print_debug(" Counters: %d\n", object_type['NumCounters'])
--stdnse.print_debug(" Instances: %d\n", object_type['NumInstances']) --stdnse.print_debug(" Instances: %d\n", object_type['NumInstances'])
--stdnse.print_debug("-----------------\n") --stdnse.print_debug("-----------------\n")
-- Bring the position to the beginning of the counter definitions -- Bring the position to the beginning of the counter definitions
pos = object_start + object_type['HeaderLength'] pos = object_start + object_type['HeaderLength']
@@ -524,7 +524,7 @@ function get_performance_data(host, objects)
msrpc.stop_smb(smbstate) msrpc.stop_smb(smbstate)
return false, pos return false, pos
end 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 end
-- Bring the position to the beginning of the instances (or counters) -- 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 -- Bring the pos to the start of the counter block
pos = instance_start + object_instances[j]['ByteLength'] pos = instance_start + object_instances[j]['ByteLength']
--stdnse.print_debug("\n INSTANCE: %s\n", instance_name) --stdnse.print_debug("\n INSTANCE: %s\n", instance_name)
--stdnse.print_debug(" Length: %d\n", object_instances[j]['ByteLength']) --stdnse.print_debug(" Length: %d\n", object_instances[j]['ByteLength'])
--stdnse.print_debug(" NameOffset: %d\n", object_instances[j]['NameOffset']) --stdnse.print_debug(" NameOffset: %d\n", object_instances[j]['NameOffset'])
--stdnse.print_debug(" NameLength: %d\n", object_instances[j]['NameLength']) --stdnse.print_debug(" NameLength: %d\n", object_instances[j]['NameLength'])
--stdnse.print_debug(" --------------\n") --stdnse.print_debug(" --------------\n")
-- The counter block -- The counter block
local status, counter_block local status, counter_block
@@ -575,7 +575,7 @@ function get_performance_data(host, objects)
end end
local counter_name = result['title_database'][counter_definitions[k]['CounterNameTitleIndex']] 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 -- Save it in the result
result[object_name][instance_name][counter_name] = counter_result result[object_name][instance_name][counter_name] = counter_result
@@ -595,7 +595,7 @@ function get_performance_data(host, objects)
end end
local counter_name = result['title_database'][counter_definitions[k]['CounterNameTitleIndex']] 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 -- Save it in the result
result[object_name][counter_name] = counter_result result[object_name][counter_name] = counter_result

View File

@@ -1771,9 +1771,9 @@ function marshall_lsa_String_array2(strings)
result = result .. marshall_int32(0) -- Offset result = result .. marshall_int32(0) -- Offset
result = result .. marshall_array(array) result = result .. marshall_array(array)
--require 'nsedebug' --require 'nsedebug'
--nsedebug.print_hex(result) --nsedebug.print_hex(result)
--os.exit() --os.exit()
return result return result
end end

View File

@@ -45,7 +45,7 @@ LCP = {
MRU = 1, MRU = 1,
AUTH_PROTO = 3, AUTH_PROTO = 3,
QUAL_PROTO = 4, QUAL_PROTO = 4,
MAGIC_NUMBER= 5, MAGIC_NUMBER = 5,
PROTO_COMPR = 7, PROTO_COMPR = 7,
ACFC = 8, ACFC = 8,
@@ -634,7 +634,7 @@ PPPoE = {
PPPoE.TagDecoder = {} PPPoE.TagDecoder = {}
PPPoE.TagDecoder.decodeHex = function(data, pos, len) return pos + len, stdnse.tohex(data:sub(pos, pos+len)) end 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.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_NAME] = PPPoE.TagDecoder.decodeStr
PPPoE.TagDecoder[PPPoE.TagType.AC_COOKIE] = PPPoE.TagDecoder.decodeHex PPPoE.TagDecoder[PPPoE.TagType.AC_COOKIE] = PPPoE.TagDecoder.decodeHex
PPPoE.TagDecoder[PPPoE.TagType.HOST_UNIQUE] = PPPoE.TagDecoder.decodeHex PPPoE.TagDecoder[PPPoE.TagType.HOST_UNIQUE] = PPPoE.TagDecoder.decodeHex

View File

@@ -708,7 +708,7 @@ function RmiDataStream:connect(host, port)
local socket = nmap.new_socket() local socket = nmap.new_socket()
socket:set_timeout(5000) socket:set_timeout(5000)
-- local bsocket = BufferedSocket:new() -- local bsocket = BufferedSocket:new()
socket:connect(host,port, "tcp") socket:connect(host,port, "tcp")
-- Output and input -- Output and input
@@ -1360,11 +1360,11 @@ function readFieldDesc(dis)
j_field:setType(fieldType) j_field:setType(fieldType)
j_field:setName(name) j_field:setName(name)
-- setType = function( self, typ ) self.type = typ end, -- setType = function( self, typ ) self.type = typ end,
-- setSignature = function( self, sig ) self.signature = sig end, -- setSignature = function( self, sig ) self.signature = sig end,
-- setName = function( self, name ) self.name = name end, -- setName = function( self, name ) self.name = name end,
-- setObjectType = function( self, ot ) self.object_type = ot end, -- setObjectType = function( self, ot ) self.object_type = ot end,
-- setReference = function( self, ref ) self.ref = ref end, -- setReference = function( self, ref ) self.ref = ref end,
dbg("Created java field:".. tostring(j_field)) dbg("Created java field:".. tostring(j_field))
@@ -1407,7 +1407,7 @@ Registry ={
setmetatable(o, self) setmetatable(o, self)
self.__index = self -- DIY inheritance self.__index = self -- DIY inheritance
-- Hash code for sun.rmi.registry.RegistryImpl_Stub, which we are invoking : -- Hash code for sun.rmi.registry.RegistryImpl_Stub, which we are invoking :
-- hex: 0x44154dc9d4e63bdf , dec: 4905912898345647071 -- hex: 0x44154dc9d4e63bdf, dec: 4905912898345647071
self.hash = '44154dc9d4e63bdf' self.hash = '44154dc9d4e63bdf'
-- RmiRegistry object id is 0 -- RmiRegistry object id is 0
self.objId = 0 self.objId = 0

View File

@@ -1083,9 +1083,9 @@ function negotiate_protocol(smb, overrides)
smb['server'] = "" smb['server'] = ""
pos, ch, dummy = bin.unpack("<CC", data, pos) pos, ch, dummy = bin.unpack("<CC", data, pos)
-- if(dummy == nil) then --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]" -- return false, "SMB: ERROR: Server returned less data than it was supposed to (one or more fields are missing); aborting [13]"
-- end --end
while ch ~= nil and ch ~= 0 do while ch ~= nil and ch ~= 0 do
smb['domain'] = smb['domain'] .. string.char(ch) smb['domain'] = smb['domain'] .. string.char(ch)
pos, ch, dummy = bin.unpack("<CC", data, pos) pos, ch, dummy = bin.unpack("<CC", data, pos)

View File

@@ -149,16 +149,16 @@ end
--@param is_admin [optional] Set to 'true' the account is known to be an administrator. --@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) function add_account(host, username, domain, password, password_hash, hash_type, is_admin)
-- Save the username in a global list -- TODO: restore this -- Save the username in a global list -- TODO: restore this
-- if(nmap.registry.usernames == nil) then -- if(nmap.registry.usernames == nil) then
-- nmap.registry.usernames = {} -- nmap.registry.usernames = {}
-- end -- end
-- nmap.registry.usernames[username] = true -- nmap.registry.usernames[username] = true
-- --
-- -- Save the username/password pair in a global list -- -- Save the username/password pair in a global list
-- if(nmap.registry.smbaccounts == nil) then -- if(nmap.registry.smbaccounts == nil) then
-- nmap.registry.smbaccounts = {} -- nmap.registry.smbaccounts = {}
-- end -- end
-- nmap.registry.smbaccounts[username] = password -- nmap.registry.smbaccounts[username] = password
-- Check if we've already recorded this account -- Check if we've already recorded this account
if(account_exists(host, username, domain)) then 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 -- Reset the credentials
next_account(host, 1) 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 end
---Retrieve the current set of credentials set in the registry. If these fail, <code>next_credentials</code> should be ---Retrieve the current set of credentials set in the registry. If these fail, <code>next_credentials</code> should be