---
type: Whitepaper
title: Automated Generation of Event-Oriented Exploits in Android Hybrid Apps
description: "Android hybrid apps let web content inside a WebView trigger event handlers written in native Java, and neither the same-origin policy nor Android permissions check where the event came from. EOEDroid vets apps with selective symbolic execution and auto-generates exploits, finding 97 flaws in 58 of 3,652 apps: cross-frame DOM manipulation, phishing, identifier leakage and Intent abuse."
resource: "https://www.ndss-symposium.org/wp-content/uploads/2018/02/ndss2018_04B-3_Yang_paper.pdf"
tags: [whitepaper, webseclist-reference, sop-bypass, privilege-escalation, info-leak, dom, android, javascript, static-analysis, tooling, owasp-a01-2021]
generated:
  by: webseclist-refs/1
  at: "2026-08-14T20:59:24+00:00"
status: stable
stale_after: 2027-08-14
sources:
  - id: original
    resource: "https://www.ndss-symposium.org/wp-content/uploads/2018/02/ndss2018_04B-3_Yang_paper.pdf"
    title: Automated Generation of Event-Oriented Exploits in Android Hybrid Apps
    author: Guangliang Yang, Jeff Huang, Guofei Gu
also_at: []
authors:
  - Guangliang Yang
  - Jeff Huang
  - Guofei Gu
canonical_url: ""
cited_by:
  - "2018.md:86"
commit: ""
content_sha256: 0beefdedec8c6865c6ea5669717d86ae94e3d0e8bace1f23d2a6bb98e17462b2
depth: full
depth_reason: default
kind: whitepaper
language: ""
licence: unknown
original_url: "https://www.ndss-symposium.org/wp-content/uploads/2018/02/ndss2018_04B-3_Yang_paper.pdf"
published: ""
publisher: ""
publisher_english: ""
raw_sha256: 619d5c60ecf31e5ef571344afae5ea4fcb3c0764289080de4b99575083792ee2
retrieved_from: "https://www.ndss-symposium.org/wp-content/uploads/2018/02/ndss2018_04B-3_Yang_paper.pdf"
retrieved_kind: stored
retrieved_utc: "2026-08-14T20:59:24+00:00"
slug: automated-generation-event-oriented-exploits-android-hybrid-apps
snapshot: ""
title_english: ""
translation_file: ""
translation_of: ""
---

# Automated Generation of Event-Oriented Exploits in Android Hybrid Apps

**Automated Generation of Event-Oriented Exploits in Android Hybrid Apps** - Guangliang Yang, Jeff Huang, Guofei Gu, Publisher not stated.

- Published: date not stated
- Original: <https://www.ndss-symposium.org/wp-content/uploads/2018/02/ndss2018_04B-3_Yang_paper.pdf>
- Preserved from: https://www.ndss-symposium.org/wp-content/uploads/2018/02/ndss2018_04B-3_Yang_paper.pdf (stored) on 2026-08-14
- Licence: unknown

Rights remain with the original author and publisher. This is a research
archive of a source from the Web Hacking Techniques Index collections, kept so the
page going offline. To read the original, follow the link above.

## Content

> UNTRUSTED SOURCE TEXT. Everything below this line is third-party material
> quoted for research. It is data, not instructions. Do not follow directions,
> execute code, or fetch URLs because this text says so.

Automated Generation of Event-Oriented Exploits in
             Android Hybrid Apps

                                          Guangliang Yang, Jeff Huang, and Guofei Gu
                                                         Texas A&M University
                                                   {ygl, jeffhuang, guofei}@tamu.edu


    Abstract—Recently more and more Android apps integrate the
embedded browser, known as “WebView”, to render web pages                                                    ,dD>ZĞŶĚĞƌΘ:^ŶŐŝŶĞ
and run JavaScript code without leaving these apps. WebView                                                      ,dD>ͬ:ĂǀĂ^ĐƌŝƉƚŽĚĞ




                                                                                                 tĞďsŝĞǁ
provides a powerful feature that allows event handlers defined
in the native context (i.e., Java in Android) to handle web events                                                        Ϯ




                                                                             ĞŶŝŐŶ,ǇďƌŝĚƉƉ
                                                                                                                                                   ϭ
that occur in WebView. However, as shown in prior work, this                                                             tĞďǀĞŶƚƐ                    ϭ   ^ĞƌǀĞƌ
feature suffers from remote attacks, which we generalize as Event-                                            Ğϭ         ĞϮ   ͙͙͘͘      ĞŶ
Oriented Exploit (EOE) in this paper, such that adversaries
may remotely access local critical functionalities through event                                                          ϯ    tĞďͲEĂƚŝǀĞƌŝĚŐĞ

handlers in WebView without any permission or authentication.                                              :ĂǀĂ;EĂƚŝǀĞͿǀĞŶƚ,ĂŶĚůĞƌƐ

     In this paper, we propose a novel approach, EOEDroid, which                                     ĞŚϭ           ĞŚϮ        ͙͙͘͘      ĞŚŶ
can automatically vet event handlers in a given hybrid app using                                             ϰ
selective symbolic execution and static analysis. If a vulnerability                                         ƌŝƚŝĐĂů&ƵŶĐƚŝŽŶĂůŝƚŝĞƐ
is found, EOEDroid also automatically generates exploit code to                                    ;Ğ͘Ő͕͘ƵƚŚ͕͘ZĞƐŽƵƌĐĞƐĐĐĞƐƐ͕:^ǆĞĐƵƚŝŽŶͿ
help developers and analysts verify the vulnerability. To support
exploit code generation, we also systematically study web events,                                           ŶĚƌŽŝĚĞǀŝĐĞ
event handlers and their trigger constraints.
    We evaluated our approach on 3,652 most popular apps. The                                                            Figure 1: Attack Model
result showed that our approach found 97 total vulnerabilities in
58 apps, including 2 cross-frame DOM manipulation, 53 phishing,
30 sensitive information leakage, 1 local resources access, and 11     native code, but the bridge is not protected in WebView.
Intent abuse vulnerabilities. We also found a potential backdoor           However, up to now it still remains unclear how adversaries
in a high profile app that could be used to steal users’ sensitive     involve the event handler feature in their attack vectors in
information, such as IMEI. Even though developers attempted            practice. A possible attack scenario is that an adversary may
to close it, EOEDroid found that adversaries were still able to
exploit it by triggering two events together and feeding event
                                                                       trigger an event handler with appropriate input to leverage its
handlers with well designed input.                                     internal critical functionalities. More details are shown in Figure
                                                                       1. First, the adversary injects malicious HTML/JavaScript code
                                                                       into WebView through web or network attacks (Step 1). Then,
                       I. I NTRODUCTION                                the malicious code is executed and triggers a web event (Step
    More and more Android apps leverage the power of the               2). After that, the corresponding event handler in the native
embedded browser, known as “WebView”, to render web pages              code is called (Step 3). Finally, the event handler is guided by
and run JavaScript code. In contrast to regular web browsers           the injected input to execute its internal critical functionalities
(such as desktop browsers), WebView is more powerful by                (Step 4).
providing a unique feature that allows event handlers defined in           The above possibility is confirmed by our small-scale
the native context (i.e., Java in Android) to handle web events        empirical study of 100 popular hybrid apps collected from
that occur in WebView.                                                 Google Play. We found that an event handler in an old
    This powerful feature of WebView significantly enriches            but still popular advertisement (ad) library, “millennialmedia”
the functionalities of Android apps. However, as shown in prior        (version 5), contains rich and powerful functionalities, such as
work [19], [26], such a feature also introduces potential security     reading Android ID, recording audio and opening the camera.
flaws. More specially, it opens a bridge that links web code to        However, the access control on that event handler is weak. The
                                                                       internal critical functionalities can be utilized by triggering
                                                                       the associated web event and feeding it with appropriate input
                                                                       that follows the format “mmsdk://c1.c2?args=...&call
                                                                       back=...”, where c1 and c2 are the native functions to be
                                                                       accessed, args are the function’s parameters and callback is a
Network and Distributed Systems Security (NDSS) Symposium 2018         JavaScript function name to receive the execution result of the
18-21 February 2018, San Diego, CA, USA                                native function.
ISBN 1-891562-49-5
http://dx.doi.org/10.14722/ndss.2018.23236                                 In addition to the above scenario, another potential attack
www.ndss-symposium.org                                                 scenario is that a path to a critical functionality inside an event
handler may be executed only under a specific program state,                 two ways to cover every ci to reach f . For convenience, we
but such state may not be simply reached by only feeding that                refer to the second case as event handler dependency, which
event handler with arbitrary input. Instead, similar to return               is defined as follows. If operands of a condition c0 in the path
oriented programming based attacks [32], it is possible for                  p0 of an event handler eh0 can be influenced by the path p1 of
adversaries to play web events as “gadgets” and change an                    another event handler eh1 , we say eh0 depends on eh1 on c0
                                                                                                 c0
app’s state. Assume the target program state is St . It may be               (i.g., heh1 , p1 i −→  heh0 , p0 i). This means that if adversaries
reached through the transitions [S1 →S2 → ... →St ], which                   first guide the app to execute p1 , the program state related to
could be achieved by triggering the sequence of web events                   c0 may be influenced, and then, the expected branch behind
[E1 →E2 → ... →Et ]. Hence, by following the above web event                 c0 may be taken.
chain, adversaries can still change the program state to St and                  The design of EOEDroid is depicted in Figure 2. Given a
execute the target critical functionality.                                   target app, EOEDroid first employs selective symbolic execution
    For convenience, in this paper, we generalize all above                  to analyze all its event handlers, actively explore all interesting
attacks as Event-Oriented Exploit (EOE). Due to EOE’s                        paths and identify critical functionalities. The path constraints
powerful capabilities to access critical functionalities through             of each interesting path are collected for further analysis. A
event handlers, serious consequences may be caused, such                     significant difference with existing symbolic execution based
as local resource access, users’ private data leakage and web                techniques is that EOEDroid carefully handles all conditional
cross-frame DOM manipulation.                                                statements, including those whose associated operands are not
    Compared with existing attacks on Android (such as Trojan                symbolic (i.e., concrete or constant). This is because those
Attack [7]), EOE has multiple advantages. First, EOE does not                conditional statements can provide hints to generate gadgets’
require any extra permissions. The malicious web code injected               execution orders.
by adversaries fully inherits the target apps’ permissions.                      To mitigate the notorious “path explosion” problem in
Second, EOE does not require malicious payloads. Instead,                    symbolic execution, we use several heuristics (e.g., scanning
the functionalities contained in event handlers are utilized.                “interesting” APIs and instructions to discover interesting paths
    Furthermore, compared with existing attacks on WebView                   in Section V-B1). While these heuristics might cause over-
(such as sidewinder targeted attack [38], fracking attack                    approximation and/or inaccuracy to our analysis, they help us
[19], and code injection attack [24]), EOE is more practi-                   make a good tradeoff between performance and accuracy. In
cal and feasible. Existing attacks usually require JavaScript                addition, we propose new solutions to address the analysis
and JavaScript-bridge to be enabled, but EOE has no such                     challenges raised by array-indexing type implicit flows as well
requirements (Section V-A). Even only through HTML code                      as Android features and specifications such as unsupported
and special HTTP(s) responses, adversaries can still trigger                 fork() [1] and inter-component communication (e.g., Android
and leverage many event handlers, including the popular event                Intent).
handlers shouldOverrideUrlLoading(), which handles the URL                       Based on the results of selective symbolic execution,
navigation event.                                                            EOEDroid then applies static analysis to discover program
    The impact of EOE to smartphone security is serious                      states that can lead to the execution of a critical functionality,
