加固您的 phpMyAdmin 安装
遵循我们的 安全公告 https://www.phpmyadmin.net/security/ _ 并在每次有漏洞发布时都将 phpMyAdmin 更新。
定时检查更新版本就好
仅使用 HTTPS 提供 phpMyAdmin 服务,最好一并使用 HSTS 机制,这样可以防御协议降级攻击。
Centos 7 配置 apache https访问
Ubuntu 18.04配置 apache https 访问
确保 PHP 安装遵循了生产环境站点的推荐配置,如应该禁用 display_errors 。
whereis php.ini
php: /usr/bin/php /usr/lib64/php /etc/php.d /etc/php.ini /usr/include/php /usr/share/php /usr/share/man/man1/php.1.gz
cat /etc/php.ini |grep display_errors
; display_errorsdisplay_errors = Off; separately from display_errors. We strongly recommend you set this to 'off'
除非你正在开发并需要测试套件,否则从phpMyAdmin中删除 test 目录。
rm -rf /var/www/html/phpmyadmin/test
从phpMyAdmin中删除 setup 目录,初始设置后你可能不会使用它。
先使用 .htaccess ,确认不用了在删除
正确选择认证方式 - Cookie 认证方式 是共享主机的最好选择。
config.inc.php 缺省就是这样子配置的
您应在您的网站服务器设置中禁止对 ./libraries 和 ./setup/lib 这两个子文件夹的访问。在 Apache 中您可以通过 .htaccess 文件设置,其它网站服务器请自行设置。通过该设置可预防路径泄露和跨站脚本攻击。
cat /var/www/html/phpmyadmin/libraries/.htaccess
Require all denied Deny from all
cat /var/www/html/phpmyadmin/setup/.htaccess
Require all denied Deny from all
禁止访问临时文件,参见 $cfg[‘TempDir’] ,如果它位于你的 web root,参见 Web 服务器上传/保存/导入目录 。
简单设置这 2 个都放在 tmp 目录,然后,使用 .htaccess 控制访问
cat config.inc.php
....../*** Directories for saving/loading files from server*/$cfg['UploadDir'] = './tmp';$cfg['SaveDir'] = './tmp';// wzh 20230315$cfg['TempDir'] = './tmp';......
您还可以禁止搜索引擎访问公开的 phpMyAdmin,因为这对它们没有任何用处。您可以使用网站服务器根文件夹的 robots.txt 文件或直接从网站服务器设置中限制其访问,参见 1.42 如何阻止爬虫机器人访问 phpMyAdmin?。
安装自带的 robots.txt 已经禁止了所有的爬虫
cat robots.txt
User-agent: *Disallow: /
如果您不希望所有 MySQL 用户都能访问 phpMyAdmin,可以使用 cfg[′Servers′][cfg['Servers'][cfg[′Servers′][i][‘AllowDeny’][‘rules’] 来限制它们,或者使用 cfg[‘Servers’][$i][‘AllowRoot’] 来拒绝 root 用户访问。
改在 Apache 配置里面去控制
为您的账户启用 双因素身份验证。
不好弄,算了!
考虑将 phpMyAdmin 隐藏在认证代理后面,这样用户在向 phpMyAdmin 提供 MySQL 凭证之前就需要进行认证。你可以通过配置你的 Web 服务器以请求 HTTP 认证来实现这一点。例如,在 Apache 中可以这样做:
Apache 使用 mod_auth_basic 模块,给网站增加一个身份认证代理
nginx 使用 ngx_http_auth_basic_module 模块,给网站增加一个身份认证代理
若您担心自动化的攻击,通过 $cfg[‘CaptchaLoginPublicKey’] 和 $cfg[‘CaptchaLoginPrivateKey’] 启用验证码会有一定作用。
没有 google 账号,一切白扯!翻墙另当别论
Failed login attempts are logged to syslog (if available, see $cfg[‘AuthLog’]). This can allow using a tool such as fail2ban to block brute-force attempts. Note that the log file used by syslog is not the same as the Apache error or access log files.
在 httpd.conf 文件里面加上
cat /etc/httpd/conf/httpd.conf
......
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
# add by wzh 20230315
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %{userID}n %{userStatus}n" pma_combined
......
In case you’re running phpMyAdmin together with other PHP applications, it is generally advised to use separate session storage for phpMyAdmin to avoid possible session-based attacks against it. You can use $cfg[‘SessionSavePath’] to achieve this.
目前没有这种需求,不处理