Skip to content

Commit 02211db

Browse files
committed
Land rapid7#8412, fix for smb_login errors
Merge branch 'land-8412' into upstream-master
2 parents 1af6c08 + 94e4dc2 commit 02211db

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ GEM
343343
rspec-mocks (~> 3.6.0)
344344
rspec-support (~> 3.6.0)
345345
rspec-support (3.6.0)
346-
ruby_smb (0.0.12)
346+
ruby_smb (0.0.14)
347347
bindata
348348
rubyntlm
349349
windows_error

lib/metasploit/framework/login_scanner/smb.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,21 @@ def attempt_login(credential)
100100
client = RubySMB::Client.new(self.dispatcher, username: username, password: password, domain: realm)
101101
status_code = client.login
102102

103-
# Windows SMB will return an error code during Session
104-
# Setup, but nix Samba requires a Tree Connect. Try admin$
105-
# first, since that will tell us if this user has local
106-
# admin access. Fall back to IPC$ which should be accessible
107-
# to any user with valid creds.
108-
begin
109-
tree = client.tree_connect("\\\\#{host}\\admin$")
110-
# Check to make sure we can write a file to this dir
111-
if tree.permissions.add_file == 1
112-
access_level = AccessLevels::ADMINISTRATOR
103+
if status_code == WindowsError::NTStatus::STATUS_SUCCESS
104+
# Windows SMB will return an error code during Session
105+
# Setup, but nix Samba requires a Tree Connect. Try admin$
106+
# first, since that will tell us if this user has local
107+
# admin access. Fall back to IPC$ which should be accessible
108+
# to any user with valid creds.
109+
begin
110+
tree = client.tree_connect("\\\\#{host}\\admin$")
111+
# Check to make sure we can write a file to this dir
112+
if tree.permissions.add_file == 1
113+
access_level = AccessLevels::ADMINISTRATOR
114+
end
115+
rescue Exception => e
116+
client.tree_connect("\\\\#{host}\\IPC$")
113117
end
114-
rescue Exception => e
115-
client.tree_connect("\\\\#{host}\\IPC$")
116118
end
117119

118120
case status_code.name

0 commit comments

Comments
 (0)