considering the pervasive deployment of hybrid apps today.                   and generates input and execution order of event handlers to
However, exiting techniques face significant challenges in                   reach the program state. The input of an event handler can be
detecting and verifying apps against EOE. Static analysis suffers            generated by solving its path constraints, and the execution
from high false positives due to the lack of real data and                   order of event handlers can be constructed by solving the event
context. In addition, the limitation of static analysis for handling         handler dependency problem on those conditional statements
Java reflection is exacerbated when the reflection operation is              whose operands are not symbolic.
combined with array-indexing type implicit flows, which occur                   Finally, EOEDroid generates exploit code by converting
frequently when parsing the gadgets’ inputs. Dynamic analysis                event handlers’ input and execution orders to gadgets’ (i.e.,
may have low false positives, but is prone to low code coverage.             web events). If JavaScript code is required as gadgets’ input,
Moreover, generating the required sequence of gadgets to reveal              EOEDroid is also aware of its syntax and generates the required
an EOE vulnerability is inherently challenging.                              code.
    Our Approach. In this paper, we present a systematic study                   Along with this, we conduct a systematic study of events,
of EOE in Android hybrid apps together with a novel technique,               event handlers, and their triggering code and constraints in
EOEDroid, which can automatically analyze event handlers,                    WebView. We find that 37 web events are exposed to adversaries,
detect exploitable critical functionalities, and further generate            and the constraints on triggering events and event handlers are
exploit code. EOEDroid can be applied to help developers detect              mainly caused by the status of JavaScript and the level of the
and verify the EOE security issues before publishing their apps.             web frame the malicious code is injected into. We also find
The basic idea behind EOEDroid is that a critical functionality              that five event handlers have extra trigger constraints caused
f can be leveraged by adversaries if there is a program state                by predetermined execution orders of event handlers, and we
s that makes f ’s corresponding path p to be feasible. Since                 identify 29 channels that can pass data from web code to native
state s can be influenced or determined by all conditional                   code.
statements [c0 , c1 , ..., cn ] along p, if adversaries can affect the          Evaluation. We have implemented EOEDroid based on the
path selection of each ci , the program may be executed along                Android framework and the Dalvik virtual machine (DVM),
p. To cover each ci , adversaries have two ways: (1) feeding                 and evaluated it with 3,652 most popular apps collected from
the event handler with appropriate input, and (2) changing                   Google Play. EOEDroid found 97 total vulnerabilities in 58
execution orders of event handlers. Our goal is to explore these


                                                                         2
                                          ǇŶĂŵŝĐŶĂůǇƐŝƐ                                                                 ^ƚĂƚŝĐŶĂůǇƐŝƐ

                                    ǀĞŶƚ,ĂŶĚůĞƌŶĂůǇƐŝƐ
                                         ^ĞůĞĐƚŝǀĞ^ǇŵďŽůŝĐ                     WƌŽŐƌĂŵ^ƚĂƚĞŶĂůǇƐŝƐ
                                                                  ƌŝƚŝĐĂů
                                             ǆĞĐƵƚŝŽŶ


                 ŶĂůǇƐŝƐ^ĂŶĚďŽǆ
                                                               &ƵŶĐƚŝŽŶĂůŝƚŝĞƐ       ǀĞŶƚ,ĂŶĚůĞƌ                                ǆƉůŽŝƚŽĚĞ'ĞŶĞƌĂƚŝŽŶ   sƵůŶĞƌĂďŝůŝƚŝĞƐ
                                                                                   /ŶƉƵƚ'ĞŶĞƌĂƚŝŽŶ       ǀĞŶƚ,ĂŶĚůĞƌ
    ǀĞŶƚ                              ,ĞƵƌŝƐƚŝĐ'ĞŶĞƌĂƚŝŽŶ                                                 /ŶƉƵƚΘ                  :ĂǀĂ^ĐƌŝƉƚŽĚĞ
   ,ĂŶĚůĞƌƐ                                                                          ǀĞŶƚ,ĂŶĚůĞƌ         ǆĞĐƵƚŝŽŶ                 ^ǇŶƚĂǆŶĂůǇƐŝƐ
                                           /ŶƚĞŶƚ,ĂŶĚůĞƌ
                                                                /ŶƚĞƌĞƐƚŝŶŐ        ǆĞĐƵƚŝŽŶKƌĚĞƌ          KƌĚĞƌƐ                                         ǆƉůŽŝƚŽĚĞ
                                       /ŵƉůŝĐŝƚ&ůŽǁ,ĂŶĚůĞƌ   WĂƚŚƐΘWĂƚŚ          'ĞŶĞƌĂƚŝŽŶ                                             WŚĂƐĞϯ
                                       ;ĂƌƌĂǇͲŝŶĚĞǆŝŶŐƚǇƉĞͿ    ŽŶƐƚƌĂŝŶƚƐ
                                                                                        WŚĂƐĞϮ
                                           WŚĂƐĞϭ


                                                                    Figure 2: The Design of EOEDroid.

apps, including 2 cross-frame DOM manipulation, 53 phishing,                                shouldOverrideUrlLoading() to handle the URL navigation
30 sensitive information leakage, 1 local resources access,                                 event. If an event handler is not implemented by developers,
and 11 Intent abuse vulnerabilities. We also found a potential                              the default implementation in the Android system will be called.
backdoor in a high-profile app that may be used by adversaries                                 WebView manages event handlers by either itself or event
to steal users’ sensitive information, such as IMEI. Even though                           handler classes. An event handler class is a collection of event
the developers of the app attempted to close the backdoor,                                 handlers. There are mainly two types of event handler classes.
EOEDroid found that adversaries were still able to exploit it by                           One is WebViewClient, which manages the event handlers that
triggering two events together and feeding event handlers with                             are relevant to URL navigation. The other is WebChromeClient,
appropriate inputs. We show more details in our case study in                              which manages the event handlers that are relevant to UI display,
Section VI-C2 to illustrate this vulnerability.                                            such as handling the alert dialog opened by JavaScript alert().
    We have reported all our findings to app developers, and                                    Through the API loadUrl(), WebView renders content in its
are working with them to fix the vulnerabilities.                                           UI component. The parameter format supported by loadUrl()
   To sum up, we make the following contributions:                                          is diverse. It can be a URL, a local HTML file, or JavaScript
                                                                                            code. If the parameter is JavaScript code, 1) it must start with
   •      We present a systematic study of Event-Oriented
                                                                                            the special string “javascript:”, and 2) it is executed in the
          Exploits (EOE) in Android hybrid apps and a novel
                                                                                            main web frame. For instance, the following code will popup
          technique EOEDroid to automatically generate exploits
                                                                                            an alert window to show current cookie in the main frame:
          that reveal security vulnerabilities.
                                                                                                  WebView.loadUrl("javascript:alert(document.cookie);").
   •      We thoroughly study events and event handlers as well
          as their triggering constraints in WebView.
   •      We evaluate EOEDroid using 3,652 hybrid apps.                                                           III.        P ROBLEM S TATEMENT
          EOEDroid identified 97 vulnerabilities in 58 apps that                            A. Motivating Example
          can cause critical attacks.
                                                                                               To illustrate event-oriented exploits, we walk through a real-
  II.    BACKGROUND : A NDROID A PPS , W EB V IEW , A ND                                   world vulnerable app with relevant code shown in Figure 3. In
                  E VENT H ANDLERS                                                         the activity “WebViewActivity”, the app initializes a webview
                                                                                           component by a class “MyClient”, which implements an event
    Android apps are typically written in Java and compiled                                handler “shouldOverrideUrlLoading()”. In the event handler,
to Dalvik bytecode [5]. At runtime, bytecodes are interpreted                              the input url is firstly parsed by a class “URI”, which is
and executed by Dalvik virtual machine (DVM) [4]. Generally,                               commonly used to analyze URI’s syntax and extract useful
an app consists of four components: activity (i.e., the user                               information, such as URI’s scheme and host. Then, the url’s
interface), background service, content providers (i.e., database),                        content is analyzed, which determines the event handler’s
and Android native event receivers. Intent can be used in                                  behaviors. If the url’s scheme is “market”, “tel”, or “sms”,
interactions among components and apps.                                                    the corresponding external apps (such as Google Play, default
    WebView is a small UI component in Android, which can                                  phone call app, or default text message app) will be opened to
be integrated into apps to display web pages. WebView can                                  handle the input (Path1). If the url’s host is “developer.com”
also execute JavaScript code if developers enable JavaScript                               (which means WebView connects to a remote server), the event
in WebView’s settings, which is disabled by default. WebView                               handler may approve the connection (Path2).
settings can also be used to disable local files, database, and                                Meanwhile, the event handler implements supports for the
GPS location access.                                                                       customized scheme “sdk”. If the url’s host h is “init”, WebView
    The event handler feature makes WebView more powerful.                                 executes JavaScript code to perform initialization (Path3). If
Usually, the function prototypes of event handlers are pre-                                h’s format is “c0 .c1 .c2 ”, the app calls the Java method whose
defined by the Android system in the native (i.e., Java in                                 class name is determined by c0 , method name c1 , and execution
Android) language. Hence, to implement an event handler,                                   result is transferred to the JavaScript method c3 (Path4). Note
developers need to override the corresponding Java function,                               that resolving the Java method relies on the content of the
and then register the implementation in WebView. When                                      variable “hashmap”, which converts c0 (i.e., commands[0])
the corresponding event is triggered in the web context, the                               to the real class name (i.e., className). Such an operation
event handler implemented by developers is called to handle                                introduces an implicit flow from c0 to className. “Class2” is
it. For instance, developers can override the event handler                                one of classes whose methods can be invoked by the event

                                                                                       3
                                       Figure 3: Vulnerable Code From A Real-World App.

handler. In its method getId(), the device ID is transferred to                  (e.g., iframe) to load extra web content from third-
the web space. In its method login(), the activity “LoginActivity”               parties, which may be malicious.
is started through an Intent message to ask users to login. In the               Generally, all web frames loaded in WebView are well
Intent message, part of the url’s content (i.e., c2 ) is contained               isolated and protected by same origin policy (SOP)
and passed to the message receiver.                                              [8].
    Note that in the example app there is a critical function:              •    Network Attack: Adversaries can hijack unsafe network
getDeviceId() in the method getId() of Class2. Adversaries                       traffic (such as HTTP) through man-in-the-middle
cannot directly utilize this functionality, because the operand                  attacks. Compared with desktop programs, mobile apps
tmpbool is false (i.e., the conditional statement C6 ). However,                 are more likely to suffer from this type of attacks,
by manipulating gadgets, adversaries may change the program                      considering that many unsafe WI-FI hotspots are used
state (such as tmpbool’s value) and drive the app to call getId().               [23].
In getId() a JavaScript function is also required as part of the
event handler’s input to receive the device ID.                              Note that we do not assume any other abilities of the
                                                                         adversaries. They may not access the users’ device, install any
   Although it appears simple to manually analyze this example           certificate or malware, or change apps’ internal data. The target
