Was talking to my friend about a site he is working on that had been attacked by SQL injection. Its something that makes you think hes not an idiot, I better recheck I’m not creating sites that are vulnerable to attacks. If the client is annoyed if some idiot can put his weird video up over their homepage thats nothing to how embarrassed the developer of that site feels.
What is a SQL Injection attack
A SQL injection attack is where someone manages to inject SQL into a database query on your site in order to alter that query so they can modify the database for your site. They can then go on to inject undesirable data, delete your data or expose data you don’t want exposed.
What to do to stop it
There are a number of steps you can take to reduce the likely hood of a SQL injection attack happening to you. If your using ready made software such as WordPress or another CMS the manufacturers should have dealt with these vulnerabilities. That is one of the best reasons to use ready made software but you should keep it up to date.
- Check input, filter it and escape it
- Set the database up securely – so that that user can only access the information they need to and has the lowest amount of privileges they need
- Parameterize your queries – so even with weird inputs the intent of the query can’t be changed.
- Don’t display useful error information – to a user, but do log it for you to analyze later.
- Encrypt sensitive data – even if someone gets into the database they won’t be able to use it.
- Know your database – SQL injection can be pretty clever, and different databases have different vulnerabilities. SQL SERVER for example has some quite esoteric features that can do some pretty weird stuff, you need to be aware of that if your going to use it.
You can hire specialists to do penetration testing1 which may be worthwhile depending on your budget and the value of your data.
Its a great idea to review your database backup regime. The morning you wake up and find your database has been compromised is bound to be the day when you find there isn’t a backup to restore to.
1) They do insist on calling themselves ‘pen testers’ which just makes me laugh.
- Open Web Application Security Project – on SQL injection
- SQL Injection
- Preventing SQL injection PHP theres probably an similar entry for your programming language/database