Files
metasploit-gs/modules/auxiliary/admin/dcerpc/samr_computer.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
3.4 KiB
Ruby
Raw Normal View History

2022-06-02 14:12:47 -04:00
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'ruby_smb/dcerpc/client'
class MetasploitModule < Msf::Auxiliary
include Msf::Exploit::Remote::SMB::Client::Authenticated
include Msf::Exploit::Remote::DCERPC
include Msf::Auxiliary::Report
2022-12-02 16:29:02 +01:00
include Msf::Exploit::Remote::MsSamr
include Msf::OptionalSession::SMB
2022-06-02 14:12:47 -04:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'SAMR Computer Management',
'Description' => %q{
Add, lookup and delete computer / machine accounts via MS-SAMR. By default
2022-06-14 14:53:12 -04:00
standard active directory users can add up to 10 new computers to the
domain. Administrative privileges however are required to delete the
created accounts.
2022-06-02 14:12:47 -04:00
},
'License' => MSF_LICENSE,
'Author' => [
2022-06-14 14:53:12 -04:00
'JaGoTu', # @jagotu Original Impacket code
2022-06-02 14:12:47 -04:00
'Spencer McIntyre',
],
'References' => [
['URL', 'https://github.com/SecureAuthCorp/impacket/blob/master/examples/addcomputer.py'],
],
'Notes' => {
'Reliability' => [],
'Stability' => [],
'SideEffects' => [ IOC_IN_LOGS ]
},
'Actions' => [
2022-06-03 13:33:55 -04:00
[ 'ADD_COMPUTER', { 'Description' => 'Add a computer account' } ],
2022-06-13 17:46:34 -04:00
[ 'DELETE_COMPUTER', { 'Description' => 'Delete a computer account' } ],
2022-06-13 17:20:34 -04:00
[ 'LOOKUP_COMPUTER', { 'Description' => 'Lookup a computer account' } ]
2022-06-02 14:12:47 -04:00
],
2022-06-03 13:33:55 -04:00
'DefaultAction' => 'ADD_COMPUTER'
2022-06-02 14:12:47 -04:00
)
)
2022-06-03 13:33:55 -04:00
register_options([
2022-06-14 14:53:12 -04:00
OptString.new('COMPUTER_PASSWORD', [ false, 'The password for the new computer' ], conditions: %w[ACTION == ADD_COMPUTER]),
2022-06-03 13:33:55 -04:00
Opt::RPORT(445)
])
2022-06-02 14:12:47 -04:00
end
def run
2022-06-03 13:33:55 -04:00
send("action_#{action.name.downcase}")
2022-12-02 16:29:02 +01:00
rescue MsSamrConnectionError => e
fail_with(Failure::Unreachable, e.message)
rescue MsSamrAuthenticationError => e
fail_with(Failure::NoAccess, e.message)
rescue MsSamrNotFoundError => e
fail_with(Failure::NotFound, e.message)
rescue MsSamrBadConfigError => e
fail_with(Failure::BadConfig, e.message)
rescue MsSamrUnexpectedReplyError => e
2022-06-14 12:16:08 -04:00
fail_with(Failure::UnexpectedReply, e.message)
2022-12-02 16:29:02 +01:00
rescue MsSamrUnknownError => e
2022-06-28 11:53:05 -04:00
fail_with(Failure::Unknown, e.message)
2022-06-03 13:33:55 -04:00
end
def action_add_computer
with_ipc_tree do |opts|
add_computer(opts)
end
2022-06-03 13:33:55 -04:00
end
2022-06-13 17:46:34 -04:00
def action_delete_computer
fail_with(Failure::BadConfig, 'This action requires COMPUTER_NAME to be specified.') if datastore['COMPUTER_NAME'].blank?
with_ipc_tree do |opts|
delete_computer(opts)
end
2022-06-13 17:46:34 -04:00
end
2022-06-13 17:20:34 -04:00
def action_lookup_computer
fail_with(Failure::BadConfig, 'This action requires COMPUTER_NAME to be specified.') if datastore['COMPUTER_NAME'].blank?
with_ipc_tree do |opts|
lookup_computer(opts)
end
end
# @yieldparam options [Hash] If a SMB session is present, a hash with the IPC tree present. Empty hash otherwise.
# @return [void]
def with_ipc_tree
opts = {}
if session
print_status("Using existing session #{session.sid}")
client = session.client
self.simple = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client)
opts[:tree] = simple.client.tree_connect("\\\\#{client.dispatcher.tcp_socket.peerhost}\\IPC$")
end
yield opts
ensure
opts[:tree].disconnect! if opts[:tree]
end
2022-06-02 14:12:47 -04:00
end