Advertisement
jvvg

Spam Reporting Script 5/23

May 23rd, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.34 KB | None | 0 0
  1. <?php
  2. $sites = array('[redacted]');
  3. shuffle($sites);
  4. $api_key = '[redacted]';
  5.  
  6. function PostToHost($data) {
  7.    $fp = fsockopen("www.stopforumspam.com",80);
  8.    fputs($fp, "POST /add.php HTTP/1.1\n" );
  9.    fputs($fp, "Host: www.stopforumspam.com\n" );
  10.    fputs($fp, "Content-type: application/x-www-form-urlencoded\n" );
  11.    fputs($fp, "Content-length: ".strlen($data)."\n" );
  12.    fputs($fp, "Connection: close\n\n" );
  13.    fputs($fp, $data);
  14.    fclose($fp);
  15. }
  16.  
  17. function curl_get($url, $refuseblank = false) {
  18.     $ch = curl_init ();
  19.     curl_setopt ( $ch, CURLOPT_URL, $url);
  20.     curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
  21.     curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  22.     curl_setopt ( $ch, CURLOPT_ENCODING, "" );
  23.     curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)" );
  24.     if (defined('SERVER_LOGIN')) { //my test server requires a login
  25.         curl_setopt($ch, CURLOPT_USERPWD, SERVER_LOGIN);
  26.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  27.     }
  28.     $out = '';
  29.     if ($refuseblank) {
  30.         while ($out == '') {
  31.             $out = curl_exec ($ch);
  32.         }
  33.     } else {
  34.         $out = curl_exec($ch);
  35.     }
  36.     curl_close($ch);
  37.     return $out;
  38. }
  39.  
  40. $spamurls = array();
  41. $i = 0;
  42. $spamcounts = array();
  43. foreach ($sites as $url) {
  44.     $spamcounts[$url] = array();
  45.     $sitecount = 0;
  46.     $continue = true;
  47.     echo 'Trying site ' . $url . "\n";
  48.     //get number of registered users
  49.     $site = curl_get($url);
  50.     while ($continue) {
  51.         $data = curl_get($url . '/spam.php?salt=' . time());
  52.         if (!strstr($data, '<?xml')) {
  53.             echo 'Site could not be harvested. Check that it is working properly.' . "\n";
  54.             $continue = false;
  55.             break;
  56.         }
  57.         $xml = new SimpleXMLElement($data);
  58.         if (!isset($xml->user)) {
  59.             $continue = false;
  60.             break;
  61.         }
  62.         foreach ($xml->user as $user) {
  63.             $username = (string)$user->username;
  64.             $email = (string)$user->email;
  65.             $ip = (string)$user->ip;
  66.             $evidence = (string)$user->evidence;
  67.            
  68.             $resp = posttohost('username=' . rawurlencode($username) . '&ip_addr=' . rawurlencode($ip) . '&evidence=' . rawurlencode($evidence) . '&email=' . rawurlencode($email) . '&api_key=' . $api_key);
  69.             $i++;
  70.             $sitecount++;
  71.             if ($sitecount % 10 == 0) {
  72.                 echo ' -> ' . $sitecount . ' entries...' . "\n";
  73.             }
  74.            
  75.             //any URLs?
  76.             $lines = explode("\n", $evidence);
  77.             foreach ($lines as $line) {
  78.                 if (strpos($line, 'http') === 0) {
  79.                     $spamurls[] = $line;
  80.                 }
  81.                 if (strpos($line, 'Registered: ') === 0) {
  82.                     preg_match('%(\d+) (.*?) (\d+)%', $line, $matches);
  83.                     $timestamp = $matches[0];
  84.                     if (isset($spamcounts[$url][$timestamp])) {
  85.                         $spamcounts[$url][$timestamp]++;
  86.                     } else {
  87.                         $spamcounts[$url][$timestamp] = 1;
  88.                     }
  89.                 }
  90.             }
  91.         }
  92.     }
  93.     if (isset($spamcounts[$url])) {
  94.         $data = file_get_contents('stats.txt');
  95.         foreach ($spamcounts[$url] as $timestamp => $count) {
  96.             $data .= $url . ',' . $timestamp . ',' . $count . "\n";
  97.         }
  98.         file_put_contents('stats.txt', $data);
  99.     }
  100.     echo ' -> ' . $sitecount . ' entries for that site' . "\n";
  101. }
  102. echo $i . ' entries processed.' . "\n";
  103.  
  104. //record any new spam urls
  105. $existingspamurls = explode("\n", file_get_contents('spamurls.txt'));
  106. $spamurls = array_unique(array_merge($existingspamurls, $spamurls));
  107. file_put_contents('spamurls.txt', implode("\n", $spamurls));
  108. unset($spamurls, $existingspamurls);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement