Protect your database from possible data theft

I recently got a mail from one of my friend Atish Ranjan regarding blog of his friend ( getting hacked by someone. So today I was analyzing if there is a way to know loophole on your domain from yourside which may lead to some hacking or data theft kind of thing and I came to know of several tricks which if used positively can led to protection of our site, domain and valuable data. Most of these are due to our negligence and laziness.

First in my list is the database’s data theft.

Database backup done unsecurely: By unsecurely I mean that the backup has not been placed securely and not the method of doing the backup. Let us assume that we recently did a complete (or partial) database backup of our site and by default it is named as “<dbname>.sql” where dbname is your database name. After having the backup it is a common practice to keep in some folder (or deep folder) and we forget about it. Keeping the backup this way is one of the unsecure way. How?

Why is it unsecure?

If the permission for that file allows third person to read or access that file then he can steal your data and above that he may use sql injection to destroy or modify your database.

How would he come to know about the existence of such file?

Google search is the key to answer such question. You can create search text which will force the google search to reveal such a kind of file. Let me show you an example Search for following text in google filetype:php

above query will list all the files which are php file(having extension php) on the domain, similarly you can search for sql files as well. Once I have the database structure of your database I can use sql injection tricks or other tricks to manipulate your data.

How to secure that?

Simple first of all do not keep such dumps or backups in the web folders(on server). If in case you must keep the file there, make it unaccessable by the third persons. You can achieve that by setting public permission to unreadable and unaccessible by users or issue a linux command something like

SITE CHMOD xx0 file.sql

Where xx is the permission for owner and group respectively(it can be anything from 0 to 7 depending on your settings) and file.sql being the file to be protected.

Or you can also set the whole directory to be unaccessible.

You can also restrict the search engine from indexing these files by writing following lines in your robot.txt file

User-agent: *
Disallow: /directory/
Disallow: /filename.ext

where directory being the directory name (if you want to restrict the whole directory) and filename.ext being the file name (if you want to restrict some particular files only). You can also diallow multiple files or directories.

Try accessing and will not allow you to view the image since its permission has been changed.

So go and have a search for your domain if it has some sql files lying unsecurely and fix it up. Replace yoursite with your domain and hit enter, it will open the search in a new window

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.