Solved

Protecting data on ubuntu server, access via PHP

Posted on 2012-04-04
5
386 Views
Last Modified: 2012-04-16
I have an ubuntu server which is running Apache and a special PHP webpage I wrote.

The PHP page allows a user to authenticate and access a special secret "document" that belongs only to them. Each user has their own secret document, and I have a back-end system for configuring the access control lists, user accounts etc. The server uses a properly signed SSL certificate, and the PHP itself is well written.

On the back-end, the documents themselves are stored in a folder on my server which is not web accessible, e.g. in /usr/share/secretstuff/[accountid]/somefile.txt. PHP currently gains access to the file via file_get_contents() and displays it to the user.

My concern is that the files are just sitting on the hard drive in plain text. I've set the chmod and chown accordingly so only www-data has access, but I'm acutely aware that ANY script running on my apache server can access these files if they know where to look.

I'm also concerned that if the server were compromised (either physically or over the network), the files are totally open.

What are some ways I can protect these files and make it so the files are accessible ONLY through authenticated access from my PHP page?

Ideally, how can I protect the server so that a knowledegable person who knows the system inside and out who has somehow gained root access to the machine, or gained physical access to the machine (e.g. removed the hard drive), still cannot access the files?
0
Comment
Question by:Frosty555
  • 3
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
I don't believe that can be done.  If I get root access, I can change anything on your system.  Your only other alternative that I know of is to encrypt the files and make sure the proper user has the only copy of the key.
0
 
LVL 31

Author Comment

by:Frosty555
Comment Utility
I should include also, that it is important that any backups that get made of the server are just as well protected as the server itself....

I was thinking encryption would be the ideal way to do this. Each user logs in using a password that only they know so I imagine I could use that password, hash it / digest it somehow, and use that as the encryption key?

The problem is that some users have access to more than one document, and an administrator needs access to all of them, so the encryption becomes a bit messy. I don't know how to do encryption with multiple keys. I know that public/private encryption is designed to help with this situation but I don't understand it well enough to get a clear picture of what a proper implementation of it would look like (nevermind the actual coding of that implementation in PHP)

This feels like the sort of problem that has already been solved by the technology used in SSL.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
SSL is used to encrypt transmissions over the network, not files on a server.  You might want that also.  Security always makes things more difficult, it is supposed to!  You need strong encryption and a plan.  Do a search for "Linux file encryption" http://www.google.com/search?q=Linux+file+encryption , there are a lot of resources available.
0
 
LVL 31

Author Comment

by:Frosty555
Comment Utility
Okay, so what would be the right way to do this then? If I encrypt the files with a passphrase, that passphrase has to exist somewhere on the server, which defeats the purpose of the original encryption? Is there a better way to protect the encryption key?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
No, the passphrase will be encrypted into the file in such a way that the encryption software will know how to handle it.  On my web sites with logins, the passwords are not found anywhere in plain text and you are welcome to spend the years it will take to break the MD5 hash to get in.  There is no reason to think that the people who wrote the encryption software did not think of this.

There is no Perfect answer.  Encryption and security is always a matter of how difficult do you want to make it.  Generally the answer is, more difficult than the people want to deal with that would otherwise steal the info.  The average computer user won't try very hard.  If some government with super-computers wants to break in, they may have the resources to do it.

Don't over think this.  People smarter than you and me have already solved this problem many times.  Make a list of your needs and find some software that will provide them.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

By default, Carbonite Server Backup manages your encryption key for you using Advanced Encryption Standard (AES) 128-bit encryption. If you choose to manage your private encryption key, your backups will be encrypted using AES 256-bit encryption.
When the confidentiality and security of your data is a must, trust the highly encrypted cloud fax portfolio used by 12 million businesses worldwide, including nearly half of the Fortune 500.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now