简体   繁体   English

安全地存储数据

[英]Securely storing data

I understand the concepts of securely storing data for the most part, including storing the data on a separate server that only allows connections from the application, key-pairs for encryption, etc. However, I'm still not understanding how separating the server makes it that much more secure. 我理解大多数情况下安全存储数据的概念,包括将数据存储在一个单独的服务器上,该服务器只允许来自应用程序的连接,加密的密钥对等等。但是,我仍然不明白如何分离服务器它更加安全。

For instance, suppose I have a web server, which is hardened and secure, and it captures the data from user input for storage. 例如,假设我有一个强化且安全的Web服务器,它从用户输入中捕获数据以进行存储。 The data is encrypted and submitted via a db query or web service to the db server. 数据经过加密并通过db查询或Web服务提交给数据库服务器。 The db server only allows connections from the web server and stores the data in an encrypted form. 数据库服务器仅允许来自Web服务器的连接,并以加密形式存储数据。 Therefore, if someone access the db, the data is worthless. 因此,如果有人访问数据库,则数据毫无价值。

But, if someone access the web server, they will have access to the db as well as the encryption algorithm and keys, no? 但是,如果有人访问Web服务器,他们将可以访问数据库以及加密算法和密钥,不是吗? That being the case, why even have the data on a different server, as the transfer of the data is just another potential point of attack? 既然如此,为什么甚至将数据放在不同的服务器上,因为数据传输只是另一个潜在的攻击点?

Is there someway to hide the connection information and encryption algorithms on the web server so that if it is compromised, access to the db server is not gained? 有没有办法在Web服务器上隐藏连接信息和加密算法,这样如果它被泄露,就无法访​​问数据库服务器? Obfuscation isn't enough, I wouldn't think. 混淆是不够的,我不会想到。 Any ideas are welcome. 欢迎任何想法。

Thanks Brian 谢谢Brian

There's a certain amount of magical thinking and folklore in the way people design for security, and you're right: storing data on a different server on its own doesn't necessarily make things more secure unless you've done all sorts of other things too. 人们为安全设计的方式有一定的神奇思维和民间传说,你是对的:将数据存储在不同的服务器上并不一定能让事情变得更加安全,除非你做过各种各样的事情。太。

Managing keys is a huge part of this; 管理密钥是其中很重要的一部分; doing this in the context of web applications is a subject apart, and I'm not aware of any robust solutions for PHP. 在Web应用程序的上下文中这样做是一个独立的主题,我不知道任何强大的PHP解决方案。 You're quite right - if your web application needs to be able to decrypt something, it needs access to the keys, and if the web app is compromized, the attacker also has access to the key. 你是对的 - 如果你的web应用程序需要能够解密某些东西,它需要访问密钥,如果web应用程序被泄露,攻击者也可以访问密钥。

This is why I've tended to use public key cryptography, and treated the public facing webserver as "write only" - ie the web server encrypts using the public key, stores in the database, and can never decrypt it; 这就是为什么我倾向于使用公钥加密,并将面向公众的Web服务器视为“只写” - 即Web服务器使用公钥加密,存储在数据库中,并且永远不能解密它; only a separate process (not available on the public internet) can use the private key to decrypt it. 只有一个单独的进程(在公共互联网上不可用)才能使用私钥对其进行解密。 This way, you can store credit card details in your database, and only the application which charges the card has the private key to decrypt it; 这样,您可以在您的数据库中存储信用卡详细信息,只有为卡充电的应用程序才有私钥来解密它; this app runs on a secure environment, not accessible from the internet. 此应用程序在安全的环境中运行,无法从Internet访问。

Secondly, there are multiple levels of compromise - for instance, an attacker might get read-only access to your server's file system. 其次,有多种级别的妥协 - 例如,攻击者可能获得对服务器文件系统的只读访问权限。 If that file system includes the database, they could get hold of the data file, restore it to a server they control, and use the decryption key to steal your private data. 如果该文件系统包含数据库,则他们可以获取数据文件,将其还原到他们控制的服务器,并使用解密密钥窃取您的私人数据。 If the database runs on a separate server(inaccessible from the internet), this attack route becomes impossible. 如果数据库在单独的服务器上运行(无法从Internet访问),则此攻击路径将变得不可能。

