简体   繁体   English

防止直接访问数据库

[英]Prevent direct access to database

I'm thinking on a way to secure a PHP application. 我正在考虑一种保护PHP应用程序的方法。 I would like to set up a user with limited rights on the database server side (MySQL), and configure this user in the PHP application for all database requests. 我想在数据库服务器端(MySQL)上设置一个权限受限的用户,并在PHP应用程序中为所有数据库请求配置该用户。

Now the problem is that someone who could have access to the source files (for example an employee) can uses the configured credentials to directly connect to the database (for example via phpmyadmin). 现在的问题是,可以访问源文件的人(例如,雇员)可以使用配置的凭据直接连接到数据库(例如,通过phpmyadmin)。 The database should be updated only through the PHP application. 仅应通过PHP应用程序更新数据库。

I would like to set up a mechanism (trigger or whatever possible on mysql side or php side or both) which checks from which client a request to the database come from, thus ignoring it or not. 我想建立一种机制(触发或mysql端或php端或两者兼有的任何可能),该机制检查来自哪个客户端的数据库请求来自哪个客户端,因此是否忽略它。 Is it possible to do that? 有可能这样做吗? Are there others ways to consider this problem? 还有其他方法可以考虑这个问题吗?

Regards 问候

Now the problem is that someone who could have access to the source files (for example an employee) can uses the configured credentials to directly connect to the database (for example via phpmyadmin). 现在的问题是,可以访问源文件的人(例如,雇员)可以使用配置的凭据直接连接到数据库(例如,通过phpmyadmin)。

This isn't something you can fully prevent. 这不是您完全可以避免的事情。 If somebody has access to the source files, you are screwed no matter what. 如果有人可以访问源文件,那么无论如何您都会被搞砸。

What is usually done to create some protection is 通常创建一些保护措施是

  • to configure mySQL in a way that it's not accessible from outside the server. 以无法从服务器外部访问的方式配置mySQL。 See Restricting MySQL connections from localhost to improve security and it should be done on Firewall level as well (talk to the sysadmin) 请参阅限制来自本地主机的MySQL连接以提高安全性,并且也应该在防火墙级别完成(与sysadmin交谈)

  • have the web app use a database user account that is limited in access to whatever tables and features the app needs to function. 让Web应用使用数据库用户帐户,该帐户只能访问该应用所需的任何表格和功能。

If you need to set the domain from which some user can login you can specify that when you grant that user priviledges: 如果需要设置某些用户可以登录的域,则可以在授予该用户特权时指定:

GRANT ALL PRIVILEGES ON yourdatabase.* TO 'username'@'192.168.10.12' IDENTIFIED BY 'goodsecret'; *将所有特权授予您的数据库。*至'username'@'192.168.10.12'由'goodsecret'标识;

This would limit the connections to 192.168.10.12, even if the password would be provided from another location it wouldn't fit this grant command. 即使将密码从其他位置提供,这也将限制在192.168.10.12进行连接,但它不适合该grant命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM