Exploit-DB #40640
Description: InfraPower PPS-02-S Q213V1 - Remote Command Execution
Type: webapps
Platform: hardware
Date: 2016-10-28
Author: LiquidWorm

Exploit:
InfraPower PPS-02-S Q213V1 Unauthenticated Remote Root Command Execution


Vendor: Austin Hughes Electronics Ltd.
Product web page: http://www.austin-hughes.com
Affected version: Q213V1 (Firmware: V2395S)
Fixed version: Q216V3 (Firmware: IPD-02-FW-v03)

Summary: InfraPower Manager PPS-02-S is a FREE built-in GUI of each
IP dongle ( IPD-02-S only ) to remotely monitor the connected PDUs.
Patented IP Dongle provides IP remote access to the PDUs by a true
network IP address chain. Only 1xIP dongle allows access to max. 16
PDUs in daisy chain - which is a highly efficient cient application
for saving not only the IP remote accessories cost, but also the true
IP addresses required on the PDU management.

Desc: InfraPower suffers from multiple unauthenticated remote command
injection vulnerabilities. The vulnerability exist due to several POST
parameters in several scripts not being sanitized when using the exec(),
proc_open(), popen() and shell_exec() PHP function while updating the
settings on the affected device. This allows the attacker to execute
arbitrary system commands as the root user and bypass access controls in
place.

Tested on: Linux 2.6.28 (armv5tel)
           lighttpd/1.4.30-devel-1321
           PHP/5.3.9
           SQLite/3.7.10


Vulnerabiliy discovered by Gjoko 'LiquidWorm' Krstic
                            @zeroscience


Advisory ID: ZSL-2016-5372
Advisory URL: http://www.zeroscience.mk/en/vulnerabilities/ZSL-2016-5372.php


27.09.2016

--


doupgrate.php:
--------------


09: <?
10: echo "Firmware Upgrate Using NFS:<BR>";
11: echo "IP=".$_POST["ipaddr"]."<BR>";
12: echo "Firmware Name=".$_POST["fwname"]."<BR>";
13: system("sh nfs.sh");
14: echo "Mounting NFS<BR>";
15: system("mount -t nfs -o nolock ".$_POST["ipaddr"].":".$_POST["nfsdir"]." /nfs");
16: system("cp /nfs/".$_POST["fwname"]." /");
17: echo "Flash erasing<BR>";
18: system("@flash_eraseall /dev/mtd0");
19: system("cp /".$_POST["fwname"]." /dev/mtd0");
20: echo "Upgrate done<BR>";
21: system("umount /nfs");
22: echo "Reboot system<BR>";
23: system("reboot");
24: ?>

---------------------------------------------------------------------


IPSettings.php:
---------------


83: $IP_setting = ereg_ip($_POST['IP']);
84: $Netmask_setting = ereg_ip($_POST['Netmask']);
85: $Gateway_setting = ereg_ip($_POST['Gateway']);
...
...
110:                    $fout = fopen("/mnt/mtd/net_conf", "w");
111:                    if($fout){
112:                        $output = substr($output, 0, -1);
113:                        fprintf($fout, "%s", $output);
114:                        //echo $change_ip.'b';
115:                        if($change_ip === '1'){
116:                            $str = '';
117:                            exec('ifconfig eth0 '.$IP_setting.' netmask '.$Netmask_setting, $str);
118: //                          echo $str."\n";
119:                        }
120:                        if($change_gw === '1'){
121:                            $str = '';
122:                            exec('ip route del default', $str);
123:                            exec('route add default gw '.$Gateway_setting, $str);
124: //                          echo $str[0]."a\n";
125:                        }
126:                    }
127:                    fclose($fout);
...
...
164:    function ereg_ip($ipstring){ 
165:         $ipstring=trim($ipstring); //移除前後空白 
166:        //格式錯誤 
167:        if(!ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$",$ipstring))return 0; 
168:        //內容檢查 
169:        $ip_segment =split("\.",$ipstring); //注意一定要加 "\"，否則會分不開。 
170:        foreach($ip_segment as $k =>$v){ 
171:            if($v >255){ 
171:                return 0; 
172:            }
173:            $ip_segment[$k]=(int)$ip_segment[$k]; //消除ip中的0，ex:1.020.003.004 =>1.20.3.4 
174:        } //end foreach 
175:        $ipstring ="$ip_segment[0].$ip_segment[1].$ip_segment[2].$ip_segment[3]"; //將字串$ip處理 
176:        return $ipstring; 
177:    }

---------------------------------------------------------------------


Login.php:
----------


126:         $UserName = getConf("/mnt/mtd/web_conf", "UserName");
127:         $[CREDENTIAL_REDACTED]("/mnt/mtd/web_conf", "Password");
128:
129:         //echo 'z'.$_POST['ID_User'].';'.$UserName.' Pwd:'.$_POST['ID_Password'].';'.$Password;
130:         if($_POST['ID_User'] === $UserName && $_POST['ID_Password'] === $Password){
...
...
140:             $_SESSION['Login'] = $_POST['ID_User'];
141: 
142:             //Login
143:             $loginTime = date("Y-m-d,H:i:s.0,P");
144:             $remoteIP = $_SERVER['REMOTE_ADDR'];
145: //----------SNMP checking ---Ed 20130307------------------------<
146:             $SNMPEnable = getConf("/mnt/mtd/snmp_conf", "enable");
147:             if ($SNMPEnable == "1") {
148:                 $TrapEnable = getConf("/mnt/mtd/snmp_conf", "trap");
149:                 if ($TrapEnable == "v2Trap") {
150:                     $trapTo = getConf("/mnt/mtd/snmp_conf", "IP");
151:                     shell_exec('/usr/bin/snmptrap -M /usr/share/snmp/mibs/ -c public -v 2c ' . $trapTo . ' \'\' InfraPower-MIB::webLogin InfraPower-MIB::objectDateTime s "' . $loginTime . '"  InfraPower-MIB::userName s "' . $_POST['ID_User'] . '" InfraPower-MIB::webAccessIpAddress s "' . $remoteIP . '"');
152:                     //echo "alert($res);";
153:                 }
154:             }

---------------------------------------------------------------------


Ntp.php:
--------


36: <?php
37: if(empty($_POST['Change']))
38:   $tzone='8';
39: else
40: {
41:
42: $tzone=$_POST['ID_timezone'];
43: $idx=$tzone+12;
44: echo "update status...";
45: exec("/usr/bin/ntpclient  -s -h 220.130.158.71");
46: exec("/usr/bin/zonegen ".$idx);
47: exec("/usr/bin/zic -d /usr/bin/ zonetime");
48: exec("mv /usr/bin/localtime /etc/localtime");
49: echo "