Skip to content

Commit 10fde42

Browse files
committed
Land rapid7#9431, Fix owa_login to handle inserting credentials for a hostname
2 parents b12953f + ba75d19 commit 10fde42

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

lib/rex/proto/http/client.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def _send_recv(req, t = -1, persist=false)
229229
send_request(req, t)
230230
res = read_response(t)
231231
res.request = req.to_s if res
232+
res.peerinfo = peerinfo if res
232233
res
233234
end
234235

@@ -628,6 +629,22 @@ def pipelining?
628629
pipeline
629630
end
630631

632+
#
633+
# Target host addr and port for this connection
634+
#
635+
def peerinfo
636+
if self.conn
637+
pi = self.conn.peerinfo || nil
638+
if pi
639+
return {
640+
'addr' => pi.split(':')[0],
641+
'port' => pi.split(':')[1].to_i
642+
}
643+
end
644+
end
645+
nil
646+
end
647+
631648
#
632649
# The client request configuration
633650
#

lib/rex/proto/http/response.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ def cmd_string
238238
#
239239
attr_accessor :request
240240

241+
#
242+
# Host address:port associated with this request/response
243+
#
244+
attr_accessor :peerinfo
241245

242246
attr_accessor :code
243247
attr_accessor :message

modules/auxiliary/scanner/http/owa_login.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ def try_user_pass(opts)
197197
return
198198
end
199199

200+
if res.peerinfo['addr'] != datastore['RHOST']
201+
vprint_status("#{msg} Resolved hostname '#{datastore['RHOST']}' to address #{res.peerinfo['addr']}")
202+
end
203+
200204
if action.name != "OWA_2013" and res.get_cookies.empty?
201205
print_error("#{msg} Received invalid repsonse due to a missing cookie (possibly due to invalid version), aborting")
202206
return :abort
@@ -207,7 +211,7 @@ def try_user_pass(opts)
207211
if res.headers['location'] =~ /expiredpassword/
208212
print_good("#{msg} SUCCESSFUL LOGIN. #{elapsed_time} '#{user}' : '#{pass}': NOTE password change required")
209213
report_cred(
210-
ip: datastore['RHOST'],
214+
ip: res.peerinfo['addr'],
211215
port: datastore['RPORT'],
212216
service_name: 'owa',
213217
user: user,
@@ -221,7 +225,7 @@ def try_user_pass(opts)
221225
if res.headers['location'] =~ /owa/ and res.headers['location'] !~ /reason/
222226
print_good("#{msg} SUCCESSFUL LOGIN. #{elapsed_time} '#{user}' : '#{pass}': NOTE a mailbox is not setup")
223227
report_cred(
224-
ip: datastore['RHOST'],
228+
ip: res.peerinfo['addr'],
225229
port: datastore['RPORT'],
226230
service_name: 'owa',
227231
user: user,
@@ -241,7 +245,7 @@ def try_user_pass(opts)
241245
# Login didn't work. no point in going on, however, check if valid domain account by response time.
242246
if elapsed_time <= 1
243247
report_cred(
244-
ip: datastore['RHOST'],
248+
ip: res.peerinfo['addr'],
245249
port: datastore['RPORT'],
246250
service_name: 'owa',
247251
user: user
@@ -287,7 +291,7 @@ def try_user_pass(opts)
287291
if res.redirect?
288292
if elapsed_time <= 1
289293
report_cred(
290-
ip: datastore['RHOST'],
294+
ip: res.peerinfo['addr'],
291295
port: datastore['RPORT'],
292296
service_name: 'owa',
293297
user: user
@@ -303,7 +307,7 @@ def try_user_pass(opts)
303307
if res.body =~ login_check
304308
print_good("#{msg} SUCCESSFUL LOGIN. #{elapsed_time} '#{user}' : '#{pass}'")
305309
report_cred(
306-
ip: datastore['RHOST'],
310+
ip: res.peerinfo['addr'],
307311
port: datastore['RPORT'],
308312
service_name: 'owa',
309313
user: user,
@@ -313,7 +317,7 @@ def try_user_pass(opts)
313317
else
314318
if elapsed_time <= 1
315319
report_cred(
316-
ip: datastore['RHOST'],
320+
ip: res.peerinfo['addr'],
317321
port: datastore['RPORT'],
318322
service_name: 'owa',
319323
user: user

spec/lib/rex/proto/http/client_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def excuse_needs_auth
119119
it "should send creds after receiving a 401" do
120120
conn = double
121121
allow(conn).to receive(:put)
122+
allow(conn).to receive(:peerinfo)
122123
allow(conn).to receive(:shutdown)
123124
allow(conn).to receive(:close)
124125
allow(conn).to receive(:closed?).and_return(false)

0 commit comments

Comments
 (0)