The fact that one route of attack leaves you open doesn't mean you can't protect against other attacks. 一条攻击路线让你打开的事实并不意味着你无法抵御其他攻击。

In most of my setups, the web server is in a DMZ of the firewall, and the DB is behind the firewall. 在我的大多数设置中,Web服务器位于防火墙的DMZ中,而DB位于防火墙后面。 I would never want to put the DB server outside the firewall. 我永远不想把数据库服务器放在防火墙之外。 That extra level of security makes it much harder for someone to get to the data without authorization. 额外的安全级别使得某人在未经授权的情况下更难获取数据。

BTW, no web server on the net should be considered "hardened and secure". 顺便说一句,网上没有网络服务器应被视为“硬化和安全”。 If it's available to the public, it can be hacked. 如果它可供公众使用,则可以被黑客入侵。 It's just a matter of how hard they want to try. 这只是他们想要尝试的难度的问题。

You're right in your assumption that if someone hacks the webserver to the point they can log in as an admin, they can read and write the database. 你的假设是正确的,如果有人攻击网络服务器,他们可以作为管理员登录,他们可以读写数据库。 But that doesn't mean you should further weaken your setup by putting the DB on the web server. 但这并不意味着您应该通过将数据库放在Web服务器上来进一步削弱您的设置。 You want more security, not less. 您需要更多安全性,而不是更少。

EDIT: 编辑:

Always think in terms of layers in your security. 始终考虑安全性中的层次 Separate critical parts into separate layers. 将关键部件分成单独的层。 This does two things. 这样做有两件事。 It makes it where the perp has more problems to solve, and it give you more time for detection and response. 它使perp有更多的问题需要解决,它给你更多的时间进行检测和响应。

So, in your scenario, access to the web server is one layer, you could then call an encryption server for a second layer (behind the firewall, which is another layer), and the encryption server could be the only machine allowed interaction with the DB server, which is another layer. 因此,在您的方案中,访问Web服务器是一层,然后您可以为第二层(防火墙后面,另一层)调用加密服务器,并且加密服务器可能是唯一允许与之交互的机器。数据库服务器,这是另一个层。

Layers make it more secure. 图层使其更安全。 They also, though, add burden, slowing the response time. 但是,它们也增加了负担,减缓了响应时间。 So keep your solution balanced for your real-world requirements. 因此,请根据您的实际需求保持平衡。

The problem here is that the keys are on the publicly-facing server which could be compromised - even if the server itself is "hardened", there may be a vulnerability in your app which gives an attacker access to keys or data. 这里的问题是密钥位于面向公众的服务器上,可能会受到损害 - 即使服务器本身“硬化”,您的应用程序中可能存在漏洞,攻击者可以访问密钥或数据。

To improve the security of your arrangement you could move just the code that handles encrypted data (along with the keys) onto a secure machine that can be accessed only by the web server, and only through a very restricted API (ie bare minimum that is needed). 为了提高安排的安全性,您可以将处理加密数据的代码(以及密钥)移动到只能由Web服务器访问的安全机器上,并且只能通过非常有限的API(即最低限度的API)需要)。 Each operation is logged in order to spot unusual behaviour, which could be symptomatic of an attempt to extract the secret data. 记录每个操作以发现异常行为,这可能是尝试提取秘密数据的症状。

From a security perspective, putting the database into a separate server doesn't really help. 从安全角度来看,将数据库放入单独的服务器并没有多大帮助。 If authentication tokens get compromised, it is game over. 如果身份验证令牌受到损害,则游戏结束。

However , it does make sense to separate database AND data access layer (DAL) from business logic and presentation. 但是 ,将数据库数据访问层(DAL)与业务逻辑和表示分开是有意义的。 That way, if the application server falls prey to unscrupulous hands, database access is restricted to specific DAL operations which can go a long way of putting data out of harms way if properly implemented. 这样,如果应用程序服务器成为不择手段的牺牲品,则数据库访问仅限于特定的DAL操作,如果正确实施,这可能会使数据摆脱危害。

Other than that, there isn't much of a security benefit in segregating data storage into a separate server. 除此之外,将数据存储隔离到单独的服务器中没有太大的安全益处。

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

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