Skip to content

Commit 54346f3

Browse files
committed
Land rapid7#3265 - Windows Post Manage Change Password
2 parents d7a6300 + 5bd9721 commit 54346f3

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_netapi32.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ def self.create_dll(dll_path = 'netapi32')
8484
['LPVOID','buffer','in']
8585
])
8686

87+
dll.add_function('NetUserChangePassword', 'DWORD', [
88+
["PWCHAR","domainname","in"],
89+
["PWCHAR","username","in"],
90+
["PWCHAR","oldpassword","in"],
91+
["PWCHAR","newpassword","in"]
92+
])
93+
8794
return dll
8895
end
8996

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
##
2+
# This module requires Metasploit: http//metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
8+
class Metasploit3 < Msf::Post
9+
10+
def initialize(info={})
11+
super(update_info(info,
12+
'Name' => "Windows Manage Change Password",
13+
'Description' => %q{
14+
This module will attempt to change the password of the targetted account.
15+
Its main purpose is when you have valid credentials on a remote host but
16+
they require a password change before you can login e.g.
17+
'System error 1907 has occurred.'
18+
},
19+
'License' => MSF_LICENSE,
20+
'Platform' => ['win'],
21+
'SessionTypes' => ['meterpreter'],
22+
'Author' => ['Ben Campbell']
23+
))
24+
25+
register_options(
26+
[
27+
OptString.new('SMBDomain', [false, 'Domain or Host to change password on, if not set will use the current login domain', nil]),
28+
OptString.new('SMBUser', [true, 'Username to change password of']),
29+
OptString.new('OLD_PASSWORD', [true, 'Original password' ]),
30+
OptString.new('NEW_PASSWORD', [true, 'New password' ]),
31+
], self.class)
32+
end
33+
34+
def run
35+
unless client.railgun
36+
print_error('This module requires a native windows payload that supports railgun.')
37+
return
38+
end
39+
40+
domain = datastore['SMBDomain']
41+
username = datastore['SMBUser']
42+
old_password = datastore['OLD_PASSWORD']
43+
new_password = datastore['NEW_PASSWORD']
44+
print_status("Changing #{domain}\\#{username} password to #{new_password}...")
45+
result = client.railgun.netapi32.NetUserChangePassword(
46+
domain,
47+
username,
48+
old_password,
49+
new_password
50+
)
51+
52+
case result['return']
53+
when 0x05
54+
err_msg = 'ERROR_ACCESS_DENIED'
55+
when 0x56
56+
err_msg = 'ERROR_INVALID_PASSWORD'
57+
when 0x92f
58+
err_msg = 'NERR_InvalidComputer'
59+
when 0x8b2
60+
err_msg = 'NERR_NotPrimary'
61+
when 0x8ad
62+
err_msg = 'NERR_UserNotFound'
63+
when 0x8c5
64+
err_msg = 'NERR_PasswordTooShort'
65+
when 0
66+
print_good('Password change successful.')
67+
else
68+
err_msg = "unknown error code: #{result['return']}"
69+
end
70+
71+
if err_msg
72+
print_error("Password change failed, #{err_msg}.")
73+
end
74+
75+
end
76+
77+
end
78+

0 commit comments

Comments
 (0)