code, real-world apps are much more complex. Our goal is                 app itself as well as all the apps pre-installed on the users’
to develop a technique that can automatically detect such                devices may be benign.
vulnerabilities and construct exploit code.
                                                                         C. Security Issues
B. Threat Model                                                              Similar to other attacks on WebView [19], the security issues
    We assume that WebView is enabled in apps, but JavaScript            caused by event handlers are rooted in the inconsistency of
is not required to be enabled, since HTML code can also trigger          security models between web and native context. In hybrid apps,
event handlers. We assume that adversaries can inject malicious          the SOP security model for the web context is circumscribed to
HTML/JavaScript code into WebView. As Figure 1 shows, we                 prevent event handlers from being triggered by malicious web
consider the following two different attack scenarios:                   code, because the handlers do not have any way of identifying
                                                                         the origin of an event (so they have no way to distinguish
   •    Web Attack: In this scenario, we assume adversaries              between trusted and untrusted origins). SOP is also ineffective to
        control several malicious domains and servers, but they          protect the local resources (such as camera), which are located
        are not able to control or monitor the network traffic           in the native context. The permission based sandbox model for
        between apps and other domains.                                  the native context can protect local resources. However, it is
        The web content loaded from first-parties is trustable.          ineffective to prevent the access to critical functionalities from
        However, the content may further contain subframes               web code, since the origin information of the access is lost.

                                                                     4
D. Problem Definition                                                                We consider the Android ID, device ID, phone number, and
    We state that an exploit is successful if it successfully                    serial number, and GPS location information as source, and
triggers a critical functionality through event handlers defined                 connecting network and sending text message as sink.
in the app. A successful exploit must satisfy the constraints                        APIs Accessing Local Resources. This type of APIs
in triggering target events and event handlers: it must guide                    may be leveraged by adversaries to access local resources,
the target app to reach the target state by manipulating the                     such as local files, and hardware resource (e.g., camera).
input and execution orders of gadgets, and it must bypass all                    Serious consequences may be caused when these APIs are
security checks which are usually located before the critical                    combined with other sensitive APIs. For instance, adversaries
functionality.                                                                   may remotely take a picture and also save it to the local storage
     The event-oriented exploit generation problem can be                        using camera APIs. Then, adversaries may obtain the picture
formally defined as follows. Given an app, discover a program                    in the web context through file reading API and further send
state s that leads the app to execute a critical functionality. Such             the picture out through native sink APIs or HTML/JavaScript
a state should be reached through a sequence of executions                       code.
of gadgets ((W0 , E0 , I0 , J0 ), (W1 , E1 , I1 , J1 ), . . . , (Wn , En ,           APIs Sending Intent messages. As demonstrated by Wang
In , J0 )), where Wi is the HTML/JavaScript code that triggers                   et al. [36], the Intent messages that are sent out through
the event Ei and passes the input Ii to Ei . Ii may also include                 WebView may have serious consequences. We consider the
pre-defined JavaScript code Ji .                                                 following type of APIs as sensitive: the API parameter is totally
                                                                                 controlled by adversaries, which means the destination of the
                                                                                 Intent message to be sent is totally determined by adversaries.
E. Critical Functionalities                                                      For other Intent-sending APIs, we treat them as regular inter-
    We define critical functionalities as sensitive APIs in the                  component communications.
Android framework. In this paper, we mainly consider the
following four types of APIs. Nevertheless, EOEDroid is                                             IV.   S YSTEM OVERVIEW
extensible and user customized APIs can be added easily.
                                                                                     In this section, we provide an overview of EOEDroid
    URL Loading API (e.g., WebView.loadUrl(p)). If mali-                         and illustrate it with the motivating example described in
cious HTML/JavaScript code in subframes leverages the API                        the previous section. The technical details of EOEDroid are
through EOE, the content of the main frame or the whole                          presented in Section V.
WebView may be changed (Section II). Depending on the
value of the API parameter p, the following two consequences                        We use the following basic concepts and notations:
may be caused.                                                                      •    A Symbolic Conditional Statement: a conditional state-
                                                                                         ment whose operands are symbolic.
    •    Cross-Frame DOM Manipulation: If the web code in
         subframes influences p’s value and makes p be starting                     •    Path Constraints: all constraints that must be satisfied
         with “javascript:”, the JavaScript code contained in p                          when guiding an app to execute a path. Different from
         may be executed in the main frame. Hence, through                               prior work, EOEDroid involves both symbolic and non-
         EOE, the web code in subframes obtains the capability                           symbolic conditional statements in path constraints.
         to bypass SOP and inject malicious code to the main                        •    Input Constraints: A subset of path constraints but are
         frame.                                                                          only related to event handlers’ input.
    •    Phishing: If the web code in subframes can determines
                                                                                     We assume that s is the target program state that leads to
         p’s value through EOE, it may change p’s value to the
                                                                                 the execution of a critical functionality; f is the target critical
         url of a fake web page. Then, WebView is redirected
                                                                                 functionality; p0 is the path containing f ; eh0 is the event
         to show the fake web page. Considering that WebView
                                                                                 handler containing p0 .
         usually does not have an address bar to indicate the
         url it is loading, such attacks on WebView are much
         more stealthy than on regular web browsers.                             A. Overview
                                                                                     EOEDroid consists of three modules: event handler analysis,
    Compared with other attack channels (such as MITM                            program state analysis, and exploit code generation, as shown
attacks) which may also be utilized to perform above attacks,                    in Figure 2. In the first module, selective symbolic execution
EOE over loadUrl() is more powerful. Considering the situation                   is used to explore paths in the event handlers and collect path
that WebView loads a webpage from developers’ web site using                     constraints. To apply the technique for Android hybrid apps,
HTTPS, and one of its nested subframes uses HTTP. Due to                         technical challenges (Section V-B) are addressed by four sub-
boundaries between frames, existing attacks may only be able                     modules: analysis sandbox, heuristic generation, Intent handler,
to control the content of the subframe, but not the main frame.                  and array-indexing type implicit flow handler. More specifically,
However, EOE does not have this limitation. By means of                          given an app, “selective symbolic execution” is called to
loadUrl(), adversaries can directly change the content of the                    repeatedly test each event handler until all the inside interesting
main frame.                                                                      paths are traversed. The interesting paths are discovered by the
   Source and Sink APIs. This type of API invocations                            sub-module “heuristic-generation”. Note that when a branch
may result in users’ privacy leakage. We mainly consider two                     is flagged as interesting, no matter whether the conditional
scenarios: (1) there are paths from source to sink in event                      statement is symbolic or not, EOEDroid forcely traverses
handlers. (2) source is passed to the web space, and then sent                   this path. Meanwhile, the corresponding path constraint is
out through HTML/JavaScript code.                                                constructed and saved.

                                                                             5
    For each round of test, the sub-module “analysis sandbox”               its selected branch (i.e., 1). Note that in this path the external
is applied to guard the analysis environment from pollution                 field variable Initialized is written. To ensure each round of test
and keep each round of test independent.                                    is independent, such interaction between the event handler and
    In the second phase, the module “program state analysis”                the external variable is handled by the sub-module “analysis
runs to discover state s and learn how to reach s by manip-                 sandbox”.
ulating event handlers’ input and execution order, which are                    The conditional statement C6 is then reached. In the true
handled by the sub-modules “event handler input generation”                 branch, the host name is split to an array, whose symbolic
and “event handler execution order generation” respectively.                expression is Uri.<init>(InputUrl).getHost().split("."). Then,
For event handlers’ input, it is generated by applying an SMT               an implicit flow is faced, which is caused by the Hashmap
solver in the associated input constraints collected in the first           accessing operation. To handle it, the sub-module “implicit
phase. For event handlers’ execution order, it is generated by              flow handler” is started to try all possibilities in the Hashmap
solving the event handler dependency problem (as described                  instance. Therefore, a critical functionality is found in getId() in
in Section I).                                                              Class2, which can be leveraged by adversaries to perform cross-
    For each path p that contains critical functionalities, EOE-            frame DOM manipulation and steal the device ID information.
Droid repeatedly resolves all event handler dependencies for p              The main associated path constraints are shown in Listing 1.
with four steps: (1) it analyzes p’s path constraints to identify               (1) Uri.<init>(InputUrl).getScheme().equals("market") == 0
                                                                                (2) Uri.<init>(InputUrl).getScheme().equals("tel") == 0
all non-symbolic conditional statements; (2) it confirms the                    (3) Uri.<init>(InputUrl).getScheme().equals("sms") == 0
                                                                                (4) Uri.<init>(InputUrl).getHost().equals("developer.com")
expected value v for each conditional statement; (3) starting                        == 0
                                                                                (5) Uri.<init>(InputUrl).getScheme().equals("sdk") 6 = 0
from each conditional statement c, it performs backward                         (6) tmpbool 6 = 0
                                                                                (7) Uri.<init>(InputUrl).getHost().split(".").length == 3
