Skip to content

Commit 5377144

Browse files
committed
Reimplemented tree connect to verify nix samba logins correctly, and fixed accepts_guest_logins() and accepts_bogus_logins()
1 parent 28b9412 commit 5377144

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

modules/auxiliary/scanner/smb/smb_login.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def check_login_status(domain, user, pass)
9898
connect()
9999
status_code = ""
100100
begin
101-
if simple.login( datastore['SMBName'],
101+
simple.login( datastore['SMBName'],
102102
user,
103103
pass,
104104
domain,
@@ -110,10 +110,11 @@ def check_login_status(domain, user, pass)
110110
datastore['NTLM::SendNTLM'],
111111
datastore['SMB::Native_OS'],
112112
datastore['SMB::Native_LM'],
113-
{:use_spn => datastore['NTLM::SendSPN'], :name => self.rhost})
114-
status_code = 'STATUS_SUCCESS'
115-
end
116-
# This does not appear to be required to validate login details? simple.connect("\\\\#{datastore['RHOST']}\\IPC$")
113+
{:use_spn => datastore['NTLM::SendSPN'], :name => self.rhost})
114+
115+
# Windows SMB will return an error code during Session Setup, but nix Samba requires a Tree Connect:
116+
simple.connect("\\\\#{datastore['RHOST']}\\IPC$")
117+
status_code = 'STATUS_SUCCESS'
117118
rescue ::Rex::Proto::SMB::Exceptions::ErrorCode => e
118119
status_code = e.get_error(e.error_code)
119120
rescue ::Rex::Proto::SMB::Exceptions::LoginError => e
@@ -125,16 +126,16 @@ def check_login_status(domain, user, pass)
125126
return status_code
126127
end
127128

128-
# Unsure how this result is different than bogus logins
129+
# If login is succesful and auth_user is unset
130+
# the login was as a guest user.
129131
def accepts_guest_logins?
130132
guest = false
131133
user = Rex::Text.rand_text_alpha(8)
132134
pass = Rex::Text.rand_text_alpha(8)
133135

134-
check_login_status(datastore['SMBDomain'], user, pass)
135-
136-
unless(simple.client.auth_user)
137-
guest = true
136+
guest_login = ((check_login_status(datastore['SMBDomain'], user, pass) == 'STATUS_SUCCESS') && simple.client.auth_user.nil?)
137+
138+
if guest_login
138139
@accepts_guest_logins['rhost'] ||=[] unless @accepts_guest_logins.include?(rhost)
139140
report_note(
140141
:host => rhost,
@@ -147,14 +148,16 @@ def accepts_guest_logins?
147148
)
148149
end
149150

150-
return guest
151+
return guest_login
151152
end
152153

154+
# If login is successul and auth_user is set
155+
# then bogus creds are accepted.
153156
def accepts_bogus_logins?
154157
user = Rex::Text.rand_text_alpha(8)
155158
pass = Rex::Text.rand_text_alpha(8)
156-
check_login_status(datastore['SMBDomain'], user, pass)
157-
return simple.client.auth_user ? true : false
159+
bogus_login = ((check_login_status(datastore['SMBDomain'], user, pass) == 'STATUS_SUCCESS') && !simple.client.auth_user.nil?)
160+
return bogus_login
158161
end
159162

160163
# This logic is not universal ie a local account will not care about workgroup
@@ -186,14 +189,11 @@ def try_user_pass(domain, user, pass)
186189
end
187190

188191
user = user.to_s.gsub(/<BLANK>/i,"")
189-
190192
status = check_login_status(domain, user, pass)
191-
192193
output_message = "#{smbhost} - %s (#{smb_peer_os}) #{user} : #{pass} [#{status}]"
193194

194195
case status
195196
when 'STATUS_SUCCESS'
196-
197197
if(simple.client.auth_user)
198198
print_good(output_message % "SUCCESSFUL LOGIN")
199199
vprint_status("Auth-User: #{simple.client.auth_user}")

0 commit comments

Comments
 (0)