Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

JTAG Combined Attack

- Another approach for fault injection -

F. Majéric, B. Gonzalvo, L. Bossuet, Senior Member, IEEE

Abstract—The combined attacks are widely spread in the System on Chip (SoC). Such devices need also to be evaluated
domain of smart cards and microcontrollers but they have not against fault injections and combined attacks. But so far, very
been yet democratized on complex embedded microprocessors few intrusive tests, were experimented on such systems. The
such as those which can be found in smart phones, tablets
and automotive systems. The main reason behind this is the rarity of these tests is essentially due to the complexity of
complexity to inject a fault at the right place and at the right interacting precisely with a targeted module integrated in a
time to make these attacks effective on such devices. However SoC at the right place and at the right time. On one hand,
for development and debug, these devices provide new tools that this complexity comes from their complex architectures and
could be considered as potential ways for attacks. It’s the case on the other hand it is also due to the size of the chip and the
of the JTAG debug tool which is present on most electronic
devices today. The improper use of this latter is already known package which coats them.
but in this paper we present a new misuse of this one: the JTAG This article presents the improper use of a widespread
as a fault injection tool. Through an example, we explain how hardware debug tool which enables to bypass the complexity
this tool can be used to perform a combined attack. of the SoCs for proceed to a combined attack. This tool is
used to disturb the right control process at the right time which
Index Terms—JTAG, SoC, combined attack, privilege escala-
tion, root privileges, Linux access right management, Android allows to execute a malicious software. The rest of this article
6.0.1 Marshmallow. is organized as follows: Section II introduces the contribution
of this work. Section III defines and gives the example which
I. I NTRODUCTION has inspired our combined attack. The Section IV describes
In 1997 and for the first time, a team of researchers proposed the environment setup and our experimentation on the device
the use of fault injections to break the RSA encryption system under test. Finally, a discussion about this study is proposed
[1]. Ever since, in an environment such as the one of smart in section V and a conclusion is given in section VI.
cards and microcontrollers, this property gave way to a whole
II. O UR CONTRIBUTION
new kind of physical attacks known as fault injection attacks.
The work in [2] gives more details about the various fault This work falls in the extended field of “combined attacks”
induction methods that are frequently used on smart cards which deals with SoCs such as those found in automobiles
in order to extract sensitive information. These methods use and mobile phones. Our research presents the debugging tool
deliberate disturbances of physical quantities related to the JTAG [5] used as a new fault injection vector. This new
systems. It was not until year 2010 that the term “combined aspect of JTAG application is used for a combined attack by
attack” appeared in [3]. The authors introduce a “new kind of privilege escalation. Through this example we show how we
attack which combines fault injection and logical tampering” can bypass complexities of injecting a fault into the SoCs and
in order to alter the security mechanisms of a JAVA card and how by combining the use of a very widespread hardware
authorize the execution of a malicious application. This new debugging tool with a software it leads our attack to success.
idea to combine logical and physical attack was expanded to The improper use of JTAG is not new but rather reserved for
smart cards under different aspects. In order to evaluate the attacks that make only use of it e.g. in [6] and [7]. In our new
securities weaknesses against such threats, a lot of studies approach, we present how to combine hardware (JTAG) and
on this topic and on security to thwart such attacks is still software (a malicious program) to reach our goal. JTAG is
conducted by researchers [4]. only used as a tool for injecting a fault, it’s a JTAG combined
However nowadays, with the democratization of smart- attack.
phones and other connected devices, the manipulation of
III. P RIVILEGE E SCALATION ATTACK
sensitive data tends to be done not only by smart cards but
also by complex and multi-purpose embedded systems like This section formally defines the privilege escalation attack
along with a working example. This latter motivates our JTAG
Fabien Majric is a PhD student with Laboratoire Hubert Curien and combined attack.
Gemalto (e-mail: fabien.majeric@{univ-st-etienne.fr, gemalto.com}).
Benoit Gonzalvo is with the Security Labs, GEMALTO (La Vigie),
Av. du Jujubier, Z.I Athelia IV, 13705 La Ciotat, France (e-mail: A. Definition
benoit.gonzalvo@gemalto.com In [8], Davi et al. define the privilege escalation attack
L. Bossuet is with the Laboratoire Hubert Curien, UMR CNRS 5516, Uni-
versity of Lyon, Saint-Etienne, 42000, France (e-mail: lilian.bossuet@univ-st- as: “An application with less permissions (a non-privileged
etienne.fr). caller) is not restricted to access components of a more
privileged application (a privileged callee)”. More generally, privileges [10]. By doing that, Alephzain allows its exploit to
a privilege escalation is the act of exploiting a bug, design find sys_setresuid address in the /proc/kallsyms
flaw or configuration oversight in an operating system or file. With this address, the exploit can reach the code of
software application to gain elevated access to resources that sys_setresuid in memory and reverses the comparison
are normally protected from an application or user. The result operation dealing with the privileges of the function’s caller. To
is that an application with more privileges than intended by do that the value considered in the comparison function "cmp
the application developer or system administrator can perform r0,#0x0" is simply replaced with "cmp r0,#0x1" or
unauthorized actions. One should keep in mind that this kind directly with the opcode because the exploit handles only in-
of attack is one of the most feared in the digital security field. tegers : "0xE3500000" is replaced with "0xE3500001".
In fact, to have an unauthorized user given permissions that he Now if a simpler user or program asks for root privileges it
should not have and having a potential capacity of jeopardizing can get it. This manipulation allows a user space application to
sensitive data or even worse, endangering the whole system, grant itself elevated permissions that it should not have. This
is a major risk. is a privilege escalation attack.
The example here below is one that inspired us to develop Since the outbreak of that attack, Samsung addressed this
our combined attack described in section IV-B . This software security breach by releasing a fix of the exploit making such
attack shows how to take advantage of a hardware weakness attacks not applicable. The /dev/exynos-mem vulnerabil-
of a device in order to gain a privilege elevation. ity does not exist any more on Samsung Exynos processors
and has never worked on other devices. But by using other
B. Samsung Exynos Kernel Exploit attack path it is possible to perform such an attack as it will
In December 2012, Alephzain, a hacker from the Android be presented in the following section.
community published a method to obtain root privileges
was proposed on many of the popular Samsung phones IV. E XPERIMENTATION
thanks to a simple executable [9]. This exploit potentially Considering the principle of the Samsung Exynos Kernel
threatens all devices embedding Exynos processor 4210 Exploit (see section III-C), if it exists another way to access
and 4412 which use Samsung Android kernel sources. to the memory and change the value of the kernel function,
The vulnerability is in the kernel memory device file this attack could be still possible.
/dev/exynos-mem which is readable and writable by The JTAG is an hardware debug tool present on most of
any unprivileged user and gives access to all physical memory. embedded CPUs. It provides an interface between the debug-
ger and the chip for debugging one or more cores. Among
other functionalities, the Debug Access is used by debugger
C. Principle of this Exploit tools to access the internals of a chip making its resources and
The vulnerability allows any unprivileged user or program functionality available, modifiable and stoppable, e.g. registers,
to read and write to physical memory through the kernel mem- memories and the system state. Considering that, the JTAG
ory device file /dev/exynos-mem. Therefore, Alephzain tool highlights the fact that we have at our disposal a new
implements a simple user privileges application and executes path for fault injection.
it on a device based on an Exynos processor. In memory, this Thus in the rest of this article, we propose a combined
application looks for the sys_setresuid kernel function attack for privilege escalation based on the same principle as
which attributes or not the root privileges. Then it modifies Samsung Exynos Kernel Exploit. Note that there is a huge
this function in order to give the root privileges to the ones amount of attack possibilities, JTAG for privilege escalation
which normally can’t get them. Finally, the user privileges is one example.
application asks to the kernel function to be upgraded to a root
privileges application and because this function is corrupted, A. Experimental Set-up
the application gets this privileges. 1) Device under Test: In our experiment we use a
More precisely, on Android devices, the symbols addresses development board with a widespread 32-bit ARM Cortex-A9
of the kernel functions in the /proc/kallsyms file are processor embedded with Android operating system version
0-masked by the /proc/sys/kernel/kptr_restrict 6.0.1 - Marshmallow. To communicate with the Android-
security feature. The addresses are only displayed to autho- powered device we use Android Debug Bridge tool (ADB)
rized users. So before modifying the sys_setresuid func- which is a command line tool without root privileges.
tion its address must be known. The Alephzain’s application
use the read-write vulnerability to map the memory device in a 2) JTAG Hardware Debugger: Although it’s easy to create
file with the mmap function. Then, it parses this file in order to a tool to communicate with the JTAG interface for performing
find the format specifier string "%pK %c %s\n" used by the boundary-scan tests, developing complex communication pro-
.text segment of kptr_restrict. For security reasons, tocols transported by JTAG to perform debugging is difficult.
the %pK format specifier is designed to hide exposed kernel Hence the debug tool that was used for the manipulations is a
pointers, specifically via /proc interfaces. Replacing %pK by commercial JTAG probe, Lauterbach trademark. The Trace32
%p force kernel to display its symbols pointers regardless of soft of this probe provides a very detailed and tailored GUI
which gives an overview of the device and can perform a available is a deterioration of the whole system security.
wide set of operations on it. With recent advancements, it Similar to the software exploit, an attacker proceeds in
exists somes tools which were earlier reserved for high-tech order to change the security of the display of the addresses
laboratories are now easily accessible to attackers thus making of kernel system calls. So the attacker has to look for a
JTAG attacks a real risk. particular kernel string pattern Psought and modify this
latter to provide addresses for everyone. The hardware
B. JTAG Combined Attack for Privilege Escalation
debug tool facilitates to directly seek this pattern in memory
The JTAG combined attack success depends on the ability but the constraint here is the size that needs to be read
to modify the system call sys_setresuid which manages to be sure Psought belongs to it. As explained in chapter
the grant of the access to the kernel code. 10 of [11], a vast majority of Android devices uses the
From this point there are two ways to proceed: either traditional 3-gig split where kernel space occupies the highest
directly look for the system call function and patch it or gigabyte of address space (≥ 0xC0000000) and user space
look for its address in the list of addresses only accessible to occupies the lower three gigabytes (below 0xC0000000).
privileged users. The first method is the pattern recognition So the proposed attack is quite simple. First it dumps
used for finding the system call in kernel code accessed by the kernel by small packages, one by one starting at the
JTAG. The pattern is the hexadecimal value of compiled code address 0xC0000000 then it parses these package to find
and this value depends on the compiler used and the options the sought string pattern included in the kernel function
selected among others things. So the desired pattern could managing addresses display. Once Psought ="0x204b7025
be different for the same function making the search more 0x25206325 0x00000a73" ("%pK %c %s\n") is
difficult. The second option uses the same method as the found, it is replaced with Psubstitution ="0x20207025
Samsung Exynos Kernel Exploit and searches a fixed pattern 0x25206325 0x00000a73" ("%p %c %s\n"), a
(the format specifier string) that determines if the system depreciated kernel command pattern which has no restriction
call addresses display must be done or not considering the for displaying the addresses of system calls. Algorithm 1
privileges of the caller requesting for it. This last option is summarizes all the steps above. This manipulation facilitates
probably more efficient on an Android OS assembled by an the display of the addresses of the system calls to anyone
unknown compiler. who asks for it. Now, to identify the address of the system
call in which the fault will be injected, a non-privileged user
So the JTAG combined attack for privilege escalation can can ask the kernel through ADB with the commande line:
be split into three main steps: ~$ cat /proc/kallsyms | grep setresuid
1) Find the address of set_setresuid which manages
the privileges. 2) Inject the fault: The manipulation made in the pre-
2) Modify this system call, i.e. inject the fault. vious paragraph 1) allows an attacker to get the address
3) From the user space, ask for root permissions. of set_setresuid function through ADB. Regarding the
system used in the experiment, the address found which marks
The first two steps are done with the JTAG probe. In the the beginning of the function is 0xC00A2954. Through the
step 1), the probe will be used to parse the code in order to JTAG probe it is easy to observe this function in RAM system
inject a fault to force the kernel to display the system call memory (see Fig. 1).
addresses. Then the address is read by software means (ADB) The fault injection is carried out at the address
from user space. In step 2), the JTAG tool is only used to 0xC00A298C which has the value 0xE3500000. In ARM
inject the fault. The last step 3) is the combined attack, in instruction assembly language this value is the opcode for
which the previous manipulations made with JTAG grants “cmp r0,#0x0” (see Fig. 2). Observing the instructions of
root permissions to a software asking for it. The following this function, it is easy to understand that the injected fault
sections describe how some of difficulties encountered in distorts the first comparison. Using the JTAG tool an attacker
these 3 points were resolved. can precisely modify this instruction which determines a
connection to another function according to its result. Through
1) Find the address of system call: Like in the exploit experiments it has been observed that:
described in section III-C, a kernel parameter is modified ∀n ∈ N, 0x0 < n ≤ 0xFF, "CMP R0,#n" ⇒ “only non-
thanks to the JTAG probe and then all the system call addresses privileged users can get root permissions, i.e. the function is
are available. The parameter modified in the kernel is a format reversed.”
specifier designed to hide kernel system call addresses to
a non-authorized user. The modification replaces the format 3) Ask for root permissions: This is the final stage of
specifier by another which has no restrictions regarding the the attack. Because sys_setresuid function has been
users authorization. reversed in the previous step 2), the simple act of asking
Like for the Exynos Exploit an attacker has the memory for root privileges by a non-root user grants this user root
access but he does not have the kernel system call address. privileges. This will be done by executing from the ADB
In this case, the manipulation for making the system calls interface a simple software without privileges. So the program
Algorithm 1: REMOVE THE 0- MASK
Input: Psought : Pattern sought,
Psubsitution : Pattern for the substitution,
Df : Data file.
Output: The list of the addresses where the pattern was
replaced : addresses = [@1 , @2 , . . .].
Function(Df , Psought , Psubsitution )
1 addresses ← [ ]
2 Ptemp ← ""
3 of f set ← @0 ; the starting address of Df
4 done ← F alse
5 while done 6= T rue do
6 SD ← size(Df )
7 SP ← size(Psought )
8 Ptemp ← Df [of f set : SP + of f set] Fig. 2. Beginning of the system call sys_setreuid thanks to the
disassembler of JTAG debug tool.
9 if Ptemp = Psought then
10 Df [of f set : SP + of f set] ← Psubstitution
11 addresses ← addresses + [of f set]
12 of f set ← of f set+0x4
13 else
14 of f set ← of f set+0x4
15 end
16 if of f set < (SD − SP ) then
17 done ← F alse
18 else
19 done ← T rue
20 end
21 end
22 return addresses

