views:

547

answers:

8

Dear Abby,

I've been working on a PHP website which utilizes a MySQL database (using PDO). I would just like to know it is secure before I go ahead and release it to the public. It is a free, non-profit website so I don't really plan on making money from it and therefore I would rather not invest hundreds or thousands of dollars for a security audit.

I know there are tools from http://owasp.org and other organizations but I can't say that I have enough time or energy to cover all my bases even with resources like this.

Ideally I would like to take care of any major holes right off the bat and then make small improvements over the course of its lifetime. I also don't feel comfortable just blatantly posting all of my code around the internet for everyone to see.

What can I do?

Edit: The point is that I would like suggestions on where my code may have flaws in it and how to fix it. I already have a good deal of security experience but I am not able to honestly say that I am patching bugs the correct way unless someone who knows what they're doing takes a look at my code.

+8  A: 

post a message on a hackers board saying that your website can not be cracked.. you'll have response soon enough. make sure you are on a dedicated server though ;-)

edit: also see my comment below..

MiRAGe
That's not really an audit.
Joe Philllips
Woah! That was my exact idea.Two things I'd like to add: first, you probably won't get helpful feedback on how you got cracked, so make sure to be super certain you save the access logs. Second, be prepared to have the entire machine reformatted, or something ridiculous like that. Back the server up to a disk image, and keep the image somewhere safe (a disk in a closet, or something)... and restore the image as soon as you've fixed your bugs. Godspeed ;)
ojrac
my answer was a bit cynical (thanks Bill Maher for that), but you could really ask some 'white hats' to audit your website. so not DDoS the crap out of it, but just some standard stuff. also, you could read up on some hacking tactics, and apply them to your website. thats how I started reading up on security a few years back, and it thought me a lot! especially about SQL injections and cookies.
MiRAGe
That isn't going to help me fix it -- just help me find the problems.
Joe Philllips
you do have to _find_ your bugs first, before you can fix them.. right?
MiRAGe
"That isn't going to help me fix it -- just help me find the problems."You asked for an audit didn't you?
jim
Generally an audit would come with recommendations. Otherwise it's just a hack attempt.
Joe Philllips
you are right. but if you find the right people (or do it yourself) hacks do to. hack is just a very wrong word I used.. if you want to call it audit, that's also fine. the trick is just to identify the problems (doesn't matter _how_), and then find a way to fix them. even if you find only bugs without recommendations, you still have pointers to search for. search, identify, destroy. kill the bugs ;)
MiRAGe
An actual audit won't tell you much about how to fix your problems, just what to fix -- it sounds like you're looking for some code review..?
ojrac
I rewrote my question a little to make it clear I'm not looking for someone to tell me what my bugs are. I would prefer a code review.
Joe Philllips
+5  A: 

Use a freely available web scanner tool. Here's a list of some popular ones: Top 10 Web Vulnerability Scanners

This will at least get you started - though it's certainly not an acceptable replacement for a full security audit if your application NEEDS to be secure. You'll need to pay money for a real audit, though.

You may find the OWASP site helpful as well.

pix0r
+3  A: 

You can use the Firefox plugin suite by Security Compass. Also, the forum at PHP Freaks also has a section where you can ask others to try to hack your site.

VirtuosiMedia
A: 

Find smart folks that know web application security, specifically with respect to php/MySQL. Ask them to code review. The scanners are good, but they will miss some things. Because you are doing this for a non-profit, I'm sure there are some security researchers who will be sympathetic to the cause of the non-profit who will donate time accordingly, just as you basically are.

K. Brian Kelley
How do you know if they are smart or not? If I already knew smart people I would already have asked them.
Joe Philllips
If they're doing it for free, take what you can get and build on their suggestions. If they're actively involved in the scene their time/input is worthwhile, even if only as a foundation. IF they're not actively involved, use their audit as a user-/UI-test.
David Thomas
+2  A: 

You should cover the major 'bases' in regards to web application security:

  • [SQL Injection] - Make sure you use parameterized SQL Queries, not just string concatenation. i.e. This is bad: "Select Login FROM Users WHERE Login = '" . $_POST['Login'] . "'"
  • [XSS] - Make sure if a user puts in something like this: <script>alert('hi');</script> into one of your fields, it doesn't cause a javascript alert when you display that on a page. Escape data that may have come from a user before outputting: echo h($variable);
  • [CSRF] - Try to keep anything things out of cookies, use tokens that can be validated on form submissions (this is a bit harder to demonstrate on 1 line).
  • Cookies, hidden fields or anywhere else exposed to the user is not a good place to put anything important or anything that provides access to something.
  • Keep your servers all patched up and backed up.

These are just a few things off the top of my head, they are no where near all inclusive. Also, keep in mind that security is something that you need to work on through the entire time you are developing an application. It isn't something that just gets reviewed at the end of a project. Also, keep learning and reviewing various hacking methods - they are continually creating new ways to hack, we need to continue to keep vigilant and modify how we program to keep things secure.

Redbeard 0x0A
How would I find the correct way to protect against those using PHP?
Joe Philllips
The correct way depends on the context in which the data is being used, but check your database API for parameterization and use htmlspecialchars for escaping all text as it is output (if user formatting is required, use a system like BBCode for this so you can escape before adding the formatting HTML.
Michael Madsen
or use htmlpurifier instead of bbcode
Schnalle
I believe this snippit is the php to prevent XSS when outputting data to the web browser :: <?php echo h($somevar); ?> It has been quite a while since I have used php, you should be able to find some other examples out on the internets.
Redbeard 0x0A
+3  A: 

Don't be afraid to post your code all over the internet. Your site is not up yet, so anyone who finds a hole and tells you is a good guy. More eyes on your code is a good thing.

Ian
I suppose that is one way to look at it.
Joe Philllips
One possible issue is that some files are fairly large and random people from the internets won't want to stare at it very long.
Joe Philllips
So the people that do are more likely to be interested and engaged?
David Thomas
+2  A: 

OWASP Open Review Project will review all code that is released as open source...

jm04469
A: 

send a mail to [email protected]. if you are hosting a non-profit site, they might audit your site for free.

badman