@@ -98,7 +98,7 @@ def check_login_status(domain, user, pass)
98
98
connect ( )
99
99
status_code = ""
100
100
begin
101
- if simple . login ( datastore [ 'SMBName' ] ,
101
+ simple . login ( datastore [ 'SMBName' ] ,
102
102
user ,
103
103
pass ,
104
104
domain ,
@@ -110,10 +110,11 @@ def check_login_status(domain, user, pass)
110
110
datastore [ 'NTLM::SendNTLM' ] ,
111
111
datastore [ 'SMB::Native_OS' ] ,
112
112
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'
117
118
rescue ::Rex ::Proto ::SMB ::Exceptions ::ErrorCode => e
118
119
status_code = e . get_error ( e . error_code )
119
120
rescue ::Rex ::Proto ::SMB ::Exceptions ::LoginError => e
@@ -125,16 +126,16 @@ def check_login_status(domain, user, pass)
125
126
return status_code
126
127
end
127
128
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.
129
131
def accepts_guest_logins?
130
132
guest = false
131
133
user = Rex ::Text . rand_text_alpha ( 8 )
132
134
pass = Rex ::Text . rand_text_alpha ( 8 )
133
135
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
138
139
@accepts_guest_logins [ 'rhost' ] ||=[ ] unless @accepts_guest_logins . include? ( rhost )
139
140
report_note (
140
141
:host => rhost ,
@@ -147,14 +148,16 @@ def accepts_guest_logins?
147
148
)
148
149
end
149
150
150
- return guest
151
+ return guest_login
151
152
end
152
153
154
+ # If login is successul and auth_user is set
155
+ # then bogus creds are accepted.
153
156
def accepts_bogus_logins?
154
157
user = Rex ::Text . rand_text_alpha ( 8 )
155
158
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
158
161
end
159
162
160
163
# 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)
186
189
end
187
190
188
191
user = user . to_s . gsub ( /<BLANK>/i , "" )
189
-
190
192
status = check_login_status ( domain , user , pass )
191
-
192
193
output_message = "#{ smbhost } - %s (#{ smb_peer_os } ) #{ user } : #{ pass } [#{ status } ]"
193
194
194
195
case status
195
196
when 'STATUS_SUCCESS'
196
-
197
197
if ( simple . client . auth_user )
198
198
print_good ( output_message % "SUCCESSFUL LOGIN" )
199
199
vprint_status ( "Auth-User: #{ simple . client . auth_user } " )
0 commit comments