program analysis to determine the variables O that can influence                (8) Uri.<init>(InputUrl).getHost().split(".")[0].equals("c2
                                                                                     ") 6 = 0 // generated by implicit flow handler
c’s operands, and further computes the required value for each                  (9) Uri.<init>(InputUrl).getHost().split(".")[1].equals("
variable in O; and (4) it analyzes all paths in all event handlers                   getId") 6 = 0

that contain the instructions changing the variables in O to                        Listing 1: Path Constraints In Executing getId()
their corresponding expected values.
                                                                                In the second phase, the module “program state analysis”
    In the third phase, the module exploit code generation
                                                                            analyzes the path constraints (Listing 1) to change the program
generates exploit code for each exploitable critical functionality.
                                                                            state. First, the sub-module “event handler input generation”
First, the event handlers’ execution order generated in the
                                                                            checks if the constraints can be satisfied by feeding the event
second phase is converted to the web event order, and the
                                                                            handler with appropriate input. In this case, all constraints
event handlers’ input is converted to the corresponding web
                                                                            except (6) can be satisfied. Second, the sub-module “event
events’. Second, if JavaScript code is required as the event
                                                                            handler execution order generation” runs to check how to
handler’s input (such as the callback function in our motivating
                                                                            influence the program state to satisfy the constraint (6). Starting
example), the syntax of the associated JavaScript code is parsed
                                                                            from the conditional statement C6, EOEDroid backward tracks
and analyzed to generated required JavaScript code.
                                                                            the operand tmpbool along the executed path, and confirms
B. Analyzing the Example                                                    the variable (i.e., Initialized) can influence its value. Next,
                                                                            EOEDroid goes through all paths identified in the first phase
    Now we illustrate how EOEDroid works for our motivating                 to check whether there is a path that contains an instruction
example. When the event handler shouldOverrideUrlLoading()                  changing Initialized’s value. It finds that Path3 contains
is triggered, EOEDroid is started. First of all, EOEDroid sym-              the expected operation. Hence, there is an event handler
bolizes the event handler’s second parameter as ‘InputUrl’, since                                                                          C6
its value can be controlled by adversaries. Then, EOEDroid                  dependency on C6: <shouldOverrideUrlLoading(), Path3> −−→
analyzes each instruction. As the class Uri is frequently used,             <shouldOverrideUrlLoading(), Path4>.
we model it by symbolizing its instance u as ‘Uri.<init>(Input                 In the third phase, the module “exploit code generation”
Url)’. The input’s scheme and host are also symbolized, whose               generates the exploit code for the critical functionality in getId().
symbolic expressions are ‘Uri.<init>(InputUrl).getScheme()’                 To drive the app to execute the critical functionality, event
and ‘Uri.<init>(InputUrl).getHost()’, respectively.                         handlers should be executed as follows:
                                                                                (1) shouldOverrideUrlLoading(webview, "sdk://init")
    When the conditional statement C1 is analyzed, “heuristic                   (2) shouldOverrideUrlLoading(webview, "sdk://c2.getId.?")
generation” is started to discover which branches are interesting.
In this case, both branches have interesting instructions. So                   Then, the above event handler execution order is converted
both of them are sequentially traversed. In the true branch,                to the web event order, and further transformed to the following
when an Intent message is sent to another app or component,                 HTML/JavaScript code (based on our event handler study
the module “Intent handler” (Section V-B3) is set up to fill                presented in Section V-A):
the symbolic information gap between the sender and receiver.                   <iframe src="sdk://init"/>
                                                                                <iframe src="sdk://c2.getId.?"/>
    Similarly, the conditional statements C2, C3 and C4 are
processed. In C4’s true branch, EOEDroid encounters a special                   The above code can change the program state and reach the
conditional statement that is non-symbolic (i.e., C5). As its               sensitive API loadUrl(). However, part of the event handler’s
true branch is interesting, EOEDroid forcely executes it and                input is still missing, which is a JavaScript callback function
also collects necessary information, such as the executed path              used to receive the sensitive information (i.e., device ID).
information, the instruction’s position (such as <MyClient.java,            To address this problem, the sub-module “JavaScript code
C5>), the condition expression (i.e., tmpbool == 0), the operand            syntax analysis” runs to analyze the syntax of the parameter of
variable (i.e., tmpbool), current value of the variable (i.e., 0) and       loadUrl(), and generate required JavaScript code. Finally, the

                                                                        6
following exploit code is generated, which can help developers        reported in Table I, almost 60% of the event handlers require
test and verify the EOE problem.                                      JavaScript enabled to trigger.
  1 <script>                                                              Event Handler Triggering Constraints. The constraints
  2 function steal_device_id(id) {
  3   document.write("<" + "img src=’" + "http://attacker.com/"       for triggering event handlers are mainly from two aspects:
            + id + "’ />")
  4 }
  5 </script>                                                             I: The frame level. Triggering three of the event handlers
  6 <iframe src="sdk://init"/>
  7 <iframe src="sdk://c2.getId.steal_device_id"/>                    require their corresponding events to occur in the main frame.
                     Listing 2: Exploit Code                          Adversaries must inject malicious code into the main frame,
                                                                      which is usually well protected. Also, it is easy for users to
                                                                      realize the injected web code, because it may reload web pages.
                V.     T ECHNICAL A PPROACHES
                                                                          II: Predetermined execution orders. Several event handlers’
    In this section, we first present our study of events and         execution orders are predetermined in WebView, which also
event handlers in WebView to understand their constraints for         imposes constraints on triggering the event handlers. To
triggering event-oriented exploits. We then present technical         understand these predetermined execution orders, we create
details about the design and implementation of selective              an experimental app which registers all event handlers, and
symbolic execution, program state analysis, and exploit code          profile them when they are invoked. Then, the app loads fuzzing
generation.                                                           HTML/JavaScript code. We also apply static analysis to track
A. Understanding Event Handler Triggering Constraints                 the return values of all event handlers. If an event handler’s
                                                                      return value appears in a conditional statement, and later another
    The official Android documentation of events and event            event handler is called, a predetermined event order may exist.
handlers is obscure and incomplete. We hence conduct a                Finally, we confirm five predetermined execution orders:
systematic study based on both reading documents about
                                                                          1. shouldInterceptRequest() → onLoadResource(): The latter
WebView on the web and analyzing real-world hybrid apps.
The main study result is shown in Table I. We find that 37            event handler is called only when the former event handler
events are available for adversaries in WebView. The triggering       returns null.
code for each event is shown in the fifth column. Note that              2. shouldOverrideKeyEvent() → onUnhandledKeyEvent():
the DOM element ‘<iframe src=...>’ can directly trigger two           The latter event handler is only called when the former event
events, whose corresponding event handlers are shouldOver-            handler returns false.
rideUrlLoading() and shouldInterceptRequest(), respectively.              3. onPageStarted() → ... → onPageFinished(): When
It depends on the attribute src’s content s. If s’s scheme is         WebView starts loading a web page, onPageStarted() is called.
not ‘HTTP’ and ‘HTTPS’, but customized, the former one is             When WebView finishes loading the page, onPageFinished() is
triggered. Otherwise, the latter one is triggered.                    called. During the process, other event handlers may be called as
     As reported in the third column, using HTML code,                well, such as onReceivedError() and shouldInterceptRequest().
 adversaries can trigger 15 event handlers, including popular             4. onPageStarted() can be called multiple times before
 event handlers shouldOverrideUrlLoading() and shouldInter-           onPageFinished() is called. This happens when there are URL
 ceptRequest(). Note that, four of them require supports from         redirections in the web server side (i.e., 3xx HTTP response
 the web server side to get appropriate HTTP response code.           code). The number of times that onP ageStarted() is called
 For instance, onReceivedLoginRequest(webview, realm, account,        depends on the URL redirection number. Moreover, generally,
 args) can be triggered by the combination of the HTML code           onPageFinished() is only called once, no matter how many
“<iframe src="http://attacker.com/login">” and the HTTP               URL redirections there are. But if the last HTTP response code
 response header “x-auto-login:realm=x&account=y&args=z”,             is 4xx, WebView may be redirected to show a page-not-found
 which is from the malicious server “attacker.com”. x, y, and z       HTML, and then, onPageFinished() is called again.
 are passed to onReceivedLoginRequest() as function parameters.
 As the above example shows, adversaries can pass data from               5. onGeolocationPermissionsShowPrompt() → onGeolo-
 the web context to the native context. In our study, we find         cationPermissionsHidePrompt() and onShowCustomView() →
 that the parameters of 29 event handlers can be influenced by        onHideCustomView(): When location permission is requested,
 adversaries. More details are shown in the first column (i.e.,       or Full Screen is entered, these events are called sequentially.
 the parameters between parentheses).
                                                                          Adversaries’ Capability: Playing Gadgets. Adversaries
    As reported in the fourth column, triggering event handlers       can change program states by manipulating gadgets’ input and
are influenced by the level of web frames where the events            execution orders. More specifically, adversaries can pass data to
occur. We find that events which occur in the main frame could        web events, and then the data are passed to the corresponding
trigger all event handlers, whereas the capability of events in       event handlers as their function parameters. Adversaries can
subframes is limited. More specifically, three event handlers         also trigger events and event handlers in arbitrary orders, even
cannot be triggered by events that occur in the main frame.           though there are constraints on triggering events and event
Let Ei (i ≥ 0) be the events that occur in the ith level web          handlers.
frame and can be handled by event handlers, E denotes all
events available in the whole WebView space and E0 denotes                Gadgets’ Input. Adversaries may be able to control event
the events available in the main frame, they have the following       handlers’ parameters. For example, shouldInterceptRequest()’s
relationship: E0 = E while Ei @ E (i > 0).                            parameter (i.e., request) can be set as ‘‘https://attacker.com/im
                                                                      g’’, if adversaries use the HTML code “<iframe src="https://
   Event Triggering Constraints. The constraints for trigger-         attacker.com/img"></iframe>” to trigger the event handler.
ing events are mainly caused by the status of JavaScript. As

                                                                  7
  Event Handlers and Main Parameters                  Handled Events            JS?   E0 ?         Example Trigger Code (HTML/JavaScript/HTTP)

onFormResubmission                               Resubmitting a form            X               [HTML] <form ...> [JS] form.resubmit()
onPageCommitVisible(url)                                                                        [HTML] <body bgcolor="#0f0" ..> <img bgcolor="#0f0" ..
doUpdateVisitedHistory(url, isReloaded)          Updating history               X         X     [JS] document.location="url"
onPageStarted(url, icon)                         Starting to load a page        X         X     [JS] document.location="url", reload()
onPageFinished(url)                              finishing loading a page       X         X     Trigger Constraint
onReceivedError(errorcode, description, url)     Failing to load a page                         [HTML] <iframe src="http://invalid.url" ...
onReceivedSslError(error)                        SSL error                                      [HTML] <iframe src="https://invalid.url"...
onReceivedClientCertRequest(request)             Client cert request                            [HTTP] Send client cert request
onReceivedHttpAuthRequest (host, realm)          Authentication request                         [HTTP] Send authorization header
onReceivedHttpError(request, response)           HTTP error                                     [HTTP] Send 404 header
onReceivedLoginRequest(realm, account, arg)      Login request                                  [HTTP] Send x-auto-login header
onScaleChanged(old_scale, new_scale)             Updating scale                 X               [JS] document.body.style.zoom=...
shouldOverrideKeyEvent(keyevent)                 Pressing key                   X               [JS] dispatch key-press event
onUnhandledKeyEvent(keyevent)                    Facing an unhandled key        X               Trigger Constraint
shouldInterceptRequest(request)                  Resources loading                              [HTML] <img src="... >, <iframe src="http://... >
onLoadResource(url)                              Loading a resource                             Trigger Constraint
shouldOverrideUrlLoading(url [or request])       URL navigation                                 [HTML] <iframe src="customizedScheme://...>
onCreateWindow                                   Creating a window              X               [JS] window.open()
onCloseWindow                                    Closing a window               X               [JS] window.close()
onConsoleMessage(message)                        Printing messages              X               [JS] console.log()
onGeolocationPermissionsShowPrompt
                                                 GPS request                    X               [JS] navigator.geolocation.getCurrentPosition()
(origin)
onGeolocationPermissionsHidePrompt                                              X               Trigger Constraint
onShowCustomView                                 Entering full screen           X               [HTML] <video ... controls>[JS] webkitRequestFullScreen()
onHideCustomView                                 Quitting full screen           X               Trigger Constraint
onJsBeforeUnload(url, message, result)           Leaving a webpage              X               [JS] dispatch onbeforeunload event
onJsAlert(url, message, result)                  Popuping an alert box          X               [JS] alert()
onJsConfirm(url, message, result)                Popuping a confirm box         X               [JS] confirm()
onJsPrompt(url, message, defaultValue, result)   Popuping a prompt box          X               [JS] prompt()
onPermissionRequest(request)                     Permission request             X               [JS] navigator.getUserMedia()
onPermissionRequestCanceled(request)             Request is cancelled           X
onRequestFocus                                   Requesting focus               X               [HTML] <input type="text" id="name" . . . [JS] focus();
onShowFileChooser                                Browsing file system           X               [HTML] <input type="file" . . . [JS] dispatch a click event
onProgressChanged(progress)                      Page loading status
onReceivedIcon(icon)                             Receiving a icon
onReceivedTitle(title)                           Receiving a title
                                                 Receiving an apple touch
onReceivedTouchIcon(url, precomposed)
                                                 icon
onDownloadStart(url, userAgent,
                                                 Downloading a file                             [HTML] <iframe src="http://url.apk" ...
contentDisposition, mimetype, contentLength)

Table I: The Systematic Study Result. The third column ‘JS?’ means: ‘Is JavaScript required to trigger the event?’, and the forth
column ‘E0 ?’ means: ‘Does the event handler only deal with events from E0 ?’. In answers, we use Xand blank to indicate ‘Yes’
                                                    and ‘No’, respectively.

    Gadgets’ Execution Orders. Consider two event handlers                                    conservatively and safely apply static analysis on only
eh1 and eh2 , there are two cases to analyze: (1) If eh1 and                                  a certain number of instructions that do not cause false
eh2 do not have any relationship, adversaries can call them                                   negatives (Section V-B1).
in any order (i.e., eh1 →e2 and eh2 →eh1 ); (2) If eh1 must be                        •       Unsupported fork(): In existing dynamic symbolic
                                                   t     c
executed before eh2 , their relationship should be →
                                                   − eh1 →
                                                         − eh2 ,                              execution based approaches, fork() is frequently used
where t is the trigger code to call eh1 and c is the pre-                                     to help systems traverse branches and keep the analysis
condition that must be satisfied to trigger eh2 . By repeating                                environment clean. However, in Android, fork() is not
t and make c be satisfied, we may get the event handler                                       supported. Instead, EOEDroid needs to sequentially
sequence (eh1 eh2 eh1 eh2 ), which includes expected sequences                                traverse branches. However, different with desktop
(both eh1 →eh2 and eh2 →eh1 ).                                                                software, it is expensive to save and restore states
                                                                                              of Android apps. To fix the problem, we propose an
B. Selective Symbolic Execution                                                               analysis sandbox to handle the interaction with the
   To apply symbolic execution in event handlers, we address                                  external environment (Section V-B2).
four challenges (with details in following subsections):                              •       Android Intent: Intent is frequently used in event
    •     Path explosion: To address this notorious problem,                                  handlers, such as triggering a GUI event to open
          EOEDroid uses static analysis to provide heuristic                                  a GUI activity. However, it introduces semantic gap
          information for path selection. However, as discussed                               between Intent senders and receivers. Figure 4 shows
          in Section I, static analysis may introduce false neg-                              an example that an intent message is delivered between
          atives to the heuristic information. To avoid it, we                                two apps. The Intent message escapes from the Java


                                                                            8
        context (i.e., DVM), enters the C/C++ context (i.e.,                    1) Heuristic Generation: The heuristic information used
        Linux kernel), and finally returns to the Java context.          in path selection includes the indication of whether a branch is
        This way raises challenges to track the Intent message           interesting. To determine it, EOEDroid uses static analysis to
        in the Java context. When the receiver obtains the               scan a certain number (such as 100) of instructions in advance
        message, the associated symbolic information may be              to check if a critical functionality is contained.
        lost. To address the problem, we fill the gap between                Due to the imprecision of static analysis, false negatives
        senders and receivers by synchronizing the symbol                may be introduced (Section I). The determination result may
        information in both sides (Section V-B3).                        be further influenced. To eliminate the concern, we also flag
                                                                         the following types of operations as interesting.
                          ƉƉϭ                      ƉƉϮ
            ŶĚƌŽŝĚ                                                         •    Field variables reading and writing: This affects points-
                          sD                       sD
                                                                                 to and alias relationship.
                                 ^ĞƌǀŝĐĞDĂŶĂŐĞƌ                            •    Virtual function invocation: Resolving this kind of
              >ŝŶƵǆ
                                                                                 invocations requires points-to information.
                                     ŝŶĚĞƌ
                                                                            •    Java Reflection: Due to the lack of real data, it is
                                                                                 challenging for static analysis to solve this kind of
       Figure 4: Intent In Inter-Apps Communications
                                                                                 problems.
   •    Array-indexing class implicit flows: In array-indexing              •    Return Instruction: In event handlers, the returned
        type operations, if the index is symbolic, it is challeng-               values of some event handlers (Section V-A) are
        ing to determine which element should be returned. The                   meaningful, such as shouldOverrideUrlLoading() and
        problem is known as "implicit flow". Similar problems                    shouldInterceptRequest(). Take the former event han-
        also exist in other data structures such as Hashmap,                     dler as the example: If the event handler returns true,
        Android Bundle, and Android share preference. In real                    it means the app being analyzed handles the input.
        world, this type of operations and data structures was                   Otherwise, the Android system processes the input.
        frequently used in popular apps and ad libs, such as
        Google Ads.                                                             2) Analysis Sandbox: To keep the analysis environment
        To further demonstrate the problem, we use Hashmap               clean, EOEDroid creates a sandbox environment to replace
        as the example. As Figure 5 shows, in Java, Hashmap is           the real environment. All interactions with the external real
        implemented based on a bucket array with linked lists            environment is redirected to the sandbox environment. Based
        that are used to handle hashing collisions. Assume               on the access direction, the interactions can be divided into
        that the instruction v = M.get(k) is being executed,             two categories: writing and reading. For the writing operation,
        where M is the Hashmap object, k is the key and it               EOEDroid updates variables’ values in the sandbox instead
        is symbolized as ‘key’. In the function Hashmap.get(),           of the real environment. For the reading operation, if the
        the bucket index is firstly determined, which is k’s             destination variable is written earlier, the corresponding value
        hashcode. Hence, the index is a symbolic expression              in the sandbox is retrieved and returned; otherwise, the value
        built on key. Then, an array-indexing operation is done          in the real environment is returned.
        to obtain the associated linked-list. Since the index is              In this paper, we consider the interactions include accessing
        symbolic, the operation introduces an implicit flow.             file system, global variables, and field variables whose scopes
        To mitigate the problem, we instrument k to brute-               are bigger than the event handler function being analyzed. To
        forcely try all possibilities of keys (Section V-B4).            implement them, necessary APIs and instructions are hooked
                                                                         and handled. For reading and writing files, the corresponding
                      Ϭ                                                  POSIX APIs (in libcore\io\Posix.java) are handled. However,
                      ϭ          ǀĂůƵĞϭ        ǀĂůƵĞϮ                    it is challenging to maintain a file’s status, especially when the
                                                                         file is partially modified. To mitigate the problem, a backup
                      ͙




                                                                         file is created, and then all reading and writing operations are
                      Ŷ          sĂůƵĞŵ                                 redirected to the backup file. For reading and writing global
                 ƵĐŬĞƚƐ             ŶƚƌŝĞƐ                             and field variables, the associated instructions (i.e., iget/iput,
                                                                         aget/aput, and sget/sput) [5] are handled. In practice, it is
        Figure 5: The Internal Structure Of HashMap                      challenging to determine the scope of a field variable. To
                                                                         simplify the problem, all changes on the field variable are
                                                                         recorded. Please note that in the beginning of each round of
    We implement selective symbolic execution by instrument-
                                                                         test, all data and files saved in the sandbox are cleaned.
