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/post/windows/manage/change_password.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post67def initialize(info = {})8super(9update_info(10info,11'Name' => 'Windows Manage Change Password',12'Description' => %q{13This module will attempt to change the password of the targeted account.14The typical usage is to change a newly created account's password on a15remote host to avoid the error, 'System error 1907 has occurred,' which16is caused when the account policy enforces a password change before the17next login.18},19'License' => MSF_LICENSE,20'Platform' => ['win'],21'SessionTypes' => ['meterpreter'],22'Author' => ['Ben Campbell'],23'Compat' => {24'Meterpreter' => {25'Commands' => %w[26stdapi_railgun_api27]28}29}30)31)3233register_options(34[35OptString.new('SMBDomain', [false, 'Domain or Host to change password on, if not set will use the current login domain', nil], fallbacks: ['DOMAIN']),36OptString.new('SMBUser', [true, 'Username to change password of'], fallbacks: ['PASSWORD']),37OptString.new('OLD_PASSWORD', [true, 'Original password' ]),38OptString.new('NEW_PASSWORD', [true, 'New password' ]),39]40)41end4243def run44unless client.railgun45print_error('This module requires a native Windows payload that supports Railgun.')46return47end4849domain = datastore['SMBDomain']50username = datastore['SMBUser']51old_password = datastore['OLD_PASSWORD']52new_password = datastore['NEW_PASSWORD']53print_status("Changing #{domain}\\#{username} password to #{new_password}...")54result = client.railgun.netapi32.NetUserChangePassword(55domain,56username,57old_password,58new_password59)6061case result['return']62when 0x0563err_msg = 'ERROR_ACCESS_DENIED'64when 0x5665err_msg = 'ERROR_INVALID_PASSWORD'66when 0x92f67err_msg = 'NERR_InvalidComputer'68when 0x8b269err_msg = 'NERR_NotPrimary'70when 0x8ad71err_msg = 'NERR_UserNotFound'72when 0x8c573err_msg = 'NERR_PasswordTooShort'74when 075print_good('Password change successful.')76else77err_msg = "unknown error code: #{result['return']}"78end7980if err_msg81print_error("Password change failed, #{err_msg}.")82end83end84end858687