1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 14:11:29 +00:00

Fix SSH publickey auth checking: result was not returned.

This commit is contained in:
dmiller
2017-11-03 19:04:07 +00:00
parent 53e4e92e32
commit a33f6b7c61
2 changed files with 21 additions and 6 deletions

View File

@@ -163,12 +163,22 @@ end
-- --
-- @param username A username to authenticate as. -- @param username A username to authenticate as.
-- @param key Base64 decrypted public key. -- @param key Base64 decrypted public key.
-- @return true if the public key can be used to authenticate as the user, false otherwise
-- @return Error message if an error occurs.
function SSHConnection:publickey_canauth (username, key) function SSHConnection:publickey_canauth (username, key)
local status, err
if self.session then if self.session then
libssh2.publickey_canauth(self.session, username, key) status, err = pcall(libssh2.publickey_canauth, self.session, username, key)
if status then
-- no error thrown; return the actual result
status = err
err = nil
end
else
status = false
err = "No session established"
end end
return status, err
end end
return _ENV return _ENV

View File

@@ -60,9 +60,14 @@ function action (host, port)
local status, result = helper:read_publickey(publickeys[i]) local status, result = helper:read_publickey(publickeys[i])
if not status then if not status then
stdnse.verbose("Error reading key: " .. result) stdnse.verbose("Error reading key: " .. result)
elseif helper:publickey_canauth(usernames[j], result) then else
table.insert(r, "Key " .. publickeys[i] .. " accepted for user " .. usernames[j]) local status, err = helper:publickey_canauth(usernames[j], result)
stdnse.verbose("Found accepted key: " .. publickeys[i] .. " for user " .. usernames[j]) if status then
table.insert(r, "Key " .. publickeys[i] .. " accepted for user " .. usernames[j])
stdnse.verbose("Found accepted key: " .. publickeys[i] .. " for user " .. usernames[j])
elseif err then
stdnse.debug("Error in publickey_canauth: %s", err)
end
helper:disconnect() helper:disconnect()
helper:connect(host, port) helper:connect(host, port)
end end