Exemple #1
0
 protected function check(SblamURI $link)
 {
     $domain = $link->getDomain();
     $min = max(2, count(explode('.', $domain)) + 1);
     $res = $this->blacklist->check($link->getHostname());
     if ($res >= $min) {
         return $res + 1 - $min;
     }
     return 0;
 }
Exemple #2
0
 function index()
 {
     $pdo = $this->services->getDB();
     $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
     $sblam = $this->getSblam();
     $pdo->exec("/*maxtime15*/DELETE from dupes where expires < unix_timestamp(now())");
     $pdo->exec("TRUNCATE bayeswordsh_s");
     $pdo->exec("TRUNCATE linkswordsh_s");
     $pdo->exec("/*maxtime15*/UPDATE plonker f join dnscache d on f.ip=d.ip left join trustedproxies t on t.host=d.host\n\t\tset f.added=f.added,f.spampoints = f.spampoints/2 where\n\t\td.host like '%.adsl.tpnet.pl' or\n\t\td.host like '%.dialog.net.pl' or\n\t\td.host like '%.proxy.aol.com' or\n\t\td.host like '%.chello.pl' or\n\t\td.host like '%.unregistered.net.telenergo.pl' or\n\t\tt.host is not null\n\t\t");
     $pdo->exec("/*maxtime10*/DELETE from plonker where (spampoints<50 and added < now() - interval 3 month) or spampoints<5");
     $pdo->exec("/*maxtime10*/DELETE from dnscache where host is NULL or rand()<0.4");
     $pdo->exec("/*maxtime10*/DELETE from dnsrevcache where ip = 0 or rand()<0.4");
     $pdo->exec("/*maxtime10*/delete from plonker where ip = inet_aton('127.0.0.1') or\nip between inet_aton('172.16.0.0') and inet_aton('172.31.255.255') or\nip between inet_aton('192.168.0.0') and inet_aton('192.168.255.255') or\nip between inet_aton('10.0.0.0') and inet_aton('10.255.255.255') or\nip between inet_aton('224.0.0.0') and inet_aton('255.255.255.255');");
     $n = 0;
     $q = $pdo->query("/*maxtime15*/SELECT t.host FROM trustedproxies t left join dnscache d ON d.host = t.host WHERE d.host is NULL");
     if ($q) {
         foreach ($q->fetchAll(PDO::FETCH_ASSOC) as $res) {
             SblamURI::gethostbyname($res['host']);
         }
     }
     $pdo->exec("/*maxtime10*/INSERT into dnscache (host,ip) select t.host,r.ip FROM trustedproxies t left join dnscache d ON d.host = t.host join dnsrevcache r on t.host = r.host WHERE d.host is NULL;");
     $pdo->exec("DELETE from plonker WHERE ip BETWEEN  INET_ATON('192.168.0.0') AND INET_ATON('192.168.255.255')");
     $pdo->exec("DELETE from plonker WHERE ip BETWEEN  INET_ATON('172.16.0.0' ) AND INET_ATON('172.31.255.255')");
     $pdo->exec("DELETE from plonker WHERE ip BETWEEN  INET_ATON('127.0.0.0' ) AND INET_ATON('127.0.0.255')");
     /*
     		set @minid = least((select id-40000 from posts_meta order by id desc limit 1),(select id+5000 from posts_meta order by id limit 1)); insert into posts_archive
     		select * from posts_meta left join posts_data on posts_meta.id = posts_data.id where posts_meta.id < @minid; delete from posts_meta where id < @minid;
     */
     if (date("d") % 1) {
         $pdo->exec("/*maxtime30*/DELETE from bayeswordsh where spam<4 and ham<2 and added < now() - interval 2 month limit 20000");
     } else {
         $pdo->exec("/*maxtime30*/DELETE from linkswordsh where spam<3 and ham<2 and added < now() - interval 2 month limit 10000");
     }
     return array('page_content' => 'ok');
 }
Exemple #3
0
 function getCheckIPResults()
 {
     $out = array();
     foreach ($this->ips as $ip => $ipinfo) {
         list($reason, $scorefactor) = $ipinfo;
         $res = SblamURI::gethostbynamel($this->reverse($ip));
         if ($res) {
             foreach ($res as $resip) {
                 $tmp = $this->score($ip, $resip, $reason, $scorefactor);
                 if ($tmp) {
                     $out[] = $tmp;
                 }
             }
         }
     }
     if (!count($out)) {
         return NULL;
     }
     $res = Sblam::sumResults($out);
     if ($res[0] > 1) {
         $res[0] = 1;
     }
     if ($res[1] > self::CERTAINITY_HIGH) {
         $res[1] = self::CERTAINITY_HIGH;
     }
     return $res;
 }
