The Java Mobile Risk
The Java Mobile Risk
DOI 10.1007/s11416-006-0014-0
O R I G I NA L PA P E R
Received: 3 January 2006 / Accepted: 5 May 2006 / Published online: 8 June 2006
© Springer-Verlag France 2006
Abstract Mobile security is a relatively new field of ogy of the experimental study will be explained. Then,
research. The specific risks and counter-measures have Sect. 5 underlines some problems that are seldom men-
not been studied thoroughly yet. Java can be useful in tioned for the user. Finally, Sect. 6 underlines a few
this field because it has been designed to run untrust- problems that analysts have to consider in order to
ed code safely on mobile, heterogeneous networks. This disassemble a midlet correctly.
paper, based on an experimental study of the low-level
security of Java 2 Micro Edition (JSR 118 Expert Group,
2006), identifies some potential problems and their solu- 2 Quick Introduction to J2ME
tions in case Java malicious applications appear in the
wild. This section briefly explains what is J2ME compared to
J2SE and J2EE and how it is organised.
Java technology is particularly interesting in mobile envi- Java was supposed to be a kind of universal language,
ronments because of its built-in security features and able to run on smart cards as well as on mainframes.
portability. These features include downloading over the As obviously you do not expect the same features from
air and running untrusted code in a safe environment, as such different devices, the Java technology has to adapt
well as end-to-end security with networking and cryp- to what people expect from it and to the capabilities
tography APIs. of the device it is running on. For example, a Java pro-
This paper focuses on the practical aspects of the risks gram must be able to run for days without rebooting
associated with Java 2 Micro Edition. Though the archi- on an enterprise server. But on a workstation, you have
tecture is roughly the same as the standard edition, there different expectations: you probably want to use short
are differences that induce specific problems. An exper- term applications with an efficient graphical user inter-
imental study of J2ME low-level security has been con- face. That’s why Java comes in different flavours:
ducted on a Series 60 phone in order to identify and
evaluate some of these risks. • Java 2 Enterprise Edition (J2EE), for running scal-
After a quick introduction to J2ME, configurations, able enterprise applications;
profiles and the new verification scheme, the methodol- • Java 2 Standard Edition (J2SE), aimed at worksta-
tions;
• Java 2 Micro Edition (J2ME), for mobile devices;
D. Reynaud-Plantey (B) • Java Card, for smart cards.
Ecole Supérieure et d’Application des Transmissions,
Laboratoire de virologie et de cryptologie,
B.P. 18, 35998 Rennes Armées, France For the Java developer, it means two things: with a single
e-mail: [email protected] language, you can write applications for every platform.
102 D. Reynaud-Plantey
But it also means that you will have to write code for a rations are not enough and as a result profiles have been
given platform, and it usually means that you may have defined. A profile is a set of APIs which sit on top of a
to use different language constructs (for example you given configuration in order to take better advantage of
might not perform floating point operations on a smart the features of a device.
card), and you will definitely have to use different APIs. Six profiles have been defined, but only one is a CLDC
This might or might not be a big deal, depending on what profile: Mobile Information Device Profile (MIDP). It is
you want to do exactly. From a security perspective, the made to take advantage of the capabilities of the latest
broad range of devices might sound appealing to mali- mobile phones, and its APIs cover user interfaces, con-
cious programmers but they will have to face another nectivity, data storage, messaging and gaming. Profiles
drawback of the Java technology: the lack of low-level only address security issues at the application and end-
control (such as pointer arithmetic or OS-specific fea- to-end levels. For instance, they can provide cryptogra-
tures). phy APIs or features such as access to the file system.
3.1 Configurations The main difference between J2SE and J2ME from the
security approach is that J2ME introduces a new ver-
So far, we have seen that J2ME was intended to bring ification algorithm. A Java program is subject to some
Java to mobile devices. These devices include mobile restrictions: it cannot explicitly deallocate memory, ac-
phones and PDAs as well as washing machines, TV set- cess a specific memory location, or interact directly with
top boxes or car electronic equipment. What do they all the OS. To ensure that a Java program can’t perform
have in common? They are mobile, which means they these operations, it is first loaded in memory and then
have a limited amount of memory and computing power. verified. The verification process is a very complex topic
All their other characteristics may vary, some of them and if it is not made correctly the whole security architec-
might need batteries, some might have a good band- ture collapses. The new verification algorithm in J2ME
width or not, and some might not even have a screen. comes along with an important modification in the class
As a consequence, Java needs again to be adapted to file format specification: a new attribute called Stack-
different kinds of mobile devices, depending on their Map has been defined. Each method must contain a
capabilities. This is the role of a configuration [4]: pro- StackMap attribute which makes the verification pro-
vide the basic set of functionalities for a specific group cess faster and less memory-consuming. Basically, there
of devices with similar characteristics, such as the total must be a stack map at the beginning of each basic block
amount of memory and network connectivity. There- in a method indicating the number and the types of the
fore, a configuration provides a virtual machine and a objects on the stack for this basic block. The former
set of core classes. algorithm consisted in inferring and then checking type
Two configurations have been defined: safety, with StackMap attributes the inference step can
be skipped.
• Connected, Limited Device Configuration (CLDC) From the developer’s point-of-view, it means that
[10]: it is the configuration currently in use on mobile additional steps are required before a program can be
phones and some PDAs. It is defined in the Java run. After the compilation, the classes must be preveri-
Specification Request (JSR) 30. fied (by the developer) and packed in a jar file. The so-
• Connected Device Configuration (CDC): for de- called preverification step adds the StackMap attributes
vices with more memory and processing power. From along with some other modifications. The name is quite
the developer point of view it is closer to J2SE. deceptive however, because it is actually an additional
compilation more than a verification. The real verifica-
3.2 Profiles tion can only take place on the virtual machine of the
user.
We have seen that J2ME had to be split into configura- There are some other important differences between
tions in order to fit on different devices. But even similar J2ME and J2SE from the security perspective, for exam-
devices like mobile phones might offer different ranges ple in J2ME there is no support for custom classloaders
of memory and processing power. They also might have and for the Java Native Interface (JNI). These two fea-
more to offer in terms of underlying user interface, or tures are very useful for virus writers and are almost
advanced features like Bluetooth. This is why configu- needed for high-level, sophisticated viruses.
The Java mobile risk 103
4 Experimental study
• They must give sufficient low-level control over the • A Nokia 6680. It is a Series 60 v2 phone, with CLDC
creation of binary files (zip and class); 1.1 and MIDP 2.0 on Symbian OS v8.0a;
• The disassembling tools must work on broken, in- • Sun Wireless Toolkit 2.3 Beta as the emulator;
valid, illegal or truncated files. This is a very strong • Java 1.5 SDK on Windows XP SP2 as the J2SE run-
constraint, and this is one of the top reasons to create time environment.
new tools;
• The tools must automate a maximum of the process Finally, what is the nature of the errors in the jar and the
of creating invalid midlet suites. class files? The ZIP file format specification and the class
file format specification define data structures with cer-
The toolkit has been written in Java, it has a command- tain structural or semantic constraints. The idea was to
line interface and has been released under the GNU create jar and class files with invalid values for each data
General Public License [8]. It contains the following structure, one at a time. For example, for an unsigned
tools: 4-byte value in a class file, it can be tested for the values
0, 0xFFFF, 0x7FFFFFFF, 0xFFFFFFFF and some other
values that might seem interesting or are declared for-
• zip2xml: a zip “disassembler”. It converts a zip file bidden for this particular data structure. This technique
to an equivalent xml file, each element in the xml is inspired from a more general idea called fuzzing [1],
file representing a data structure defined in the ZIP which can be applied to any input parser and which
File Specification [6]. consists in generating slightly invalid input for a given
• xml2zip: the opposite tool, taking the xml represen- parser, or valid input but with unusual sizes or values in
tation of a zip file and producing the binary file. The order to find implementation flaws.
output file can be totally invalid because each value
in the specification can be modified manually.
• jasmin: the de-facto standard Java assembler. For 4.6 Test results
the occasion, it has been updated in order to give
more control over the output files. Some of the latest First of all, no security flaw was discovered during the
Java attributes are now also supported. study. However, some interesting results were found and
• dejasmin: a Java disassembler, able to produce out- their consequences are going to be detailed in the fol-
put in the new Jasmin format. lowing sections. Here is a quick summary:
A detailed analysis of the results as well as the results has to answer yes when prompted and you have full
raw data can be found at [9]. access to the system of the victim.
To have a midlet signed for the trusted third party do-
main, it is possible to use the Java Verified program [2].
5 The Java mobile risk for the user It was initiated by the industry under the Unified Test-
ing Initiative label. It is a commercial program giving
This section underlines the importance of mobile de- you the opportunity to promote your midlet and to use
vices security for the user and some problems that might the Java Powered logo. In order to be signed, the midlet
not always be obvious: namely that a nice logo does not has to be tested automatically and manually by a test
necessarily mean the product is secure and that installing provider (which is a company). If the midlet is compli-
a program without even running it can be dangerous. ant with some quality and behaviour rules it is signed
and will run in the trusted third party domain on mobile
phones for which the UTI Root Certificate is available.
5.1 A sensitive environment Users have to be aware that running a Java program
with the Java Powered logo, which has been thoroughly
Why would there be a specific risk for mobile Java? The tested and digitally signed does not mean it is not a
short answer is the potential cost for the user. Java is malicious application. This is possible because programs
widely used on the web for applets and though there such as Java Verified are commercial and are therefore
have been historical security problems with them, hos- made for commercial applications. It means that when
tile applets have not been that important. Given the fact you submit your midlet for testing, you do not have to
that the average workstation can be considered compro- provide the source code. And due to some intellectual
mised in some way, people don’t seem to pay too much property legislation, the tester probably does not have
attention to “exotic” threats such as Java malware. How- the right to reverse engineer the application to check
ever, if a malicious application gains control of a mobile that there are no hidden features. So the tester can just
phone, it may be able to send an arbitrary number of ensure that the program is not a malware by just using it a
SMS or MMS, or even issue calls. Therefore, the serious few times, which is of course impossible. Consequently,
risk here is to end up with a huge monetary cost for the malicious applications can undergo the Java Verified
user. testing process successfully, the malware author just
Another problem specific to mobile phones is that has to implement something like: if (date < some-
the damage done to the device can be hard to put back. Date) then showFakeGame() else launchReal
It might for example be impossible to totally disinfect Malware(). This is not specific to the Java Verified
a virus or restore some data. The simplest solution in program, it is true for every behaviour-based testing
many cases is probably to just replace the telephone program.
with a new one.
5.3 Malicious installation
5.2 Signed midlets
The study which led to this paper outlined many prob-
To gain more privileges on the target device, a mid- lems in the Application Management Software on the
let can be signed. It can then access a different pro- telephone. It is the piece of software responsible for the
tection domain, depending on the MIDP version and installation and removal of applications on the phone.
the root certificate used to sign the application. MIDP Most of these problems showed up while testing the
2.0 defines four protection domains: Untrusted, Trusted JAR file format. The purpose was to study the response
Third Party, Operator and Manufacturer. An unsigned of the virtual machine to specially crafted JAR files
midlet runs in the untrusted protection domain, with but it turned out that most of the time these JAR files
very few privileges. For example, an untrusted midlet never reached the virtual machine at all because they
can only access the file system with explicit user approval caused errors in the AMS. It was surprising because
and the access to some files might not be permitted at some behaviours that have been observed were totally
all. The trusted third party domain does not allow full unexpected, for example on the tested telephone the
access to the system, as opposed to the situation with ap- AMS seemed to unpack each class file in the archive
plets. And it is no longer interesting to self-sign midlets (even unused class files) and to parse them up to this_
because they will run in the untrusted domain. The sit- class (it is a field in class files located after the constant
uation is better for malware development with applets: pool). Though there must be a good reason for it to be
you can self-sign your malicious applet and the user just implemented this way, it is quite puzzling.
106 D. Reynaud-Plantey
The problem with these kind of behaviours is that they 6.1 What you see is not what you run
are unexpected because they are totally undocumented.
For testers, it sounds more likely to find bugs in undocu- This is particularly true if midlets are to be reverse engi-
mented pieces of software that in publicly specified and neered. Analysts are very skilled people but they are
reviewed processes such as the bytecode verification. It humans: they are going to use tools to do their job. The
turned out to be true: it was very easy to find bugs in the problem is that most Java reverse engineering tools are
AMS and they might eventually become security flaws. outdated, if maintained at all. Most disassemblers and
This is even more deceptive for the user because we decompilers have been developed at a time when people
naturally have the intuition that it might be dangerous found it revolutionary that you could translate accu-
to run something. In this case, it might be dangerous rately Java bytecode back to source code. In the mean
to install something, without even having to run it to time, the Java language has evolved and J2ME appeared.
trigger the payload. J2ME introduces a new verification process with Stack-
Map attributes. If a vulnerability is found in the verifier,
it may use malformed StackMap attributes. Therefore
5.4 Need for more usability
it might be impossible to understand the vulnerability
without looking at the StackMap attributes. And here is
The general impression is that the whole J2ME secu-
a big problem for the analyst: StackMap attributes are
rity architecture is way too tight. Developers need more
silently ignored by most Java reverse engineering tools,
features, and users want more usability. For example,
along with other new attributes. So it is possible to spend
they want to be able to install a game without being
hours trying to figure out what a given program does, but
prompted five times with “are you sure?”, and then five
it is just impossible without some “hidden” attributes.
more times in the game when it tries to use Bluetooth
The last problem of analysis tools is the way they re-
to connect to their friend and to access the file system to
solve ambiguities. Sometimes, file format specifications
save the game. In the early times there was no support
might contain ambiguities that might complicate the file
at all for Bluetooth or file I/O, now it is supported but
parsing. The class file format is very well specified and
with a lot of security prompts. These security prompts
there are only very few ambiguities. Here is an exam-
are likely to disappear or at least to be less omnipresent.
ple of ambiguity: as specified in the Java Virtual Ma-
This approach, setting up a J2ME environment with “too
chine Specification, the attribute_length field of a
tight” security, must be intentional. The industry prob-
ConstantValue attribute must be 2. But what hap-
ably did not want a virus outbreak in the early days of
pens if a class file parser encounters an attribute with
mobile Java but the situation is probably going to evolve
name “ConstantValue”, a physical length of 2 but an
as J2ME environments mature.
attribute_length value different from 2? The behav-
On the tested telephone, it seemed to be impossible to
iour is implementation-dependant and might vary be-
make a Java virus without breaking the sandbox because
tween a real virtual machine which might skip this attri-
the file connection attempts at other JAR files threw a
bute and a reverse engineering tool which might not
SecurityException. This is good news. However, the bad
know what to do with this strange attribute. These kinds
news is that the file permission system is not transpar-
of ambiguities are very common in the zip file format.
ent at all, and it is more than likely that it is telephone
The solution to these problems is to use up-to-date,
dependant and maybe even firmware dependant. Any-
reliable and low-level reverse engineering tools. The tin-
way, it is not transparent at all, therefore there is a risk
apoc toolkit described in Sect. 4 has been created for this
as explained above.
purpose.