Skip to content

Commit 2a6b367

Browse files
committed
Add connection addr+port info to http response object.
Update owa_login to use this instead of doing lookups on its own.
1 parent e9ce237 commit 2a6b367

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

lib/rex/proto/http/client.rb

Lines changed: 15 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,20 @@ 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
638+
return {
639+
'addr' => pi.split(':')[0],
640+
'port' => pi.split(':')[1].to_i
641+
}
642+
end
643+
nil
644+
end
645+
631646
#
632647
# The client request configuration
633648
#

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 & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
##
55

66
require 'rex/proto/ntlm/message'
7-
require 'rex/socket'
87

98
class MetasploitModule < Msf::Auxiliary
109
include Msf::Auxiliary::Report
@@ -94,19 +93,6 @@ def initialize
9493
deregister_options('BLANK_PASSWORDS', 'RHOSTS')
9594
end
9695

97-
def lookup_addr(host)
98-
return host if Rex::Socket.dotted_ip?(host)
99-
100-
begin
101-
addr = Rex::Socket.resolv_to_dotted(host)
102-
vprint_status("#{msg} Resolved hostname '#{host.to_s}' to address #{addr.to_s}")
103-
rescue ResolverArgumentError, Errno::ETIMEDOUT, ::NoResponseError, ::Timeout::Error => e
104-
print_error("#{msg} Failed to lookup address for #{host}, datastore persistence skipped")
105-
addr = nil
106-
end
107-
addr
108-
end
109-
11096
def setup
11197
# Here's a weird hack to check if each_user_pass is empty or not
11298
# apparently you cannot do each_user_pass.empty? or even inspect() it
@@ -211,6 +197,10 @@ def try_user_pass(opts)
211197
return
212198
end
213199

200+
if res.peerinfo['addr'] != datastore['RHOST']
201+
vprint_status("#{msg} Resolved hostname '#{datastore['RHOST']}' to address #{res.peerinfo['addr']}")
202+
end
203+
214204
if action.name != "OWA_2013" and res.get_cookies.empty?
215205
print_error("#{msg} Received invalid repsonse due to a missing cookie (possibly due to invalid version), aborting")
216206
return :abort
@@ -221,7 +211,7 @@ def try_user_pass(opts)
221211
if res.headers['location'] =~ /expiredpassword/
222212
print_good("#{msg} SUCCESSFUL LOGIN. #{elapsed_time} '#{user}' : '#{pass}': NOTE password change required")
223213
report_cred(
224-
ip: lookup_addr(datastore['RHOST']),
214+
ip: res.peerinfo['addr'],
225215
port: datastore['RPORT'],
226216
service_name: 'owa',
227217
user: user,
@@ -235,7 +225,7 @@ def try_user_pass(opts)
235225
if res.headers['location'] =~ /owa/ and res.headers['location'] !~ /reason/
236226
print_good("#{msg} SUCCESSFUL LOGIN. #{elapsed_time} '#{user}' : '#{pass}': NOTE a mailbox is not setup")
237227
report_cred(
238-
ip: lookup_addr(datastore['RHOST']),
228+
ip: res.peerinfo['addr'],
239229
port: datastore['RPORT'],
240230
service_name: 'owa',
241231
user: user,
@@ -255,7 +245,7 @@ def try_user_pass(opts)
255245
# Login didn't work. no point in going on, however, check if valid domain account by response time.
256246
if elapsed_time <= 1
257247
report_cred(
258-
ip: lookup_addr(datastore['RHOST']),
248+
ip: res.peerinfo['addr'],
259249
port: datastore['RPORT'],
260250
service_name: 'owa',
261251
user: user
@@ -301,7 +291,7 @@ def try_user_pass(opts)
301291
if res.redirect?
302292
if elapsed_time <= 1
303293
report_cred(
304-
ip: lookup_addr(datastore['RHOST']),
294+
ip: res.peerinfo['addr'],
305295
port: datastore['RPORT'],
306296
service_name: 'owa',
307297
user: user
@@ -317,7 +307,7 @@ def try_user_pass(opts)
317307
if res.body =~ login_check
318308
print_good("#{msg} SUCCESSFUL LOGIN. #{elapsed_time} '#{user}' : '#{pass}'")
319309
report_cred(
320-
ip: lookup_addr(datastore['RHOST']),
310+
ip: res.peerinfo['addr'],
321311
port: datastore['RPORT'],
322312
service_name: 'owa',
323313
user: user,
@@ -327,7 +317,7 @@ def try_user_pass(opts)
327317
else
328318
if elapsed_time <= 1
329319
report_cred(
330-
ip: lookup_addr(datastore['RHOST']),
320+
ip: res.peerinfo['addr'],
331321
port: datastore['RPORT'],
332322
service_name: 'owa',
333323
user: user

0 commit comments

Comments
 (0)