Fortinet FSSO Exploits

In my last post, I fuzzed FSSO on port 8000 with Peach fuzzer to replicate the exploitable overflow discovered by Enrique Nissim of Core Security.  It turns out that the DC Agent service on UDP port 8002 also has an exploitable overflow that seems to have been patched after build 143.  In this post we’ll present an exploit for each of these issues.

DCAgent Protocol

The DCAgent protocol is a collector service that aggregates login events from other domain controllers.  There is no authentication and it’s transported over UDP.  We’ll ignore the obvious security flaw here — anyone can send a UDP packet and will be authenticated in FSSO as any user they choose.  Instead we’ll fuzz the service and see if we can find an exploitable crash.

To get an idea of the various fields in this protocol, you can download the Peach Pit from github.  It’s basically a header and trailer with a login record encapsulated within.  The login record is comprised of the user’s IP address and their “DOMAIN\user” AD username.

Fuzzing this protocol on build 143 results in some fairly obvious stack overwrites:

eax=00000000 ebx=75e89894 ecx=00000000 edx=11a9f744 esi=75ea47ad edi=75e8dbeb
eip=41fffe41 esp=11a9f848 ebp=1c6fcf60 iopl=0 nv up ei pl nz na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010206
41fffe41 ?? ???

ChildEBP RetAddr Args to Child
WARNING: Frame IP not in any known module. Following frames may be wrong.
11a9f844 41fffe41 41fffe41 41fffe41 41fffe41 0x41fffe41
11a9f848 41fffe41 41fffe41 41fffe41 41fffe41 0x41fffe41
11a9f84c 41fffe41 41fffe41 41fffe41 41fffe41 0x41fffe41
11a9f850 41fffe41 41fffe41 41fffe41 41fffe41 0x41fffe41
11a9f854 41fffe41 41fffe41 41fffe41 41fffe41 0x41fffe41
11a9f858 41fffe41 41fffe41 41fffe41 41fffe41 0x41fffe41

This appears to be triggered by overflowing the IP address string field in the login record, resulting in direct return address overwrite. Why they wouldn’t use /GS and SafeSEH (not to mention ASLR) on a service providing authentication is beyond me.

The first step towards developing a stack buffer overflow exploit is figuring out the buffer offset to the EIP overwrite.  I used Metasploit’s pattern_create/pattern_offset utilities for this purpose.  This provided reliable control over EIP.

Unfortunately, there is still DEP to contend with.  Normally, when DEP is combined with ASLR, it forms a fairly robust defense against stack buffer overflow exploitation.  DEP is opt-out on Windows 2008 and Windows 2012 Server, so it is enabled by default.  ASLR, on the other hand, is opt-in.  It requires that the libraries and binary are relocatable.  In the FSSO service, both collectoragent.exe and ssleay32.dll are not relocatable and no ASLR is applied to these modules.

Without ASLR, we can reuse existing pieces of the code contained in non-ASLR modules so that we are not required to directly execute code from the stack.  This can be accomplished by using a ROP Chain.  There are a few other issues however.

First, we have very limited buffer space since the exploit must fit in a small buffer within a single UDP packet.  This means we have to keep the ROP chain quite small.

Second, at the point of EIP overwrite, our buffer has been modifed — all lower case characters have been converted to upper case.  Normally this would make exploitation very difficult since it’s nearly impossible to build a ROP chain without any lower case characters (it’s tricky enough to build a ROP chain in the first place).  Using the debugger, I discovered that the original buffer is still on the stack.  We’ll have to adjust ESP through a phase I ROP chain in order to pivot to the unmodified buffer.

Third, we can’t use nulls since the exploitable condition is a result of a libc string handling function, probably an sprintf or strcpy (I haven’t actually checked).  To make things even more fun, we also can’t use the forward slash (byte value 0x2f) because this is the delimiter between the IP Address, domain and user name.  These values, 0x00 and 0x2f, are so-called bad characters.

The ROP Chain

Given the constraints above, I decided to keep things simple (or hacky, depending on your perspective).  I’ll use a short chain to call WinExec.  WinExec will launch a short snippet of Powershell code, which will call back to our web server and pull down a Powershell payload.

