Skip to content

Instantly share code, notes, and snippets.

@ruslanchek
Created August 5, 2012 21:42
Show Gist options
  • Save ruslanchek/3267237 to your computer and use it in GitHub Desktop.
Save ruslanchek/3267237 to your computer and use it in GitHub Desktop.
Litle DDoS hack :-)
<?PHP
if((!isset($_COOKIE) || !isset($_GET['r'])) || $_GET['r'] != $_COOKIE['r']){
$rnd = md5(mt_rand());
if($_SERVER['QUERY_STRING'] && !$_GET['r']){
$s = '?' . $_SERVER['QUERY_STRING'] . '&r='.$rnd;
}else{
$s = '?r='.$rnd;
};
$request = "http://" . $_SERVER['HTTP_HOST'] . "/" . $_SERVER['PHP_SELF'] . $s;
die('<html><head><script type="text/javascript">
function setCookie (name, value, expires, path, domain, secure) {
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
};
var d = new Date();
d.setHours(d.getHours() + 1);
setCookie("r", "'.$rnd.'", d, "/");
document.location.href="'.$request.'"
</script></head><body></body></html>');
};
@ruslanchek
Copy link
Author

Скрипт пишет при помощи JS куку, с рандомным MD5-хешем, затем перебрасывает клиента опять на тот же самый, запрошенный им ранее адрес, с теми же параметрами + тот самый хеш, и проверяет его, в случае несовпадения или отсутствия куки делает die().

Помогает от небольших атак DDOS-ботов.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment