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_version.rb
Views: 11623
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Tcp7include Msf::Auxiliary::Scanner8include Msf::Auxiliary::Report9include Msf::OptionalSession::MySQL1011def initialize12super(13'Name' => 'MySQL Server Version Enumeration',14'Description' => %q{15Enumerates the version of MySQL servers.16},17'Author' => 'kris katterjohn',18'License' => MSF_LICENSE19)2021register_options([22Opt::RPORT(3306)23])24end2526# Based on my mysql-info NSE script27def run_host(ip)28begin29if session30sql_conn = session.client31version = sql_conn.server_info32print_good("#{sql_conn.peerhost}:#{sql_conn.peerport} is running MySQL #{version}")33report_service(34:host => sql_conn.peerhost,35:port => sql_conn.peerport,36:name => "mysql",37:info => version38)39return40else41socket = connect(false)42data = socket.get_once(-1, 10)43disconnect(socket)44end4546if data.nil?47print_error "The connection to #{rhost}:#{rport} timed out"48return49end50rescue ::Rex::ConnectionError, ::EOFError51vprint_error("#{rhost}:#{rport} - Connection failed")52return53rescue ::Exception54print_error("Error: #{$!}")55return56end5758offset = 05960l0, l1, l2 = data[offset, 3].unpack('CCC')61length = l0 | (l1 << 8) | (l2 << 16)6263# Read a bad amount of data64return if length != (data.length - 4)6566offset += 46768proto = data[offset, 1].unpack('C')[0]6970# Application-level error condition71if proto == 25572offset += 273err_msg = Rex::Text.to_hex_ascii(data[offset..-1].to_s)74print_status("#{rhost}:#{rport} is running MySQL, but responds with an error: #{err_msg}")75report_service(76:host => rhost,77:port => rport,78:name => "mysql",79:info => "Error: #{err_msg}"80)81else82offset += 183version = data[offset..-1].unpack('Z*')[0]84print_good("#{rhost}:#{rport} is running MySQL #{version} (protocol #{proto})")85report_service(86:host => rhost,87:port => rport,88:name => "mysql",89:info => version90)91end92end93end949596