mysqld
Concerning Security
LOAD DATA LOCAL
Access denied
Errors
Anyone using MySQL on a computer connected to the Internet should read this section to avoid the most common security mistakes.
In discussing security, we emphasise the necessity of fully protecting the entire server host (not simply the MySQL server) against all types of applicable attacks: eavesdropping, altering, playback, and denial of service. We do not cover all aspects of availability and fault tolerance here.
MySQL uses security based on Access Control Lists (ACLs) for all connections, queries, and other operations that a user may attempt to perform. There is also some support for SSL-encrypted connections between MySQL clients and servers. Many of the concepts discussed here are not specific to MySQL at all; the same general ideas apply to almost all applications.
When running MySQL, follow these guidelines whenever possible:
root
user) access to the
user
table in the mysql
database! This is critical.
The encrypted password is the real password in MySQL.
Anyone who knows the password which is listed in the user
table
and has access to the host listed for the account can easily log
in as that user.
GRANT
and
REVOKE
commands are used for controlling access to MySQL. Do
not grant any more privileges than necessary. Never grant privileges to all
hosts.
Checklist:
mysql -u root
. If you are able to connect successfully to the
server without being asked for a password, you have problems. Anyone
can connect to your MySQL server as the MySQL
root
user with full privileges!
Review the MySQL installation instructions, paying particular
attention to the item about setting a root
password.
SHOW GRANTS
and check to see who has access to
what. Remove those privileges that are not necessary using the REVOKE
command.
MD5()
, SHA1()
or
another one-way hashing function.
nmap
. MySQL uses port 3306 by default. This port should
be inaccessible from untrusted hosts. Another simple way to check whether
or not your MySQL port is open is to try the following command
from some remote machine, where server_host
is the hostname of
your MySQL server:
shell> telnet server_host 3306If you get a connection and some garbage characters, the port is open, and should be closed on your firewall or router, unless you really have a good reason to keep it open. If
telnet
just hangs or the
connection is refused, everything is OK; the port is blocked.
; DROP
DATABASE mysql;
''. This is an extreme example, but large security leaks
and data loss may occur as a result of hackers using similar techniques,
if you do not prepare for them.
Also remember to check numeric data. A common mistake is to protect only
strings. Sometimes people think that if a database contains only publicly
available data that it need not be protected. This is incorrect. At least
denial-of-service type attacks can be performed on such
databases. The simplest way to protect from this type of attack is to use
apostrophes around the numeric constants: SELECT * FROM table
WHERE ID='234'
rather than SELECT * FROM table WHERE ID=234
.
MySQL automatically converts this string to a number and
strips all non-numeric symbols from it.
Checklist:
%22
(`"'), %23
(`#'), and %27
(`'') in the URL.
addslashes()
function.
As of PHP 4.0.3, a mysql_escape_string()
function is available
that is based on the function of the same name in the MySQL C API.
mysql_real_escape_string()
API call.
escape
and quote
modifiers for query streams.
quote()
method or use placeholders.
PreparedStatement
object and placeholders.
tcpdump
and strings
utilities. For most cases,
you can check whether MySQL data streams are unencrypted
by issuing a command like the following:
shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings(This works under Linux and should work with small modifications under other systems.) Warning: If you do not see data this doesn't always actually mean that it is encrypted. If you need high security, you should consult with a security expert.
Posted by George Toft on Wednesday January 22 2003, @4:54am | [Delete] [Edit] |
Placing a database server in a DMZ is *NOT* a good security practice. Databases should be inside the company, which means there are at least two firewalls (three if using an application server in a three-tier architecture) between the Internet and the database server.
Posted by Ben Powell on Wednesday February 26 2003, @5:53am | [Delete] [Edit] |
Searchdatabase.com author criticises mySQL security, says it should not be used for critical/private data:
http://searchdatabase.techtarget.com/ateQuestionNResponse/0,289625,sid13_cid511679_tax285648,00.html
Posted by [name withheld] on Friday July 4 2003, @1:31pm | [Delete] [Edit] |
The 'expert' talked and talked about what he would do if he discovered an associate was holding confidential data in a MySQL database, but provided no grounding for his findings whatsoever.
On another note, notice that mysql doesnt follow their own recomendations. Here is the error i got while registering (notice they store the passwords in plain text, which they rrecomend against doing incase the system is comprimised):
INSERT user SET email='paul@mydomain.com',pass='lazypass',show_email='N',firstname='',lastname='',address='',city='',state='',zipcode='',country_id='',phone='',cell='',fax='',company='',title='',news='none',newsgroup='',created=NOW(),last_modified=NOW()
Duplicate entry 'paul@mydomain.com' for key 2Duplicate entry 'paul@mydomain.com' for key 2
INSERT user SET email=?,pass='lazypass',show_email='N',firstname='',lastname='',address='',city='',state='',zipcode='',country_id='',phone='',cell='',fax='',company='',title='',news='none',newsgroup='',created=NOW(),last_modified=NOW()
Posted by Ben Powell on Wednesday March 5 2003, @4:10am | [Delete] [Edit] |
You're right he didn't give examples of MySQL weaknesses; I don't follow the last part of your post (newbie). I think the new versions of MySQL are robust, and as with his comments re SQL Server, it is as much to do with the system you run it on and in this case I don't think you can fault Linux.
Posted by Ben Powell on Wednesday March 5 2003, @4:11am | [Delete] [Edit] |
On re-reading, do you mean to say this site is insecure :-)