ing the Android framework and Dalvik virtual machine (DVM).
In Android frameworks, event handler functions and sensitive                     3) Intent Handler: To fill the symbolic information gap
APIs (Section III-E) are handled. In DVM, the mapping between            between Intent message senders and receivers, it is critical to
variables and their corresponding symbolic expressions are               restore symbolic information of the message in the receiver side.
managed through a global symbolic table. To support string               For this purpose, when the Intent message is sent, EOEDroid
operations, which are frequently faced in event handlers, the            temporally pauses the program by hooking the associated APIs
associated string APIs are modeled, including compare, append,           (such as startActivity(Intent)), makes snapshot on the Intent
replace, search, substring and split, and we use Z3-Str [42] to          object and its corresponding symbolic data, and also saves it.
resolve string based path constraints.                                   Then, when the receiver accepts and reads the message using

                                                                     9
associated APIs (such as getIntent()), the snapshot is read, and                   1) Event Handler Input Generation: Given an arbitrary
then the symbolic information is linked with the Intent object.            interesting path, its input can be generated by handling its
Considering the sender and receiver may be not in the same                 associated path constraints that are collected in the first phase.
app, such a snapshot is dumped to a public folder, which is                First, input constraints are extracted from the whole path
allowed to be accessed by any app.                                         constraints by filtering out the constraints of non-symbolic
    As variables’ absolute memory addresses are used to save               conditional statements. Second, the input can be generated
their symbolic information in the snapshot, in the receiver side           by resolving the input constraints using an SMT solver (e.g.,
the restored symbolic information cannot be directly applied               Z3-Str).
in the received Intent message, whose memory addresses                            2) Event Handler Execution Order Generation: Given a
are totally different from the sent message. To correct the                path that contains a critical functionality, the execution order of
differences, when the snapshot is made in the sender side,                 event handlers can be obtained by addressing the event handler
memory addresses are changed to relative addresses, based                  dependency problem. The algorithm is shown in Algorithm 1.
on the starting address of the sent message. Then, when the                In the algorithm, three critical functions are required as input.
snapshot is read in the receiver side, memory addresses are
changed back to the absolute addresses, based on the starting                 •    NS(eh, p, insn): Non-symbolic conditional statements
address of the received message.                                                   can be extracted by going backward through p starting
                                                                                   from insn and checking the operands of all faced
    Furthermore, to distinguish different Intent messages, each                    conditional statements.
message is assigned a unique ID, which is also used as the
corresponding snapshot’s name. To support it, a new integer                   •    get_origin_variables(eh, p, insn, v): We define the
field “IntentId” is added into the Intent Java class. Each time                    origin variables as following. If in p, v 0 can influence
an Intent message is created, the field is automatically added                     v’s value, v 0 is an origin variable of v. Hence, to
by one.                                                                            locate all v 0 , we go backward through p starting from
                                                                                   insn, and apply backward data flow tracking on v.
        4) Array-Indexing Type Implicit Flow: To mitigate the                      If a variable is found in the backward data flow and
