BBGameZone.net PBBG Network | BuildingBrowserGames | Top-PBBG
March 11, 2010, 07:12:45 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Our Scripts Vault contains many game scripts that you can use to create your own game!
 
  Home   Forum   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: From the Trenches :: Issue #6  (Read 956 times)
codestryke
Administrator
Level 31
*****

Reputation: 18
Offline Offline

Posts: 519



View Profile WWW
« on: April 05, 2009, 09:33:04 PM »

I got hacked. Yup just recently a player of ours found a SQL Injection point in one of our games. Yes I know I preach a lot about security, the hows and the whys but hey I'm human. Sometimes I just code stuff without thinking and I put up bad code just because it works. This article though isn't about preaching writing good secure code and scubbing your data etc. We have enough of these articles on the web what I want to talk about is what you can do to found out how you were hacked. Something not covered or discussed a lot.

I've been hacked so many times I can't even count them anymore. So it's been over time that I've leaned how to find out how the hack took place and fix it. When your looking at your game there are just so many lines of code and SQL statements its way to daughting to look though every line of code in the game. You need to take action and you need to take it now.

First thing to know is a little htaccess. Why? You need to shut your site down temporarily. You don't know how far the information has traveled. It all depends on when it happened vs when you were told or discovered it. We are going under the assumption now that you need to get the site down so you can investigate. To do this edit or add the following lines to your .htaccess file in the first public directory of your web site.

Code:
AuthName "restricted stuff"
AuthType Basic
AuthUserFile "htpasswd.acl"
require valid-user

Normally what this does is the Apache web server prompts you for a user name password. Once entered it looks to a file called htpasswd.acl on your server. This file has a user name and encrypted password but we don't want or even need the file. The file doesn't exist so no one has access to the game via the web, including you. You don't need access right now, what you need is time to look at your log files! Ok so now your site is closed.

Next is to find you Apache log files, there are so many variances on server installations I can't even begin to tell you where they might be located. If you don't know where they are now, find them and commit them to memory, sticky note or anything, just know where they are. On our recent hack we found out that we only had a day's worth of web logs, not good. We have since changed that to store 3 days worth of logs, you should find out and do the same. If you only have one game running I would recommend storing at least 5 days of logs. Just because someone breaches your server on day one doesn't mean they'll exploit it, most know that server logs because of there size rotate out of existence. Luckily our latest hacker couldn't resist exploiting what he had found, which was to our benefit.

This is a point of knowledge now, either download the Apache log files or just ssh into the server. Either way pull up the logs in your favorite text editor. Now we need to find a query string that is way out of the norm for the game in question. Many ways to do this but someone trying to exploit your game via SQL injection is going to try some normal attacks. Search the Apache log file for SELECT, UNION or 1=1. These are the most common ways to probe the database, some more elegant hacks use other methods and if that happens they you are  going to have to go line by line to find where it happened. Hopefully though you'll hit upon one of the three things I mention and now you'll have what page and query parameter they are exploiting. Fix it, delete the .htaccess file and your game is up and running (minus any fixing you might have to do to player accounts).

Most player's that have SQL injected on my sites actually tell me they found the hole and never exploit it for personal gain. Unfortunately though you can't always rely on this so knowing the above will hopefully aid you in finding and fixing the exploit.


Logged

Creating online addictions, one game at a time:
www.extremecast.com
travo
Level 18
*

Reputation: 2
Offline Offline

Posts: 186



View Profile
« Reply #1 on: June 08, 2009, 03:04:29 AM »

Thanks for the tips. Did the person do much damage?
Logged

MystressNyx
Administrator
Level 14
*****

Reputation: 4
Offline Offline

Posts: 105



View Profile WWW
« Reply #2 on: June 08, 2009, 01:07:00 PM »

No, thankfully he was all about ego. So, instead of harming the players, he logged into our Admin chat as me, informed the community of who he was, and proceeded to brag until we shut it down. lol
Logged

ckumarjha
Level 7
*

Reputation: 0
Offline Offline

Posts: 28



View Profile
« Reply #3 on: August 06, 2009, 03:47:40 PM »

gr8 article there..... that was really helpful...
I don't know much about security stuff.... so any info is gold to me
can someone tell me where to find good tutorials or similar articles on security
specially related to mysql, php and web servers.......
Logged
Sunchaser
Level 17
*

Reputation: 1
Offline Offline

Posts: 153



View Profile WWW
« Reply #4 on: August 08, 2009, 03:03:42 AM »

Thanks. Codestryke, i heard about some tools you can run toward your site that check for sql injection holes, do you know some of them by any chance?

btw, some frameworks automatically sanitize sql statements, so the developer can concentrate on game content.
Logged

Top PBBG - free traffic for your game
codestryke
Administrator
Level 31
*****

Reputation: 18
Offline Offline

Posts: 519



View Profile WWW
« Reply #5 on: August 08, 2009, 01:33:42 PM »

I've heard of such tools but never used them myself.

One thing I have been keeping an eye on (development wise) is GreenSQL

Logged

Creating online addictions, one game at a time:
www.extremecast.com
Karlos
Level 6
*

Reputation: 2
Offline Offline

Posts: 25


View Profile
« Reply #6 on: August 19, 2009, 10:30:40 PM »

Hmm.. I'll keep an eye on that tool, might come in handy with some development one day.

Thanks codestryke
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
SimplePortal 2.2 © 2008-2009
Valid XHTML 1.0! Valid CSS!