Exemple #4
0
 function getCheckHostResults()
 {
     $score = 0;
     foreach ($this->addedhosts as $host => $whatever) {
         $host .= '.multi.surbl.org';
         $res = SblamURI::gethostbynamel($host);
         if ($res && count($res)) {
             d($res, "found banned {$host}");
             $score += 3;
             $mask = 0;
             foreach ($res as $ip) {
                 $mask |= ip2long($ip);
             }
             $mask &= 127 - 1 - 16;
             // outblaze list has false positives, so lower score
             d($mask, "banned mask");
             while ($mask) {
                 $score++;
                 $mask >>= 1;
             }
             d("total surbl score until now is {$score}");
         } else {
             d("{$host} not listed {$res}");
         }
     }
     $finalscore = min(0.4 + $score / 25, 1.5);
     if ($score) {
         return array($finalscore, $score >= 13 ? self::CERTAINITY_HIGH : self::CERTAINITY_NORMAL, "Linked sites in SURBL (" . round($finalscore, 1) . " = {$score})");
     }
     return NULL;
 }
Exemple #5
0
 private function lookup(array $hosts)
 {
     $sblam = $this->getSblam();
     // init SblamURI
     foreach ($hosts as $h) {
         d(SblamURI::gethostbyname($h['host']), $h['host']);
     }
 }
Exemple #6
0
 static function init($tldsfile, PDO $db = NULL)
 {
     //d('initializing tlds');
     self::$tlds = new DomainMatch($tldsfile);
     self::$db = $db;
     if (!$db) {
         warn("No cache");
     }
     self::$useasync = AsyncDNS::supported();
 }
Exemple #7
0
 protected function readConfig(array $ini)
 {
     if (!empty($ini['tlds'])) {
         SblamURI::init($ini['tlds'], $this->services->getDB());
     } else {
         warn('tlds not given!');
     }
     if (!empty($ini['dns'])) {
         AsyncDNS::init(preg_split('![\\s,]+!', $ini['dns'], NULL, PREG_SPLIT_NO_EMPTY));
     } else {
         warn('dns not given!');
     }
     foreach ($ini as $name => $settings) {
         if (!is_array($settings) || $name == 'db') {
             continue;
         }
         if (!empty($settings['disabled']) || isset($settings['enabled']) && !$settings['enabled']) {
             /*d($name,'disabled');*/
             continue;
         }
         try {
             include_once "tests/" . strtolower($name) . ".php";
             $classname = "SblamTest" . ucfirst($name);
             if (!class_exists($classname)) {
                 warn($name, "Problem loading test plugin");
             }
             $info = call_user_func(array($classname, 'info'));
             if (!empty($info['remote']) && isset($ini['remote']) && !$ini['remote']) {
                 d($info, 'Its a remote service, remote disabled, skipping');
                 continue;
             }
             if (!empty($info['unsupported'])) {
                 d($info, 'unsupported in this configuration');
                 continue;
             }
             $test = new $classname($settings, $this->services);
             if (!$test instanceof ISblamTest) {
                 warn($test, 'Not a test');
                 continue;
             }
             //d($classname,"instantiated");
             $this->addTest($test, isset($settings['phase']) ? $settings['phase'] : 10);
         } catch (Exception $e) {
             warn($e, "Failed to initialize plugin {$name}");
         }
     }
     return true;
 }
Exemple #8
0
 private function severity($ip)
 {
     $rev = SblamURI::gethostbyaddr($ip);
     if (is_array($rev)) {
         warn($rev, "gethostbyaddr returned array!?");
         $rev = reset($rev);
     }
     if (!$rev) {
         return 3;
     }
     if (preg_match('/(^|[.-])(vp[sn]|srv)[.\\d-]|(^|\\.)(colo|dedi?)[-.]|dedic|resell|serv(er|[.\\d-])|^ns\\d*\\.|^mail\\d*\\.|multicast|invalid|unknown/', $rev)) {
         return 2;
     }
     if (preg_match('/internetdsl\\.|static/', $rev) || preg_match('/^[^\\d]+$/', $rev) || strlen($rev) < 10) {
         return 1.5;
     }
     if (preg_match('/^nat[\\d.-]|cache|proxy|gprs[^a-z]|dynamic|\\.dhcp\\.|\\.sta\\.|ppp[\\d.-]|\\.dyn\\.|(^|[.-])adsl[.0-9-]/', $rev)) {
         return 0.8;
     }
     return 1;
 }