The WinExec function isn’t present in any of the non-ASLR module’s import address tables (IATs), so we’ll have to use an offset from a Kernel32 export present in the IAT.  I’m using GetTimeZoneInformation for this purpose, which is probably not a great choice.  The caveat with using a delta is that we must use hard-coded values.  The delta between the GetTZInfo function and WinExec is Windows version specific and it often changes between service pack or even between security updates.

Strictly speaking, we also can’t use a hard-coded delta since this contains nulls, instead we must use the binary 1’s complement in the actual ROP chain and hope that it doesn’t contain any bad characters.  I’ve included most of the magic values for versions of the kernel32.dll used by Windows Server 2008 R2 and 2012 R2 in the exploit.  If I missed a version you’d like to test with, use this short stand-alone Ruby script to generate magic values for kernel32.dll.  I admit it’s a bit of a kludge.

The PoC exploit, complete with ROP chain, is available on github here.  This issue seems to be patched after build 143.

FSSO Exploit

Now that we have a working ROP chain we can plug that into the FSSO exploit and it should just work.  Again we’ll need to use MSF pattern_create/pattern_offset to find the EIP overwrite.  For our exploit, this is at 96 bytes into the serial number field of the FSSO packet.  We can simply start the ROP chain right at offset 96.

You can find the PoC exploit for FSSO on TCP port 8000 here.  This issue is patched in build 237, but the ROP chain currently only works up to build 143 due to changes in the OpenSSL libraries (feel free to tweak if you need to pop build 161).

Next Steps

While the DCAgent overflow requires such a convoluted ROP chain due to bad characters and space limitations, the FSSO overflow does not have these limitations.  It is triggered via a bad memcpy into a stack buffer, so nulls are allowed.  If I have time I’ll write a new ROP chain for that exploit in order to make it more portable (or at least not Windows version specific).  Until then, happy exploitation!

Fuzzing for Domain Admin

Last week Enrique Nissim of Core Security published an article called Analysis of a Remote Code Execution Vulnerability on Fortinet Single Sign On.  Lately I’ve been using Deva Vu Security’s excellent Peach Fuzzer to find vulnerabilities, and I wanted to see how easy this would be to reproduce.

First, I installed Wireshark, Windbg, Peach 3 and FSSO 4.3.143 onto a Windows 2008 R2 server VM.  While Windows 2008 R2 is 64-bit only, FSSO is always 32-bit, which should make writing the exploit simpler.  Next, I loaded up a FortiGate VM and configured FSSO according to the documentation.  All Fortinet products can be downloaded and trialed for 14-days which makes vulnerability hunting a breeze, although you will have to set up an account first.

As indicated by Enrique’s article, FSSO communicates via TCP port 8000.  A Wireshark capture shows the structure of the hello packet:


The capture shows the packet format as follows:

  • A packet header, comprised of 32-bit big endian size field of the whole payload including the size field, a tag value of 80, and a type value of 06.  These tag and type value correspond to a hello packet.
  • TLV-like structures, with the same size, tag, type and value structures.
  • TLVs for version, serial number and an MD5 authentication hash.

Peach fuzzer uses XML to describe how to fuzz a target.  The portion of the XML that describes the packet format is the data model.  Other sections include a state model, which describes stateful protocols (we’re only fuzzing the hello packet), an agent, which describes how to instrument the target, and a test, which describes how to interface with the target.  The full Peach Pit can be found on github.

Running the Peach Pit is simple.  I’ve installed Peach into the directory c:\peach on the Windows 2008 R2 VM.  You can start fuzzing by copying the Pit to the peach directory and running “peach.exe fsso.xml”.

After only 41 fuzz runs, I obtained the following crash:

(13f8.e54): Access violation - code c0000005 (first chance)
eax=fffffffe ebx=00000658 ecx=75e898da edx=1c781104 esi=ffffffff edi=1c7e2ce8
eip=41414141 esp=1cbbfe1c ebp=00000000 iopl=0         nv up ei pl nz ac pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010216
41414141 ??              ???

Textbook stack buffer overflow.  To make the situation worse, two modules in the FSSO service do not use ASLR:


So we know we can get 0x41414141, and we know we have at least two modules that do not have ASLR enabled, and one of them contains address values with no nulls, which is perfect for a ROP chain.

