Blog Hoch
May 2018·2 tup leghDe'wI' ghItlhta'

SPAM protection methods N° 1: Honeypot

#block#honeypot#spam#spambot#spamprotection

Internet beginning vo' annoying topic SPAM (canned meat pagh - Internet law' qan). bored weekend: SPAM (webcrawler je) avoid chay' think, "SPAM protection methods" series chenmoH. series part 1: annoying SPAM bots website vo' lock; automated tools (SiteSucker) 'ej automated scripts (Chromium) keep out je. reH (naDev je): article inspiration neH, 1:1 thoughtlessly copy Qo'. wrong use vaj script regular users exclude laH (content preloader lo' pagh browser itself content preload).

1. Concept

wa'DIch bot detect, cha'DIch block. original idea: htaccess file via bot block. script bot detect vaj htaccess end Daq line deny {IP} write. good idea, implementation problematic: .htaccess chmod writable make poQ - pulse ~200 rise. alternative: "Sessions". user status session Daq store, blocked IP addresses database Daq. new user site Daq arrive vaj database check: IP blocked'a'. session variable assign (page load Hoch check, SQL queries save). legh: sessions alone Dun pagh - cookie delete help. bot detect Qatlh. jIH solution "hidden link" insert: Ultra Fancy Link. spam bot (link visible Sov pagh - href attribute neH relevant) target.php call (honeypot Daq). 'ach browsers plugins content precache page call vaj "normal" user honeypot Daq fall laH. avoid poQ. problem solve: path https://example.com/target.php robots.txt Daq write. browsers content precache robots.txt respect (good ones) - "false positive" avoid. target.php database IP address browser feed neH.

2. Implementation

Step 1: database

tables database Daq create:

CREATE TABLE `spamblock` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `ip` text,
  `stamp` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Spamblock table: primary ID, "ip" field (IP address), "stamp" (timestamp).

Step 2: target.php

target.php (pIm pong laH). IP address 'ej timestamp table Daq insert, session variable set.

<?php
$dbname = "dbname";
$username = "username";
$password = "password";

$pdo = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
$ip = $_SERVER['REMOTE_ADDR'];
$stamp = time();

$stmt = $pdo->prepare("INSERT INTO spamblocked (ip, stamp) VALUES (:ip, :stamp)");
$stmt->bindParam(':ip', $ip);
$stmt->bindParam(':stamp', $stamp);
$stmt->execute();
?>

dbname, username, password replace.

Step 3: variable check

page call Hoch $_SESSION['spamblock'] true pagh false check. script htaccess via auto prepend: php_value auto_prepend_file "/var/www/virtual/david/check.php" (absolute path!) pagh line page Hoch beginning Daq add:

<?php
session_start();
if (isset($_SESSION['spamblock']) && $_SESSION['spamblock'] === true) die();
?>

$_SESSION['spamblock'] set 'ej true check. yes vaj script end.

Step 4: Robots.txt

target.php robots.txt Daq add ("good" crawlers scare pagh, precaching problems pagh).

User-agent: *
Disallow: /target.php

robots.txt structure self-explanatory.

Step 5: Hidden link pagh other redirect

hidden link regular page Daq insert (as far "front" possible: index.php good, /unterseite/unterseite/unterseite/irgendeinfile.php bad). crawler whole page process 'ej end Daq lock vaj sense pagh. JavaScript redirect je laH. possibility 1: "display:none" attribute link Daq.

<a href='target.php' style='display:none'>

possibility 2: JavaScript (crawler JavaScript disabled poQ; regular user JavaScript disabled vaj lock je. thought stimulus, serious solution pagh).

<noscript>
  <iframe src="target.php"></iframe>
</noscript>

extend laH. ideas vaj comments Daq.

Step 6: conclude

Hoch files upload, database prepare, insert.php "Username" "Password" database credentials replace ;-)

Addition: adblocker use

more: adblocker (almost every user install, crawler pagh). target.php subtarget.php rename, target.php iFrame write:

<iframe src="subtarget.php" id="advert"></iframe>

"normal" user AdBlocker resource block; bot iFrame load 'ej IP address database Daq write. id "advert" set pagh subtarget.php advertisting.php pong - Adblock active.

chu'HTTP Range Request PHP rap processqanJavascript Promises