Exemple #9
0
 function index()
 {
     $pdo = $this->services->getDB();
     $sblam = $this->getSblam();
     // inits urls
     $table = 'plonker';
     // FIXME: read config!
     $accumulate = array();
     $max = 10;
     while ($max--) {
         foreach ($pdo->query("SELECT ip,added from {$table} where flags=0 order by rand() limit 2000") as $r) {
             try {
                 $ip = long2ip($r['ip']);
                 $rev = preg_replace('!(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)!', '\\4.\\3.\\2.\\1.dul.dnsbl.sorbs.net', $ip);
                 $r['rev1'] = $rev;
                 SblamURI::gethostbynameasync($rev);
                 $rev = preg_replace('!(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)!', '\\4.\\3.\\2.\\1.korea.services.net', $ip);
                 $r['rev2'] = $rev;
                 SblamURI::gethostbynameasync($rev);
                 $accumulate[] = $r;
                 usleep(50000);
                 if (count($accumulate) >= 20) {
                     foreach ($accumulate as $r) {
                         $res = SblamURI::gethostbyname($r['rev1']) ? 'dul' : 'nodul';
                         $res .= ',' . (SblamURI::gethostbyname($r['rev2']) ? 'wild' : 'nowild');
                         $q = "update {$table} set flags = '{$res}', added = added where ip = {$r['ip']}";
                         d($q);
                         if (!$pdo->query($q)) {
                             warn($pdo->errorInfo());
                         }
                     }
                     $accumulate = array();
                 }
             } catch (Exception $e) {
             }
         }
     }
     return array('redirect' => '/admin/plonker');
 }
Exemple #10
0
 function testPost(ISblamPost $p)
 {
     // whitelist only direct connection (because other can be forged) and only when there aren't any objectionable hosts there
     $out = array();
     $firstIP = true;
     $whitelisted = false;
     foreach ($p->getAuthorIPs() as $ip) {
         $rev = SblamURI::gethostbyaddr($ip);
         if (!$rev) {
             continue;
         }
         if (is_array($rev)) {
             warn($rev, 'gethostbyaddr returned array');
             $rev = reset($rev);
         }
         // WTF?
         if (preg_match('!(?:\\.|^)(?:' . $this->isps . ')$!', $rev)) {
             $out[] = array(0.5, self::CERTAINITY_LOW, "Sent from blacklisted ISP ({$rev})");
         } else {
             if ($firstIP && preg_match('!\\.(?:' . $this->whitelist . ')$!', $rev)) {
                 $whitelisted = true;
             } else {
                 if (preg_match('!\\.(?:' . $this->blacklist . ')$!', $rev)) {
                     $out[] = array(0.35, self::CERTAINITY_LOW, "Sent from blacklisted TLD ({$rev})");
                 }
             }
         }
         $firstIP = false;
     }
     if (!count($out) && $whitelisted) {
         return array(-0.25, self::CERTAINITY_LOW, "Sent from whitelisted TLD ({$rev})");
     }
     if (count($out)) {
         return $out;
     }
 }
Exemple #11
0
 function addURI(array &$urls, SblamURI $link, $prefix = '')
 {
     if ($link->isTLD()) {
         return;
     }
     if ($hostname = $link->getHostname()) {
         $hostname = preg_replace(array('!^www\\.!', '!\\d\\d+!'), array('', 'D'), $hostname);
         // normalise digits! (block bulk registrations)
         $urls[$prefix . $hostname] = true;
         if ($domain = $link->getDomain()) {
             $urls[$prefix . $domain] = true;
         }
         if ($p = $link->getPath()) {
             $p = preg_replace('!^(/[^#]{1,7}[^#/\\?]{0,5}).*$!', '\\1', $p);
             // shorten path. its mainly for getting real tinyurl adresses, not every spammy subpage out there
             if ($p !== '/') {
                 $urls[$prefix . $hostname . $p] = true;
             }
         }
     }
     if (preg_match('!\\b(?:site:|https?://)([a-zA-Z0-9.-]+)!', urldecode($link->getPath()), $m)) {
         $this->addURI($urls, new SblamURI('http://' . $m[1]), $prefix);
     }
 }
Exemple #12
0
 private function queue_prefetch(array $spams)
 {
     foreach ($spams as $spam) {
         foreach ($spam->getAuthorIPs() as $ip) {
             SblamURI::gethostbyaddrasync($ip);
         }
     }
 }