FSSO usually runs as domain administrator.  If we’re able to exploit this service we effectively have control over the entire network.  While Fortinet might not be a common household name like Cisco or Microsoft, Fortinet has sold over a million firewalls and FSSO is widely deployed.  It is also quite likely that there are other vulnerabilities in this service, such as the DCAgent protocol running on UDP port 8002 (which is also enabled by default).  Next week I’ll demonstrate how to build a working Metasploit module for this vulnerability, and we’ll try some fuzzing of the DCAgent protocol.

Get Off Of MyCloud

I bought a 4TB WDMyCloud NAS the other day, and dare I say, it’s a beautiful piece of kit.  Inside you’ll find a 1.2GHz dual-core ARM processor with 256M of RAM, running Linaro Ubuntu.  You can enable SSH via the web admin page and the default credentials are root:welc0me.  Props to WD for making this a great box for DIYers.

The web interface is implemented in PHP using the Orion framework.  It’s RESTful API supporting the full gamut of HTTP verbs including GET, POST, PUT and DELETE.  The overall quality of the web interface is not something you usually see on embedded consumer-grade devices.  Also, it looks pretty fantastic.


This device has a few interesting features, some of which I’m still exploring.  It uses UPnP to tunnel ports 80 and 443 through your home router automatically.  This means you can access it from the Internet.  Luckily, WD was smart enough not to allow access to the full RESTful API from the Internet though; they included code to check $_SERVER[‘REMOTE_ADDR’] and make sure it’s on the same subnet.  There is a WebDAV interface accessible however, so that mobile devices and their thick client can access it remotely.

You can check for these devices via Shodan by searching for the Etag header value of e1-4e533dd6020c0, which yields 27225 devices at last count.  With an average capacity of 2TB, this implies that if you can compromise these devices remotely you get a cool 54 Petabytes of cloud storage (and one hell of a botnet).

I did a quick scan of the source after I enabled SSH access and found an interesting flaw.  In order to configure features such as new shares, users and other Linux features, they call out to a system shell using an exec wrapper function named exec_runtime.  You can grep the source on the box with a quick “find /var/www -name *.php -exec egrep -Hn ‘exec_runtime’ {} \;”.  What’s interesting, is that variables are passed to shell scripts using string interpolation with no escaping.  This means that nearly every single call to this function is vulnerable to command injection.

This vulnerability gets worse for two reasons.  First, www-data is in the sudoers file:


That’s not great.  Second, this bug exists in the language selection API call, which is accessible before authentication.

In order to exploit the issue, you must use a PUT request to the vulnerable URL at /api/2.1/rest/language_configuration?language= and use backticks to inject a shell command.  We’ve already established that we cannot access this API from the Internet (at least not directly), and we cannot use a PUT request to trigger a CSRF without CORS cooperation.  This last point probably needs some explanation.

If you issue an XMLHTTPRequest with the PUT verb on a modern browser, it will issue an OPTIONS request with the header “Access-Control-Request-Method: PUT” before the PUT request is made.  This is specifically designed to prevent CSRF issues from occurring with PUT requests.  Most web frameworks provide a convenient way around this due to the fact that old browsers (IE mostly) cannot make PUT requests (XHR or not).  In this case, we can use a GET request with the extra parameter of rest_method=PUT in order to simulate a PUT request.

One thing that prevents CSRF from being widely exploited in general is that you must know the IP address or hostname of the CSRF target beforehand.  For internally hosted resources, this generally requires some insider knowledge.  The WDMyCloud is a NAS though, and as such it advertises it’s DNS name by default so that users can see it in Mac Finder and Windows Explorer.  So in our case, this is not an issue (unless the user has changed the name).

With all this in mind, I’ve written a Metasploit module to exploit this vulnerability via CSRF.

My research is still ongoing and there are likely other issues.  If we can find an SSRF, XXE or RFI vulnerability somewhere, it may be possible to trigger this issue remotely over the Internet.

Update: Western Digital fixed this issue in version 03.04.01-219. Great job WD, that was quick.

Old School Home Automation

