What is MySQL
What is MySQL
• Keep MySQL Updated: Always install the latest patches and versions
to fix any security holes. This ensures you’re protected against known
vulnerabilities.
• Limit User Permissions: Give users only the permissions they need.
Avoid using the powerful root account for everyday tasks. Instead,
create specific accounts with restricted access.
• Encrypt Your Data: Protect sensitive data both at rest and in transit
using encryption methods like SSL/TLS. This ensures that even if
someone gains access, they can’t read the data.
3. Enforce 2FA for Users: Update user access policies to require 2FA
for accessing the database.
Example Configuration
# Install necessary 2FA modules
sudo apt-get install libpam-google-authenticator
Recommended Strategies
consider the following strategies to enhance MySQL database security:
• Frequent Security Audits: To find and fix any possible issues in the
MySQL environment conduct regular security audits and vulnerability
evaluations.
MySQL is one crucial database system that aids in talking to and managing
the storage of data for innumerable websites and applications. By that, the
way you lock your front door to protect the house, the same way you secure
your MySQL Database in the hope that in case your data is hacked, only
concerned people can get in and no illicit people can make some changes.
Let’s go ahead with some easy and effective ways to keep your MySQL
database secure.
Create Unique Users for Each Application Different MySQL users for various
applications allow isolating access and permissions.
This can be achieved through the principle of least privilege, whereby only
privileges that are essential to performing the duties are awarded to every
user.
Strong passwords
Ensure that strong and complex passwords are in use, and also consider
putting in place password expiration policies.
Purpose: 2FA ensures that the user has further protection by demanding two
kinds of authentication; usually, something they know and something they
have, such as a password and a code obtained from a mobile application.
Data Encryption
Data encryption is one of the essential elements of MySQL security. It provides
security for sensitive information at rest and in transit. When you are
encrypting data, even if somebody intercepts the data or views them in
malice, it will still be useless to the particular entity. Following are the best
practices to apply in data encryption using MySQL:
Encrypt Data at Rest
Purpose: Ensure that data transmitted between the MySQL server and clients
is protected from interception and eavesdropping.
Example
[mysqld]
ssl-ca=/path/to/ca-cert.pem
ssl-cert=/path/to/server-cert.pem
ssl-key=/path/to/server-key.pem
Objective: The objective of this control is to identify the accounts that are
not active or for which MySQL Database access is no longer needed.
Objective: This control aims to classify accounts that are less than very active
and verify if they are truly needed.
Implementation: Check the last login time for each user account, if
available. MySQL Enterprise Edition includes an audit plugin which allows
tracking of user activity. Otherwise, look for accounts assigned to projects or
users which no longer exist.
MySQL Security
MySQL is one crucial database system that aids in talking to and managing
the storage of data for innumerable websites and applications. By that, the
way you lock your front door to protect the house, the same way you secure
your MySQL Database in the hope that in case your data is hacked, only
concerned people can get in and no illicit people can make some changes.
Let’s go ahead with some easy and effective ways to keep your MySQL
database secure.
Create Unique Users for Each Application Different MySQL users for various
applications allow isolating access and permissions.
This can be achieved through the principle of least privilege, whereby only
privileges that are essential to performing the duties are awarded to every
user.
Strong passwords
Ensure that strong and complex passwords are in use, and also consider
putting in place password expiration policies.
Authentication and Authorization
It is in regard to the two important parts of MySQL security: authentication
and authorization, thus ensuring with utmost care that only valid users may
access the database and, at the same time, are properly authorized for their
duties. The following section represents detailed best practices related to
authentication and authorization management in MySQL:
Purpose: 2FA ensures that the user has further protection by demanding two
kinds of authentication; usually, something they know and something they
have, such as a password and a code obtained from a mobile application.
Data Encryption
Data encryption is one of the essential elements of MySQL security. It provides
security for sensitive information at rest and in transit. When you are
encrypting data, even if somebody intercepts the data or views them in
malice, it will still be useless to the particular entity. Following are the best
practices to apply in data encryption using MySQL:
Purpose: Ensure that data transmitted between the MySQL server and clients
is protected from interception and eavesdropping.
Example
[mysqld]
ssl-ca=/path/to/ca-cert.pem
ssl-cert=/path/to/server-cert.pem
ssl-key=/path/to/server-key.pem
Objective: The objective of this control is to identify the accounts that are
not active or for which MySQL Database access is no longer needed.
Objective: This control aims to classify accounts that are less than very active
and verify if they are truly needed.
Implementation: Check the last login time for each user account, if
available. MySQL Enterprise Edition includes an audit plugin which allows
tracking of user activity. Otherwise, look for accounts assigned to projects or
users which no longer exist.
MySQL Vulnerabilities
We are living in a digital era, as the internet and technology are expanding
and becoming more and more popular with each passing day, so are the
crimes committed on it. In recent years, the cyber-crimes on businesses or in
general have significantly grown. These malicious cybercriminals take
advantage of poorly designed or flawed systems used by these businesses for
either some self-monetary gains by selling data, Ransom, or by any other
means; or for besmirching the company’s name and its reputation. MySQL
relational database management system is among one of the most popular
open-source RDBMS in use currently, the main purpose of using it is to store
the data for web servers or websites. Mostly all of the currently popular web
servers and also the frameworks use MySQL as their preferred database. Just
like any other piece of software MySQL too has some vulnerabilities which can
be exploited and can cause significant damage if carried out properly, so to
avoid them and to secure the data let’s look at what these vulnerabilities are
and their possible fixes.
1. SQL Injection: It is among the most common and perilous attacks, in this
type of attack the attackers steal information or foist data loss by attacking
the database. Basically, it is an injection-type attack where the attacker runs
malicious SQL queries that could have various serious implications such as
losing data or even data stealing.
Mostly SQL Injections are carried out on web apps. Attackers make use of
some known loopholes and vulnerabilities to target the application by SQL
Injection vulnerabilities mainly to bypass application authentication process
and security or to cause some harm to the database.
After carrying out a successful attack the malicious user can access the
authorized and authenticated sections of web servers and applications, and
can also modify, add or delete the data and can also retrieve the records as
well.
Let’s take an example of a situation where we are trying to authenticate a
user on some application. To do that first we would have to send or input the
user’s login credentials for authentication purposes.
After the credentials are entered the application will build an SQL query below
to check if the user with the entered credentials already exists or not. Query:
SELECT * FROM utable WHERE username = “UserName001”
This was the case of a normal user. Now, what if an attacker is trying to exploit
the system they might enter the password as “ ’*’ OR ‘1’ = ‘1’ ” and when the
application builds its query it will look like this:
Query:
SELECT * FROM utable WHERE username = “UserName001”
So, whenever the system runs this query it would always give the result to be
true and the application thinks that the password is correct. In this query, the
first part will look for the user with username “UserName001” with the
password “*” and it will either give no result or rule it out to be false. This is
where the second part of the query comes into play, here the password will
always result in true. The application will let the query pass and hence the
malicious user will be able to bypass the authentication. In similar ways, the
attacker can also modify, add, delete or retrieve the data as they please.
However, this can be circumvented either by using parameterized query/
prepared SQL statements or by sanitizing the user inputs, before the
application generates the query for the provided inputs.
The other issue with this type of vulnerability is that it allows remote
authenticated users to cause a DoS attack by using a crafted SELECT
statement along with a UpdateXML() command with many unique nested
elements. The result of this is a more susceptible MySQL to DoS vulnerability.
An attacker could exploit this flaw to takedown the whole database and its
instances, rendering other services useless and making them inaccessible to
the user.
The payload along with the commands that can be used in this scenario is as
follows:
Syntax:
$mysql->query("SELECT UpdateXML('<a>$a<b>ccc</b>
To avoid this vulnerability the updated versions of MySQL can be used where
this exploit has been patched, version 5.5.* and above are free from this
vulnerability.
In MySQL, this can give rise to a race condition, which can be considered a
serious problem. It allows a local user to access the database and after that,
they can use privilege escalation or escalate their user privileges and after
changing their user privileges, they can carry out an arbitrary code execution
attack as a local user of the database. This problematic concurrent execution
using shared resources with improper synchronization condition is present in
MySQL versions before version 5.5.51, 5.6.x to 5.6.32, 5.7.x to 5.7.14 and
8.x to 8.0.0; MariaDB is also affected with this condition MariaDB versions
before version 5.5.52, 10.0.x to 10.0.27, and 10.1.x to 10.1.17. The attackers
can use this vulnerability to their advantage by exploiting it and bypassing the
imposed security restrictions to run unauthorized and arbitrary commands.
This could in turn be used as a launchpad for other attacks. Though now this
vulnerability has been patched on the vulnerable versions.
If the code is vulnerable then a command like the below could be crafted and
used to exploit this vulnerability.
Syntax:
./gh-ost -user test -password -test -alter