2009-04-02 04:31:48 +00:00
|
|
|
##
|
2010-04-30 08:40:19 +00:00
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2009-04-02 04:31:48 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2009-04-13 14:33:26 +00:00
|
|
|
# http://metasploit.com/framework/
|
2009-04-02 04:31:48 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
include Msf::Auxiliary::Scanner
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-04-02 04:31:48 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
2010-05-27 21:19:53 +00:00
|
|
|
'Name' => 'SIP Username Enumerator (UDP)',
|
2009-11-17 00:05:19 +00:00
|
|
|
'Version' => '$Revision$',
|
2009-04-02 04:31:48 +00:00
|
|
|
'Description' => 'Scan for numeric username/extensions using OPTIONS/REGISTER requests',
|
|
|
|
'Author' => 'et',
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptInt.new('BATCHSIZE', [true, 'The number of hosts to probe in each set', 256]),
|
|
|
|
OptInt.new('MINEXT', [true, 'Starting extension',0]),
|
|
|
|
OptInt.new('MAXEXT', [true, 'Ending extension', 9999]),
|
|
|
|
OptInt.new('PADLEN', [true, 'Cero padding maximum length', 4]),
|
2010-04-30 08:40:19 +00:00
|
|
|
OptString.new('METHOD', [true, 'Enumeration method to use OPTIONS/REGISTER','REGISTER']),
|
2009-04-02 04:31:48 +00:00
|
|
|
Opt::RPORT(5060),
|
2010-02-09 16:47:38 +00:00
|
|
|
Opt::CHOST,
|
2009-04-02 04:31:48 +00:00
|
|
|
Opt::CPORT(5060)
|
2010-04-30 08:40:19 +00:00
|
|
|
], self.class)
|
2009-04-02 04:31:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Define our batch size
|
|
|
|
def run_batch_size
|
|
|
|
datastore['BATCHSIZE'].to_i
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-04-02 04:31:48 +00:00
|
|
|
# Operate on an entire batch of hosts at once
|
|
|
|
def run_batch(batch)
|
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
begin
|
2009-04-02 04:31:48 +00:00
|
|
|
udp_sock = nil
|
|
|
|
idx = 0
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2010-02-09 16:47:38 +00:00
|
|
|
# Create an unbound UDP socket if no CHOST is specified, otherwise
|
|
|
|
# create a UDP socket bound to CHOST (in order to avail of pivoting)
|
2010-04-30 08:40:19 +00:00
|
|
|
udp_sock = Rex::Socket::Udp.create(
|
2010-02-09 16:47:38 +00:00
|
|
|
{
|
|
|
|
'LocalHost' => datastore['CHOST'] || nil,
|
2010-05-01 16:26:24 +00:00
|
|
|
'LocalPort' => datastore['CPORT'].to_i,
|
|
|
|
'Context' => { 'Msf' => framework, 'MsfExploit' => self }
|
2010-02-09 16:47:38 +00:00
|
|
|
}
|
|
|
|
)
|
2010-05-01 16:26:24 +00:00
|
|
|
add_socket(udp_sock)
|
2009-04-02 04:31:48 +00:00
|
|
|
|
|
|
|
mini = datastore['MINEXT']
|
|
|
|
maxi = datastore['MAXEXT']
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-04-02 04:31:48 +00:00
|
|
|
batch.each do |ip|
|
|
|
|
for i in (mini..maxi)
|
|
|
|
testext = padnum(i,datastore['PADLEN'])
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-04-02 04:31:48 +00:00
|
|
|
case datastore['METHOD']
|
|
|
|
when 'REGISTER'
|
|
|
|
data = create_probe(ip,testext,'REGISTER')
|
2010-04-30 08:40:19 +00:00
|
|
|
when 'OPTIONS'
|
2009-04-02 04:31:48 +00:00
|
|
|
data = create_probe(ip,testext,'OPTIONS')
|
|
|
|
else
|
|
|
|
print_error("Method not found.")
|
2010-04-30 08:40:19 +00:00
|
|
|
return
|
2009-04-02 04:31:48 +00:00
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-04-02 04:31:48 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
udp_sock.sendto(data, ip, datastore['RPORT'].to_i, 0)
|
|
|
|
rescue ::Interrupt
|
|
|
|
raise $!
|
|
|
|
rescue ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionRefused
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if (idx % 10 == 0)
|
|
|
|
while (r = udp_sock.recvfrom(65535, 0.01) and r[1])
|
|
|
|
parse_reply(r,datastore['METHOD'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
idx += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
while (r = udp_sock.recvfrom(65535, 3) and r[1])
|
|
|
|
parse_reply(r,datastore['METHOD'])
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-04-02 04:31:48 +00:00
|
|
|
rescue ::Interrupt
|
|
|
|
raise $!
|
|
|
|
rescue ::Exception => e
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("Unknown error: #{e.class} #{e}")
|
2009-04-02 04:31:48 +00:00
|
|
|
ensure
|
|
|
|
udp_sock.close if udp_sock
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# The response parsers
|
|
|
|
#
|
|
|
|
def parse_reply(pkt,meth)
|
|
|
|
|
|
|
|
return if not pkt[1]
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-04-02 04:31:48 +00:00
|
|
|
if(pkt[1] =~ /^::ffff:/)
|
|
|
|
pkt[1] = pkt[1].sub(/^::ffff:/, '')
|
|
|
|
end
|
|
|
|
|
|
|
|
resp = pkt[0].split(/\s+/)[1]
|
2010-04-30 08:40:19 +00:00
|
|
|
repcode = ''
|
2009-04-02 04:31:48 +00:00
|
|
|
agent = ''
|
|
|
|
verbs = ''
|
|
|
|
serv = ''
|
2010-04-30 08:40:19 +00:00
|
|
|
prox = ''
|
|
|
|
|
2009-04-02 04:31:48 +00:00
|
|
|
if(pkt[0] =~ /^To\:\s*(.*)$/i)
|
|
|
|
testn = "#{$1.strip}".split(';')[0]
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-04-02 04:31:48 +00:00
|
|
|
case resp.to_i
|
2010-04-30 08:40:19 +00:00
|
|
|
when 401
|
2009-04-02 04:31:48 +00:00
|
|
|
print_status("Found user: #{testn} [Auth]")
|
2010-06-17 14:03:53 +00:00
|
|
|
#Add Report
|
|
|
|
report_note(
|
|
|
|
:host => rhost,
|
2011-02-04 01:54:32 +00:00
|
|
|
:proto => 'udp',
|
2011-02-22 20:49:44 +00:00
|
|
|
:sname => 'sip',
|
2010-06-17 14:03:53 +00:00
|
|
|
:port => rport,
|
|
|
|
:type => "Found user: #{testn} [Auth]",
|
|
|
|
:data => "Found user: #{testn} [Auth]"
|
|
|
|
)
|
2010-04-30 08:40:19 +00:00
|
|
|
when 200
|
2009-04-02 04:31:48 +00:00
|
|
|
print_status("Found user: #{testn} [Open]")
|
2010-06-17 14:03:53 +00:00
|
|
|
#Add Report
|
|
|
|
report_note(
|
|
|
|
:host => rhost,
|
2011-02-04 01:54:32 +00:00
|
|
|
:proto => 'udp',
|
2011-02-22 20:49:44 +00:00
|
|
|
:sname => 'sip',
|
2010-06-17 14:03:53 +00:00
|
|
|
:port => rport,
|
|
|
|
:type => "Found user: #{testn} [Open]",
|
|
|
|
:data => "Found user: #{testn} [Open]"
|
|
|
|
)
|
2009-04-02 04:31:48 +00:00
|
|
|
else
|
2010-04-30 08:40:19 +00:00
|
|
|
#print_error("Undefined error code: #{resp.to_i}"
|
2009-04-02 04:31:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_probe(ip,toext,meth)
|
|
|
|
suser = Rex::Text.rand_text_alphanumeric(rand(8)+1)
|
|
|
|
shost = Rex::Socket.source_address(ip)
|
|
|
|
src = "#{shost}:#{datastore['CPORT']}"
|
|
|
|
|
|
|
|
data = "#{meth} sip:#{toext}@#{ip} SIP/2.0\r\n"
|
|
|
|
data << "Via: SIP/2.0/UDP #{src};branch=z9hG4bK.#{"%.8x" % rand(0x100000000)};rport;alias\r\n"
|
|
|
|
data << "From: #{toext} <sip:#{suser}@#{src}>;tag=70c00e8c\r\n"
|
|
|
|
data << "To: #{toext} <sip:#{toext}@#{ip}>\r\n"
|
|
|
|
data << "Call-ID: #{rand(0x100000000)}@#{shost}\r\n"
|
|
|
|
data << "CSeq: 1 #{meth}\r\n"
|
|
|
|
data << "Contact: <sip:#{suser}@#{src}>\r\n"
|
|
|
|
data << "Content-Length: 0\r\n"
|
|
|
|
data << "Max-Forwards: 20\r\n"
|
|
|
|
data << "User-Agent: #{suser}\r\n"
|
|
|
|
data << "Accept: text/plain\r\n"
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-04-02 04:31:48 +00:00
|
|
|
def padnum(num,padding)
|
2010-04-30 08:40:19 +00:00
|
|
|
if padding >= num.to_s.length
|
2009-04-02 04:31:48 +00:00
|
|
|
('0'*(padding-num.to_s.length)) << num.to_s
|
2010-04-30 08:40:19 +00:00
|
|
|
end
|
|
|
|
end
|
2009-04-02 04:31:48 +00:00
|
|
|
end
|
2010-05-01 16:26:24 +00:00
|
|
|
|