Jump to content


Photo

How do I fight this forum hacker? How to get his ip info?


  • Please log in to reply
11 replies to this topic

#1 cardoso

cardoso
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationToronto

Posted 30 August 2006 - 01:27 PM

Hi All,  I have a community site that I've created as a hobby.... over the past month os so, there's been this guy/girl who has made it their mission to enter loads of crap on my site.  At first it was only 2 or 3 a day... yesterday it was 160.

So I implimented one of those "captcha" thing to make it harder... that only helped for a few hours.  Then I started filtering the content in my sql statement... that's getting to be more work then it's worth... he/she has far too many words for me to keep up.  Now I decided to capture and write to the DB the user's info based on ip... so I get the following:
$ip = $_SERVER['REMOTE_ADDR'];
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$referrer_page = $_SERVER['HTTP_REFERER'];
$requested_page = $_SERVER['REQUEST_URI'];
$AllUserInfo = "----IP:".$ip."----HOSTNAME:".$hostname."----REFERRER PAGE:".$referrer_page."----REQUESTED PAGE:".$requested_page;

But that did not work...  I get a NULL value... he's somehow blocking that information.

Can someone help?  This is a free site I've created out of the love for my community and this person is making it so hard for me to want to continue.

Thanks for any help you might throw my way.

Nelson Cardoso

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 30 August 2006 - 01:32 PM

You could only allow posts where $_SERVER['REMOTE_ADDR'] is available - that way you could back trace.

Even if they spoof an ip address you will get another measure of how they are circumventing your system - and then prevent that.
follow me on twitter @PHPsycho

#3 cardoso

cardoso
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationToronto

Posted 30 August 2006 - 02:38 PM

Good call!!!  I've already implimented your idea.  I'm a bit of a newbie with sql so I hadn't thought of that.

Thank you soooooooooo much.

Nelson Cardoso

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 30 August 2006 - 02:46 PM

Did yu create the forum yourself, if you did then it sounds like you have an exploit in your code which the hacker is using to spam your forum.

#5 cardoso

cardoso
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationToronto

Posted 30 August 2006 - 02:52 PM

Hi wildteen88... any gotcha's that I should look out for?  Any "recommends" for solutions?

Thanks for replying to my email

Nelson

#6 cardoso

cardoso
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationToronto

Posted 30 August 2006 - 03:03 PM

ToonMariner, not sure if you're still following this thread... can you help with one more thing (or anyone else)?

I added what another snippet to my if statement before my insert code:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "malta_add") && ($_SERVER['REMOTE_ADDR'] != "")) {.......

I added the:  && ($_SERVER['REMOTE_ADDR'] != "")

This was to try to avoid the hacker from even submitting if the ip was empty.  But it didn't work because he was able to submit... and when I look at the database, no value was captured in my "user ip" field.  Have I written this wrong?  Shouldn't that addition have stopped a post if there was no value for $_SERVER['REMOTE_ADDR'?

Thanks a million!!

Nelson

#7 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 30 August 2006 - 03:30 PM

I added what another snippet to my if statement before my insert code:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "malta_add") && ($_SERVER['REMOTE_ADDR'] != "")) {.......

Have I written this wrong?  Shouldn't that addition have stopped a post if there was no value for $_SERVER['REMOTE_ADDR']


You could try this:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "malta_add") && (!$_SERVER['REMOTE_ADDR'])) {.......

I think this should work if $_SERVER['REMOTE_ADDR'] is empty.

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#8 cardoso

cardoso
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationToronto

Posted 30 August 2006 - 04:18 PM

Wow!!!  This forum is fantastic!!!  You people have been a great help....

HuggieBear... the only change I made was "I took out the '!'"... because I want them to submit if there is an ip address.

You got me 99% over that hurdle (I have to do some thinking for myself)... thanks so much!

Take care.
Nelson

#9 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 30 August 2006 - 04:20 PM


Even if they spoof an ip address you will get another measure of how they are circumventing your system - and then prevent that.


I agree.

here is a very good article that describes various methods of insertion and how to prevent them. Here is one that is just good general reading. I found these to be very infomative and think that they should be standard reading for all.

The most improtant thing is to sanitize the user imputed data. Use something like mysql_real_escape_string and maybe preg_match, to pervent unwanted caricatrues.

The reason that the ip field is empty is most likely that they are bypassing that field. What I would do is have a time stamp that for each post(You may already have that). I would then create a table (called something like `hits`)and a script that would  record the ip of every person that enters my site along with the referrer and timestamp.

Then when the unwanted posts are placed then you could search the `hits` table by the timestamp in the post. And there we go. You should now have the ip of the person that is posting these posts.

They may also be posting from out side your site. So another thing that I would do is do something like this

if (!$_SERVER['HTTP_REFERER'] !== 'http://yoursite.com/the_posting_page.php')
    header("HTTP/1.1 404 Not Found");
}

Or maybe a acess denied error. I would stick with the the 404.

Good luck,
Tom



Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#10 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 30 August 2006 - 04:23 PM

HuggieBear... the only change I made was "I took out the '!'"... because I want them to submit if there is an ip address.

You got me 99% over that hurdle (I have to do some thinking for myself)... thanks so much!


Sorry about the '!' I misread the code...  :o

Glad you picked up on it though  :)
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#11 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 30 August 2006 - 04:32 PM

also, just to clear up that you bug isn't actually somewhere else, is this person's the ONLY person that your db is not getting their ip address? In other words, is your db storing other people's ip addresses just fine?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#12 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 30 August 2006 - 04:34 PM

Another thing that I would do is put size limits on all of my text fields , something like 20, and maybe pass all of the fields that are going to be placed in database through htmlentities

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users