SAP Afaria Stored XSS vulnerability - detailed review

Wednesday, October 21, 2015

Alexander Polyakov

7d55c20d433dd60022642d3ab77b8efb

Today we will show how SAP Afaria, an MDM solution from a world-famous software vendor, works and how cybercriminals can attack it in different ways.

In a nutshell, MDM is a set of services that help an administrator of a large company to control the mobile devices (smartphones, tablets, phablets and so on and so forth) of employees, thus establishing the security measures of corporate data stored and processed on those devices. A special application called MDM client is installed on a device and allows administrators to implement settings.

Afaria is used by companies around the world. We have found about 140 Afaria servers available via the Internet.

SAP Afaria worldwide

As you can see from the graph, the largest number of Afaria services is implemented in the US and China.

We also have discovered several SAP Afaria vulnerabilities and would like to describe the most interesting of them.

Stored XSS vulnerability

The administrative part of SAP Afaria performs the basic functionality and is available via browser. Web administrative console is where a system administrator can view a list of all connected devices, create new mobile device configurations, download applications, control devices, etc.

So, the XSS vulnerability in the administrative console is likely to be critical for the entire system and for the administrator in particular. A common Afaria user, of course, can’t obtain access to these functionalities. However, an injection of user data is still possible. So, let's examine what will happen if we try to connect a new device to the server without the proper rights (and the user account).

connection to the server without rights and accounts

That’s what we get: the server, of course, does not allow us to connect this device. However, the list of devices in the administrative console (it is the administrator’s main workspace) shows the information about the device marked as “Not approved”. It means that an attacker can inject some data into the administrative console anonymously. Guess in which field a JS injection is possible. The server does not filter the information before displaying the device IMEI.

It looks like a typical stored XSS. However, the exploit seems interesting because the length of IMEI field is restricted by 15 characters. This restriction doesn’t allow one to inject malicious JavaScript code. But nothing prevents attackers from sending several connection requests specifying only a part of the JS payload and comments.

Let’s assume the attackers want to inject the following JS code:

 

alert('Hello Afaria! U so secure!');

To do so, they have to send a request to the server with the following values in the IMEI field:

 


/*zzzzzz
*/a00="alert";/*
*/a01="('Hel";/*
*/a02="lo Af";/*
*/a03="aria!";/*
*/a04=" U so";/*
*/a05=" secu";/*
*/a06="re!')";/*
*/a07=";";/*zzzz
*/zzz=a00+a01+/*
*/a02+a03+a04+/*
*/a05+a06+a07+/*
*/'';/*zzzzzzzzz
*/eval(zzz);/*zz
zzzzz*/

As you may notice, there are special characters /**/ in every query. They are used to mark comments in JS. This way, unnecessary parts of HTML markup that prevent getting the final result are deleted.

What’s the final result? The web server will build an HTML page in the admin panel in which all the little pieces will be brought together into one JS script to be executed during the administrator’s session. It allows the attacker to gain data from the Afaria admin panel, and thus to control all devices connected to the server.

The screenshot below shows the administrative console’s source code with JS injected into the device IMEI field:

administrative console’s source code with injected JS

Stored XSS vulnerability: Wrap-up

The XSS vulnerability was closed by SAP. Install SAP Note 2152669 to fix this issue.

Please keep in mind that this issue is very critical because it can be remotely exploited without authentication, and there are at least 140 servers available on the Internet. An attacker can get full control over all mobile devices of organization, such as remotely wipe data, lock all smartphones, or even force to upload malicious backdoor which will control user’s data, send critical documents to C&C server, spy on employees, read messages, and record video from cameras.

We also recommend reading our whitepaper about XSS Vulnerabilities in SAP and how to prevent them in custom code.

Stay tuned for our new updates about SAP Afaria vulnerabilities and more SAP security research.

Possibly Related Articles:
15912
CVE Vulnerabilities
SAP Afaria
Post Rating I Like this!
The views expressed in this post are the opinions of the Infosec Island member that posted this content. Infosec Island is not responsible for the content or messaging of this post.

Unauthorized reproduction of this article (in part or in whole) is prohibited without the express written permission of Infosec Island and the Infosec Island member that posted this content--this includes using our RSS feed for any purpose other than personal use.