Path: blob/master/modules/post/windows/manage/delete_user.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Windows::Accounts78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Windows Manage Local User Account Deletion',13'Description' => %q{14This module deletes a local user account from the specified server,15or the local machine if no server is given.16},17'License' => MSF_LICENSE,18'Author' => [ 'chao-mu'],19'Platform' => [ 'win' ],20'SessionTypes' => [ 'meterpreter' ],21'Notes' => {22'Stability' => [SERVICE_RESOURCE_LOSS],23'SideEffects' => [CONFIG_CHANGES],24'Reliability' => []25}26)27)2829register_options(30[31OptString.new('USERNAME', [ true, 'The username of the user to delete (not-qualified, e.g. BOB)' ]),32OptString.new('SERVER_NAME', [ false, 'DNS or NetBIOS name of remote server on which to delete user' ]),33]34)35end3637def run38username = datastore['USERNAME']39target_server = datastore['SERVER_NAME']4041status = delete_user(username, target_server || nil)4243case status44when :success45print_status 'User was deleted!'46when :invalid_server47print_error 'The server you specified was invalid'48when :not_on_primary49print_error 'You must be on the primary domain controller to do that'50when :user_not_found51print_error 'User did not exist!'52when :access_denied53print_error 'Sorry, you do not have permission to delete that user'54when nil55print_error 'Could not delete user. Something horrible just happened. Sorry.'56else57print_error 'This module is out of date'58end59end60end616263