Promise VTrak M500f: Difference between revisions

From fakedWiki
Jump to: navigation, search
No edit summary
m (74 revisions imported)
 
(65 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Promise Technology VTrak M500f ===
{{TOCright|limit=2|width=500}}
== Exploit ==
I'm using a Promise VTrak M500f storage at work, and every couple of weeks it crashes. Updating to the latest firmware didn't help much.
 
It always starts with the device's webserver being unresponsive, and not much later the whole device just breaking down.
 
Usually, when i notice that the device starts to act up again, i just reboot it and it's fine for the next couple of weeks.
 
To do this, i log in on the serial console and run:
 
<pre>
administrator@cli> shutdown -a restart
</pre>
So the last time this happened, i noticed something is different with the CLI over serial console... it was... way more interesting!
 
 
 
=== Oh, exploitable! ===
Here's one of the problem sources: in line 23 and 24 of ''/islavista/sw/php/promise/language.php'', which is included in the code that's executed when you access the device's WebPAM PROe webinterface, PHP is told to get the language of the user's browser from a header that the browser sends on each request.
 
No problem there, your browser provides this header, so you probably won't ever see any error from this code.
 
But if you're using a monitoring tool like Nagios, to check if the webinterface is still alive, your Nagios check doesn't send that header and PHP will throw an error of the level E_NOTICE.
 
<pre>
$ php -a
Interactive mode enabled
 
<?php
preg_match('/^([a-z\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
    $lang=$matches[1];
    switch(substr($lang,0,2))
    {
      case 'en':
  $language='en_US';
        break;
      // [...]
      default:
        $language='en_US';
        break;
    }
?>
PHP Notice:  Undefined index: HTTP_ACCEPT_LANGUAGE in - on line 2
PHP Notice:  Undefined offset: 1 in - on line 3
</pre>
 
Of course, being the good developer that you are, you hide those errors, should they ever arise at all, from the user - and only write them to a logfile somewhere on your device's internal flash.
 
<pre>
[08-Jul-2011 19:52:24] PHP Notice:  Undefined index:  HTTP_ACCEPT_LANGUAGE in /islavista/sw/php/promise/language.php on line 23
[08-Jul-2011 19:52:24] PHP Notice:  Undefined offset:  1 in /islavista/sw/php/promise/language.php on line 24
[08-Jul-2011 19:52:26] PHP Notice:  Undefined index:  HTTP_HOST in /islavista/sw/php/promise/index.php on line 182
</pre>
 
Being a bit unsure yourself of how good of a developer you really are, you tell PHP in its config file ''/islavista/conf/sw/php.ini'' to not only log real errors of the levels E_WARNING or E_ERROR, or like the healthy default recommends, "E_ALL & ~E_NOTICE" (everything except E_NOTICE)... no, you want them all, so you can write impeccable code!
 
Have you ever wondered why it's called "default" setting? The De-Fault setting? Also known as the "Please don't break anything!" setting? You'll find out soon.
 
So, your Nagios checks the webserver every 5 minutes, every hour of the day, every day of the week, etc., and every time there are a couple of lines appended to the logfile, because you want to be in control an see each and any issue in you code.
 
Now what would you think will happen if that logfile gets so big that there is no space left on that flash?
 
I can tell you what will happen:
<pre>
islavista> _
</pre>
 
When i told Promise about the issue, one of their support engineers had only this to say:
<pre>
"I just can repeat [to] you one more time, you should not even know the word 'islavista' related to this device."
</pre>
 
Okay, that was a lie, it wasn't the only thing he said. He added:
<pre>
"You need a new controller."
</pre>
O RLY? I don't think that replacing '''my''' hardware will fix an issue in '''your''' firmware.
 
(Speaking of which, i'm still unsure if i should publish the whole conversation via their ticketing system, that will be pretty embarassing for them... they tried to convince me that my hardware is faulty and needs to be replaced. Yeah, right.)
 
 
 
=== Privilege Escalation ===
The 3 lines per request equal 354 Bytes of text, and my storage crashed when the logfile was roughly 3.5 MB in size, so in theory ~10.000 requests are all that's needed for this exploit to work its magic.
 
Nagios checks every 5 minutes, that's 288 requests per day, which means that after ~35 days the log should have filled all available space.
 
Can we speed this up? Yes, we can. A ''wget'' request to the webinterface takes me an average of 6 seconds, so with the following simple script i can get ~14400 requests per day, which means it takes ~17 hours fill all available space.
<pre>
$ while [ true ]; do wget -O /dev/null "http://192.168.0.2"; done
</pre>
Check the webinterface from time to time, when you see an PHP error that it couldn't write it's session because /tmp is full, you're golden! Fire up you serial console and enjoy.
 
You can automate this, too:
<pre>
$ while [ true ]; do if `lynx --dump "http://192.168.0.2/" | grep -q "tmp"`; then echo "EOF" | mail -s 'Exploit ready!' you@example.com; break; fi; done
</pre>
 
=== Remote Privilege Escalation, too? ===
Still unconfirmed, but in theory this should also work over Telnet instead of the serial console, provided that Telnet is enabled on the device.
 
 
 
 
== Firmware ==
 
 
=== Getting Started ===
 
Download the most recent firmware, at the time of this writing it was v2.39, and also make sure you have ''binwalk'' installed, an incredibly helpful tool when analyzing firmware files:
 
*Download Page: http://firstweb.promise.com/support/download/download2_eng.asp?productID=153&category=all&os=100
*Download Page: http://firstweb.promise.com/support/download/download2_eng.asp?productID=153&category=all&os=100
*Link to Firmware: http://firstweb.promise.com/upload/Support/Firmware/Mx00_series_v2.39.0000.00_with_notes.zip
*Firmware: http://firstweb.promise.com/upload/Support/Firmware/Mx00_series_v2.39.0000.00_with_notes.zip
*Link to binwalk: http://code.google.com/p/binwalk/
*binwalk: http://code.google.com/p/binwalk/


=== Analyzing the Firmware file ===
Use binwalk to look for the addresses of files within the firmware file:
<pre>
<pre>
binwalk -v iv2p_all_20110303_16mb.img
$ binwalk -v iv2p_all_20110303_16mb.img
</pre>
</pre>
This gives you a nice table with the decimal offset of each file in the firmware, and also the most likely format of this file:
<pre>
<pre>
Scan Time:    Aug 03, 2011 @ 20:13:21
Scan Time:    Aug 03, 2011 @ 20:13:21
Line 17: Line 133:
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
18204          0x471C          gzip compressed data, from Unix, last modified: Thu Apr 20 05:12:30 2006, max compression
18204          0x471C          gzip compressed data, from Unix, last modified: Thu Apr 20 05:12:30 2006, max compression
871968          0xD4E20        Linux Compressed ROM filesystem data, little endian size 2584576 version #2 sorted_dirs           CRC 0xeeb623f0, edition 0, 1217 blocks,           7 files
871968          0xD4E20        Linux Compressed ROM filesystem data, little endian size 2584576 version #2 sorted_dirs, CRC 0xeeb623f0, edition 0, 1217 blocks, 7 files
3456544        0x34BE20        Linux Compressed ROM filesystem data, little endian size 3231744 version #2 sorted_dirs           CRC 0xf1e0771a, edition 0, 2870 blocks,           946 files
3456544        0x34BE20        Linux Compressed ROM filesystem data, little endian size 3231744 version #2 sorted_dirs, CRC 0xf1e0771a, edition 0, 2870 blocks, 946 files
3528967        0x35D907        bzip2 compressed data
3528967        0x35D907        bzip2 compressed data
6688288        0x660E20        gzip compressed data, from Unix, last modified: Thu Mar  3 03:51:40 2011, max compression
6688288        0x660E20        gzip compressed data, from Unix, last modified: Thu Mar  3 03:51:40 2011, max compression
11309493        0xAC91B5        Linux Compressed ROM filesystem data, little endian size 1277952 version #2 sorted_dirs           CRC 0x477edaab, edition 0, 802 blocks,           142 files
11309493        0xAC91B5        Linux Compressed ROM filesystem data, little endian size 1277952 version #2 sorted_dirs, CRC 0x477edaab, edition 0, 802 blocks, 142 files
12882033        0xC49071        LZMA compressed data, properties: 0x5D, dictionary size: 335544320 bytes, uncompressed size: 30 bytes
12882033        0xC49071        LZMA compressed data, properties: 0x5D, dictionary size: 335544320 bytes, uncompressed size: 30 bytes
13215338        0xC9A66A        LZMA compressed data, properties: 0x85, dictionary size: 740294656 bytes, uncompressed size: 16388 bytes
13215338        0xC9A66A        LZMA compressed data, properties: 0x85, dictionary size: 740294656 bytes, uncompressed size: 16388 bytes
Line 31: Line 147:
13221354        0xC9BDEA        LZMA compressed data, properties: 0x90, dictionary size: 65536 bytes, uncompressed size: 65536 bytes
13221354        0xC9BDEA        LZMA compressed data, properties: 0x90, dictionary size: 65536 bytes, uncompressed size: 65536 bytes
</pre>
</pre>
==== part 1 ====
 
=== Extracting the Firmware parts ===
 
The principle is pretty simple: use ''dd'' to read a segment from the firmware (if=), using a blocksize (bs=) of 1, starting (skip=) at the decimal offset of the file you want, with a length (count=) of "the next file's offset minus this file's offset" and write it to an ouput file (of=). It makes it a lot easier if you give the output file the extension of the filetype that binwalk tells you.
 
 
 
==== Part 1 ====
<pre>
<pre>
dd if=iv2p_all_20110303_16mb.img bs=1 skip=18204 count=853764 of=part1.gz
$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=18204 count=853764 of=part1.gz
gunzip part1.gz
$ gunzip part1.gz
file part1
$ file part1
</pre>
</pre>
<pre>
<pre>
part1: data
part1: data
</pre>
</pre>
Probably the kernel and initrd?


==== part 2 ====
 
 
==== Part 2 ====
<pre>
<pre>
dd if=iv2p_all_20110303_16mb.img bs=1 skip=871968 count=2584576 of=part2.cramfs
$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=871968 count=2584576 of=part2.cramfs
mkdir part2
$ mkdir part2
mount -o loop parts2.cramfs part2/
$ mount -o loop parts2.cramfs part2/
ls -l part2/
$ ls -l part2/
</pre>
</pre>
<pre>
<pre>
Line 57: Line 183:
-rw-r--r-- 1 root root  619697 Jan  1  1970 xfc.o
-rw-r--r-- 1 root root  619697 Jan  1  1970 xfc.o
</pre>
</pre>
Kernel modules, boooring!


==== part 3 ====
 
 
==== Part 3 ====
<pre>
<pre>
dd if=iv2p_all_20110303_16mb.img bs=1 skip=3456544 count=72423 of=part3.cramfs
$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=3456544 count=72423 of=part3.cramfs
mount -o loop part3.cramfs part3/
$ mount -o loop part3.cramfs part3/
ls -lR part3/
$ ls -lR part3/
</pre>
</pre>
[[Promise VTrak M500f Firmware/part3|Full contents of Part 3]]
[[Promise VTrak M500f Firmware/part3|Full contents of Part 3]]
==== part 4 ====
 
The webinterface and some non-standard binaries, so this must be their own code.
 
When accessing a file you'll get an error, though. Quick check:
<pre>
$ fsck.cramfs part3.cramfs
</pre>
<pre>
<pre>
dd if=iv2p_all_20110303_16mb.img bs=1 skip=3528967 count=3159321 of=part4.bz2
fsck.cramfs: file length too short
bunzip2 part4.bz2
</pre>
Damn.
 
 
 
==== Part 4 ====
<pre>
$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=3528967 count=3159321 of=part4.bz2
$ bunzip2 part4.bz2
</pre>
</pre>
<pre>
<pre>
bunzip2: part4.bz2 is not a bzip2 file.
bunzip2: part4.bz2 is not a bzip2 file.
</pre>
</pre>
Hmm, strange.


==== part 5 ====
 
 
==== Part 5 ====
<pre>
<pre>
dd if=iv2p_all_20110303_16mb.img bs=1 skip=6688288 count=4621205 of=part5.gz
$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=6688288 count=4621205 of=part5.gz
gunzip part5.gz
$ gunzip part5.gz
file part5
$ file part5
</pre>
</pre>
<pre>
<pre>
part5: Linux rev 1.0 ext2 filesystem data, UUID=1e4f9d2b-b406-4a38-bbf8-8f1fcf52e5c7
part5: Linux rev 1.0 ext2 filesystem data, UUID=1e4f9d2b-b406-4a38-bbf8-8f1fcf52e5c7
</pre>
</pre>
So it's a gzip, but that contains an ext2 partition.
<pre>
<pre>
mv part5 part5.ext2
$ mv part5 part5.ext2
mkdir part5
$ mkdir part5
mount -o loop part5.ext2 part5/
$ mount -o loop part5.ext2 part5/
ls -lR part5/
$ ls -lR part5/
</pre>
</pre>
[[Promise VTrak M500f Firmware/part5|Full contents of Part 5]]
[[Promise VTrak M500f Firmware/part5|Full contents of Part 5]]
==== part 6 ====
 
BusyBox, libraries, you name it. This must be the base Linux part.
 
==== Part 6 ====
<pre>
$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=11309493 count=1572540 of=part6.cramfs
$ mkdir part6/
$ mount -o loop part6.cramfs part6/
$ ls -lR part6/
</pre>
[[Promise VTrak M500f Firmware/part6|Full contents of Part 6]]
 
'''fw''' and '''sw''', this is probably the interesting stuff? But where's the /islavista/conf/sw/php.ini?
 
=== Fixing Part 3 ===
Part 3 is a broken CramFS, and Part 4 is a bzip2 file that is not a bzip2 file... smells fishy.
Let's say Part 3 is actually Part 3.1 and Part 4 is Part 3.2:
<pre>
<pre>
dd if=iv2p_all_20110303_16mb.img bs=1 skip=11309493 count=1572540 of=part6.cramfs
$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=3456544 count=3231744 of=part3.cramfs
mkdir part6/
$ fsck.cramfs -v part3.cramfs
mount -o loop part6.cramfs part6/
ls -lR part6/
</pre>
</pre>
<pre>
<pre>
part6/:
cramfs endianness is little
total 1
part3.cramfs: OK
drwxr-xr-x 1 root root 88 Jan  1  1970 fw
</pre>
drwxr-xr-x 1 root root 72 Jan  1  1970 sw
Bingo!


part6/fw:
=== The Missing Link ===
total 514
There are a lot of strings throughout the fimware that point at 4 MTD blocks which get mounted into the /islavista/conf, /islavista/fw, /islavista/sw and /oem directories.
-rw-r--r-- 1 root root 393216 Jan  1  1970 evtinfo.conf
-rw-r--r-- 1 root root 131072 Jan  1  1970 evtlogloc.conf
-rw-r--r-- 1 root root  1616 Jan  1  1970 OEMCoercionTable.conf


part6/sw:
Finding the contents of those blocks that gets written to the flash is the interesting part...
total 3
drwxr-xr-x 1 root root  40 Jan  1  1970 cli
drwxr-xr-x 1 root root  48 Jan  1  1970 event
drwxr-xr-x 1 root root 132 Jan  1  1970 gui
-rw-r--r-- 1 root root 661 Jan  1  1970 oem.xml


part6/sw/cli:
<pre>
total 1
/dev/mtdblock5  /islavista/fw      cramfs  suid,dev,exec,auto,nouser,async,ro
-rw-r--r-- 1 root root 306 Jan 1 1970 clioem.xml
/dev/mtdblock6 /islavista/sw      cramfs suid,dev,exec,auto,nouser,async,ro
drwxr-xr-x 1 root root 24 Jan 1 1970 clu
/dev/mtdblock2 /islavista/conf    jffs2  defaults
/dev/mtdblock7 /oem                cramfs suid,dev,exec,auto,nouser,async,ro
</pre>


part6/sw/cli/clu:
The directory /islavista/flash seems to be the upload destination for firmware updates via the webinterface.
total 80
The filesystem in Part 6 gets mounted to /oem.
-rw-r--r-- 1 root root 81901 Jan  1  1970 cluhelp.txt


part6/sw/event:
So where do the juicy bits come from? Let's binwalk part1:
total 141
<pre>
-rw-r--r-- 1 root root 122361 Jan  1  1970 event_EN.xml
$binwalk -av -x MIPSE part1
-rw-r--r-- 1 root root  21440 Jan  1  1970 event.rng
</pre>
[[Promise VTrak M500f Firmware/part1|binwalk output]]


part6/sw/gui:
We're still looking for 2 CramFS and 1 JFFS2...
total 6
-rw-r--r-- 1 1023 232  734 Jan  1  1970 common.js
drw-r--r-- 1 1023 232  64 Jan  1  1970 css
drw------- 1 1023 232 1096 Jan  1  1970 enclosureImages
drw------- 1 1023 232  788 Jan  1  1970 icons
drw------- 1 1023 232  700 Jan  1  1970 images
drw------- 1 1023 232  640 Jan  1  1970 languages


part6/sw/gui/css:
== Todo ==
total 8
* Find the page that will throw the most errors, to speed up filling the flash.
-rw-r--r-- 1 1023 232 1473 Jan  1  1970 help.css
* Privilege Escalation is already nice, how about Remote Privilege Escalation? Confirm that this also works when using Telnet, not only serial console!
-rw-r--r-- 1 1023 232 4046 Jan  1  1970 main.css
* Where's that php.ini hidden in the firmware? Can't be found in any of the firmware parts, yet - maybe generated at runtime? Hmm, hmm, hmm.
-rw-r--r-- 1 1023 232 1959 Jan  1  1970 text1.css
* Analyze the firmware of different models/series. Code recycling FTW!


part6/sw/gui/enclosureImages:
total 595
-rwxr--r-- 1 1023 232  9102 Jan  1  1970 backEchassis.gif
-rwxr--r-- 1 1023 232  2886 Jan  1  1970 backEctrl.gif
-rwxr--r-- 1 1023 232  2687 Jan  1  1970 backJctrl.gif
-rwxr--r-- 1 1023 232  1584 Jan  1  1970 batterybad.gif
-rwxr--r-- 1 1023 232  1580 Jan  1  1970 batterycritical.gif
-rwxr--r-- 1 1023 232  1448 Jan  1  1970 batterygood.gif
-rwxr--r-- 1 1023 232  2752 Jan  1  1970 blowerbad.gif
-rwxr--r-- 1 1023 232  2831 Jan  1  1970 blowergood.gif
-rwxr--r-- 1 1023 232  1891 Jan  1  1970 blowerstop.gif
-rwxr--r-- 1 1023 232 69881 Jan  1  1970 chassisE300.gif
-rwxr--r-- 1 1023 232 70316 Jan  1  1970 chassisJ300.gif
-rwxr--r-- 1 1023 232 71104 Jan  1  1970 chassisVtrak2U_FC.gif
-rwxr--r-- 1 1023 232 70420 Jan  1  1970 chassisVtrak2U_iSCSI.gif
-rwxr--r-- 1 1023 232 70894 Jan  1  1970 chassisVtrak2U_SCSI.gif
-rwxr--r-- 1 1023 232 81885 Jan  1  1970 chassisVtrak.gif
-rwxr--r-- 1 1023 232  111 Jan  1  1970 ledGrayFlash.gif
-rwxr--r-- 1 1023 232    98 Jan  1  1970 ledGray.gif
-rwxr--r-- 1 1023 232  111 Jan  1  1970 ledGreenFlash.gif
-rwxr--r-- 1 1023 232    98 Jan  1  1970 ledGreen.gif
-rwxr--r-- 1 1023 232  111 Jan  1  1970 ledRedFlash.gif
-rwxr--r-- 1 1023 232    98 Jan  1  1970 ledRed.gif
-rwxr--r-- 1 1023 232  111 Jan  1  1970 ledYellowFlash.gif
-rwxr--r-- 1 1023 232    98 Jan  1  1970 ledYellow.gif
-rwxr--r-- 1 1023 232  3635 Jan  1  1970 psbad.gif
-rwxr--r-- 1 1023 232  3184 Jan  1  1970 pscritical.gif
-rwxr--r-- 1 1023 232  4905 Jan  1  1970 psfanbad.gif
-rwxr--r-- 1 1023 232  4862 Jan  1  1970 psfangood.gif
-rwxr--r-- 1 1023 232  3169 Jan  1  1970 psfanstop.gif
-rwxr--r-- 1 1023 232  6391 Jan  1  1970 psgood.gif
-rwxr--r-- 1 1023 232 65476 Jan  1  1970 S200p.gif
-rwxr--r-- 1 1023 232  1049 Jan  1  1970 tmpbad.gif
-rwxr--r-- 1 1023 232  883 Jan  1  1970 tmpcritical.gif
-rwxr--r-- 1 1023 232  1395 Jan  1  1970 tmpgood.gif
-rwxr--r-- 1 1023 232  181 Jan  1  1970 voltagebad.gif
-rwxr--r-- 1 1023 232  184 Jan  1  1970 voltagecritical.gif
-rwxr--r-- 1 1023 232  177 Jan  1  1970 voltagegood.gif
-rwxr--r-- 1 1023 232 11085 Jan  1  1970 VtrakFront12.gif
-rwxr--r-- 1 1023 232  8107 Jan  1  1970 VtrakFront8.gif
-rwxr--r-- 1 1023 232 21199 Jan  1  1970 VtrakFront.gif


part6/sw/gui/icons:
total 18
-rwxr--r-- 1 1023 232 179 Jan  1  1970 admin.gif
-rwxr--r-- 1 1023 232 249 Jan  1  1970 array.gif
-rwxr--r-- 1 1023 232 275 Jan  1  1970 arrays.gif
-rwxr--r-- 1 1023 232  96 Jan  1  1970 arrowdn.gif
-rwxr--r-- 1 1023 232  99 Jan  1  1970 arrowrt.gif
-rwxr--r-- 1 1023 232 952 Jan  1  1970 controller.gif
-rwxr--r-- 1 1023 232 971 Jan  1  1970 controllers.gif
-rwxr--r-- 1 1023 232 148 Jan  1  1970 enclosure.gif
-rwxr--r-- 1 1023 232 152 Jan  1  1970 enclosures.gif
-rwxr--r-- 1 1023 232 131 Jan  1  1970 fdminus1.gif
-rwxr--r-- 1 1023 232 132 Jan  1  1970 fdminus.gif
-rwxr--r-- 1 1023 232 132 Jan  1  1970 fdplus1.gif
-rwxr--r-- 1 1023 232 137 Jan  1  1970 fdplus.gif
-rwxr--r-- 1 1023 232 120 Jan  1  1970 iconCritical.gif
-rwxr--r-- 1 1023 232 129 Jan  1  1970 iconDead.gif
-rwxr--r-- 1 1023 232 103 Jan  1  1970 icon.gif
-rwxr--r-- 1 1023 232 147 Jan  1  1970 iscsi.gif
-rwxr--r-- 1 1023 232 176 Jan  1  1970 logdrv.gif
-rwxr--r-- 1 1023 232 178 Jan  1  1970 logdrvs.gif
-rwxr--r-- 1 1023 232 192 Jan  1  1970 net.gif
-rwxr--r-- 1 1023 232 172 Jan  1  1970 phydrv.gif
-rwxr--r-- 1 1023 232 183 Jan  1  1970 phydrvs.gif
-rwxr--r-- 1 1023 232 177 Jan  1  1970 spare.gif
-rwxr--r-- 1 1023 232 190 Jan  1  1970 spares.gif
-rwxr--r-- 1 1023 232 177 Jan  1  1970 storage.gif
-rwxr--r-- 1 1023 232 193 Jan  1  1970 subsystem.gif
-rwxr--r-- 1 1023 232 201 Jan  1  1970 subsystems.gif
-rwxr--r-- 1 1023 232 155 Jan  1  1970 sw.gif
-rwxr--r-- 1 1023 232  55 Jan  1  1970 tab0.gif
-rwxr--r-- 1 1023 232 111 Jan  1  1970 tab1.gif
-rwxr--r-- 1 1023 232 115 Jan  1  1970 tab2.gif
-rwxr--r-- 1 1023 232 113 Jan  1  1970 tab.gif
-rwxr--r-- 1 1023 232 170 Jan  1  1970 user.gif


part6/sw/gui/images:
== Thanks ==
total 91
* Mathis Schmieder for the ''fsck.cramfs'' tip, i was a bit lost when i discovered the errors in Part 3
-rwxr--r-- 1 1023 232    97 Jan  1  1970 arrowdn.gif
* Joris from Promise Technology, he was the one that eventually understood what i was trying to tell them all the time
-rwxr--r-- 1 1023 232  117 Jan  1  1970 ball-1.gif
-rwxr--r-- 1 1023 232    51 Jan  1  1970 ball-2.gif
-rwxr--r-- 1 1023 232  117 Jan  1  1970 ball-dn.gif
-rwxr--r-- 1 1023 232  118 Jan  1  1970 ball-rt.gif
-rwxr--r-- 1 1023 232  143 Jan  1  1970 bg.gif
-rwxr--r-- 1 1023 232    52 Jan  1  1970 blank.gif
-rwxr--r-- 1 1023 232  158 Jan  1  1970 HELP_01.gif
-rwxr--r-- 1 1023 232  148 Jan  1  1970 HELP_01-over.gif
-rwxr--r-- 1 1023 232  1570 Jan  1  1970 home-img01.gif
-rwxr--r-- 1 1023 232 14526 Jan  1  1970 home-img02.jpg
-rwxr--r-- 1 1023 232  696 Jan  1  1970 home-img03.gif
-rwxr--r-- 1 1023 232  4398 Jan  1  1970 home-img04.jpg
-rwxr--r-- 1 1023 232  1673 Jan  1  1970 home-img05.gif
-rwxr--r-- 1 1023 232  125 Jan  1  1970 home-img07.gif
-rwxr--r-- 1 1023 232  103 Jan  1  1970 home-img08.gif
-rwxr--r-- 1 1023 232  429 Jan  1  1970 home-img09.gif
-rwxr--r-- 1 1023 232  450 Jan  1  1970 line-1.gif
-rwxr--r-- 1 1023 232 47925 Jan  1  1970 login.gif
-rwxr--r-- 1 1023 232  7399 Jan  1  1970 logo.gif
-rwxr--r-- 1 1023 232  102 Jan  1  1970 select.gif
-rwxr--r-- 1 1023 232  105 Jan  1  1970 sortdn.gif
-rwxr--r-- 1 1023 232  105 Jan  1  1970 sortup.gif
-rwxr--r-- 1 1023 232  100 Jan  1  1970 tabl0.gif
-rwxr--r-- 1 1023 232  100 Jan  1  1970 tabl1.gif
-rwxr--r-- 1 1023 232  100 Jan  1  1970 tabr0.gif
-rwxr--r-- 1 1023 232  100 Jan  1  1970 tabr1.gif
-rwxr--r-- 1 1023 232  2201 Jan  1  1970 tree-bg.jpg


part6/sw/gui/languages:
 
total 1433
EOF
-rwxr--r-- 1 1023 232  3442 Jan  1  1970 de_DE_Contact.html
-rwxr--r-- 1 1023 232 171315 Jan  1  1970 de_DE_Messages.properties
-rwxr--r-- 1 1023 232  3004 Jan  1  1970 en_US_Contact.html
-rwxr--r-- 1 1023 232 157111 Jan  1  1970 en_US_Messages.properties
-rwxr--r-- 1 1023 232 181154 Jan  1  1970 es_ES_Messages.properties
-rwxr--r-- 1 1023 232  3507 Jan  1  1970 fr_FR_Contact.html
-rwxr--r-- 1 1023 232 177830 Jan  1  1970 fr_FR_Messages.properties
-rwxr--r-- 1 1023 232  3624 Jan  1  1970 it_IT_Contact.html
-rwxr--r-- 1 1023 232 171473 Jan  1  1970 it_IT_Messages.properties
-rwxr--r-- 1 1023 232  3406 Jan  1  1970 ja_JP_Contact.html
-rwxr--r-- 1 1023 232 157225 Jan  1  1970 ja_JP_Messages.properties
-rwxr--r-- 1 1023 232  3314 Jan  1  1970 ko_KR_Contact.html
-rwxr--r-- 1 1023 232 150013 Jan  1  1970 ko_KR_Messages.properties
-rwxr--r-- 1 1023 232  3847 Jan  1  1970 langList.php
-rwxr--r-- 1 1023 232  3161 Jan  1  1970 zh_CN_Contact.html
-rwxr--r-- 1 1023 232 132793 Jan  1  1970 zh_CN_Messages.properties
-rwxr--r-- 1 1023 232  3139 Jan  1  1970 zh_TW_Contact.html
-rwxr--r-- 1 1023 232 133382 Jan  1  1970 zh_TW_Messages.properties
</pre>

Latest revision as of 20:10, 26 August 2016

Template:TOCright

Exploit

I'm using a Promise VTrak M500f storage at work, and every couple of weeks it crashes. Updating to the latest firmware didn't help much.

It always starts with the device's webserver being unresponsive, and not much later the whole device just breaking down.

Usually, when i notice that the device starts to act up again, i just reboot it and it's fine for the next couple of weeks.

To do this, i log in on the serial console and run:

administrator@cli> shutdown -a restart

So the last time this happened, i noticed something is different with the CLI over serial console... it was... way more interesting!


Oh, exploitable!

Here's one of the problem sources: in line 23 and 24 of /islavista/sw/php/promise/language.php, which is included in the code that's executed when you access the device's WebPAM PROe webinterface, PHP is told to get the language of the user's browser from a header that the browser sends on each request.

No problem there, your browser provides this header, so you probably won't ever see any error from this code.

But if you're using a monitoring tool like Nagios, to check if the webinterface is still alive, your Nagios check doesn't send that header and PHP will throw an error of the level E_NOTICE.

$ php -a
Interactive mode enabled

<?php
preg_match('/^([a-z\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
    $lang=$matches[1];
    switch(substr($lang,0,2))
    {
      case 'en':
   $language='en_US';
        break;
      // [...]
      default:
        $language='en_US';
        break;
    }
?>
PHP Notice:  Undefined index: HTTP_ACCEPT_LANGUAGE in - on line 2
PHP Notice:  Undefined offset: 1 in - on line 3

Of course, being the good developer that you are, you hide those errors, should they ever arise at all, from the user - and only write them to a logfile somewhere on your device's internal flash.

[08-Jul-2011 19:52:24] PHP Notice:  Undefined index:  HTTP_ACCEPT_LANGUAGE in /islavista/sw/php/promise/language.php on line 23
[08-Jul-2011 19:52:24] PHP Notice:  Undefined offset:  1 in /islavista/sw/php/promise/language.php on line 24
[08-Jul-2011 19:52:26] PHP Notice:  Undefined index:  HTTP_HOST in /islavista/sw/php/promise/index.php on line 182

Being a bit unsure yourself of how good of a developer you really are, you tell PHP in its config file /islavista/conf/sw/php.ini to not only log real errors of the levels E_WARNING or E_ERROR, or like the healthy default recommends, "E_ALL & ~E_NOTICE" (everything except E_NOTICE)... no, you want them all, so you can write impeccable code!

Have you ever wondered why it's called "default" setting? The De-Fault setting? Also known as the "Please don't break anything!" setting? You'll find out soon.

So, your Nagios checks the webserver every 5 minutes, every hour of the day, every day of the week, etc., and every time there are a couple of lines appended to the logfile, because you want to be in control an see each and any issue in you code.

Now what would you think will happen if that logfile gets so big that there is no space left on that flash?

I can tell you what will happen:

islavista> _

When i told Promise about the issue, one of their support engineers had only this to say:

"I just can repeat [to] you one more time, you should not even know the word 'islavista' related to this device."

Okay, that was a lie, it wasn't the only thing he said. He added:

"You need a new controller."

O RLY? I don't think that replacing my hardware will fix an issue in your firmware.

(Speaking of which, i'm still unsure if i should publish the whole conversation via their ticketing system, that will be pretty embarassing for them... they tried to convince me that my hardware is faulty and needs to be replaced. Yeah, right.)


Privilege Escalation

The 3 lines per request equal 354 Bytes of text, and my storage crashed when the logfile was roughly 3.5 MB in size, so in theory ~10.000 requests are all that's needed for this exploit to work its magic.

Nagios checks every 5 minutes, that's 288 requests per day, which means that after ~35 days the log should have filled all available space.

Can we speed this up? Yes, we can. A wget request to the webinterface takes me an average of 6 seconds, so with the following simple script i can get ~14400 requests per day, which means it takes ~17 hours fill all available space.

$ while [ true ]; do wget -O /dev/null "http://192.168.0.2"; done

Check the webinterface from time to time, when you see an PHP error that it couldn't write it's session because /tmp is full, you're golden! Fire up you serial console and enjoy.

You can automate this, too:

$ while [ true ]; do if `lynx --dump "http://192.168.0.2/" | grep -q "tmp"`; then echo "EOF" | mail -s 'Exploit ready!' you@example.com; break; fi; done

Remote Privilege Escalation, too?

Still unconfirmed, but in theory this should also work over Telnet instead of the serial console, provided that Telnet is enabled on the device.



Firmware

Getting Started

Download the most recent firmware, at the time of this writing it was v2.39, and also make sure you have binwalk installed, an incredibly helpful tool when analyzing firmware files:


Analyzing the Firmware file

Use binwalk to look for the addresses of files within the firmware file:

$ binwalk -v iv2p_all_20110303_16mb.img

This gives you a nice table with the decimal offset of each file in the firmware, and also the most likely format of this file:

Scan Time:    Aug 03, 2011 @ 20:13:21
Magic File:   /etc/binwalk/magic.binwalk
Signatures:   67
Target File:  iv2p_all_20110303_16mb.img
MD5 Checksum: b8dad677c907a53ca9b222f2103c13b3

DECIMAL         HEX             DESCRIPTION
-------------------------------------------------------------------------------------------------------
18204           0x471C          gzip compressed data, from Unix, last modified: Thu Apr 20 05:12:30 2006, max compression
871968          0xD4E20         Linux Compressed ROM filesystem data, little endian size 2584576 version #2 sorted_dirs, CRC 0xeeb623f0, edition 0, 1217 blocks, 7 files
3456544         0x34BE20        Linux Compressed ROM filesystem data, little endian size 3231744 version #2 sorted_dirs, CRC 0xf1e0771a, edition 0, 2870 blocks, 946 files
3528967         0x35D907        bzip2 compressed data
6688288         0x660E20        gzip compressed data, from Unix, last modified: Thu Mar  3 03:51:40 2011, max compression
11309493        0xAC91B5        Linux Compressed ROM filesystem data, little endian size 1277952 version #2 sorted_dirs, CRC 0x477edaab, edition 0, 802 blocks, 142 files
12882033        0xC49071        LZMA compressed data, properties: 0x5D, dictionary size: 335544320 bytes, uncompressed size: 30 bytes
13215338        0xC9A66A        LZMA compressed data, properties: 0x85, dictionary size: 740294656 bytes, uncompressed size: 16388 bytes
13216042        0xC9A92A        LZMA compressed data, properties: 0x86, dictionary size: 745537536 bytes, uncompressed size: 16388 bytes
13216734        0xC9ABDE        LZMA compressed data, properties: 0x89, dictionary size: 747110400 bytes, uncompressed size: 16388 bytes
13219257        0xC9B5B9        LZMA compressed data, properties: 0x5D, dictionary size: 335544320 bytes, uncompressed size: 30 bytes
13220658        0xC9BB32        LZMA compressed data, properties: 0x95, dictionary size: 272629760 bytes, uncompressed size: 16387 bytes
13221334        0xC9BDD6        LZMA compressed data, properties: 0x90, dictionary size: 65536 bytes, uncompressed size: 65536 bytes
13221354        0xC9BDEA        LZMA compressed data, properties: 0x90, dictionary size: 65536 bytes, uncompressed size: 65536 bytes

Extracting the Firmware parts

The principle is pretty simple: use dd to read a segment from the firmware (if=), using a blocksize (bs=) of 1, starting (skip=) at the decimal offset of the file you want, with a length (count=) of "the next file's offset minus this file's offset" and write it to an ouput file (of=). It makes it a lot easier if you give the output file the extension of the filetype that binwalk tells you.


Part 1

$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=18204 count=853764 of=part1.gz
$ gunzip part1.gz
$ file part1
part1: data

Probably the kernel and initrd?


Part 2

$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=871968 count=2584576 of=part2.cramfs
$ mkdir part2
$ mount -o loop parts2.cramfs part2/
$ ls -l part2/
total 4858
-rw-r--r-- 1 root root   18204 Jan  1  1970 iodrv.o
-rw-r--r-- 1 root root  233655 Jan  1  1970 Marvell.o
-rw-r--r-- 1 root root  470713 Jan  1  1970 qla4xxx.o
-rw-r--r-- 1 root root 3193368 Jan  1  1970 raid_core.o
-rw-r--r-- 1 root root  436560 Jan  1  1970 scsi.o
-rw-r--r-- 1 root root  619697 Jan  1  1970 xfc.o

Kernel modules, boooring!


Part 3

$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=3456544 count=72423 of=part3.cramfs
$ mount -o loop part3.cramfs part3/
$ ls -lR part3/

Full contents of Part 3

The webinterface and some non-standard binaries, so this must be their own code.

When accessing a file you'll get an error, though. Quick check:

$ fsck.cramfs part3.cramfs
fsck.cramfs: file length too short

Damn.


Part 4

$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=3528967 count=3159321 of=part4.bz2
$ bunzip2 part4.bz2
bunzip2: part4.bz2 is not a bzip2 file.

Hmm, strange.


Part 5

$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=6688288 count=4621205 of=part5.gz
$ gunzip part5.gz
$ file part5
part5: Linux rev 1.0 ext2 filesystem data, UUID=1e4f9d2b-b406-4a38-bbf8-8f1fcf52e5c7

So it's a gzip, but that contains an ext2 partition.

$ mv part5 part5.ext2
$ mkdir part5
$ mount -o loop part5.ext2 part5/
$ ls -lR part5/

Full contents of Part 5

BusyBox, libraries, you name it. This must be the base Linux part.

Part 6

$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=11309493 count=1572540 of=part6.cramfs
$ mkdir part6/
$ mount -o loop part6.cramfs part6/
$ ls -lR part6/

Full contents of Part 6

fw and sw, this is probably the interesting stuff? But where's the /islavista/conf/sw/php.ini?

Fixing Part 3

Part 3 is a broken CramFS, and Part 4 is a bzip2 file that is not a bzip2 file... smells fishy. Let's say Part 3 is actually Part 3.1 and Part 4 is Part 3.2:

$ dd if=iv2p_all_20110303_16mb.img bs=1 skip=3456544 count=3231744 of=part3.cramfs
$ fsck.cramfs -v part3.cramfs
cramfs endianness is little
part3.cramfs: OK

Bingo!

The Missing Link

There are a lot of strings throughout the fimware that point at 4 MTD blocks which get mounted into the /islavista/conf, /islavista/fw, /islavista/sw and /oem directories.

Finding the contents of those blocks that gets written to the flash is the interesting part...

/dev/mtdblock5  /islavista/fw       cramfs  suid,dev,exec,auto,nouser,async,ro
/dev/mtdblock6  /islavista/sw       cramfs  suid,dev,exec,auto,nouser,async,ro
/dev/mtdblock2  /islavista/conf     jffs2   defaults
/dev/mtdblock7  /oem                cramfs  suid,dev,exec,auto,nouser,async,ro

The directory /islavista/flash seems to be the upload destination for firmware updates via the webinterface. The filesystem in Part 6 gets mounted to /oem.

So where do the juicy bits come from? Let's binwalk part1:

$binwalk -av -x MIPSE part1

binwalk output

We're still looking for 2 CramFS and 1 JFFS2...

Todo

  • Find the page that will throw the most errors, to speed up filling the flash.
  • Privilege Escalation is already nice, how about Remote Privilege Escalation? Confirm that this also works when using Telnet, not only serial console!
  • Where's that php.ini hidden in the firmware? Can't be found in any of the firmware parts, yet - maybe generated at runtime? Hmm, hmm, hmm.
  • Analyze the firmware of different models/series. Code recycling FTW!


Thanks

  • Mathis Schmieder for the fsck.cramfs tip, i was a bit lost when i discovered the errors in Part 3
  • Joris from Promise Technology, he was the one that eventually understood what i was trying to tell them all the time


EOF