mirror of
https://github.com/nmap/nmap.git
synced 2026-01-27 16:49:01 +00:00
Re-indent some NSE libraries.
https://secwiki.org/w/Nmap/Code_Standards
This commit is contained in:
198
nselib/pop3.lua
198
nselib/pop3.lua
@@ -15,11 +15,11 @@ local HAVE_SSL, openssl = pcall(require,'openssl')
|
||||
|
||||
|
||||
err = {
|
||||
none = 0,
|
||||
userError = 1,
|
||||
pwError = 2,
|
||||
informationMissing = 3,
|
||||
OpenSSLMissing = 4,
|
||||
none = 0,
|
||||
userError = 1,
|
||||
pwError = 2,
|
||||
informationMissing = 3,
|
||||
OpenSSLMissing = 4,
|
||||
}
|
||||
|
||||
---
|
||||
@@ -27,7 +27,7 @@ err = {
|
||||
-- @param line First line returned from an POP3 request.
|
||||
-- @return The string <code>"+OK"</code> if found or <code>nil</code> otherwise.
|
||||
function stat(line)
|
||||
return string.match(line, "+OK")
|
||||
return string.match(line, "+OK")
|
||||
end
|
||||
|
||||
|
||||
@@ -40,16 +40,16 @@ end
|
||||
-- @return Status (true or false).
|
||||
-- @return Error code if status is false.
|
||||
function login_user(socket, user, pw)
|
||||
socket:send("USER " .. user .. "\r\n")
|
||||
local status, line = socket:receive_lines(1)
|
||||
if not stat(line) then return false, err.user_error end
|
||||
socket:send("PASS " .. pw .. "\r\n")
|
||||
socket:send("USER " .. user .. "\r\n")
|
||||
local status, line = socket:receive_lines(1)
|
||||
if not stat(line) then return false, err.user_error end
|
||||
socket:send("PASS " .. pw .. "\r\n")
|
||||
|
||||
status, line = socket:receive_lines(1)
|
||||
status, line = socket:receive_lines(1)
|
||||
|
||||
if stat(line) then return true, err.none
|
||||
else return false, err.pwError
|
||||
end
|
||||
if stat(line) then return true, err.none
|
||||
else return false, err.pwError
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -62,16 +62,16 @@ end
|
||||
-- @return Error code if status is false.
|
||||
function login_sasl_plain(socket, user, pw)
|
||||
|
||||
local auth64 = base64.enc(user .. "\0" .. user .. "\0" .. pw)
|
||||
socket:send("AUTH PLAIN " .. auth64 .. "\r\n")
|
||||
local auth64 = base64.enc(user .. "\0" .. user .. "\0" .. pw)
|
||||
socket:send("AUTH PLAIN " .. auth64 .. "\r\n")
|
||||
|
||||
local status, line = socket:receive_lines(1)
|
||||
local status, line = socket:receive_lines(1)
|
||||
|
||||
if stat(line) then
|
||||
return true, err.none
|
||||
else
|
||||
return false, err.pwError
|
||||
end
|
||||
if stat(line) then
|
||||
return true, err.none
|
||||
else
|
||||
return false, err.pwError
|
||||
end
|
||||
end
|
||||
|
||||
---
|
||||
@@ -83,34 +83,34 @@ end
|
||||
-- @return Error code if status is false.
|
||||
function login_sasl_login(socket, user, pw)
|
||||
|
||||
local user64 = base64.enc(user)
|
||||
local user64 = base64.enc(user)
|
||||
|
||||
local pw64 = base64.enc(pw)
|
||||
local pw64 = base64.enc(pw)
|
||||
|
||||
socket:send("AUTH LOGIN\r\n")
|
||||
socket:send("AUTH LOGIN\r\n")
|
||||
|
||||
local status, line = socket:receive_lines(1)
|
||||
if not base64.dec(string.sub(line, 3)) == "User Name:" then
|
||||
return false, err.userError
|
||||
end
|
||||
local status, line = socket:receive_lines(1)
|
||||
if not base64.dec(string.sub(line, 3)) == "User Name:" then
|
||||
return false, err.userError
|
||||
end
|
||||
|
||||
socket:send(user64)
|
||||
socket:send(user64)
|
||||
|
||||
local status, line = socket:receive_lines(1)
|
||||
local status, line = socket:receive_lines(1)
|
||||
|
||||
if not base64.dec(string.sub(line, 3)) == "Password:" then
|
||||
return false, err.userError
|
||||
end
|
||||
if not base64.dec(string.sub(line, 3)) == "Password:" then
|
||||
return false, err.userError
|
||||
end
|
||||
|
||||
socket:send(pw64)
|
||||
socket:send(pw64)
|
||||
|
||||
local status, line = socket:receive_lines(1)
|
||||
local status, line = socket:receive_lines(1)
|
||||
|
||||
if stat(line) then
|
||||
return true, err.none
|
||||
else
|
||||
return false, err.pwError
|
||||
end
|
||||
if stat(line) then
|
||||
return true, err.none
|
||||
else
|
||||
return false, err.pwError
|
||||
end
|
||||
end
|
||||
|
||||
---
|
||||
@@ -122,18 +122,18 @@ end
|
||||
-- @return Status (true or false).
|
||||
-- @return Error code if status is false.
|
||||
function login_apop(socket, user, pw, challenge)
|
||||
if type(challenge) ~= "string" then return false, err.informationMissing end
|
||||
if type(challenge) ~= "string" then return false, err.informationMissing end
|
||||
|
||||
local apStr = stdnse.tohex(openssl.md5(challenge .. pw))
|
||||
socket:send(("APOP %s %s\r\n"):format(user, apStr))
|
||||
local apStr = stdnse.tohex(openssl.md5(challenge .. pw))
|
||||
socket:send(("APOP %s %s\r\n"):format(user, apStr))
|
||||
|
||||
local status, line = socket:receive_lines(1)
|
||||
local status, line = socket:receive_lines(1)
|
||||
|
||||
if (stat(line)) then
|
||||
return true, err.none
|
||||
else
|
||||
return false, err.pwError
|
||||
end
|
||||
if (stat(line)) then
|
||||
return true, err.none
|
||||
else
|
||||
return false, err.pwError
|
||||
end
|
||||
end
|
||||
|
||||
---
|
||||
@@ -146,49 +146,49 @@ end
|
||||
-- @return nil or String error message.
|
||||
function capabilities(host, port)
|
||||
|
||||
local socket, line, bopt, first_line = comm.tryssl(host, port, "" , {timeout=10000, recv_before=true})
|
||||
if not socket then
|
||||
return nil, "Could Not Connect"
|
||||
end
|
||||
if not stat(first_line) then
|
||||
return nil, "No Response"
|
||||
end
|
||||
local socket, line, bopt, first_line = comm.tryssl(host, port, "" , {timeout=10000, recv_before=true})
|
||||
if not socket then
|
||||
return nil, "Could Not Connect"
|
||||
end
|
||||
if not stat(first_line) then
|
||||
return nil, "No Response"
|
||||
end
|
||||
|
||||
local capas = {}
|
||||
if string.find(first_line, "<[%p%w]+>") then
|
||||
capas.APOP = {}
|
||||
end
|
||||
local capas = {}
|
||||
if string.find(first_line, "<[%p%w]+>") then
|
||||
capas.APOP = {}
|
||||
end
|
||||
|
||||
local status = socket:send("CAPA\r\n")
|
||||
if( not(status) ) then
|
||||
return nil, "Failed to send"
|
||||
end
|
||||
local status = socket:send("CAPA\r\n")
|
||||
if( not(status) ) then
|
||||
return nil, "Failed to send"
|
||||
end
|
||||
|
||||
status, line = socket:receive_buf("%.", false)
|
||||
if( not(status) ) then
|
||||
return nil, "Failed to receive"
|
||||
end
|
||||
socket:close()
|
||||
status, line = socket:receive_buf("%.", false)
|
||||
if( not(status) ) then
|
||||
return nil, "Failed to receive"
|
||||
end
|
||||
socket:close()
|
||||
|
||||
local lines = stdnse.strsplit("\r\n",line)
|
||||
if not stat(table.remove(lines,1)) then
|
||||
capas.capa = false
|
||||
return capas
|
||||
end
|
||||
local lines = stdnse.strsplit("\r\n",line)
|
||||
if not stat(table.remove(lines,1)) then
|
||||
capas.capa = false
|
||||
return capas
|
||||
end
|
||||
|
||||
for _, line in ipairs(lines) do
|
||||
if ( line and #line>0 ) then
|
||||
local capability = line:sub(line:find("[%w-]+"))
|
||||
line = line:sub(#capability + 2)
|
||||
if ( line ~= "" ) then
|
||||
capas[capability] = stdnse.strsplit(" ", line)
|
||||
else
|
||||
capas[capability] = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
for _, line in ipairs(lines) do
|
||||
if ( line and #line>0 ) then
|
||||
local capability = line:sub(line:find("[%w-]+"))
|
||||
line = line:sub(#capability + 2)
|
||||
if ( line ~= "" ) then
|
||||
capas[capability] = stdnse.strsplit(" ", line)
|
||||
else
|
||||
capas[capability] = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return capas
|
||||
return capas
|
||||
end
|
||||
|
||||
---
|
||||
@@ -200,23 +200,23 @@ end
|
||||
-- @return Error code if status is false.
|
||||
function login_sasl_crammd5(socket, user, pw)
|
||||
|
||||
socket:send("AUTH CRAM-MD5\r\n")
|
||||
socket:send("AUTH CRAM-MD5\r\n")
|
||||
|
||||
local status, line = socket:receive_lines(1)
|
||||
local status, line = socket:receive_lines(1)
|
||||
|
||||
local challenge = base64.dec(string.sub(line, 3))
|
||||
local challenge = base64.dec(string.sub(line, 3))
|
||||
|
||||
local digest = stdnse.tohex(openssl.hmac('md5', pw, challenge))
|
||||
local authStr = base64.enc(user .. " " .. digest)
|
||||
socket:send(authStr .. "\r\n")
|
||||
local digest = stdnse.tohex(openssl.hmac('md5', pw, challenge))
|
||||
local authStr = base64.enc(user .. " " .. digest)
|
||||
socket:send(authStr .. "\r\n")
|
||||
|
||||
local status, line = socket:receive_lines(1)
|
||||
local status, line = socket:receive_lines(1)
|
||||
|
||||
if stat(line) then
|
||||
return true, err.none
|
||||
else
|
||||
return false, err.pwError
|
||||
end
|
||||
if stat(line) then
|
||||
return true, err.none
|
||||
else
|
||||
return false, err.pwError
|
||||
end
|
||||
end
|
||||
|
||||
-- Overwrite functions requiring OpenSSL if we got no OpenSSL.
|
||||
|
||||
Reference in New Issue
Block a user