While the home automation is steadily moving towards embedded devices (the so-called Internet of Things), it wasn’t always this way.  In fact, two of the more popular home automation applications run on Windows.  They’re clunky Visual Basic apps with outdated web interfaces, but they still have a following due to their broad protocol and device support.

The first platform I examined was HAL2000.  This is a VB app that uses the Dart web server to provide the user access to the FoxPro database backend, and middleware for controlling the various home automation sensors and controllers.  As you can see, it’s pretty sexy:


Okay, not so sexy.  Still HAL2000 is very feature complete though, and sells for only $249.  You can also buy a HAL2000 appliance for a mere $2499.

HAL2000 has many issues.  A quick scan yielded 23 XSS vulnerabilities, and it’s also vulnerable to CSRF.  I also found a probable SQL injection issue, but I have no idea who to exploit SQLi in Visual Foxpro, so that’s tentative.  You can also download database files and logs with direct browsing, such as /WHAT.DBF or /log/DART24012014.log, so there’s really no need to exploit SQLi.  Still, nothing really that interesting.

I almost gave up scanning, then decided to do some manual testing.  HAL2000 has a login form and authenticated sessions are maintained with the DartSession cookie which normally contains a GUID looking value.  As it turns out, if you set this cookie to DartSession=1, it just works.  I have no idea why, but we’ll call that a win.

Second up to bat is HomeSeer.  It’s a VB.NET app with a web front end, and the middleware seems to be implemented as ActiveX controls.  It also sells for $249.


HomeSeer HS3 is pretty bad, security wise.  It uses HTTP basic auth, and the default username is “default”.  Authentication is not enabled by default.  Even if it is, it should be fairly simply to brute force the “default” account.

The list of vulns is a who’s who of web exploitation:

Directory traversal:
GET /..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\windows\win.ini

GET /EventLog4ad93<script>alert(1)<%2fscript>988899b0c82


File system browser at GET /test

Stored XSS:
Setup -> Custom -> Custom Page Title
(Executed on every page load)

And finally, remote code execution.  If you navigate to Tools->Control Panel, you’ll see a dialog for a script command.  One of the scripting commands is hs.Launch, which as the name implies, will launch an executable.  I’ve taken the liberty of packaging this up into a Metasploit module which works with Windows 7 and higher (it uses powershell).  You could exploit this on Windows XP easily too though.

I hope you enjoyed this journey into old school home automation software.  In future posts, we’ll look at new school home automation and a lot more.

A Plex Drive-By

I recently took at look at the Plex home media server running on Windows 7, in order to assess the security of the web administration interface. By default, Plex listens on port 32400 on localhost. This doesn’t limit the attack surface since they’ve explicitly disabled same origin policy in almost all cases.

plex_2The Plex web service has a few severe web security issues. All the URLs starting with /web, such as /web/index.html, are subject to directory traversal (using dot-dot-backslash). There are SQL injection vulnerabilities in some of the /library URLs. The most serious issue however, is that Plex responds with a CORS header allowing * when a request is sent with an Origin header. To make matters worse, CSRF protection is not provided, and SOP is disabled for Flash and Silverlight (via crossdomain.xml and clientaccesspolicy.xml, respectively).

This means that any web site you visit can issue an XHR to localhost:32400 and obtain access to your media, and possibly your entire filesystem.

Getting Code Execution

While arbitrary file read is interesting, a cross-browser drive-by download is more interesting. As it turns out, Plex uses a Python-based plugin system. The developers have sandboxed the plugins using RestrictedPython, so it’s not enough to load a malicious plugin (unless you have a sandbox bypass).

Something has to bootstrap the plugin environment though, and it turns out this is done in the file  It’s located in the following path by default:

%APPDATA%/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/

In order to get unrestricted code execution on Plex via drive-by download, all we need to do is use JavaScript to launch an XHR PUT to /:/prefs, and set the plugin directory for a UNC path. We will need to host the directory and file on a Samba share on the Internet.

I’ve prepared a Metasploit module to exploit this issue. It has been tested on Windows 7 x64, and relies on Powershell for stage 2 execution. It appears Metasploit has a Python meterpreter loader too, so that’s probably a more portable option. Note that the Metasploit module only works on Kali — it reconfigures Samba to host the share, and makes some assumptions about it’s default configuration and filesystem layout.

You can find the module here.