Code Injection Attacks on HTML5-Based Mobile Apps
Total Page:16
File Type:pdf, Size:1020Kb
Code Injection Attacks on HTML5-based Mobile Apps Xing Jin, Tongbo Luo, Derek G. Tsui, Wenliang Du Dept. of Electrical Engineering & Computer Science, Syracuse University, Syracuse, NY Abstract—HTML5-based mobile apps become more and more using different languages. If other OSes catch up to Android popular, mostly because they are much easier to be ported across and iOS, developers’ lives will become harder and harder. different mobile platforms than native apps. HTML5-based apps HTML5-based mobile apps provide a solution to the above are implemented using the standard web technologies, including HTML5, JavaScript and CSS; they depend on some middlewares, problem. Unlike native apps, this type of apps are developed such as PhoneGap, to interact with the underlying OS. using the HTML5 technology, which is platform agnostic, be- Knowing that JavaScript is subject to code injection attacks, cause all mobile OSes need to support this technology in order we have conducted a systematic study on HTML5-based mobile to access the Web. HTML5-based apps use HTML5 and CSS apps, trying to evaluate whether it is safe to rely on the web to build the graphical user interface, while using JavaScript for technologies for mobile app development. Our discoveries are quite surprising. We found out that if HTML5-based mobile the programming logic. Because HTML5, CSS, and JavaScript apps become popular–it seems to go that direction based on the are standard across different platforms, porting HTML5-based current projection–many of the things that we normally do today apps from one platform to another becomes easy and transpar- may become dangerous, including reading from 2D barcodes, ent. Due to this portability advantage, HTML5-based mobile scanning Wi-Fi access points, playing MP4 videos, pairing with apps are rapidly gaining popularity. A survey of 1200 app Bluetooth devices, etc. This paper describes how HTML5-based apps can become vulnerable, how attackers can exploit their developers carried out by Evans Data shows that 75% of them vulnerabilities through a variety of channels, and what damage are using the HTML5 technology [1]. A recent Gartner report can be achieved by the attackers. In addition to demonstrating claims that HTML5-based web apps will split the market with the attacks through example apps, we have studied 186 PhoneGap native apps by 2016 [2]. plugins, used by apps to achieve a variety of functionalities, and Unfortunately, the decision to use HTML5, JavaScript and we found that 11 are vulnerable. We also found two real HTML5- based apps that are vulnerable to the attacks. CSS to write mobile apps introduces new risks that do not exist for native languages. The Web is still battling with the I. INTRODUCTION Cross-Site Scripting (XSS) attack, which is caused by the fact Finding free Wi-Fi access points, scanning 2D barcodes, that data and code can be mixed together in a string, and the sending SMS messages and listening to music are very com- technology can pick out the code from the string and run the mon practices that a typical mobile device user may do in code. In mobile devices, data can come from untrusted external his/her daily life. It seems that nothing needs to be worried entities; if they contain code and if the app is not aware of the about for these practices. That is true, but only for now. risk, the code from outside may be executed inside the app, An emerging technology trend that has been rapidly gaining leading to security breaches. This paper conducts a systematic popularity in the mobile industry is going to change the study on such an attack. Our study has led to the following picture. When this technology becomes widely adopted, the discoveries and contributions: practice mentioned above can become risky. MP3 files, Wi- • We have identified that HTML5-based mobile apps can Fi access points, SMS messages, and 2D barcodes can all be attacked using a technique that is similar to the Cross- become vehicles for attackers to inject malicious code into Site Scripting attack. These attacks are real, and we have the smartphone, leading to damages. The attack does not stop found real-world apps that can be successfully attacked at one victim phone; it can be spread to other phones like a using the technique. HTML5-based apps from all major worm. The more popular the technology becomes, the more platforms can be affected, including Android, iOS, and quickly such a worm can spread out. Blackberry. This disrupting technology is the HTML5 technology, which • We present a systematic study to identify potential chan- is the base for the HTML5-based mobile apps. Before this nels that can be used to launch the attack. We have proof- technology is adopted by the app development for mobile of-concept attacks using most of the channels. systems, mobile apps are typically written in the native lan- • We have identified challenges faced by attackers, and guage that is supported by their OSes. For instance, native have shown how they can be overcome. Android apps are written in Java, and native iOS apps are written in Objective-C. Porting apps from one platform to II. BACKGROUND another is difficult. Due to the popularity of Android and iOS, HTML5-based mobile apps cannot directly run on most developers usually do not have many choices, but to learn mobile systems, such as Android and iOS, because these two different systems and develop two versions for their apps systems do not support HTML5 and JavaScript natively; a web 1 container is needed for rendering HTML5-based user interface and executing JavaScript code. Most mobile systems have such a container: it is called WebView in Android, UIWebView in iOS, and WebBrowser in Windows Phone. For simplicity, we only use the term WebView throughout the paper. WebView. WebView was originally designed to allow native apps to process and display web contents. It basically packages the web-browsing functionalities into a class, which can be embedded into an app, essentially making web browser a component of the app. With the APIs provided by WebView, Fig. 1: The PhoneGap Architecture mobile apps can also customize the HTML pages inside. Since WebView is intended for hosting web contents, which are usually untrusted, WebView, like browsers, implements a and the number will definitely increase. sandbox, so JavaScript code inside can only run in an isolated A plugin is mainly written in the language natively sup- environment. Such a sandbox is appropriate for web contents, ported by its hosting mobile system, but to make it more but it is too restrictive for mobile apps: an app running in convenient for JavaScript to invoke plugins, many plugins an isolated environment cannot legitimately access the system provide companion JavaScript libraries; some even provide resources, such as files, device sensors, cameras, etc. sample JavaScript code that teaches developers how to use WebView allows applications to add a bridge between the the plugins. When JavaScript code inside WebView needs JavaScript code inside and the native code (e.g., Java) outside. to access system or external resources, it calls the APIs This bridge makes it possible for JavaScript code to invoke provided in the plugin library. The library code will then call the outside native code, which is not restricted by WebView’s the PhoneGap APIs, and eventually, through the PhoneGap sandbox and can access system resources as long as the framework, invoke the Java code in the corresponding plugin. app has the required permissions. Developers can write their When the plugin finishes its job, it returns the data back to own native code to work with the code inside WebView, but the page, also through the PhoneGap framework. That is how that lowers the portability of the app. The most common JavaScript code inside the WebView gets system or external practice is to use a third-party middleware for the native- resources. Figure 1 depicts the entire process. code part, leaving the portability issue to the developers of III. THE CODE INJECTION ATTACK the middleware. Well-established middlewares do support a variety of mobile platforms. It is well known that the Web technology has a dangerous Several middleware frameworks have been developed, in- feature: it allows data and code to be mixed together, i.e., cluding PhoneGap [3], RhoMobile [4], Appcelerator [5], etc. when a string containing both data and code is processed In this paper, we focus on the most popular one—PhoneGap. by the web technology, the code can be identified and sent However, our attacks can be applied to other middlewares. to the JavaScript engine for execution. This feature is made We study the attack on the Android platform, but since apps by design, so JavaScript code can be embedded freely inside are portable across platforms, so are their vulnerabilities. HTML pages. Unfortunately, the consequence of this feature Therefore, our attacks also work on other platforms. is that if developers just want to process data but use the wrong APIs, the code in the mixture can be automatically PhoneGap and PhoneGap Plugin. PhoneGap helps devel- and mistakenly triggered. If such a data-and-code mixture opers create HTML5-based mobile apps using the standard comes from an untrustworthy place, malicious code can be web technologies. Developers write apps in HTML pages, injected and executed inside the app. This is the JavaScript JavaScript code, and CSS files. The PhoneGap framework by code injection attack. A special type of this attack is called default embeds a WebView instance in the app, and relies Cross-Site Scripting (XSS), which, according to the OWASP on this WebView to render the HTML pages and execute top-ten list [6], is currently the third most common security JavaScript code.