Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/admin/dcerpc/samr_computer.rb
Views: 11784
##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::SMB::Client::Authenticated9include Msf::Exploit::Remote::DCERPC10include Msf::Auxiliary::Report11include Msf::Exploit::Remote::MsSamr::Computer12include Msf::OptionalSession::SMB1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'SAMR Computer Management',19'Description' => %q{20Add, lookup and delete computer / machine accounts via MS-SAMR. By default21standard active directory users can add up to 10 new computers to the22domain. Administrative privileges however are required to delete the23created accounts.24},25'License' => MSF_LICENSE,26'Author' => [27'JaGoTu', # @jagotu Original Impacket code28'Spencer McIntyre',29],30'References' => [31['URL', 'https://github.com/SecureAuthCorp/impacket/blob/master/examples/addcomputer.py'],32],33'Notes' => {34'Reliability' => [],35'Stability' => [],36'SideEffects' => [ IOC_IN_LOGS ]37},38'Actions' => [39[ 'ADD_COMPUTER', { 'Description' => 'Add a computer account' } ],40[ 'DELETE_COMPUTER', { 'Description' => 'Delete a computer account' } ],41[ 'LOOKUP_COMPUTER', { 'Description' => 'Lookup a computer account' } ]42],43'DefaultAction' => 'ADD_COMPUTER'44)45)4647register_options([48OptString.new('COMPUTER_PASSWORD', [ false, 'The password for the new computer' ], conditions: %w[ACTION == ADD_COMPUTER]),49Opt::RPORT(445)50])51end5253def run54send("action_#{action.name.downcase}")55rescue MsSamrConnectionError => e56fail_with(Failure::Unreachable, e.message)57rescue MsSamrAuthenticationError => e58fail_with(Failure::NoAccess, e.message)59rescue MsSamrNotFoundError => e60fail_with(Failure::NotFound, e.message)61rescue MsSamrBadConfigError => e62fail_with(Failure::BadConfig, e.message)63rescue MsSamrUnexpectedReplyError => e64fail_with(Failure::UnexpectedReply, e.message)65rescue MsSamrUnknownError => e66fail_with(Failure::Unknown, e.message)67end6869def action_add_computer70with_ipc_tree do |opts|71add_computer(opts)72end73end7475def action_delete_computer76fail_with(Failure::BadConfig, 'This action requires COMPUTER_NAME to be specified.') if datastore['COMPUTER_NAME'].blank?77with_ipc_tree do |opts|78delete_computer(opts)79end80end8182def action_lookup_computer83fail_with(Failure::BadConfig, 'This action requires COMPUTER_NAME to be specified.') if datastore['COMPUTER_NAME'].blank?84with_ipc_tree do |opts|85lookup_computer(opts)86end87end8889# @yieldparam options [Hash] If a SMB session is present, a hash with the IPC tree present. Empty hash otherwise.90# @return [void]91def with_ipc_tree92opts = {}93if session94print_status("Using existing session #{session.sid}")95client = session.client96self.simple = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client)97opts[:tree] = simple.client.tree_connect("\\\\#{client.dispatcher.tcp_socket.peerhost}\\IPC$")98end99100yield opts101ensure102opts[:tree].disconnect! if opts[:tree]103end104end105106107