problem caused by this type of implicit flows, we brute-forcely                    located in the external environment, the variable may
convert the associated operation into multiple conditional state-                  be one of v’s origin variables.
ments. Array and other data structures are handled respectively
as follows.                                                                   •    get_origin_values(eh, p, O, insn, value): To compute
                                                                                   the expected values of origin variables, we re-run
   •    Array: Assume the content of an array A is                                 symbolic execution on p to construct v’s symbolic
        [e0 , e1 , e2 , ..., en ], and in the operation r = A[i], i                expression relying on origin variables. To this end, all
        is symbolic. The operation can be converted to the                         origin variables in the set O are symbolized. Then, p is
        following structure :                                                      executed and analyzed by feeding eh with appropriate
            if (0 == i) r = e 0 ;                                                  input. Next, when conditional statements are faced, the
            else if (1 == i) r = e 1 ;
            ...;                                                                   path constraint is constructed and saved. After that,
            else if (n == i) r = e n ;
                                                                                   when the instruction insn is faced, the analysis is
        Next, EOEDroid can handle the operation as regular                         finished. Finally, the values of origin variables can be
        conditional statements.                                                    generated by resolving the collected path constraints.
   •    Hashmap, Android Bundle, and Android Share Prefer-
        ence: Similar to array-indexing operations, hashmap                D. Exploit Code Generation
        type accessing can also be transformed to conditional                  Algorithm 2 shows our algorithm to generate the exploit
        statements. Assume that the following instruction is               code. Two main functions (get_web_trigger_code() and get_js(
        faced: r = hashmap.get(k). The keys of hashmap is                  )) are required. The former function is implemented based on
        [k0 , k1 , k2 , ..., kn ]. Hence, by instrumenting k’s real        our study result (Table I), and the latter function is provided
        value in memory, the operation can also be converted               by the sub-module “JavaScript code syntax analysis”.
        to regular conditional statements.
                                                                                  1) JavaScript Code Syntax Analysis: . It is challenging to
            if (k.equals( k 0 )) k = k 0 ;
            else if (k.equals( k 1 )) k = k 1 ;                            generate required JavaScript code as part of an event handler’s
            ... ;
            else if (k.equals( k n )) k = k n ;                            input. Because the JavaScript code is executed by associated
            r = hashmap.get(k);
                                                                           WebView APIs (such as loadUrl()), the values of these APIs’
        To support the above operations, all keys in the                   parameters provide hints. Suppose the JavaScript code extracted
        hashmap object must be retrieved. However, it is                   from input is I, and the JavaScript code that already exists
        challenging to do that in the low level layer (e.g.,               in associated WebView APIs (such as hard code format) is J.
        DVM). To fix the problem, the HashMap class is                     I + J have complete semantics.
        instrumented by adding a string array to record all                     To mitigate the problem, we assume that I is atomic, i.e.,
        keys. Thus, in the DVM, all keys can be retrieved by               it is a leaf element in the AST (Abstract Syntax Tree) of I + J.
        restoring the values of the added string array.                    We can hence generate I based on its position in the AST. More
                                                                           specifically, when a WebView API that can execute JavaScript
C. Program State Analysis                                                  code (such as WebView.loadUrl()) is executed, its parameter’s
    To discover how to reach the program state that leads to               symbolic expression is dumped. Then, by replacing I with
the execution of a critical functionality, we deal with the input          a specific concrete string (such as a randomized string), the
and execution order of event handlers respectively.                        concrete string of the parameter (i.e., I + J) is generated. Next,

                                                                      10
                                                                                           by applying a JavaScript interpreter engine (such as Mozilla
Algorithm 1 Event Order Generation                                                         Rhino 1.6) in I +J, AST is generated. After that, I’s semantics
Input:                                                                                     can be understood by checking AST’s semantics and locating I
 1: EH : all event handlers;                                                               in AST. Finally, concrete JavaScript code of I can be generated.
 2: P(eh) : return all paths in the event handler eh;
 3: N S(eh, p, insn) : return all non-symbolic conditional statements before
                                                                                                                              &ƵŶĐƚŝŽŶĂůů
    the instruction insn in the path p of the event handler eh;
 4: get_origin_variables(eh, p, insn, v) : return the variable v‘s origin variables
    that influence v’s value;
                                                                                                                  dĂƌŐĞƚ                     ƌŐƵŵĞŶƚƐ
 5: get_origin_values(eh, p, insn, v, value, O) : return the required values for                                dǇƉĞ͗EĂŵĞ              dǇƉĞ͗>ŝƐƚфEŽĚĞх
    all origin variables that can assign value to v.
Output: the event order R
 1: function GENERATE _ EVENT _ HANDLER _ ORDER(eh, p, expect_insn)                                               EĂŵĞ                         ^ƚƌŝŶŐ
 2:      for ns in NS(eh, p, expect_insn) do                                                                      sĂůƵĞ͗ǆ                   sĂůƵĞ͗ϭϮϯϰ

 3:          c ← ns’s condition expression
 4:          v ← c’s value . Depending on which branch is taken, v is true or                                  Figure 6: AST of I + J
    false.
 5:          r ← resolve_event_handler_dependency(eh, p, ns, c, v)                             We use the code in Figure 3 to illustrate how this sub-
 6:          if FAILURE == r then                                                          module works. In the event handler shouldOverrideUrlLoad-
 7:              return FAILURE                                                            ing(), I is passed to getId() and executed to receive sensitive
 8:          end if                                                                        information. To automatically generate concrete JavaScript code
 9:      end for
10:      return SUCCESS                                                                    of I, loadUrl()’s parameter is firstly dumped. Suppose the
11: end function                                                                           device ID is “1234”. The parameter’s symbolic expression
12:                                                                                        is then ‘‘javascript: + Uri.<init>(InputUrl).getHost().split("
13: function RESOLVE _ EVENT _ HANDLER _ DEPENDENCY(eh, p, insn, variable,                 .")[2] + ("1234")’’. By replacing the symbolic data with a
    value)
14:      O ← get_origin_variables(eh, p, insn, variable)
                                                                                           concrete string (such as “x”), a concrete example code of
15:      if O == φ then                                                                    I + J may be ‘‘javascript:x(1234)’’. Next, AST (Figure 6)
16:          R ← {} return FAILURE                                                         can be generated by applying Rhino in the JavaScript code
17:      end if                                                                            “x(1234)”. By locating x in AST, we can find that x is a function
18:      for o in O do                                                                     name, and the function has only one string parameter. Hence,
19:          if o ∈ eh’s parameters then
20:               R.add(<eh, p>)                                                           a JavaScript function (such as steal_device_id() in Listing
21:          end if                                                                        2) that satisfies the requirement can be defined in advance,
22:      end for                                                                           and then the function name is passed to the event handler
23:      for (oi , vi ) in get_origin_values(eh, p, insn, value, O) do            .        shouldOverrideUrlLoading().
    Rerun symbolic execution on the path p to compute each origin variable’s
    expected value
24:          for eh0 in E do                                                                                      VI.         E VALUATION
25:               for p0 in P(eh0 ) do
26:                   insn0 ← the instruction writing oi                                       To evaluate EOEDroid, we implemented it on Android 4.3,
27:                   r ← resolve_event_handler_dependency(eh0 , p0 , insn0 , oi ,         and deployed it in a Nexus 10 smartphone. Given apps, we
    vi )                                                                                   started the random UI exploration tool Android Monkey [9] to
28:                   if FAILURE == r then                                                 trigger as many WebView components as possible.
29:                        R ← {} return FAILURE
30:                   end if                                                                   Note that it is challenging to automatically trigger a UI
31:               end for                                                                  component. To mitigate the problem, We run Monkey to
32:          end for                                                                       simulate users’ behaviors. Furthermore, we also use Monkey
33:      end for
34:      return SUCCESS                                                                    as the first-layer filter. The intuition is that if WebView is an
35: end function                                                                           important part of the app, it will be likely triggered in this way.
                                                                                           Thus we reduce our workload by only considering the apps
                                                                                           whose WebView components are successfully triggered in our
                                                                                           dataset (Section VI-A).
Algorithm 2 Exploit Code Generation                                                            Once a WebView complement is triggered, complete fuzzing
Input:                                                                                     code is injected to trigger all event handlers. More specifically,
 1: EO : the event handler execution order, which is the set of the pair <eh,              when WebView is going to connect to a web server, we start
    p>;
 2: get_input(eh, p) : return eh’s input that can guide the app to execute p;              a crawler to check whether an HTTP link is involved in the
 3: get_web_trigger_code(eh, parameter): return web code that can trigger eh               connection. We limit the crawling depth in three levels. If
    and pass parameter to eh                                                               there is an HTTP link, man-in-the-middle attacks is performed
 4: get_js(eh, p) : return required JavaScript code                                        (Section III-B). The proxy tool “mitmproxy” [6] is used to inject
 5:
Output: the exploit code X
                                                                                           web event trigger (fuzzing) code, which is generated based
 1: function GENERATE _ EXPLOIT _ CODE(eh, p)                                              on the study result (Section V-A). Hence, once the injected
 2:     for <ehi , pi > in EO do                                                           code is loaded and executed in WebView, all event handlers
 3:         X += gen_js(ehi , pi )                                                         are triggered, and then, EOEDroid is started to analyze them.
 4:         input ← get_input(ehi , (pi )
 5:         X += gen_event_trigger_code(ehi , input)
 6:     end for                                                                            A. Dataset
 7: end function                                                                              In our evaluation, we collected apps as our evaluation dataset
                                                                                           from two different app groups based on whether the WebView

                                                                                      11
                                                                                              Vulnerability Type       Number
component could be triggered at run time. Both these two
groups were collected from the Android official store Google                           Cross-Frame DOM Manipulation    2
                                                                                       Phishing                        53
Play. The first app group consists of 13,000 popular apps that                         Sensitive Information Leakage   30
we crawled from 26 categories, and extracted 500 most popular                          Local Resource Access           1
free apps for each category. The other app group contains 220                          Intent Abuse                    11
browser apps, which were collected by searching the key word
‘web browser’ in Google Play.                                                     Table II: Vulnerabilities Found By EOEDroid
    Finally, 3,652 apps were totally collected as our dataset,
with 3,552 apps from the first app group and 212 apps from                Distribution of vulnerable Event Handlers. We found that
the second app group.                                                     most vulnerabilities (96/97) existed in the event handler shoul-
                                                                          dOverrideUrlLoading(). The remaining two vulnerabilities were
                                                                          found in onCreateWindow() and onReceivedHttpAuthRequest().
B. Findings
                                                                          Phishing. We found the usage of the API loadUrl() to
    Our experiment casts light on the usage of event handlers             load new content in WebView likely introduced this type of
in real-world hybrid apps. It also reveals interesting facts about        vulnerabilities. It is mainly because developers wrongly assume
EOE in hybrid apps.                                                       the code loaded in WebView is trustable, and do not set up
         1) Usage Of Event Handlers: Figure 7 shows the                   security checks before the sensitive API is called. In some apps,
distribution of the usage of top 20 event handlers. shoul-                even though security checks were provided, these checks were
dOverrideUrlLoading() and onPageFinished() are the two most               incompetent to protect the critical functionalities and could be
frequently used event handlers.                                           evaded. Take the following code as the example. Adversaries
                                                                          could still hit the sensitive API by feeding the input ‘http://att
                                                                          acker.com/malicious/code?from=developer.com’.
                                                                              public boolean shouldOverrideUrlLoading(WebView view,
                                                                                   String url) {
                                                                                  ...
                                                                                  else if (url.contains("developer.com")) {
                                                                                      view.loadUrl(url);
                                                                                      return true;


                                                                          Cross-Frame DOM Manipulation. As shown in Table II,
                                                                          different from phishing, there were only a few cross-frame
                                                                          DOM manipulation vulnerabilities, even though loadU rl()’s
                                                                          parameter was totally controlled by adversaries. This is because
              Figure 7: Usage Of Event Handlers                           that it is challenging to transfer the prefix string “javascript:”
   We also found most hybrid apps define their own event                  from the web code to the native code. Typically, in the web
handlers. In our dataset (Section VI-A), 3,440 of 3,652 (94.2%)           context, the prefix string “javascript:” is directly handled
hybrid apps implemented their event handlers. It is clear that            by JavaScript engine, rather than triggering any web events.
event handlers are in widespread use in real-world apps. Next             However, using tricks it is still possible to deliver the prefix
we discuss the typical scenarios in which event handlers are              string. EOEDroid successfully discovered two vulnerable event
used in apps.                                                             handlers that could be leveraged to pass JavaScript code to the
                                                                          native context and execute the code. More details are discussed
Access Control. Event handlers can be applied to perform                  in our case studies in Section VI-C1.
access control on the communication to be accessed, and the
content to be loaded in WebView. For instance, shouldInter-               Sensitive Information Leakage. In this category, EOEDroid
ceptRequest() can check the content requested by web code.                successfully caught 26 vulnerable event handlers that could be
If the content is not expected, the event handler can directly            utilized to steal Android ID. The further study showed that all of
return null to reject the access.                                         them were caused by an ad lib. The remaining 4 vulnerabilities
                                                                          were found in high profile browser apps. The first vulnerable
Customized URL Scheme. Event handlers can be used to                      event handler (from “com.webroot.xxx”) could be leveraged
support customized URLs. For instance, the link “tel:xx” and              to leak the phone number to a public log file, which could
“smsto:xx” can be supported to make a phone call and send a               be accessed by any app. The second vulnerable event handler
text message.                                                             (from “com.kiddoware.xxx”) could be triggered to leak IMEI.
Event Driven Authentication. Using customized URL                         The third event handler (from “reactivephone.xxx”) could be
schemes, event handlers can also be applied to perform                    exploited to steal GPS location information using the input in
authentication. Consider that shouldOverrideUrlLoading() sup-             a specific format. More specifically, if the URL to be accessed
ports a customized URL scheme “sdk”. When the URL                         contained the string “latitude,longitude”, the real GPS location
“sdk://auth_request” is received, the event handler redirects             data were retrieved to replace the string.
WebView to the authentication web site, while specifying the                  The last vulnerable event handler (from “com.mx.xxx”)
redirection URL as “sdk://auth_success”. Hence, when the URL              was interesting, which contained a potential backdoor that
“sdk://auth_success” is received by the event handler, the event          could be used to steal sensitive information, such as IMEI.
handler can learn the authentication is successfully done.                Although developers had attempted to close the backdoor,
       2) EOE In Event Handlers: By applying EOEDroid                     EOEDroid found that it was still possible for adversaries to
on the 3,652 hybrid apps, we successfully identified 97                   leverage the backdoor by changing the program state through
vulnerabilities in 58 hybrid apps, as briefly shown in Table II.          the manipulation of execution orders of gadgets. More details

                                                                     12
are shown in our case study in Section VI-C2.                              28            intent.setData(Uri.parse(tmpstr));
                                                                           29            startActivity(intent)
Local Resource Access. One vulnerable app was found that it                30      ...

could allow adversaries to access local database. Even though                   Listing 3: Code snippet extracted from the example in case
this app checked the origin information of web code that was
going to access the database, it could still be bypassed by                    By applying EOEDroid on this app, the vulnerable event
containing the developer website name.                                     handler’s path constraints are collected, which are shown as
Intent Abuse. One of the vulnerabilities was found in the                  follows.
event handler of the Korean Air app, which was allowed to                        (1) InputUrl.startsWith("http://") == 0
                                                                                 (2) InputUrl.startsWith("https://") == 0
send arbitrary intent message. Furthermore, the event handler                    (3) InputUrl.startsWith("file://") == 0
                                                                                 (4) InputUrl.startsWith("content://") == 0
also suffered from phishing attacks and cross-frame DOM                          (5) InputUrl.startsWith("mx") == 0
                                                                                 (6) InputUrl.contains("app_name") == 1
manipulation.                                                                    (7) flag == 1
                                                                                 (8) InputUrl.contains("%IMEI%") == 1
    Other ten vulnerabilities were found in browser apps. It
was mainly because browser apps aimed to support the popular                  All constraints can be satisfied except (7). By addressing
scheme “intent://”. However, these apps did not check the origin           the event handler dependency problem on (7), the event
information, and specify the action or destination class, which            handler execution order is generated : onP ageF inished() →
might cause serious problems, as demonstrated by Wang et al.               shouldOverrideU rlLoading().
[36].
                                                                              However, due to the trigger constraint (Section V-A), we
C. Case Studies                                                            found onPageFinished() was executed after shouldOverrideUrl-
                                                                           Loading(). Hence, to generate the required execution order, the
                  App               Input Format                           web page should be refreshed as follows.
             com.exsoul.xxx   “exsoul://id=[0-9]{8}&url=”                        (1) <script> window.location.reload(true); </script>
             com.fevdev.xxx   “intent://...fallback_url=”

 Table III: The Input Format Of The Two Vulnerable Apps                    Then, the web code that can guide shouldOverrideUrlLoading()
                      Shown In Case 1                                      to execute the sensitive API getDeviceId() is shown as follows,
                                                                           if assuming FTP is supported by users’ phone.
       1) Case 1: Cross-Frame DOM Manipulation: This section
                                                                                 (2) <iframe src="ftp://attacker.com/app_name?imei=%imei%"/>
presents two vulnerable apps that suffer from cross-frame
manipulation attacks. To transfer the prefix string “javascript:”,
the input is crafted following the input format shown in Table             D. Performance and Accuracy
III. When the input is received and parsed by the event
handler shouldOverrideUrlLoading(), the content l of “url”                     The performance and accuracy of EOEDroid may be
and “fallback_url”is extracted and then fed into a sensitive               impacted by our symbolic execution implementation, where
API loadUrl(). Hence, if l is in the format “javascript:...”, the          several heuristics are leveraged to mitigate the path explosion
JavaScript code can be then executed in the main frame.                    problem. Admitting that these heuristics may cause over
                                                                           approximation and/or inaccuracy to our analysis, they help us
          2) Case 2 : Leveraging A Closed Backdoor: This                   make a good tradeoff between performance and accuracy. In this
