metasploit-framework/modules/auxiliary/scanner/http/rails_mass_assignment.rb

111 lines
3.4 KiB
Ruby
Raw Normal View History

2012-03-15 14:56:38 +00:00
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
# http://metasploit.com/
##
require 'rex/proto/http'
require 'msf/core'
require 'uri'
class Metasploit3 < Msf::Auxiliary
include Msf::Exploit::Remote::HttpClient
include Msf::Auxiliary::WmapScanUniqueQuery
include Msf::Auxiliary::Scanner
include Msf::Auxiliary::Report
def initialize(info = {})
super(update_info(info,
2012-03-15 21:10:05 +00:00
'Name' => 'Ruby On Rails Attributes Mass Assignment Scanner',
2012-03-15 16:21:41 +00:00
'Description' => %q{
2012-03-15 14:56:38 +00:00
This module scans Ruby On Rails sites for
models with attributes not protected by attr_protected or attr_accessible.
2012-03-15 21:10:05 +00:00
After attempting to assign a non-existent field, the default rails with
active_record setup will raise an ActiveRecord::UnknownAttributeError
exeption, and reply with HTTP code 500.
2012-03-15 14:56:38 +00:00
},
'References' =>
[
[ 'URL', 'http://guides.rubyonrails.org/security.html#mass-assignment' ]
],
'Author' => [ 'Gregory Man <man.gregory[at]gmail.com>' ],
'License' => MSF_LICENSE
))
register_options(
[
OptEnum.new('METHOD', [true, 'HTTP Method', 'POST', ['GET', 'POST'] ]),
OptString.new('PATH', [ true, "The path to test mass assignment", '/users/1']),
OptString.new('QUERY', [ false, "HTTP URI Query", nil]),
OptString.new('DATA', [ false, "HTTP Body Data", '']),
OptString.new('COOKIE',[ false, "HTTP Cookies", ''])
], self.class)
end
def run_host(ip)
case datastore['METHOD']
when 'POST'
parsed_data = queryparse(URI.unescape(datastore['DATA']))
when 'GET'
parsed_data = queryparse(URI.unescape(datastore['QUERY']))
end
data_base_params = get_base_params(parsed_data)
if data_base_params.blank?
2012-03-15 21:10:05 +00:00
vprint_error("#{ip} - Non-standart rails params schema (maybe not a RoR website)")
2012-03-15 14:56:38 +00:00
return
end
2012-03-15 21:10:05 +00:00
check_data(ip, parsed_data, data_base_params)
2012-03-15 14:56:38 +00:00
end
def get_base_params(parsed_query_string)
base_params_names = []
parsed_query_string.each do |key, val|
key.gsub(/(.*)\[(\w*)\]$/) do
base_params_names << $1
end
end
return base_params_names.uniq
end
2012-03-15 21:10:05 +00:00
def check_data(ip, parsed_data, base_params)
2012-03-15 14:56:38 +00:00
base_params.each do |param|
query = parsed_data.dup
test_param = { param + "[#{Rex::Text.rand_text_alpha(10)}]" => Rex::Text.rand_text_alpha(10) }
query.merge!(test_param)
resp = send_request_cgi({
'uri' => normalize_uri(datastore['PATH']),
2012-03-15 16:21:41 +00:00
'vars_get' => datastore['METHOD'] == 'POST' ? queryparse(datastore['QUERY'].to_s) : query,
'method' => datastore['METHOD'],
'ctype' => 'application/x-www-form-urlencoded',
'cookie' => datastore['COOKIE'],
'data' => datastore['METHOD'] == 'POST' ? query.to_query : datastore['DATA']
2012-03-15 14:56:38 +00:00
}, 20)
if resp and resp.code == 500
2012-03-15 21:10:05 +00:00
print_good("#{ip} - Possible attributes mass assignment in attribute #{param}[...] at #{datastore['PATH']}")
2012-03-15 14:56:38 +00:00
report_web_vuln(
2012-03-15 16:21:41 +00:00
:host => rhost,
:port => rport,
2012-03-15 14:56:38 +00:00
:vhost => vhost,
:ssl => ssl,
2012-03-15 16:21:41 +00:00
:path => "#{datastore['PATH']}",
2012-03-15 14:56:38 +00:00
:method => datastore['METHOD'],
:pname => param,
:proof => "rails mass assignment",
:risk => 2,
:confidence => 80,
:category => 'Rails',
:description => "Possible attributes mass assignment in attribute #{param}[...]",
:name => 'Ruby On Rails Attributes Mass Assignment'
)
end
end
end
2012-03-18 05:07:27 +00:00
end