Bug: MySQL Password Escaping

  • Version: i-MSCP 1.3.0
    SQL Server: MySQL / MariaDB (remote server)

    Problem
    On installation / upgrade, in I-MSCP 1.3.0 a new config file will be created for mysqldump: /etc/mysql/conf.d/imscp.cnf. Inside this config file, the Password is escaped:


    Code
    1. [mysqldump]
    2. host = <hostname>
    3. port = 3306
    4. user = "imscp_user"
    5. password = "'<password>'"


    The escaping might be done due to special characters such as "#[([])}~^-+", however, it makes the dump stop working with following error message:


    Quote

    An error has been raised while executing function main::run in/var/www/imscp/engine/backup/imscp-backup-all:iMSCP::Database::mysql::dumpdb: mysqldump: Got error: 1045: Access deniedfor user 'imscp_user'@'<host>' (using password: YES) when trying toconnect

    Workaround
    Delete additional single quotes (') inside the password string.


    Fix
    Remove escapeShell() all from line 188 in Servers::sqld::remote_server.pm.

    Edited 2 times, last by Starlight: updated fix, after found solution ().

  • Benedikt,


    Normally, only double quotes are escaped and the final password shouldn't be surrounded with single quotes:

    Perl
    1. (my $pwd = decryptBlowfishCBC( $main::imscpDBKey, $main::imscpDBiv, $main::imscpConfig{'DATABASE_PASSWORD'} ) ) =~ s/"/\\"/g;


    See https://github.com/i-MSCP/imsc…d/mysql/installer.pm#L247


    Could you say us what was the password exactly (PM if you prefer).


    Thanks.

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • @Starlight


    I've just tried to reproduce the issue with the 1.3.x branch:


    Shell-Script
    1. # perl imscp-autoinstall -dasr sql


    Password set to ouch'ouch"ouch


    Resulting file:

    PHP
    1. [mysqldump]host = localhostport = 3306user = "imscp_user"password = "ouch'ouch\"ouch"[mysqld]event_scheduler = DISABLEDdefault_password_lifetime = 0innodb_use_native_aio = 1performance_schema = 0sql_mode = "NO_AUTO_CREATE_USER"[mysql_upgrade]host = localhostport = 3306user = "imscp_user"password = "ouch'ouch\"ouch"socket = /var/run/mysqld/mysqld.sock

    As you can see here, only the double quotes are escaped. Then, result of a dump (I use the imscp-backup-imscp script here but the result would be same with the imscp-backup-all script):

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • @Starlight


    Could you also give us the content of the /etc/imscp/mysql/imscp.cnf file on your system?


    Should normally look like https://github.com/i-MSCP/imsc….3.0/configs/debian/mysql (with 1.3.0)


    Thanks.

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • Dear @Nuxwin,


    the file "/etc/imscp/mysql/imscp.cnf" has the right content:


    Code
    1. [mysqldump]
    2. host = {DATABASE_HOST}
    3. port = {DATABASE_PORT}
    4. user = "{DATABASE_USER}"
    5. password = "{DATABASE_PASSWORD}"

    Did you try passwords with #~()?

  • @Starlight


    Yes and I cannot confirm the problem. Please try with last 1.3.x on vm.


    Thank you.

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • @Nuxwin, could it be, that the encrypted database string in /etc/imscp/imscp.conf has the extra chars already? How to I decrypt or create a new encrypted string without re-running the installation?


    It is re-producible after every update.

  • could it be, that the encrypted database string in /etc/imscp/imscp.conf has the extra chars already?

    You mean, escape characters?


    How to I decrypt or create a new encrypted string without re-running the installation?

    By coding a little script. See the attachment or pastbin link below ;)


    Pastbin link: http://pastebin.com/7fEFfAb7


    handle_passwd.pl

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206

  • By coding a little script. See the attachment or pastbin link below ;)

    I thought so, I should have asked a more precise question. ;)



    Wow, thank you for creating this. Result: The encrypted password is the original password without any additional escape chars. Nonetheless, the extra ' are added by the setup / upgrade script.


    I compared your script with the with the Servers::sqld::Remote_Server.pl and found a small but important difference:


    In line 188 you are calling escapeShell() and this adds the additional chars around the string.


    escapeShell() triggers always when the tested string contains other chars than [a-zA-Z0-9_\-].


    The fix should be trivial and I do not see any security issues.

  • @Starlight



    In line 188 you are calling escapeShell() and this adds the additional chars around the string.


    escapeShell() triggers always when the tested string contains other chars than [a-zA-Z0-9_\-].


    The fix should be trivial and I do not see any security issues.

    Ah... in remote server implementation.... Ok I've just looked at MySQL implementation. I'll check and fix. Sorry for the misunderstanding.


    Thank you for your investigations ;)

    badge.php?id=1239063037&bid=2518&key=1747635596&format=png&z=547451206