Fixes #629 by handling error conditions with a APIError exception

git-svn-id: file:///home/svn/framework3/trunk@7721 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2009-12-06 04:16:24 +00:00
parent 619f82a420
commit 72fa415fd1
1 changed files with 27 additions and 3 deletions

View File

@ -120,9 +120,14 @@ class Plugin::Nexpose < Msf::Plugin
rescue ::Exception
end
print_status("Connecting to NeXpose instance at #{host}:#{port} with username #{user}...")
nsc = ::Nexpose::Connection.new(host, user, pass, port)
nsc.login
begin
print_status("Connecting to NeXpose instance at #{host}:#{port} with username #{user}...")
nsc = ::Nexpose::Connection.new(host, user, pass, port)
nsc.login
rescue ::Nexpose::APIError => e
print_error("Connection failed: #{e.reason}")
return
end
@nsc = nsc
end
@ -690,8 +695,15 @@ class APIRequest
end
def execute
begin
resp, data = @http.post(@uri.path, @req, @headers)
@res = parse_xml(data)
if(not @res.root)
@error = "NeXpose service returned invalid XML"
return @sid
end
@sid = attributes['session-id']
if(attributes['success'] and attributes['success'].to_i == 1)
@ -707,11 +719,23 @@ class APIRequest
end
end
end
rescue ::Interrupt
@error = "received a user interrupt"
rescue ::Timeout::Error, ::Errno::EHOSTUNREACH,::Errno::ENETDOWN,::Errno::ENETUNREACH,::Errno::ENETRESET,::Errno::EHOSTDOWN,::Errno::EACCES,::Errno::EINVAL,::Errno::EADDRNOTAVAIL
@error = "NeXpose host is unreachable"
rescue ::Errno::ECONNRESET,::Errno::ECONNREFUSED,::Errno::ENOTCONN,::Errno::ECONNABORTED
@error = "NeXpose service is not available"
end
if ! (@success or @error)
@error = "NeXpose service returned an unrecognized response"
end
@sid
end
def attributes(*args)
return if not @res.root
@res.root.attributes(*args)
end