Skip to content

Vulnerable to CVE-2015-3152 when using TLS with mysql 5.5/5.6 client libs #98

@edmorley

Description

@edmorley

tl;dr: mysql 5.5/5.6 client libraries have unfortunate defaults which means TLS connections can be silently man-in-the-middled - so if mysqlclient-python is used with them, is vulnerable to CVE-2015-3152.

With mysql client libraries < v5.7, if a CA certificate is specified, the client neither requires TLS/SSL, nor actually checks the CA certificate matches the hostname. This means that if the connection is MITMed and redirected to malicious mysql server instance that pretends to not support TLS, it proceeds anyway, silently leaking credentials (if using username/password rather than client cert/key).

For example when using:

  • Ubuntu 14.04 with the latest Ubuntu trusty libmysqlclient-dev package (which is libmysqlclient18 - ie mysql v5.5)
  • mysqlclient-python v1.3.7
  • mysql-server running on localhost with TLS disabled

And then running:

import MySQLdb

conn = MySQLdb.connect(
    host='localhost',
    user='foo',
    passwd='bar',
    ssl= {
        'ca': 'unrelated-ca-cert.pem',
    }
)

Expected:
Some kind of TLS error.

Actual:

Traceback (most recent call last):
  File "./mysql-test.py", line 10, in <module>
    'ca': 'unrelated-ca-cert.pem',
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 204, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'foo'@'localhost' (using password: YES)")

...ie our credentials were just sent in plaintext.

This means anyone can MITM a connection to eg an Amazon RDS instance from a local dev's machine (or say Heroku, where we can't set up a VPC with the RDS instance) running mysql 5.5/5.6 client libraries, and the client will be none the wiser. Note this also affects the command line mysql client too (see: http://bugs.mysql.com/bug.php?id=79862).

Thankfully this has been fixed in mysql 5.7 (ie if a CA certificate is specified it defaults to enforcing TLS and that the cert matches the hostname; see here), however we can't easily use mysql 5.7 on Ubuntu 14.04 on Heroku/Travis/....

As for mysql 5.5/5.6, recent point releases (specifically 5.5.49 and 5.6.30) have added opt-in support for enforcing TLS/CA cert verification, however neither mysqlclient-python nor MySQLdb support enabling these.

Edit: It turns out the backported libmysqlclient 5.5/5.6 fixes are insufficient to solve this after all - there's no way mysqlclient-python can be securely used with them...

Whilst recent point releases of MySQL 5.5/5.6's libmysqlclient (specifically 5.5.49 and 5.6.30) have added opt-in support for verifying the CA certificate (using MYSQL_OPT_SSL_VERIFY_SERVER_CERT):
(a) neither mysqlclient-python nor MySQLdb currently support enabling it (though there is a PR open against MySQLdb to add it: farcepest/MySQLdb1#100)
(b) even with this option enabled, if the remote server pretends to not support TLS, then the connection can be silently downgraded to non-TLS (the "enforce TLS" options from 5.7 were only backported for the command line mysql client and not the C API)

Oracle's own MySQL Python connector does support (a) (by passing ssl_verify_cert=True), however is still vulnerable to (b). I've filed an upstream MySQL bug requesting further libmysqlclient 5.5/5.6 backports of the 5.7 fixes.

As such at the moment, there is no secure way to use mysqlclient-python, MySQLdb or MySQL Connector Python with libmysqlclient 5.5/5.6.

See also:
https://dev.mysql.com/doc/refman/5.5/en/mysql-options.html
https://dev.mysql.com/doc/refman/5.6/en/mysql-options.html
http://www.ocert.org/advisories/ocert-2015-003.html
https://mariadb.org/information-on-the-ssl-connection-vulnerability-of-mysql-and-mariadb-2/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions