Official hpHosts Support Forums
http://forum.hosts-file.net/

[CODE] Querying the fSpamList and StopForumSpam databases
http://forum.hosts-file.net/viewtopic.php?f=64&t=737
Page 1 of 2

Author:  MysteryFCM [ Sun Sep 21, 2008 3:18 pm ]
Post subject:  [CODE] Querying the fSpamList and StopForumSpam databases

I've modified the code that was originally posted by Smurf_Minions to the StopForumSpam forums, to additionally allow it to;

1. Check the fSpamList databases (IP, username and e-mail)
2. Check the SFS database for the username

You can see this in action at;

http://temp.it-mate.co.uk/

NOTE: There's a new version of this code a little further down

The code for this, if you'd like to use it yourself, is below.

Code:
<?php
// Modified from the script found at:
//   http://guildwarsholland.nl/phphulp/testspambot.php
//
// Modified by: MysteryFCM
//    Date: 21-09-2008
//
// Modification corrected by my friend SysAdMini at MalwareDomainList (cheers dude :))
// .... well, it is only my second PHP script, and I didn't write all of this myself hehe.

function checkSpambots($mail,$ip,$name){
    $sfsspambot = false;
    $fslspambot = false;
    $spambot = false;
    echo 'Checking fSpamList ....<br />';
    //check the e-mail address against fSpamlist
    $xml_string = file_get_contents('http://www.fspamlist.com/xml.php?email='.$mail);
    $xml = new SimpleXMLElement($xml_string);
    if($xml->Email == 'True'){
        $fslspambot = true;
        echo '<span style="color: #ff0000">E-mail found in: fSpamList</span><br />';
    }elseif($fslspambot != true){
        //e-mail not found in the database, now check the ip
        $xml_string = file_get_contents('http://www.fspamlist.com/xml.php?ip='.$ip);
        $xml = new SimpleXMLElement($xml_string);
        if($xml->IP == 'True'){
            $fslspambot = true;
            echo '<span style="color: #ff0000">IP found in: fSpamList</span><br />';
        }elseif($fslspambot != true){
            // IP not found, lets check the username
            $xml_string = file_get_contents('http://www.fspamlist.com/xml.php?username='.$name);
            $xml = new SimpleXMLElement($xml_string);
            if($xml->Username == 'True'){
                $fslspambot = true;
                echo '<span style="color: #ff0000">Username found in: fSpamList</span><br />';
            }
        }
    }
    echo 'fSpamList checked....<br />';
    echo 'Checking StopForumSpam ....<br />';
    //check the e-mail address against StopForumSpam
    $sfsxml_string = file_get_contents('http://www.stopforumspam.com/api?email='.$mail);
    $sfsxml = new SimpleXMLElement($sfsxml_string);
    // Used for debugging
    //$sfsxml_string = str_replace("<", "&lt;", $sfsxml_string);
    //$sfsxml_string = str_replace(">", "&gt;", $sfsxml_string);
    //echo $sfsxml_string;
    //echo '<br />';
    // END Used for debugging
    if($sfsxml->appears == 'yes'){
        $sfsspambot = true;
        echo '<span style="color: #ff0000">E-mail found in: StopForumSpam</span><br />';
    }elseif($sfsspambot != true){
        //e-mail not found in the database, now check the ip
        $sfsxml_string = file_get_contents('http://www.stopforumspam.com/api?ip='.$ip);
        $sfsxml = new SimpleXMLElement($sfsxml_string);
        if($sfsxml->appears == 'yes'){
            $sfsspambot = true;
            echo '<span style="color: #ff0000">IP found in: StopForumSpam</span><br />';
        }elseif($sfsspambot != true){
            // IP not found, lets check the username
            $sfsxml_string = file_get_contents('http://www.stopforumspam.com/api?username='.$name);
            $sfsxml = new SimpleXMLElement($sfsxml_string);
       if($sfsxml->appears == 'yes'){
                $sfsspambot = true;
                echo '<span style="color: #ff0000">Username found in: StopForumSpam</span><br />';
      }
        }
    }
    echo 'StopForumSpam Checked ....<br />';
    // create a .txt file with the info of the spambot, if this one already exists, increase its amount of try's
    if($sfsspambot == true){
        $spambot = true;
        $file = str_replace("*", "", $mail);
        if(file_exists('spambots/sfs_'.$file.'.txt')){
            $spambot_old_info = file_get_contents('spambots/sfs_'.$file.'.txt');
            $spambot_old_info = explode(',',$spambot_old_info);
            $spambot_old_info[2] = $spambot_old_info[2]+1;
            $spambot_old_info = implode(',',$spambot_old_info);
            file_put_contents('spambots/sfs_'.$file.'.txt',$spambot_old_info);
        }else{
            $spambot_info = $ip.','.$name.',1';
            file_put_contents('spambots/sfs_'.$file.'.txt',$spambot_info);
        }
    }
    if($fslspambot == true){
        $spambot = true;
        $file = str_replace("*", "", $mail);
        if(file_exists('spambots/fsl_'.$file.'.txt')){
            $spambot_old_info = file_get_contents('spambots/fsl_'.$file.'.txt');
            $spambot_old_info = explode(',',$spambot_old_info);
            $spambot_old_info[2] = $spambot_old_info[2]+1;
            $spambot_old_info = implode(',',$spambot_old_info);
            file_put_contents('spambots/fsl_'.$file.'.txt',$spambot_old_info);
        }else{
            $spambot_info = $ip.','.$name.',1';
            file_put_contents('spambots/fsl_'.$file.'.txt',$spambot_info);
        }
    }
    return $spambot;
}
if(isset($_GET['email'])){
    $spambot = checkSpambots($_GET['email'],$_GET['ip'],$_GET['name']);
    if($spambot == true){
        echo '<span style="color: #ff0000">Spammer identified!</span>';
    }else{
        echo 'Nope, it\'s not a spammer';
    }
}else{
   echo 'Enter the e-mail AND username (or IP) you\'d like to check (only the e-mail is mandatory)';
}
?>
<form method='GET' name='checkspamdb'>
Name: <input type='text' name='name' value='<?php if(isset($_GET['name'])){echo $_GET['name'];} ?>'><br>
E-mail: <input type='text' name='email' value='<?php if(isset($_GET['email'])){echo $_GET['email'];} ?>'><br>
IP: <input type='text' name='ip' value='<?php if(isset($_GET['ip'])){echo $_GET['ip'];} ?>'><br>
<input type='submit' name='submit' value='check'>
</form>

