Skip to content

Commit d060312

Browse files
authored
Merge pull request rapid7#19666 from smashery/smb_change_pw
Change/Reset passwords over SMB
2 parents b31d3e3 + 8b93f1a commit d060312

File tree

5 files changed

+358
-10
lines changed

5 files changed

+358
-10
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ GEM
499499
ruby-progressbar (1.13.0)
500500
ruby-rc4 (0.1.5)
501501
ruby2_keywords (0.0.5)
502-
ruby_smb (3.3.11)
502+
ruby_smb (3.3.13)
503503
bindata (= 2.4.15)
504504
openssl-ccm
505505
openssl-cmac

LICENSE_GEMS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ ruby-prof, 1.4.2, "Simplified BSD"
181181
ruby-progressbar, 1.13.0, MIT
182182
ruby-rc4, 0.1.5, MIT
183183
ruby2_keywords, 0.0.5, "ruby, Simplified BSD"
184-
ruby_smb, 3.3.11, "New BSD"
184+
ruby_smb, 3.3.13, "New BSD"
185185
rubyntlm, 0.6.5, MIT
186186
rubyzip, 2.3.2, "Simplified BSD"
187187
sawyer, 0.9.2, MIT
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Introduction
2+
3+
Allows changing or resetting users' passwords.
4+
5+
"Changing" refers to situations where you know the value of the existing password, and send that to the server as part of the password modification.
6+
"Resetting" refers to situations where you may not know the value of the existing password, but by virtue of your permissions over the target account, you can force-change the password without necessarily knowing it.
7+
8+
Note that users can typically not reset their own passwords (unless they have very high privileges).
9+
10+
This module works with existing sessions (or relaying), especially for Reset use cases, wherein the target's password is not required.
11+
12+
## Actions
13+
14+
- `RESET` - Reset the target's password without knowing the existing one (requires appropriate permissions). New AES kerberos keys will be generated.
15+
- `RESET_NTLM` - Reset the target's NTLM hash, without knowing the existing password. AES kerberos authentication will not work until a standard password change occurs.
16+
- `CHANGE` - Change the password, knowing the existing one. New AES kerberos keys will be generated.
17+
- `CHANGE_NTLM` - Change the password to a NTLM hash value, knowing the existing password. AES kerberos authentication will not work until a standard password change occurs.
18+
19+
## Options
20+
21+
The required options are based on the action being performed:
22+
23+
- When resetting a password, you must specify the `TARGET_USER`
24+
- When changing a password, you must specify the `SMBUser` and `SMBPass`, even if using an existing session (since the API requires both of these to be specified, even for open SMB sessions)
25+
- When resetting or changing a password, you must specify `NEW_PASSWORD`
26+
- When resetting or changing an NTLM hash, you must specify `NEW_NTLM`
27+
28+
**SMBUser**
29+
30+
The username to use to authenticate to the server. Required for changing a password, even if using an existing session.
31+
32+
**SMBPass**
33+
34+
The password to use to authenticate to the server, prior to performing the password modification. Required for changing a password, even if using an existing session (since the server requires proof that you know the existing password).
35+
36+
**TARGET_USER**
37+
38+
For resetting passwords, the user account for which to reset the password. The authenticated account (SMBUser) must have privileges over the target user (e.g. Ownership, or the `User-Force-Change-Password` extended right)
39+
40+
**NEW_PASSWORD**
41+
42+
The new password to set for `RESET` and `CHANGE` actions.
43+
44+
**NEW_NTLM**
45+
46+
The new NTLM hash to set for `RESET_NTLM` and `CHANGE_NTLM` actions. This can either be an NT hash, or a colon-delimited NTLM hash.

lib/msf/core/exploit/remote/smb/client.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,19 @@ def unicode(str)
149149
# You should call {#connect} before calling this
150150
#
151151
# @param simple_client [Rex::Proto::SMB::SimpleClient] Optional SimpleClient instance to use
152+
# @param opts [Hash] Options to override the datastore options
153+
# @option :username [String] Override SMBUser datastore option
154+
# @option :domain [String] Override SMBDomain datastore option
155+
# @option :password [String] Override SMBPass datastore option
156+
# @option :auth_protocol [String] Override SMB::Auth datastore option
152157
# @return [void]
153-
def smb_login(simple_client = self.simple)
158+
def smb_login(simple_client = self.simple, opts: {})
159+
username = opts.fetch(:username) {datastore['SMBUser']}
160+
domain = opts.fetch(:domain) {datastore['SMBDomain']}
161+
password = opts.fetch(:password) {datastore['SMBPass']}
162+
smb_auth = opts.fetch(:auth_protocol) {datastore['SMB::Auth']}
154163
# Override the default RubySMB capabilities with Kerberos authentication
155-
if datastore['SMB::Auth'] == Msf::Exploit::Remote::AuthOption::KERBEROS
164+
if smb_auth == Msf::Exploit::Remote::AuthOption::KERBEROS
156165
fail_with(Msf::Exploit::Failure::BadConfig, 'The Smb::Rhostname option is required when using Kerberos authentication.') if datastore['Smb::Rhostname'].blank?
157166
fail_with(Msf::Exploit::Failure::BadConfig, 'The SMBDomain option is required when using Kerberos authentication.') if datastore['SMBDomain'].blank?
158167
offered_etypes = Msf::Exploit::Remote::AuthOption.as_default_offered_etypes(datastore['Smb::KrbOfferedEncryptionTypes'])
@@ -162,9 +171,9 @@ def smb_login(simple_client = self.simple)
162171
host: datastore['DomainControllerRhost'].blank? ? nil : datastore['DomainControllerRhost'],
163172
hostname: datastore['Smb::Rhostname'],
164173
proxies: datastore['Proxies'],
165-
realm: datastore['SMBDomain'],
166-
username: datastore['SMBUser'],
167-
password: datastore['SMBPass'],
174+
realm: domain,
175+
username: username,
176+
password: password,
168177
framework: framework,
169178
framework_module: self,
170179
cache_file: datastore['Smb::Krb5Ccname'].blank? ? nil : datastore['Smb::Krb5Ccname'],
@@ -178,9 +187,9 @@ def smb_login(simple_client = self.simple)
178187

179188
simple_client.login(
180189
datastore['SMBName'],
181-
datastore['SMBUser'],
182-
datastore['SMBPass'],
183-
datastore['SMBDomain'],
190+
username,
191+
password,
192+
domain,
184193
datastore['SMB::VerifySignature'],
185194
datastore['NTLM::UseNTLMv2'],
186195
datastore['NTLM::UseNTLM2_session'],

0 commit comments

Comments
 (0)