简体   繁体   English

如何保证 mySQL 数据库的安全?

[英]How do I keep a mySQL database secure?

I'm going to be implementing a PHP/mySQL setup to store credit card information.我将实施一个PHP/mySQL设置来存储信用卡信息。

It seems like AES_ENCRYPT/AES_DECRYPT is the way to go,似乎AES_ENCRYPT/AES_DECRYPT是要走的路,

but I'm still confused on one point:但我仍然对某一点感到困惑:

How do I keep the encryption key secure?如何保证加密密钥的安全?

Hardwiring it into my PHP scripts (which will live on the same server as the db) seems like a major security hole.将它硬连接到我的 PHP 脚本(它将与数据库位于同一服务器上)似乎是一个主要的安全漏洞。

What's the "best practice" solution here?这里的“最佳实践”解决方案是什么?

You should think long and hard about whether you REALLY need to keep the CC#.您应该仔细考虑是否真的需要保留 CC#。 If you don't have a great reason, DON'T!如果你没有充分的理由,不要! Every other week you hear about some company being compromised and CC#'s being stolen.每隔一周,您就会听到一些公司遭到入侵和 CC# 被盗的消息。 All these companies made a fatal flaw - they kept too much information.所有这些公司都有一个致命的缺陷——他们保存了太多的信息。 Keep the CC# until the transaction clears.保持 CC# 直到交易清除。 After that, delete it.之后,删除它。

As far as securing the server, the best course of action is to secure the hardware and use the internal system socket to MySQL, and make sure to block any network access to the MySQL server.至于保护服务器,最好的做法是保护硬件并使用内部系统套接字连接到 MySQL,并确保阻止对 MySQL 服务器的任何网络访问。 Make sure you're using both your system permissions and the MySQL permissions to allow as little access as needed.确保您同时使用系统权限和 MySQL 权限,以根据需要允许尽可能少的访问。 For some scripts, you might consider write-only authentication.对于某些脚本,您可能会考虑只写身份验证。 There's really no encryption method that will be foolproof (as you will always need to decrypt, and thus must store the key).真的没有任何加密方法是万无一失的(因为您总是需要解密,因此必须存储密钥)。 This is not to say you shouldn't - you can store your key in one location and if you detect system compromise you can destroy the file and render the data useless.这并不是说您不应该 - 您可以将您的密钥存储在一个位置,如果您检测到系统受损,您可以销毁文件并使数据变得无用。

MySQL, there is six easy steps you can do to secure your sensitive data. MySQL,您可以通过六个简单的步骤来保护您的敏感数据。

Step 1: Remove wildcards in the grant tables步骤 1:删除授权表中的通配符

Step 2: Require the use of secure passwords第 2 步:要求使用安全密码

Note: Use the MySQL “--secure-auth” option to prevent the use of older, less secure MySQL password formats.注意:使用 MySQL 的“--secure-auth”选项来防止使用较旧的、安全性较低的 MySQL 密码格式。

Step 3: Check the permissions of configuration files第三步:检查配置文件的权限

Step 4: Encrypt client-server transmissions第 4 步:加密客户端-服务器传输

Step 5: Disable remote access第 5 步:禁用远程访问

Step 6: Actively monitor the MySQL access log第六步:主动监控MySQL访问日志

Security Tools安全工具

I agree, but don't the cc if you don't need too.我同意,但如果你不需要也不要抄送。 But if you really have too, make sure the file that have it is not accessible on the web.但是,如果您真的也有,请确保无法在网络上访问包含它的文件。 You can write a binary that would return the key.您可以编写一个可以返回密钥的二进制文件。 This way it's not store in clear text.这样它就不会以明文形式存储。 But if your server is compromise it's still easy to get it.但是,如果您的服务器受到威胁,它仍然很容易获得。

Put your database files outside computer lets say external hdd and keep it at safe place.将您的数据库文件放在计算机外部,比如外部硬盘并将其保存在安全的地方。 Works only if you can develop this project at only place where this external drive is placed :) Or you can at least protect those files using file system encryption tools like https://itsfoss.com/password-protect-folder-linux/仅当您只能在放置此外部驱动器的地方开发此项目时才有效:) 或者您至少可以使用文件系统加密工具(如https://itsfoss.com/password-protect-folder-linux/)保护这些文件

In case of production environment I agree with Kyle Cronin.在生产环境的情况下,我同意凯尔克罗宁。

the security you need depends on your application.您需要的安全性取决于您的应用程序。 for example, if the only time the cc# will be used is when the user is logged in (thin online store type scenario), then you can encrypt the cc# with the a hash of the user's plain-text password, a per-user salt, and a dedicated cc# salt.例如,如果 cc# 仅在用户登录时使用(瘦在线商店类型的场景),那么您可以使用用户的纯文本密码的哈希值对 cc# 进行加密,每个-用户盐和专用的 cc# 盐。 do not store this value permanently.不要永久存储此值。

since you're not storing this value, the only time you can get this value is when the user enters their password to log in. just make sure you have good session expiration and garbage collection policies in place.由于您没有存储此值,因此您只能在用户输入密码登录时获取此值。只需确保您有良好的会话过期和垃圾收集策略。

if this situation does not apply to you, please describe your situation in more detail so we can provide a more appropriate answer.如果这种情况不适用于您,请更详细地描述您的情况,以便我们提供更合适的答案。

Any data in a SQL database that needs encryption can be put in any file type and uploaded to a BLOB field. SQL 数据库中需要加密的任何数据都可以放入任何文件类型并上传到 BLOB 字段。 To ensure that even when this database could be compromised I use this free tool Encyptro before uploading it to the database.为确保即使此数据库可能遭到破坏,我也会在将其上传到数据库之前使用此免费工具Encyptro It is a AES-256 encryption for files, and as long you keep that password offline and well protected it will be hard to break it without let's say a Quantum computer (Science fiction)它是对文件的 AES-256 加密,只要您将该密码保持离线状态并受到良好保护,如果没有量子计算机(科幻小说),就很难破解它

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

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