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

269 lines
6.6 KiB
Ruby
Raw Normal View History

2009-12-30 22:24:22 +00:00
##
# $Id$
##
##
# This file is part of the Metasploit Framework and may be subject to
2009-12-30 22:24:22 +00:00
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/framework/
##
require 'rex/proto/http'
require 'msf/core'
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,
2009-12-30 22:24:22 +00:00
'Name' => 'HTTP Error Based SQL Injection Scanner',
'Description' => %q{
This module identifies the existence of Error Based SQL injection issues. Still requires alot of work
2009-12-30 22:24:22 +00:00
},
'Author' => [ 'et [at] cyberspace.org' ],
'License' => BSD_LICENSE,
'Version' => '$Revision$'))
2009-12-30 22:24:22 +00:00
register_options(
[
OptString.new('METHOD', [ true, "HTTP Method",'GET']),
OptString.new('PATH', [ true, "The path/file to test SQL injection", '/default.aspx']),
OptString.new('QUERY', [ false, "HTTP URI Query", '']),
OptString.new('DATA', [ false, "HTTP Body/Data Query", ''])
2009-12-30 22:24:22 +00:00
], self.class)
2009-12-30 22:24:22 +00:00
register_advanced_options(
[
OptBool.new('NoDetailMessages', [ false, "Do not display detailed test messages", true ])
], self.class)
2009-12-30 22:24:22 +00:00
end
def run_host(ip)
2011-02-04 05:57:26 +00:00
qvars = nil
2009-12-30 22:24:22 +00:00
sqlinj = [
[ "'" ,'Single quote'],
[ "')",'Single quote and parenthesis'],
[ "\"",'Double quote'],
[ "%u0027",'unicode single quote'],
[ "%u02b9",'unicode single quote'],
[ "%u02bc",'unicode single quote'],
[ "%u02c8",'unicode single quote'],
[ "%c0%27",'unicode single quote'],
[ "%c0%a7",'unicode single quote'],
[ "%e0%80%a7",'unicode single quote'],
[ "#{rand(10)}'", 'Random value with single quote']
2009-12-30 22:24:22 +00:00
]
2009-12-30 22:24:22 +00:00
errorstr = [
["Unclosed quotation mark after the character string",'MSSQL','string'],
["Syntax error in string in query expression",'MSSQL','string'],
["Microsoft OLE DB Provider",'MSSQL','unknown'],
["You have an error in your SQL syntax",'MySQL','unknown'],
2011-02-04 05:57:26 +00:00
["java.sql.SQLException",'unknown','unknown'],
["ORA-",'ORACLE','unknown'],
["PLS-",'ORACLE','unknown'],
["Syntax error",'unknown','unknown'],
2009-12-30 22:24:22 +00:00
]
2009-12-30 22:24:22 +00:00
#
# Dealing with empty query/data and making them hashes.
#
2011-02-22 20:49:44 +00:00
if datastore['METHOD'] =='GET'
if not datastore['QUERY'].empty?
qvars = queryparse(datastore['QUERY']) #Now its a Hash
else
return
end
2009-12-30 22:24:22 +00:00
else
if not datastore['DATA'].empty?
qvars = queryparse(datastore['DATA']) #Now its a Hash
else
return
2011-02-22 20:49:44 +00:00
end
2009-12-30 22:24:22 +00:00
end
#
# Send normal request to check if error is generated
2009-12-30 22:24:22 +00:00
# (means the error is caused by other means)
#
#
2011-02-04 05:57:26 +00:00
if datastore['METHOD'] == 'POST'
reqinfo = {
'uri' => datastore['PATH'],
'query' => datastore['QUERY'],
'data' => datastore['DATA'],
2011-02-04 05:57:26 +00:00
'method' => datastore['METHOD'],
'ctype' => 'application/x-www-form-urlencoded',
'encode' => false
2011-02-04 05:57:26 +00:00
}
else
reqinfo = {
'uri' => datastore['PATH'],
'query' => datastore['QUERY'],
'method' => datastore['METHOD'],
'ctype' => 'application/x-www-form-urlencoded',
'encode' => false
2011-02-04 05:57:26 +00:00
}
end
2011-02-22 20:49:44 +00:00
2011-02-04 05:57:26 +00:00
begin
normalres = send_request_raw(reqinfo, 20)
2009-12-30 22:24:22 +00:00
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
rescue ::Timeout::Error, ::Errno::EPIPE
2009-12-30 22:24:22 +00:00
end
2009-12-30 22:24:22 +00:00
if !datastore['NoDetailMessages']
print_status("Normal request sent.")
2009-12-30 22:24:22 +00:00
end
2009-12-30 22:24:22 +00:00
found = false
inje = nil
dbt = nil
injt = nil
2009-12-30 22:24:22 +00:00
if normalres
errorstr.each do |estr,dbtype,injtype|
if normalres.body.include? estr
found = true
inje = estr
dbt = dbtype
injt = injtype
2009-12-30 22:24:22 +00:00
end
end
2009-12-30 22:24:22 +00:00
if found
print_error("[#{wmap_target_host}] Error string appears in the normal response, unable to test")
print_error("[#{wmap_target_host}] Error string: '#{inje}'")
2009-12-30 22:24:22 +00:00
print_error("[#{wmap_target_host}] DB TYPE: #{dbt}, Error type '#{injt}'")
2009-12-30 22:24:22 +00:00
report_note(
:host => ip,
2011-02-04 05:57:26 +00:00
:proto => 'tcp',
:sname => 'HTTP',
2009-12-30 22:24:22 +00:00
:port => rport,
:type => 'DATABASE_ERROR',
:data => "#{datastore['PATH']} Error: #{inje} DB: #{dbt}"
)
2009-12-30 22:24:22 +00:00
return
end
else
print_error("[#{wmap_target_host}] No response")
return
2009-12-30 22:24:22 +00:00
end
2009-12-30 22:24:22 +00:00
#
# Test URI Query parameters
#
2009-12-30 22:24:22 +00:00
found = false
2011-02-04 05:57:26 +00:00
if qvars
2009-12-30 22:24:22 +00:00
sqlinj.each do |istr,idesc|
if found
break
2009-12-30 22:24:22 +00:00
end
2011-02-04 05:57:26 +00:00
qvars.each do |key,value|
if datastore['METHOD'] == 'POST'
qvars = queryparse(datastore['DATA']) #Now its a Hash
else
qvars = queryparse(datastore['QUERY']) #Now its a Hash
end
2011-02-04 05:57:26 +00:00
qvars[key] = qvars[key]+istr
2009-12-30 22:24:22 +00:00
if !datastore['NoDetailMessages']
print_status("- Testing query with #{idesc}. Parameter #{key}:")
2009-12-30 22:24:22 +00:00
end
2011-02-22 20:49:44 +00:00
fstr = ""
2011-02-22 20:49:44 +00:00
qvars.each_pair do |var,val|
fstr += var+"="+val+"&"
end
2011-02-22 20:49:44 +00:00
2011-02-04 05:57:26 +00:00
if datastore['METHOD'] == 'POST'
reqinfo = {
'uri' => datastore['PATH'],
'query' => datastore['QUERY'],
'data' => fstr,
2011-02-04 05:57:26 +00:00
'method' => datastore['METHOD'],
'ctype' => 'application/x-www-form-urlencoded',
'encode' => false
2011-02-04 05:57:26 +00:00
}
2009-12-30 22:24:22 +00:00
else
2011-02-04 05:57:26 +00:00
reqinfo = {
'uri' => datastore['PATH'],
'query' => fstr,
2011-02-04 05:57:26 +00:00
'method' => datastore['METHOD'],
'ctype' => 'application/x-www-form-urlencoded',
'encode' => false
2011-02-04 05:57:26 +00:00
}
2009-12-30 22:24:22 +00:00
end
2009-12-30 22:24:22 +00:00
begin
2011-02-22 20:49:44 +00:00
testres = send_request_raw(reqinfo, 20)
2009-12-30 22:24:22 +00:00
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
rescue ::Timeout::Error, ::Errno::EPIPE
2009-12-30 22:24:22 +00:00
end
if testres
errorstr.each do |estr,dbtype,injtype|
if testres.body.include? estr
found = true
inje = estr
dbt = dbtype
injt = injtype
2009-12-30 22:24:22 +00:00
end
end
2009-12-30 22:24:22 +00:00
if found
print_status("[#{wmap_target_host}] SQL Injection found. (#{idesc}) (#{datastore['PATH']})")
2011-02-04 05:57:26 +00:00
print_status("[#{wmap_target_host}] Error string: '#{inje}' Test Value: #{qvars[key]}")
print_status("[#{wmap_target_host}] Vuln query parameter: #{key} DB TYPE: #{dbt}, Error type '#{injt}'")
2009-12-30 22:24:22 +00:00
report_note(
:host => ip,
2011-02-04 05:57:26 +00:00
:proto => 'tcp',
:sname => 'HTTP',
2009-12-30 22:24:22 +00:00
:port => rport,
:type => 'SQL_INJECTION',
2011-02-04 05:57:26 +00:00
:data => "#{datastore['PATH']} Location: QUERY Parameter: #{key} Value: #{istr} Error: #{inje} DB: #{dbt}"
2009-12-30 22:24:22 +00:00
)
2011-02-04 05:57:26 +00:00
return
2009-12-30 22:24:22 +00:00
end
else
print_error("[#{wmap_target_host}] No response")
2009-12-30 22:24:22 +00:00
return
end
end
end
2011-02-22 20:49:44 +00:00
if datastore['METHOD'] == 'POST'
qvars = queryparse(datastore['DATA']) #Now its a Hash
else
qvars = queryparse(datastore['QUERY']) #Now its a Hash
end
end
2011-02-22 20:49:44 +00:00
end
2009-12-30 22:24:22 +00:00
end