Author:  MysteryFCM [ Sun Sep 21, 2008 3:29 pm ]
Post subject:  Re: [CODE] Querying the fSpamList and StopForumSpam databases

For those running with ASP, I wrote a function last year, to do the same thing, for a couple of my own sites/applications;

Code:
   '// Blacklists
   Function IsUserBlacklisted(sIP, sName, sEMail)
      '// We need to make sure we can actually create the MSXML object
      If IsObject(CreateObject("MSXML2.ServerXMLHTTP")) = False Then IsUserBlacklisted = "Error: MSXML2.ServerXMLHTTP could not be created, please check MSXML is installed (v6 or above is recommended)": Exit Function
      '// Set init bool to false
      bBlacklisted = False
      set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP") 
      objXMLHTTP.open "GET", "http://www.stopforumspam.com/api?username=" & sName & "&email=" & sEMail & "&ip=" & sIP, false
      objXMLHTTP.setRequestHeader "User-Agent", Request.ServerVariables("HTTP_HOST")
      objXMLHTTP.send ""
      if objXMLHTTP.status = 200 then
         If Instr(1, objXMLHTTP.ResponseText, " yes ", vbTextCompare) > 0 Then bBlacklisted = True
      end if
      set objXMLHTTP = nothing
      '// Check fSpamList.com
      set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP") 
      objXMLHTTP.open "GET", "http://www.fspamlist.com/xml.php?username=" & sName & "&ip=" & sIP & "&email=" & sEMail, false
      objXMLHTTP.setRequestHeader "User-Agent", Request.ServerVariables("HTTP_HOST")
      objXMLHTTP.send ""
      if objXMLHTTP.status = 200 then
         If Instr(1, objXMLHTTP.ResponseText, "True", vbTextCompare) > 0 Then bBlacklisted = True
      end if
      set objXMLHTTP = nothing
      IsUserBlacklisted = bBlacklisted
   End Function

Author:  Guest [ Mon Sep 29, 2008 9:17 pm ]
Post subject:  Re: [CODE] Querying the fSpamList and StopForumSpam databases

MysteryFCM wrote:
...cheers to Ax Slinger (SFS) for reminding me that I'd forgotten to mention this...

Just trying to help those who don't know about such things. Mr. Green

Author:  MysteryFCM [ Mon Sep 29, 2008 9:40 pm ]
Post subject:  Re: [CODE] Querying the fSpamList and StopForumSpam databases

hehe Smile

Author:  Guest [ Mon Sep 29, 2008 11:10 pm ]
Post subject:  Re: [CODE] Querying the fSpamList and StopForumSpam databases

This is truly awesome. Thanks Steven and to everyone who was involved!

Author:  MysteryFCM [ Mon Sep 29, 2008 11:14 pm ]
Post subject:  Re: [CODE] Querying the fSpamList and StopForumSpam databases