Fig. 3. jtag_based_abuse.c

operations.
V. D ISCUSSION
Throughout the paper we described how JTAG can be use
to modify the code on the fly in order to tamper with any
Operating Systems. Thus we did not crash the system but
simply hijacked it. However a strong assumption was made
on the feasibility of such an attack : the access to the JTAG
interface without restrictions. For the sake of practicality,
Fig. 1. Beginning of the system call sys_setresuid opcode in the RAM most of the time, the development boards have their JTAG
memory displayed by JTAG debugger. port available and unlocked. But what about the commercial
systems?

jtag_based_abuse.c (see Fig. 3) is compiled and loaded From there two approaches can be addressed:
in the /data/local/tmp directory of the OS running on
the SoC. Then it is executed from ADB comand-line and A. Anyway, try to access to the JTAG interface
provides to new terminal window with the root privileges. This tool is used in circuit fabrication to ensure the quality
However, it should be noted that in order to finalize this of the product or to load the manufacturer’s data and it’s also
attack, root privileges obtained through ADB the attacker useful in the life cycle of devices. Indeed, by using such
must restore sys_setresuid, the function of permission a tool it is possible to perform maintenance operations, re-
management to its initial state to perform future privileged flash the memory and detect defective product areas. Depriving
electronic industry of such tools would be an obstacle to the VI. C ONCLUSION
quick marketing of some products. Considering this, there are We have demonstrated the use of JTAG debugger to modify
several points of view. The first is to not be aware or worried the code on the fly in order to tamper with an Operating
by the risks related to JTAG. This is still the case, too many System no matter what it is. JTAG can be considered as
manufacturers feel that simply removing the JTAG connector a new fault injection tool for performing or simulating the
is enough to restrict its access. Which is not the case as it is feasibility of a combined attack targeting complex embedded
easy to find many tutorials online which explain how to take microprocessor. The example presented in this article is based
control of such devices without JTAG connector. on an existing software exploit which is now ineffective by the
The second point of view is to become aware of the risks recent updates for Android operating systems. However using
associated with JTAG. As explained in some academic articles our demonstrated technique this attack is still feasible.
such as [6] it is possible to take preventive measures to The only constraint in carrying out this type of attack is
ensure the JTAG integrity. Also many manufacturers provide to have unrestricted access to the JTAG interface. This last
limited solutions such as NXP which offers 3 security level assumption is decisive, however, given the state of the art about
for JTAG access [12]: Open access, password access and current security measures for the JTAG access, our attack is
no-debug functionality access. The JTAG security mode is still relevant.
selected irreversibly with fuses. Moreover a disabled JTAG
access mode prevents the use of the JTAG debug tool. This R EFERENCES
secured JTAG access prevents the use of the debug tool for [1] D. Boneh, R. DeMillo, and R. Lipton, “On the importance of checking
malicious purposes. cryptographic protocols for faults,” in Advances in Cryptology EURO-
CRYPT 97, ser. Lecture Notes in Computer Science.
Therefore, it is interesting to study these new protection [2] H. Bar-El, H. Choukri, D. Naccache, M. Tunstall, and C. Whelan, “The
mechanism. As shown in this work [13], it is possible to sorcerer’s apprentice guide to fault attacks,” Proceedings of the IEEE,
vol. 94, no. 2, pp. 370–382, Feb 2006.
imagine new attack paths and several fault injections in order [3] “Attacks on java card 3.0 combining fault and logical attacks,” in
to bypass such security mechanism and get access to the JTAG. Smart Card Research and Advanced Application, ser. Lecture Notes in
Computer Science, D. Gollmann, J.-L. Lanet, and J. Iguchi-Cartigny,
In the same context of securing the JTAG, new architectures Eds., vol. 6035.
with security measures are emerging in recent years. For [4] E. Vetillard and A. Ferrari, “Combined attacks and countermeasures,”
example the idea in TrustZone/TEE architectures proposed in Smart Card Research and Advanced Application, ser. Lecture Notes
in Computer Science.
by ARM, with hardware support (via a dedicated bus) it is [5] IEEE Std 1149.1-2013: IEEE Standard for Test Access Port and
possible to limit the access permissions to various modules Boundary-Scan Architecture – IEEE Computer Society, May 2013,
based on their privileges (including JTAG). The possibility of (Revision of IEEE Std 1149.1-2001).
[6] K. Rosenfeld and R. Karri, “Attacks and defenses for jtag,” Design Test,
bypassing the protections on the JTAG represent an important IEEE, vol. PP, no. 99, pp. 1–1, 2013.
domain of study for the security of such systems. [7] “Forensic analysis of mobile phone internal memory,” in Advances in
Digital Forensics, ser. IFIP The International Federation for Information
Processing, M. Pollitt and S. Shenoi, Eds., vol. 194.
B. Use the JTAG to simulate an prepare a fault injection [8] “Privilege escalation attacks on android,” in Information Security,
ser. Lecture Notes in Computer Science, M. Burmester, G. Tsudik,
S. Magliveras, and I. Ili, Eds., vol. 6531.
In the introduction we explain the complexity to set up a [9] Alephzain, “Root exploit on Exynos,” http://forum.xda-
fault injection attack on SoCs. Even if the JTAG is disabled developers.com/galaxy-s3/general/root-root-exploit-exynos-t2047991,
on the device that an attacker would like to attack, it could December 2012, [Online; accessed 15-December-2012].
[10] D. Rosenberg, “kptr restrict for hiding kernel pointers from unprivi-
be still used on a development board similar to this device leged users,” https://lwn.net/Articles/420403/, December 2010, [Online;
in order to simulate if an attack is feasible. On our privilege accessed 18-December-2010].
escalation attack we have seen that only one bit have to be [11] J. J. Drake, Z. Lanier, C. Mulliner, P. O. Fora, S. A. Ridley, and
G. Wicherski, Android Hacker’s Handbook, 1st ed. Wiley Publishing,
flipped. By using other physical quantity like electromagnetic 2014.
field for example, it is possible to measure the emission field [12] NXP, “Configuring secure jtag for the i.mx 6 series
related to the call of the function and detect it. This kind of family of applications processors - application note,”
http://www.nxp.com/files/32bit/doc/app note/AN4686.pdf, March
detection is already done for encryption process on SoCs [14]. 2015, document Number: AN4686 Rev. 1.
Once the function call is detected by pattern matching on [13] “Breakthrough silicon scanning discovers backdoor in military chip,”
the fly or by interrupts, an electromagnetic pulse is injected in Cryptographic Hardware and Embedded Systems CHES 2012, ser.
Lecture Notes in Computer Science, E. Prouff and P. Schaumont, Eds.,
in order to disturb it, as in [15]. The set up of this kind vol. 7428.
of manipulation is very important but by repeating the call [14] J. Longo, E. De Mulder, D. Page, and M. Tunstall, “Soc it to em:
to the function and the EM pulse injection it is statistically Electromagnetic side-channel attacks on a complex system-on-chip,” in
Cryptographic Hardware and Embedded Systems – CHES 2015: 17th
possible to succeed. International Workshop, Saint-Malo, France, September 13-16, 2015,
Proceedings.
[15] S. Ordas, L. Guillaume-Sage, and P. Maurine, “EM injection: Fault
Both approaches show that the JTAG should not be model and locality,” in 2015 Workshop on Fault Diagnosis and
considered as a risk only linked to debug. This tool can also Tolerance in Cryptography, FDTC 2015, Saint Malo, France,
be seen as a support for the set up of a fault attack. September 13, 2015, 2015, pp. 3–13. [Online]. Available:
http://dx.doi.org/10.1109/FDTC.2015.9

You might also like