How to secure phpMyAdmin

后端 未结 9 584
清歌不尽
清歌不尽 2020-12-02 04:40

I have noticed that there are strange requests to my website trying to find phpmyadmin, like

/phpmyadmin/
/pma/

etc.

Now I have ins

相关标签:
9条回答
  • 2020-12-02 05:03

    The biggest threat is that an attacker could leverage a vulnerability such as; directory traversal, or using SQL Injection to call load_file() to read the plain text username/password in the configuration file and then Login using phpmyadmin or over tcp port 3306. As a pentester I have used this attack pattern to compromise a system.

    Here is a great way to lock down phpmyadmin:

    • DO NOT ALLOW REMOTE ROOT LOGINS! Instead phpmyadmin can be configured to use "Cookie Auth" to limit what user can access the system. If you need some root privileges, create a custom account that can add/drop/create but doesn't have grant or file_priv.
    • Remove file_priv permissions from every account. file_priv is one of the most dangerous privileges in MySQL because it allows an attacker to read files or upload a backdoor.
    • Whitelist IP address who have access to the phpmyadmin interface. Here is an example .htaccess reulset:
    Order deny,allow
    Deny from all
    allow from 199.166.210.1
    
    • Do not have a predictable file location like: http://127.0.0.1/phpmyadmin. Vulnerability scanners like Nessus/Nikto/Acunetix/w3af will scan for this.

    • Firewall off tcp port 3306 so that it cannot be accessed by an attacker.

    • Use HTTPS, otherwise data and passwords can be leaked to an attacker. If you don't want to fork out the $30 for a cert, then use a self-signed. You'll accept it once, and even if it was changed due to a MITM you'll be notified.
    0 讨论(0)
  • 2020-12-02 05:05

    You can use the following command :

    $ grep "phpmyadmin" $path_to_access.log | grep -Po "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" | sort | uniq | xargs -I% sudo iptables -A INPUT -s % -j DROP 
    

    Explanation:

    Make sure your IP isn't listed before piping through iptables drop!!

    This will first find all lines in $path_to_access.log that have phpmyadmin in them,

    then grep out the ip address from the start of the line,

    then sort and unique them,

    then add a rule to drop them in iptables

    Again, just edit in echo % at the end instead of the iptables command to make sure your IP isn't in there. Don't inadvertently ban your access to the server!

    Limitations

    You may need to change the grep part of the command if you're on mac or any system that doesn't have grep -P. I'm not sure if all systems start with xargs, so that might need to be installed too. It's super useful anyway if you do a lot of bash.

    0 讨论(0)
  • 2020-12-02 05:13

    Another solution is to use the config file without any settings. The first time you might have to include your mysql root login/password so it can install all its stuff but then remove it.

    $cfg['Servers'][$i]['auth_type'] = 'cookie';

    $cfg['Servers'][$i]['host'] = 'localhost';

    $cfg['Servers'][$i]['connect_type'] = 'tcp';

    $cfg['Servers'][$i]['compress'] = false;

    $cfg['Servers'][$i]['extension'] = 'mysql';

    Leaving it like that without any apache/lighhtpd aliases will just present to you a log in screen. enter image description here

    You can log in with root but it is advised to create other users and only allow root for local access. Also remember to use string passwords, even if short but with a capital, and number of special character. for example !34sy2rmbr! aka "easy 2 remember"

    -EDIT: A good password now a days is actually something like words that make no grammatical sense but you can remember because they funny. Or use keepass to generate strong randoms an have easy access to them

    0 讨论(0)
提交回复
热议问题