hehe my pleasure Smile

Ax Slinger has pointed me to a potential bug though. Whilst it doesn't seem to affect queries against the fSpamList database, it does affect queries against the SFS database;

http://www.stopforumspam.com/forum/p139 ... 3A29#p1399

I'm looking into what's causing it Smile (my PHP knowledge still isn't great, so may take a while)

Author:  MysteryFCM [ Tue Sep 30, 2008 12:27 am ]
Post subject:  Re: [CODE] Querying the fSpamList and StopForumSpam databases

I've updated the code in the first post. Firstly to allow debugging, and secondly, to allow for errors when attempting to create a file that contains "*" (it will replace this char with a null to allow the file to be created/edited)

Author:  Guest [ Wed Oct 01, 2008 9:26 pm ]
Post subject:  Re: [CODE] Querying the fSpamList and StopForumSpam databases

I like it... And specially because it's a stand alone program that can be used by anyone regardless of what kind of program they have, forum, blog, photo gallery, or whatever.

So here's a little html table for it that I whipped together.

Step 1:
Copy this code and save it as index.php:

Code:
<?

include("config.php");

?>
<html>

<head>
<title><? echo $page_title ?></title>
</head>

<body>

<table align="center" cellpadding="2" cellspacing="0" style="border: <? echo $border ?> solid 0px;" width="100%">
  <tr>
    <td><table border="0" align="center" cellpadding="2" cellspacing="0" style="border: <? echo $border ?> solid 1px;" width="100%">
      <tr>
        <td align="center" bgcolor="<? echo $header_title_bg ?>" style="border: <? echo $border ?> solid 0px;" background="<? echo $header_title_image ?>" height="30" width="100%"><font size="4" color="<? echo $header_title_text ?>" face="<? echo $font ?>">&nbsp;<b>SpamBot Search Tool</b>&nbsp;</font></td>
      </tr>
      <tr>
        <td align="center" valign="top" bgcolor="<? echo $body_bg ?>" style="border: <? echo $border ?> solid 0px; border-top-width: 1px;"><div align="center"><table border="0" cellpadding="4" cellspacing="0" width="100%">
         <tr>
            <td>
           
            <? include("check_spammers.php"); ?>
           
            </td>
          </tr>
        </table>
        </div></td>
      </tr>
      <tr>
        <td align="center" bgcolor="<? echo $footer_title_bg ?>" style="border: <? echo $border ?> solid 0px; border-top-width: 1px;" height="24"><font size="1" color="<? echo $footer_title_text ?>" face="<? echo $font ?>"><b>Copyright © <?php echo $CopyrightYear; ?> MysteryFCM</b></font></td>
      </tr>
    </table>
    </td>
  </tr>
</table>
</body>
</html>


Step 2:
Copy this code and save it as config.php:

Code:
<?php

$page_title='SpamBot Search Tool';
$border='#000000';
$header_title_image='http://your_website.com/path/to/tile_back.gif';
$header_title_bg='#E7E9EB';
$footer_title_bg='#EFEFEF';
$body_bg='#EEEEEE';
$header_title_text='#000000';
$footer_title_text='#000000';
$font='Verdana, Arial, Helvetica, sans-serif';
$Year = date('Y');
if ($Year > 2008) {
$CopyrightYear = "2008 - $Year";
}
else {
$CopyrightYear = $Year;
}

?>

And edit it accordingly to set the path to the tile_back.gif image, and the various colors. Currently it's set to make a table similar to one like the hpHosts phpbb forum would have, but you can set any color combination you like and make a new tile_back.gif image for the title bar background, and match it to just about any forum skin. Save the file after editing.

Step 3:
Download a copy this image, tile_back.gif:

Image

Step 4:
Upload tile_back.gif, index.php, config.php, and check_spammers.php files to a folder of your choice. (Where ever you specified the tile_back.gif image would be in the config.php.)

Open the folder and you should see the program displayed in a table similar to a forum category.

Author:  MysteryFCM [ Wed Oct 01, 2008 10:21 pm ]
Post subject:  Re: [CODE] Querying the fSpamList and StopForumSpam databases

I've modified your HTML somewhat, but;

http://temp.it-mate.co.uk/

I've attached a copy of the files too Smile

Attachments:
Check_Spammers.zip [7.94 KiB]
Downloaded 46 times

Author:  Guest [ Thu Oct 02, 2008 12:04 am ]
Post subject:  Re: [CODE] Querying the fSpamList and StopForumSpam databases

That was the intended purpose of it. To make it easy to set up however you like. So there ya go. Mr. Green

Page 1 of 2 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/