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/scanner/mysql/mysql_writable_dirs.rb
Views: 11783
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::MYSQL7include Msf::Auxiliary::Report8include Msf::Auxiliary::Scanner9include Msf::OptionalSession::MySQL1011def initialize12super(13'Name' => 'MYSQL Directory Write Test',14'Description' => %Q{15Enumerate writeable directories using the MySQL SELECT INTO DUMPFILE feature, for more16information see the URL in the references. ***Note: For every writable directory found,17a file with the specified FILE_NAME containing the text test will be written to the directory.***18},19'Author' => [ 'AverageSecurityGuy <stephen[at]averagesecurityguy.info>' ],20'References' => [21[ 'URL', 'https://dev.mysql.com/doc/refman/5.7/en/select-into.html' ]22],23'License' => MSF_LICENSE24)2526register_options([27OptPath.new('DIR_LIST', [ true, "List of directories to test", '' ]),28OptString.new('FILE_NAME', [ true, "Name of file to write", Rex::Text.rand_text_alpha(8) ]),29OptString.new('USERNAME', [ true, 'The username to authenticate as', "root" ])30])3132end3334# This function does not handle any errors, if you use this35# make sure you handle the errors yourself36def mysql_query_no_handle(sql)37res = self.mysql_conn.query(sql)38res39end4041def run_host(ip)42print_warning("For every writable directory found, a file called #{datastore['FILE_NAME']} with the text test will be written to the directory.")43print_status("Login...") unless session4445# If we have a session make use of it46if session47print_status("Using existing session #{session.sid}")48self.mysql_conn = session.client49else50# otherwise fallback to attempting to login51return unless mysql_login_datastore52end5354File.read(datastore['DIR_LIST']).each_line do |dir|55check_dir(dir.chomp)56end5758end5960def check_dir(dir)61begin62print_status("Checking #{dir}...")63res = mysql_query_no_handle("SELECT _utf8'test' INTO DUMPFILE '#{dir}/" + datastore['FILE_NAME'] + "'")64rescue ::Rex::Proto::MySQL::Client::ServerError => e65print_warning(e.to_s)66rescue Rex::ConnectionTimeout => e67print_error("Timeout: #{e.message}")68else69print_good("#{dir} is writeable")70report_note(71:host => mysql_conn.peerhost,72:type => "filesystem.file",73:data => "#{dir} is writeable",74:port => mysql_conn.peerport,75:proto => 'tcp',76:update => :unique_data77)78end79end80end818283