Our website is 100% API based (with an SPA client). Recently, a hacker managed to get our admin's password (hashed with SHA-256) through SQL injection (and cracking pwd) like this:
https://example.com/api/products?userId=3645&type=sqlinject here
It is just an example, but it is deadly to us. Fortunately, it was a nice hacker and he just emailed us about the hack. Lucky for a website under constants attacks throughout it's 5 years of existence.
Yes we DO know that we need to check user input everywhere and do properly format/escape/prepared statement before sending data to MySQL. We know, and we are fixing it. But we do not have enough developers/testers to make it 100% safe.
Now assuming we have 0.1% chance of being SQL injected somehow. How do we make it harder for hacker to find it and limit the damage as possible?
What we do so far as quick fixes/additional measurements:
At the output "gate" shared by all APIs, we no longer send the raw PDOException and message like before. But we still have to tell the client that exception occurred:
{type: exception, code: err643, message: 'contact support for err643'}
I am aware that if hacker see exception, he will keep trying...
The user PHP uses to connect to MySQL can only CRUD to tables. Is that safe enough?
Rename all tables (we use open source so hacker can guess the tables name).
What else should we do?
Update : since there are many comments, I would like to give some side info
- First of all, this is LEGACY app, developed by some student-like folks, not enterprise grade. The dev team is nowhere to be found, now only 1-2 hybrid dev-test guy handling hundreds of Data Access class.
- The password is hash with SHA-256, yes it sucks. And we are changing it to recommended php way.
- SQL injection is 17 years old. Why is it still around?
- Are prepared statements 100% safe against SQL injection?