MYSQL attacks

Default Configuration

sudo apt install mysql-server -y
cat /etc/mysql/mysql.conf.d/mysqld.cnf | grep -v "#" | sed -r '/^\s*$/d'
[client]
port		= 3306
socket		= /var/run/mysqld/mysqld.sock

[mysqld_safe]
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
nice		= 0

[mysqld]
skip-host-cache
skip-name-resolve
user		= mysql
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
port		= 3306
basedir		= /usr
datadir		= /var/lib/mysql
tmpdir		= /tmp
lc-messages-dir	= /usr/share/mysql
explicit_defaults_for_timestamp

symbolic-links=0

!includedir /etc/mysql/conf.d/

Dangerous Settings

Settings

Description

user

Sets which user the MySQL service will run as.

password

Sets the password for the MySQL user.

admin_address

The IP address on which to listen for TCP/IP connections on the administrative network interface.

debug

This variable indicates the current debugging settings

sql_warnings

This variable controls whether single-row INSERT statements produce an information string if warnings occur.

secure_file_priv

This variable is used to limit the effect of data import and export operations.

Footprinting the Service

MySQL - Read Local Files in MySQL

  • https://www.w3resource.com/mysql/string-functions/mysql-load_file-function.php

Write Local Files

  • In MySQL, a global system variable secure_file_priv limits the effect of data import and export operations, such as those performed by the LOAD DATA and SELECT … INTO OUTFILE statements and the LOAD_FILE() function. These operations are permitted only to users who have the FILE privilege.

  • secure_file_priv may be set as follows

    • If empty, the variable has no effect, which is not a secure setting.

    • If set to the name of a directory, the server limits import and export operations to work only with files in that directory. The directory must exist; the server does not create it.

    • If set to NULL, the server disables import and export operations.

  • In the following example, we can see the secure_file_priv variable is empty, which means we can read and write data using MySQL:

MySQL - Secure File Privileges

User Defined Functions

  • MySQL supports User Defined Functions which allows us to execute C/C++ code as a function within SQL

    • there's one User Defined Function for command execution in this GitHub repository.

    • It is not common to encounter a user-defined function like this in a production environment, but we should be aware that we may be able to use it.

Last updated