Attacking Android
Attacking Android
COM
Attacking Android
· Mar 11, 2024 · 35 min read
Table of contents
ContentProvider Management in Android Applications
Noncompliant Code Example:
Proof of Concept:
Compliant Solution:
Risk Assessment:
Protecting Exported Services with Strong Permissions in Android Applications
Background:
Noncompliant Code Example:
Compliant Solutions:
Usage in Other Applications:
Risk Assessment:
Protecting Against Directory Traversal Vulnerabilities in Android ContentProviders
Background:
Noncompliant Code Example 1:
Noncompliant Code Example 2:
Proof of Concept:
Compliant Solution:
Applicability:
Risk Assessment:
Preventing Unauthorized Access to Sensitive Activities in Android Applications
Background:
Noncompliant Code Example:
Compliant Solution (Do not export activity):
Compliant Solution (Twicca):
Risk Assessment:
Avoid Storing Sensitive Information on External Storage (SD Card) Without Encryption
Background:
Noncompliant Code Example:
Compliant Solution #1 (Save a File on Internal Storage):
Risk Assessment:
Logging Sensitive Information in Android
Background:
Logging Sensitive Information:
Noncompliant Code Example:
Proof of Concept (Obtaining Log Output):
Compliant Solution:
Risk Assessment:
Securing Sensitive Data in Android
Background:
Noncompliant Code Example:
Compliant Solution:
Risk Assessment:
Cache
Noncompliant Code Example:
Compliant Solution:
Risk Assessment:
Do not use world readable or writeable to share files between apps
Noncompliant Code Example 1:
Noncompliant Code Example 2:
For OAuth, use an explicit intent method to deliver access tokens
Noncompliant Code Example:
Compliant Solution:
Do not broadcast sensitive information using an implicit intent
Do not allow WebView to access sensitive local resource through file scheme
WebView Security Concerns:
Noncompliant Code Example:
Compliant Solution:
Risk Assessment:
Do not provide addJavascriptInterface method access in a WebView which could contain
untrusted content. (API level JELLY_BEAN or below)
Noncompliant Code Example:
Compliant Solutions:
Applicability:
Risk Assessment:
Enable serialization compatibility during class evolution
Noncompliant Code Example:
Compliant Solutions:
Risk Assessment:
Do not deviate from the proper signatures of serialization methods
Serialization Methods:
Compliant Solution for writeObject() and readObject():
readResolve() and writeReplace() Methods:
Noncompliant Code Examples for readResolve() and writeReplace():
Compliant Solution for readResolve() and writeReplace():
Risk Assessment:
Exclude unsanitized user input from format strings
Noncompliant Code Example:
Compliant Solution:
Risk Assessment:
Sanitize untrusted data included in a regular expression
Risks of Regex Injection:
Vulnerable Constructs in Regex:
Noncompliant Code Example:
Compliant Solutions:
Risk Assessment:
Define wrappers around native methods
Native Method Overview:
Noncompliant Code Example:
Compliant Solution:
Exceptions:
Risk Assessment:
Do not allow exceptions to expose sensitive information
Risks of Exception Propagation:
Noncompliant Code Example 1: Leaks from Exception Message and Type
Risk:
Noncompliant Code Example 2: Wrapping and Rethrowing Sensitive Exception
Risk:
Noncompliant Code Example 3: Sanitized Exception
Risk:
Compliant Solution 1: Security Policy
Solution:
Compliant Solution 2: Restricted Input
Solution:
Considerations:
Risk Assessment:
Do not encode noncharacter data as a string
Noncompliant Code Example:
Compliant Solution:
Using toString() and getBytes():
Using Base64 Encoding:
Risk Assessment:
Do not release apps that are debuggable
Noncompliant Code Example:
Compliant Solution:
Risk Assessment:
Consider privacy concerns when using Geolocation API
Noncompliant Code Example:
Compliant Solution #1:
Compliant Solution #2:
Risk Assessment:
Properly verify server certificate on SSL/TLS
Noncompliant Code Example:
Compliant Solution:
Risk Assessment:
Specify permissions when creating files via the NDK
Noncompliant Code Example:
Compliant Solution (Set Umask):
Compliant Solution (Specify File Permissions):
Risk Assessment:
Sensitive classes must not let themselves be copied
Noncompliant Code Example:
Malicious Subclass:
Compliant Solution (Final Class):
Compliant Solution (Final clone()):
Risk Assessment:
References
Show less
In this comprehensive guide, we delve into the world of Android security from an
offensive perspective, shedding light on the various techniques and methodologies
used by attackers to compromise Android devices and infiltrate their sensitive data.
From exploiting common coding flaws to leveraging sophisticated social engineering
tactics, we explore the full spectrum of attack surfaces present in Android
environments.
Private Access:
A ContentProvider can be made private to restrict access from other applications.
From API Level 17 onwards, a ContentProvider is private by default if
android:exported is not specified.
<provider
android:exported="false"
android:name="MyContentProvider"
android:authorities="[Link]" />
3. Restricted Access:
More details are needed for implementing restricted access. This section
requires further elaboration.
Noncompliant Code Example:
The example of noncompliant code demonstrates a Twitter client application
inadvertently exposing sensitive information through a public ContentProvider .
Proof of Concept:
The provided code snippet illustrates how the vulnerability in the ContentProvider can
be exploited to extract sensitive data from the Twitter client application.
Compliant Solution:
The compliant solution involves making the ContentProvider private in the
[Link] file to prevent unauthorized access to sensitive data.
COPY
<provider
android:name=".[Link]"
android:exported="false"
android:authorities="[Link]" />
Risk Assessment:
Declaring a ContentProvider as public without proper access control can lead to
leakage of sensitive information to malicious applications.
Compliant Solutions:
1. Removing <intent-filter> :
By removing the <intent-filter> , access to the service is restricted to
components within the same application or applications with the same user
ID.
2. Using Custom Permissions:
If the intention is to allow access from other applications, custom
permissions should be used instead of relying on default permissions like
"normal." This prevents unauthorized access to confidential data.
Compliant Solution Code:
COPY
<permission android:name="customPermission"
android:protectionLevel="dangerous" ...></permission>
<activity
android:permission="customPermission"
... >
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
<intent-filter >
<action android:name="package_name.MyAction" />
<category android:name="[Link]" />
</intent-filter>
</activity>
COPY
<uses-permission
android:name="customPermission"
android:maxSdkVersion=.. />
COPY
Risk Assessment:
Failure to protect exported services with strong permissions poses a high risk,
potentially leading to sensitive data exposure or denial of service attacks.
Proof of Concept:
Malicious code can exploit these vulnerabilities by supplying specially crafted URI
strings to the content provider, leading to unauthorized file access or traversal.
Compliant Solution:
The compliant solution ensures protection against directory traversal by decoding the
URI string and canonicalizing the file path:
COPY
Applicability:
This guideline is applicable to any Android application that exchanges files through a
ContentProvider, ensuring protection against directory traversal attacks.
Risk Assessment:
Failure to properly decode and canonicalize file paths received by a ContentProvider
may result in directory traversal vulnerabilities, leading to unauthorized access or
corruption of sensitive data.
<activity
android:configChanges="keyboard|keyboardHidden|orientation"
android:name=".[Link]"
android:theme="@style/[Link]"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter android:icon="@drawable/yfrog_icon"
android:label="@string/YFROG">
<action android:name="[Link].ACTION_UPLOAD" />
<category android:name="[Link]" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
</intent-filter>
</activity>
<activity
android:configChanges="keyboard|keyboardHidden|orientation"
android:name=".[Link]"
android:theme="@style/ [Link]"
android:windowSoftInputMode="stateAlwaysHidden"
android:exported="false">
</activity>
Risk Assessment:
Failure to validate the caller's identity before acting on received intents may lead to
sensitive data exposure or denial of service attacks.
try {
File file = new File(getExternalFilesDir(TARGET_TYPE), filename);
fos = new FileOutputStream(file, false);
[Link]([Link]());
} catch (FileNotFoundException e) {
// handle FileNotFoundException
} catch (IOException e) {
// handle IOException
} finally {
if (fos != null) {
try {
[Link]();
} catch (IOException e) {
// handle error
}
}
}
try {
fos = openFileOutput(filename, Context.MODE_PRIVATE);
[Link]([Link]());
} catch (FileNotFoundException e) {
// handle FileNotFoundException
} catch (IOException e) {
// handle IOException
} finally {
if (fos != null) {
try {
[Link]();
} catch (IOException e) {
// handle error
}
}
}
Risk Assessment:
Storing sensitive information on external storage without encryption can lead to data
leakage to malicious apps, compromising the confidentiality of the data. Implementing
proper encryption or storing data in internal storage mitigates this risk.
COPY
COPY
// Example code to obtain log output from a vulnerable application
final StringBuilder slog = new StringBuilder();
try {
Process mLogcatProc;
mLogcatProc = [Link]().exec(new String[]
{"logcat", "-d", "LoginAsyncTask:I APIClient:I method:V *:S" });
String line;
String separator = [Link]("[Link]");
} catch (IOException e) {
// handle error
}
Compliant Solution:
Developers should ensure that sensitive information is not logged. They can achieve
this by:
1. Reviewing code to identify and remove any logging of sensitive information.
2. Using custom logging mechanisms that automatically turn off logging in release
builds.
3. Employing obfuscation tools like ProGuard to remove specific logging calls.
Risk Assessment:
Logging sensitive information can lead to data leakage, compromising user privacy
and potentially exposing sensitive data to malicious apps.
COPY
In this example, the file is created with the MODE_WORLD_READABLE flag, allowing any
application to read its contents, which poses a security risk.
Compliant Solution:
COPY
By using MODE_PRIVATE , the file can only be accessed by the app that created it,
ensuring data security.
Risk Assessment:
Failure to secure sensitive data can lead to data leakage, compromising user privacy
and potentially exposing confidential information to unauthorized apps or entities.
Cache
Caching data can pose security risks as it may become accessible to other
applications or unauthorized users if the device is lost or stolen. Here's a breakdown
of the key points mentioned in the guideline:
1. Caching web application data: Storing data such as URL histories, HTTP
headers, HTML form inputs, and cookies in the cache can expose sensitive
information to other applications.
2. Keyboard cache: Words entered by the user via the keyboard are stored in the
Android user dictionary for auto-correction. This data is accessible to any app
without requiring permission, potentially leading to the leakage of sensitive
information.
3. Cached camera images: Apps may cache images captured by the device's
camera, which can remain accessible even after the app has finished. Storing
such images without proper security measures can compromise user privacy.
4. GUI objects caching: Application screens retained in memory can enable access
to transaction histories by anyone with device access. Caching sensitive
information in memory increases the risk of data exposure.
To address these concerns, developers should:
Avoid caching sensitive information whenever possible.
Use methods like clearCache() to delete cached data, especially when accessing
sensitive data with a WebView .
Utilize server-side headers like no-cache to prevent caching of particular content
by the application.
Noncompliant Code Example:
COPY
// Caching web application data (noncompliant)
[Link]().setCacheMode(WebSettings.LOAD_DEFAULT);
In this noncompliant code example, web application data is cached using the default
cache mode, potentially revealing sensitive information such as URL histories, HTTP
headers, and cookies.
Compliant Solution:
COPY
COPY
COPY
By avoiding the use of these constants and opting for more secure mechanisms like
ContentProvider, BroadcastReceiver, and Service, developers can minimize the risk of
security vulnerabilities in their Android applications.
For OAuth, use an explicit intent method to deliver access tokens
This guideline emphasizes the importance of using explicit intents over implicit intents
in Android applications to protect user information and prevent potential security
risks. Explicit intents specify the target component explicitly, while implicit intents
declare general actions that all applications can use, potentially exposing sensitive
user actions.
Noncompliant Code Example:
COPY
In the noncompliant code example, an implicit intent is used to send access tokens by
invoking a specific action without specifying the target component explicitly. This
approach can lead to security vulnerabilities and expose user information to
unintended recipients.
Compliant Solution:
COPY
The proof of concept demonstrates how a malicious broadcast receiver can intercept
the implicit intent and access sensitive data sent by the vulnerable application.
Compliant Solution:
COPY
// turn on javascript
WebSettings settings = [Link]();
[Link](true);
// Proof of Concept
// Malicious application prepares some crafted HTML file,
// places it on a local storage, makes accessible from
// other applications. The following code sends an
// intent to a target application ([Link])
// to make it access and process the malicious HTML file.
// Compliant Solution
public class MyBrowser extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link]);
[Link](url);
}
}
The noncompliant code initializes a WebView object, enables JavaScript, and loads a
URL received via Intent without proper validation. This can lead to security
vulnerabilities if malicious content is loaded.
The proof of concept demonstrates how a malicious application can exploit this
vulnerability by sending an intent to a target application with a crafted HTML file URI.
The compliant solution validates the received URL to ensure it starts with "http" or
"https" before loading it into the WebView. This helps mitigate the risk of loading
potentially malicious local content.
Compliant Solution:
A compliant solution validates URIs received via Intent before rendering them with
WebView. It checks that the URI starts with "http" to ensure that only trusted URLs
are loaded. This approach helps mitigate the risk of loading malicious local content.
Risk Assessment:
Failure to implement proper security measures in WebView usage can result in
information leaks and other security breaches. It's essential to validate input and
configure WebView settings carefully to minimize these risks.
COPY
class JsObject {
private String sensitiveInformation;
By allowing JavaScript to control the host, this code opens up avenues for potential
scripting attacks, utilizing Java reflection to access public methods of injected
objects and thereby gaining access to sensitive information.
Compliant Solutions:
1. Refrain from using addJavascriptInterface : In this approach, the code refrains
from using the addJavascriptInterface method altogether.
COPY
WebView webView = new WebView(this);
setContentView(webView);
<manifest>
<uses-sdk android:minSdkVersion="17" />
...
</manifest>
Applicability:
Android Version Applicability: Applies to Android API versions 16 (JELLY_BEAN)
and below.
Risk Assessment:
Risk Level: High
Probability: Probable
Impact: Medium
Priority: P12
Likelihood: L1
serialized form. Any changes to the internal structure of the class may break
compatibility with previously serialized objects.
COPY
Compliant Solutions:
1. Using serialVersionUID : In this solution, the class declares a private static
final long serialVersionUID , providing a unique identifier for the class version.
This allows the JVM to deserialize objects even if the class definition has
changed, as long as the version ID remains the same.
COPY
Risk Assessment:
Risk Level: Low
Probability: Probable
Impact: High
Priority: P2
Likelihood: L3
COPY
// Private declaration
class Extendable implements Serializable {
private Object readResolve() {
// ...
}
// Static declaration
class Extendable implements Serializable {
protected static Object readResolve() {
// ...
}
Risk Assessment:
Risk Level: High
Probability: Likely
Impact: Low
Priority: P27
Likelihood: L1
output, but they pose security risks if untrusted data is incorporated into the format
string.
Noncompliant Code Example:
The noncompliant code incorporates untrusted data into a format string, potentially
leaking sensitive information or allowing a denial-of-service attack.
COPY
class Format {
static Calendar c = new GregorianCalendar(1995,
[Link], 23);
public static void main(String[] args) {
// args[0] should contain the credit card expiration date
// but might contain %1$tm, %1$te or %1$tY format specifiers
[Link](
args[0] + " did not match! HINT: It was issued on %1$terd of
some month", c
);
}
}
Compliant Solution:
The compliant solution avoids incorporating untrusted user input into the format
string, rendering any format specifiers inert.
COPY
class Format {
static Calendar c = new GregorianCalendar(1995,
[Link], 23);
public static void main(String[] args) {
// args[0] is the credit card expiration date
// Perform comparison with c,
// if it doesn't match, print the following line
[Link](
"%s did not match! HINT: It was issued on %terd of some month",
args[0], c
);
}
}
Risk Assessment:
Risk Level: Medium
Probability: Unlikely
Impact: Medium
Priority: P4
Likelihood: L3
2. Greediness: Injection attempts may change the regex to match as much of the
string as possible, potentially exposing sensitive information.
3. Grouping: Attackers may manipulate regex groupings by supplying untrusted
input.
Noncompliant Code Example:
The provided code dynamically constructs a regex pattern using untrusted user input,
making it vulnerable to regex injection attacks.
COPY
Compliant Solutions:
1. Whitelisting: Sanitize search terms by filtering out non-alphanumeric characters.
COPY
Compliant Solution:
The compliant solution addresses security concerns by declaring the native method
as private and implementing a doOperation() wrapper method with proper security
checks, input validation, and defensive copying.
COPY
if (data == null) {
throw new NullPointerException();
}
// Validate input
if ((offset < 0) || (len < 0) || (offset > ([Link] - len))) {
throw new IllegalArgumentException();
}
nativeOperation(data, offset, len);
}
static {
// Load native library in static initializer of class
[Link]("NativeMethodLib");
}
}
Exceptions:
JN100-J-EX0: Native methods like int rand(void)that don't require security
manager checks, argument validation, or defensive copying do not need
wrapping.
Risk Assessment:
Risk Level: Medium
Probability: Probable
Impact: High
Priority: P4
Likelihood: L3
Printing the stack trace can also result in unintentionally leaking information about the
structure and state of the process to an attacker. When a Java program that is run
within a console terminates because of an uncaught exception, the exception's
message and stack trace are displayed on the console; the stack trace may itself
contain sensitive information about the program's internal structure. Consequently,
any program that may be run on a console accessible to an untrusted user must never
abort due to an uncaught exception.
Risks of Exception Propagation:
Information Leaks: Exceptions can reveal sensitive details about the application's
internal structure, system configuration, or user environment.
Denial of Service (DoS): Attackers can exploit exceptions to gather information
for potential DoS attacks or exploit vulnerabilities.
Noncompliant Code Example 1: Leaks from Exception Message and Type
COPY
class ExceptionExample {
public static void main(String[] args) throws FileNotFoundException
{
FileInputStream fis =
new FileInputStream([Link]("APPDATA") + args[0]);
}
}
Risk:
Exposes sensitive information about the file system layout to attackers.
Allows attackers to reconstruct the underlying file system by passing fictitious
path names.
Noncompliant Code Example 2: Wrapping and Rethrowing Sensitive Exception
COPY
try {
FileInputStream fis =
new FileInputStream([Link]("APPDATA") + args[0]);
} catch (FileNotFoundException e) {
// Log the exception
throw new IOException("Unable to retrieve file", e);
}
Risk:
Even when the logged exception is not directly accessible to the user, the original
exception can still provide information about the file system layout to attackers.
Noncompliant Code Example 3: Sanitized Exception
COPY
try {
FileInputStream fis =
new FileInputStream([Link]("APPDATA") + args[0]);
} catch (FileNotFoundException e) {
// Log the exception
throw new SecurityIOException();
}
Risk:
Although this approach is less likely to leak useful information, it still reveals that
the specified file cannot be read, enabling attackers to infer sensitive details
about the file system.
Compliant Solution 1: Security Policy
COPY
class ExceptionExample {
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream(file);
} catch (FileNotFoundException x) {
[Link]("Invalid file");
return;
}
}
}
Solution:
Implements a security policy that restricts file access to a specific directory
( c:\homepath ).
Provides a generic error message to conceal information about the file system
layout outside the permitted directory.
Compliant Solution 2: Restricted Input
COPY
class ExceptionExample {
public static void main(String[] args) {
FileInputStream fis = null;
try {
switch([Link](args[0])) {
case 1:
fis = new FileInputStream("c:\\homepath\\file1");
break;
case 2:
fis = new FileInputStream("c:\\homepath\\file2");
break;
//...
default:
[Link]("Invalid option");
break;
}
} catch (Throwable t) {
[Link](t); // Sanitize
}
}
}
Solution:
Operates under the policy that only specific files ( c:\homepath\file1 and
c:\homepath\file2 ) are permitted to be opened by the user.
Uses a centralized exception reporting mechanism ( MyExceptionReporter ) to filter
sensitive information from any resulting exceptions.
Considerations:
Handling Security Exceptions: Ensure that security-related exceptions are
appropriately logged and sanitized.
Scalability: Design solutions to handle a range of inputs efficiently, considering
future scalability requirements.
Risk Assessment:
Risk Level: Medium
Probability: Probable
Impact: High
Priority: P4
Likelihood: L3
array using toByteArray() method, then creating a string from the byte array using
the String(byte[] bytes) constructor, and finally converting the string back to a byte
array and then to a BigInteger . This approach risks data integrity issues because not
all byte arrays can be safely converted to strings and back.
COPY
BigInteger x = new BigInteger("530500452766");
byte[] byteArray = [Link]();
String s = new String(byteArray); // Risk of data corruption
byteArray = [Link]();
x = new BigInteger(byteArray); // Unlikely to reproduce the original
value
Compliant Solution:
Using toString() and getBytes() :
This compliant solution ensures data integrity by first converting the BigInteger
object to a string using the toString() method, which generates valid character data.
Then, it converts the string to a byte array and back to a BigInteger .
COPY
the [Link].Base64 class, providing encoders and decoders for the Base64
encoding scheme.
COPY
$ adb shell
shell@android:/ $ run-as [Link] sh
shell@android:/data/data/[Link] $ id
uid=10060(app_60) gid=10060(app_60)
shell@android:/data/data/[Link] $ ls files/
secret_data.txt
shell@android:/data/data/[Link] $ cat files/secret_data.txt
password=GoogolPlex
account_number=31974286
With android:debuggable set to true, users can easily access sensitive data related to
the app, posing a security risk.
Compliant Solution:
To ensure app security, the android:debuggable attribute must be set to false before
releasing the app. This prevents users from accessing sensitive information and
debugging the app without authorization.
COPY
android:debuggable="false"
<configuration>
<compilation debug="true"/>
</configuration>
Risk Assessment:
Releasing an app with android:debuggable set to true poses a high risk as it can leak
sensitive information and make the app vulnerable to decompilation and alteration of
its source code. Attackers can exploit this additional information to mount targeted
attacks on the app's framework, database, or other resources.
if([Link]("SECURITY_ENABLE_GEOLOCATION_INFORMATION",
true)) {
WebViewHolder.a(this.a).permissionShowPrompt(origin,
callback);
}
else {
[Link](origin, false, false);
}
}
Risk Assessment:
Sending a user's geolocation information without obtaining the user's permission
violates the security and privacy considerations of the Geolocation API, potentially
leaking sensitive information. Therefore, it's crucial to implement proper user interface
mechanisms to ask for consent before accessing and transmitting geolocation data.
COPY
((SSLSocketFactory)mySSLSocketFactory).setHostnameVerifier(SSLSocketFa
ctory.ALLOW_ALL_HOSTNAME_VERIFIER);
}
// Rest of the code
}
catch(Exception e) {
// Handle exception
}
return httpClient;
}
Compliant Solution:
The compliant solution would involve implementing proper SSL certificate verification
mechanisms. Depending on the specific implementation requirements, this could
include:
Ensuring that checkClientTrusted() and checkServerTrusted() methods perform
appropriate certificate validation.
Enabling hostname verification to match the server's certificate with the intended
hostname.
Avoiding the use of ALLOW_ALL_HOSTNAME_VERIFIER to prevent bypassing hostname
verification.
Risk Assessment:
Failure to properly verify server certificates in SSL/TLS communication can lead to
significant security risks, including man-in-the-middle attacks where an attacker
intercepts and manipulates the communication between the client and the server.
This can result in the exposure of sensitive user data, undermining the confidentiality
and integrity of the application's communication channels.
umask(002);
FILE *fp = fopen("/data/data/[Link]/[Link]", "a");
fprintf(fp, "Don't corrupt this content.\n");
fclose(fp);
S_IRGRP , and S_IWGRP flags, the file's access is restricted to user and group,
Risk Assessment:
Failure to properly set file permissions when creating files in native code may result in
files being accessible or modifiable by unauthorized users or applications. This can
lead to the exposure or corruption of sensitive data, posing significant security risks
to the application and its users.
Sensitive classes must not let themselves be copied
importance of preventing the copying of classes containing private, confidential, or
sensitive data. Failing to define proper copy mechanisms, such as a copy constructor,
can lead to security vulnerabilities, including unauthorized data access or
modification.
Noncompliant Code Example:
In the noncompliant code example, a class SensitiveClass is defined, containing a
character array for storing a file name and a Boolean variable for managing shared
access. However, the class lacks a copy constructor, allowing potential vulnerabilities
if the class is copied improperly.
COPY
class SensitiveClass {
private char[] filename;
private Boolean shared = false;
SensitiveClass(String filename) {
[Link] = [Link]();
}
Malicious Subclass:
A malicious subclass MaliciousSubclass is created, which extends SensitiveClass and
overrides the clone() method. This subclass allows unauthorized access and
modification of the sensitive data.
COPY
class SensitiveClass {
// ...
public final SensitiveClass clone() throws
CloneNotSupportedException {
throw new CloneNotSupportedException();
}
}
Risk Assessment:
Failure to prevent the copying of sensitive classes can result in unauthorized data
access or modification, leading to security vulnerabilities. Implementing proper copy
mechanisms or making classes noncopyable mitigates these risks and ensures the
integrity of sensitive data.
References
[Link]
Android Application Secure Design/Secure Coding Guidebook by Japan
Smartphone Security Association(JSSEC)
MORE ARTICLES
Reza Rashidi Reza Rashidi
Reza Rashidi
Attacking APIs
APIs (Application Programming
Interfaces) have become integral
components of modern software
systems…