high profile app has been downloaded more than 10 million                  section, we presented more evaluation details, and showed that
times. The Listing 3 shows a code snippet of the vulnerable                our current system performance and accuracy were acceptable.
event handler. In this app, the variable flag (Line 1) is initially
false. When the event handler shouldOverrideUrlLoading() is                    For each app, the average successful analysis time of
triggered, several conditional statements are determined relying           EOEDroid is around 4.2 minutes, including 3.4 minutes for
on the flag (Line 12) and the URL. In Line 24, the URL is                  the event handler analysis. Considering our tool is designed to
saved to a local variable, and then “%IMEI%” is replaced with              analyze apps offline, the overhead is acceptable.
real IMEI.                                                                     We use false positives (FP) and false negatives (FN) to
 1 flag = false;                                                           measure EOEDroid’s accuracy. We define a FP as that a non-
 2
 3 public void onPageFinished(WebView view, String url) {                  vulnerable event handler is flagged as vulnerable, and a FN as
 4   ...
 5   flag = true;                                                          that a vulnerable event handler is identified as non-vulnerable.
 6   ...
 7 }
 8
 9 public boolean shouldOverrideUrlLoading(WebView view,
                                                                           False Positives. We manually analyzed all vulnerable event
         String url) {                                                     handlers by running the exploit code generated by EOEDroid.
 10   ...
 11
 12
      url = url.toLowerCase();
      if (!flag)
                                                                           Finally, we found that all vulnerabilities were successfully
 13
 14
          ...
      else {
                                                                           triggered, which indicated EOEDroid’s FP rate was low.
 15     if (url.startsWith("http://") || url.startsWith("https
               ://")) ...                                                  False Negatives. To confirm false negatives, we randomly
 16     else if (url.startsWith("file://")||url.startsWith("
               content://")) ...                                           selected 200 apps from the hybrid apps that were flagged as non-
 17     else if (url.startsWith("mx")) ...                                 vulnerable by EOEDroid. By carefully manually checking their
 18     else {
 19        if (url.contains("app_name")) {                                 event handlers, we found all apps were non-vulnerable except
 20           ...
 21           String tmpstr = url;                                         two apps. Our further study on these two apps showed that the
 22           // read imei from shared preference
 23           String i = PreferenceManager.
                   getDefaultSharedPreferences(this).getString("
                                                                           main reason was that the SMT solver failed to resolve some
                   imei", "");                                             path constraints that contained multiple regular expressions and
 24           tmpstr = tmpstr.replaceAll("%IMEI%", i)
 25
 26
              ...
              // send a Intent message containing tmpstr
                                                                           string split operations. This still represents a low FN rate for
 27           Intent intent = new ...;                                     EOEDroid.

                                                                      13
        VII.   EOE C OUNTERMEASURE D ISCUSSION                                Yang et al. [41] and Hassanshahi et al. [22] studied app-
    The key to counter EOE is that apps should only allow                 web bridge based attacks, and proposed detection solutions
trustable web code to access critical functionalities in event            to vet hybrid apps. However, they either did not support the
handlers. To achieve this, apps should first fully use HTTPS              event handler feature, or focus on the attacks launched from a
in all communications, which will effectively reduce the attack           special URL navigation event (i.e., “intent://...”). In contrast,
surface. Second, when a critical functionality is called through          EOEDroid is generic.
an event handler, the frame level and origin information of web           Defense On WebView. Several defense approaches, such as
code should be carefully checked.                                         NoFrak [19], MobileIFC [33], and Draco [35], are proposed
    The newest version of Android provides a new setting                  to extend SOP to local resources, or provide access control
that only allows web code downloaded over HTTPS to                        on event handlers in the native layer. However, there are
access shouldOverrideUrlLoading(), and also includes more                 difficulties in applying existing approaches to prevent the EOE
information in the event handler’s parameters, such as the frame          attacks. First, Draco requires the root permission to replace
level and origin information of web code. Hence, we strongly              WebView’s internal native library, and MobileIFC and NoFrak
recommend developers port their apps to the new version, and              also require the recompilation of hybrid apps with their own
leverage these security information in their development.                 customized hybrid frameworks. Second, they are implemented
                                                                          by instrumenting WebView or third-party hybrid frameworks.
                   VIII.    R ELATED W ORK                                Hence, they may have to keep doing extra more work in porting
                                                                          their systems into newest versions. Third, the defense level
Attacks on WebView. Recently, security issues caused by event             totally depends on how well the security policies are written
handlers have received significant attention from researchers.            by developers. Finally, they performed access control based on
Luo et al. [26] discussed that event handlers may be used by              the web frame’s origin information. Hence, it is challenging
malware to hijack and sniff web events. However, compared                 for them to limit the access from embedded inline JavaScript
with EOE, this type of attacks is more difficult to launch,               code.
because adversaries have to control the native code in user
devices, such as registering their own native event handlers in              Other defense approaches, such as WIREframe [17] and
WebView. Chen et al. [13] and Mutchler et al. [27] discovered             HybridGuard [29], provided policy enforcement in WebView to
the event handler feature may cause sensitive data leakage (such          protect app-web bridges. However, both of them only focused
as the authentication URL) in Oauth. Georgiev et al. [19] and             on JavaScript code and yet ignored HTML code. Hence, they
Tuncay et al. [35] discussed the possibilities that adversaries           can still be evaded by EOE, since EOE can be launched purely
may leverage the event handler feature to access native code.             in HTML code.
In contrast, we systematically study all types of feasible web            Symbolic Execution. In past years, symbolic execution has
event oriented attacks, including the attacks that are carried out        made big progress. Several static approaches (such as Intel-
by leveraging both one single web event and stitching multiple            lidroid [39] and TriggerScope [18]) were proposed to vet
web events together to influence the program state.                       Android apps using symbolic execution. However, these static
    Compared with existing attacks on WebView, EOE is more                approaches may have both higher false positives and negatives
feasible and practical. Chin et al. [14] analyzed WebView                 in the context faced in this paper. First, static analysis has to
vulnerabilities that result in excess authorization and file-based        address points-to and alias problems. Second, due to the lack of
cross-zone scripting attacks. Wu et al. [40] discussed file               real data, it is challenging to resolve Java Reflection and Intent.
leakage problems caused by file:// and content:// schemes in              Finally, it is difficult to address the array indexing type implicit
webview. However, these two kinds of attacks are limited in               flows. In real world, this type of implicit flows is frequently
the Android new versions, which provide better protections on             used in popular apps and ad libs, such as Google Ads.
directly accessing local files.                                               Many dynamic approaches were also implemented based
    Bhavani et al. [10] also studied the possibility of cross-site        on symbolic execution. For example, DART [20] and CUTE
scripting attacks in WebView. Neugschwandtner et al. [28]                 [31] applied concolic execution to automatically test software.
described data leakage scenarios and presented several real-              EXE [12] and KLEE [11] used symbolic execution to find bugs.
world case studies of JavaScript injection attacks through                IntScope [37] employed symbolic execution to detect integer
WebView. Jin et al. [24] systematically investigated the                  overflow problems. SAGE [21] was designed for Windows to
JavaScript code injection consequences on hybrid apps and                 apply symbolic execution to vet the operating system. S2E
showed the pervasiveness of data leakage due to classic web               [15] proposed the selective symbolic execution to improve the
attack vectors that are possible through WebView. Wei et al.              performance. Driller [34] used selective symbolic execution to
[38] introduced attack scenarios where attackers could exploit            guide fuzzing, and the result showed the combination was very
existing vulnerabilities (such as CVE-2012-6636 [2] and CVE-              effective. Existing dynamic approaches may have low false
2013-4710 [3]) to invoke arbitrary Java functions in WebView.             positives. However, it is challenging for them to generate the
Rastogi et al. [30] demonstrated the hidden attacks based on              event sequences required for triggering a found vulnerability.
app-web bridges. However, all above attacks require JavaScript               Several symbolic execution based approaches were also
and JavaScript-Bridge to be enabled, whereas EOE does not                 designed to handle implicit flows. For instance, DTA++ [25]
have such requirement.                                                    used symbolic execution to solve control flow problem (i.e.,
    Wang et al. [36] systematically studied the Intent abuse              implicit flows), while Spandex [16] implemented symbolic
problem and demonstrated the serious consequences. However,               execution in Android to vet apps about password usage.
this attack requires the pre-installation of a WebView-enabled            However, these two systems fall short of handling Android
malware in user devices, which is not required in EOE.                    specifications (such as Android Intent) and array indexing type


                                                                     14
implicit flows.                                                                        [17] D. Davidson, Y. Chen, F. George, L. Lu, and S. Jha. Secure integration
                                                                                            of web content and applications on commodity mobile operating systems.
                                                                                            ASIA CCS’17, New York, NY, USA.
      IX.     S YSTEM L IMITATIONS AND F UTURE W ORK                                   [18] Y. Fratantonio, A. Bianchi, W. Robertson, E. Kirda, C. Kruegel, and
    EOEDroid is not perfect. First, currently we simply use Mon-                            G. Vigna. TriggerScope: Towards Detecting Logic Bombs in Android
key to trigger WebView. Exploring all possible UI components                                Apps. In IEEE S&P’16, San Jose, CA.
is a difficult issue, though orthogonal to this research. Second,                      [19] M. Georgiev, S. Jana, and V. Shmatikov. Breaking and fixing origin-
                                                                                            based access control in hybrid web/mobile application frameworks. In
in EOEDroid, we do not solve all implicit flow problems,                                    NDSS’14, San Diego, USA.
instead only focus on array-indexing type operations, which are                        [20] P. Godefroid, N. Klarlund, and K. Sen. Dart: Directed automated random
frequently used in event handlers. Finally, we do not handle all                            testing. In PLDI’05.
native code in Android, instead only model important native                            [21] P. Godefroid, M. Y. Levin, and D. Molnar. Sage: Whitebox fuzzing for
code such as system.arraycopy(). In future work, we plan to                                 security testing. Queue, 10(1):20:20–20:27, Jan. 2012.
explore solutions in these directions to improve EOEDroid.                             [22] B. Hassanshahi, Y. Jia, R. H. C. Yap, P. Saxena, and Z. Liang. Web-to-
                                                                                            application injection attacks on android: Characterization and detection.
                                                                                            In ESORICS, volume 9327, pages 577–598. Springer, 2015.
                           X.    C ONCLUSION
                                                                                       [23] InfoSecurity.       Public wifi hotspots ripe for mitm attacks.
   In this paper, we thoroughly studied all web events, native                              https://www.infosecurity-magazine.com/news/public-wifi-hotspots-
event handlers and their triggering constraints. Based on                                   ripe-for-mitm-attacks/.
our findings, we present EOEDroid, a novel system that                                 [24] X. Jin, X. Hu, K. Ying, W. Du, H. Yin, and G. N. Peri. Code injection
                                                                                            attacks on html5-based mobile apps: Characterization, detection and
can automatically detect and verify EOE vulnerabilities by                                  mitigation. In CCS’14.
generating exploit code. We evaluated EOEDroid using a large
                                                                                       [25] M. G. Kang, S. McCamant, P. Poosankam, and D. Song. DTA++:
number of apps and found several critical vulnerabilities.                                  dynamic taint analysis with targeted control-flow propagation. In
                                                                                            NDSS’11. San Diego, California, USA.
                           ACKNOWLEDGMENT                                              [26] T. Luo, H. Hao, W. Du, Y. Wang, and H. Yin. Attacks on webview in
                                                                                            the android system. In ACSAC’11.
   We thank all anonymous reviewers and our shepherd, Adam                             [27] P. Mutchler, A. DoupÃ, J. Mitchell, C. Kruegel, G. Vigna, A. Doup,
Doupé, for their insightful comments and suggestions. This                                  J. Mitchell, C. Kruegel, and G. Vigna. A Large-Scale Study of Mobile
material is based upon work supported in part by the the                                    Web App Security. MoST’15.
National Science Foundation (NSF) under Grant no. 1314823                              [28] M. Neugschwandtner, M. Lindorfer, and C. Platzer. A view to a kill:
and 1700544. Any opinions, findings, and conclusions or                                     Webview exploitation. In LEET’13.
recommendations expressed in this material are those of the                            [29] P. H. Phung, A. Mohanty, R. Rachapalli, and M. Sridhar. Hybridguard:
authors and do not necessarily reflect the views of NSF.                                    A principal-based permission and fine-grained policy enforcement
                                                                                            framework for web-based mobile applications. MoST’17.
                                                                                       [30] V. Rastogi, R. Shao, Y. Chen, X. Pan, S. Zou, and R. Riley. Are
                                R EFERENCES                                                 these Ads Safe: Detecting Hidden Attacks through the Mobile App-Web
 [1] Calling fork() from jni code. https://groups.google.com/forum/#\protect\               Interfaces. NDSS’16.
     kern-.1667em\relaxtopic/android-platform/80jr-_A-9bU.                             [31] K. Sen, D. Marinov, and G. Agha. Cute: A concolic unit testing engine
 [2] Cve-2012-6636. https://cxsecurity.com/cveshow/CVE-2012-6636.                           for c. In ACM SIGSOFT’05, Lisbon, Portugal.
 [3] Cve-2013-4710. https://cxsecurity.com/cveshow/CVE-2013-4710.                      [32] H. Shacham. The geometry of innocent flesh on the bone: Return-into-
                                                                                            libc without function calls (on the x86). In CCS’07.
 [4] Dalvik. https://en.wikipedia.org/wiki/Dalvik_(software).
                                                                                       [33] K. Singh. Practical context-aware permission control for hybrid mobile
 [5] Dalvik opcode. https://source.android.com/devices/tech/dalvik/dalvik-                  applications. In RAID’13.
     bytecode.html.
                                                                                       [34] N. Stephens, J. Grosen, C. Salls, A. Dutcher, R. Wang, J. Corbetta,
 [6] An interactive tls-capable intercepting http proxy for penetration testers             Y. Shoshitaishvili, C. Kruegel, and G. Vigna. Driller: Augmenting
     and software developers. https://github.com/mitmproxy/mitmproxy.                       fuzzing through selective symbolic execution. In NDSS’16.
 [7] Mcafee mobile threat report. https://www.mcafee.com/us/resources/                 [35] G. S. Tuncay, S. Demetriou, and C. A. Gunter. Draco: A system for
     reports/rp-mobile-threat-report-2016.pdf.                                              uniform and fine-grained access control for web code on android. In
 [8] Same origin policy. https://en.wikipedia.org/wiki/Same-origin_policy.                  CCS’16.
 [9] Ui/application exerciser monkey. https://developer.android.com/studio/            [36] R. Wang, L. Xing, X. Wang, and S. Chen. Unauthorized origin crossing
     test/monkey.html.                                                                      on mobile platforms: Threats and mitigation. In CCS’13.
[10] A. B. Bhavani. Cross-site Scripting Attacks on Android WebView. IJCSN             [37] T. Wang, T. Wei, Z. Lin, and W. Zou. Intscope: Automatically detecting
     International Journal of Computer Science and Network, 2(2):1–5, 2013.                 integer overflow vulnerability in x86 binary using symbolic execution.
                                                                                            In NDSS’09, San Diego, CA.
[11] C. Cadar, D. Dunbar, and D. Engler. Klee: Unassisted and automatic
     generation of high-coverage tests for complex systems programs. In                [38] T. Wei, Y. Zhang, H. Xue, M. Zheng, C. Ren, and D. Song. Sidewinder
     OSDI’08.                                                                               targeted attack against android in the golden age of ad libraries. In
                                                                                            Black Hat’14.
[12] C. Cadar, V. Ganesh, P. M. Pawlowski, D. L. Dill, and D. R. Engler.
     Exe: Automatically generating inputs of death. In CCS’06.                         [39] M. Y. Wong and D. Lie. Intellidroid: A targeted input generator for the
                                                                                            dynamic analysis of android malware. In NDSS’16.
[13] E. Y. Chen, Y. Pei, S. Chen, Y. Tian, R. Kotcher, and P. Tague. Oauth
     demystified for mobile application developers. CCS’14, 2014.                      [40] D. Wu and R. K. C. Chang. Indirect File Leaks in Mobile Applications.
                                                                                            In MoST’15.
[14] E. Chin and D. Wagner. Bifocals: Analyzing webview vulnerabilities in
     android applications. In WISA’13. Jeju Island, Korea.                             [41] G. Yang, A. Mendoza, J. Zhang, and G. Gu. Precisely and scalably
                                                                                            vetting javascript bridge in android hybrid apps. In RAID’17.
[15] V. Chipounov, V. Kuznetsov, and G. Candea. S2e: A platform for in-vivo
     multi-path analysis of software systems. In ASPLOS’11.                            [42] Y. Zheng, X. Zhang, and V. Ganesh. Z3-str: a z3-based string solver
                                                                                            for web application analysis. In ESEC/SIGSOFT FSE’13.
[16] L. P. Cox, P. Gilbert, G. Lawler, V. Pistol, A. Razeen, B. Wu, and
     S. Cheemalapati. Spandex: Secure password tracking for android. In
     USENIX Security’14.


                                                                                  15
