2

I start the mysql :

mysqld_safe --user=_mysql

and I create a file which blongs to root:

-rw-r--r--   1 root        staff     0 12  4 19:40 a

and exec:

mysql> system rm /home/test/a

and the file was deleted。

has anyone kown how to make 'system' command unavailable when the mysql account which is specified by 'mysqld -u' are different to the account of system(file or others)

2
  • Not the solution but a security recommendation: user profiles should only be writable their owner Commented Dec 4, 2016 at 12:06
  • thx for your advice :) Commented Dec 4, 2016 at 14:46

2 Answers 2

2

The system command in the mysql client command line program doesn't run commands on the MySQL server machine. (If it did, can you imagine how easy it would be for cybercriminals to pwn IT infrastructure?)

It runs them on the same machine upon which you are running mysql.

The mysql command ordinarily runs with the same user and set of permissions as the shell program that invoked it. So, anything users could do with mysql system they could also do in the shell used to run it.

Therefore, disabling the mysql system command is unnecessary and insufficient for tightening system security.

(Users without shells are another story. If you have those kinds of users, you probably should disable the system command.)

If you don't trust the user who must run the mysql client you'll need to grant them a limited environment. You can look up chroot for that.

2
  • 1
    I disagree that they could also do in the shell used to run it. Some users do not have shells, and are still using the mysql CLI on the server. There is even a patch for this feature which was never applied due to licensing concerns. Commented Nov 16, 2018 at 16:13
  • 2
    > (Users without shells are another story. If you have those kinds of users, you probably should disable the system command.) This begs the question: how?
    – ebarrere
    Commented Jul 3, 2019 at 17:56
0

A way to make the system command unavailable in mysql is by using a wrapper script. Below is some simple code for a script that I call mysql_more_secure.sh. It needs a mysql_unsecure binary which is just a hard-link or a copy of the normal mysql binary.

#!/bin/bash
ulimit -u 0
exec /path/to/mysql_unsecure "$@"

You can go further than "just" providing this wrapper script by forcing it for all usage of the MySQL client by replacing the mysql binary with this script.

Note: this wrapper borks the MySQL client when using the pager command (at least for 8.0.36 and 8.3.0).

This script is inspired by the Unix & Linux Stack Exchange article Block/allow specific subprocesses being launched by a process.

Hopefully, one day, Oracle will provide a SECURE feature in the MySQL client, see Bug#14328: Please provide a "secure mode" for the MySQL Client. In the meantime, this wrapper script is the most simple solution I can think of. If you want to be even more secure, you could set this script to run in a chroot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.