APPLICATION SECURITY
(Threats and Malpractices)
Speaker: Dimitrios Valsamaras | @Ch0pin
Common Malpractices
Accessibility Service
The accessibility service provides user interface enhancements to assist users with disabilities, or who may temporarily be unable to fully interact with a device. For example, users who are driving, taking care of a young child might need additional or alternative interface feedback.
? ?
A powerful set of API calls, used by many popular apps including Google Assistant, Google maps, password managers, app lockers
but also from ….
Trojans, backdoors, bots, phishing apps e.t.c.
Accessibility Service from a security perspective
An application for which the accessibility service has been granted can run in the background and…
… Pretty much, it can act in behalf of the user
Accessibility Service - How to enable (Android 10)
Settings → Accessibility →
Click on the app →
Use Service→ Allow
Accessibility Service - Implementation
Implementation Class
Intent filter
Permission
Configuration
AccessibilityService_accessibilityEventTypes: The event types this service would like to receive as specified in AccessibilityEvent. This setting can be changed at runtime by calling
Accessibility Service - Java Code Implementation
Override Required
Class name declared in the Manifest
Accessibility Service - Accessibility Event
Accessibility Service - View Hierarchy Example
Accessibility Service - Event Lifecycle
UI changed
Match ?
Ignore
No
Yes
Trigger Callback
Accessibility Service - Abuse
Accessibility Service - Abuse
Accessibility Service - Abuse, Overlays
Monitoring the API calls performed by the accessibility service implementation.
Accessibility Service - Abuse
Accessibility Service - Abuse
When correctly coordinated it can perform chain of actions to automate more complex tasks (e.g. screen recording)
Common Malpractices
Device Admin
Definition: The Device Administration API provides device administration features at the system level. These APIs allow you to create security-aware apps that are useful in enterprise settings, in which IT professionals require rich control over employee devices.
Device Admin
Device Admin - Implementation
DeviceAdminReceiver subclass
Permission
Filter
Device Admin - Callbacks
Permission
Common Malpractices
Java Reflection
Reflection is commonly used by programs which require the ability to examine or modify the runtime behavior of applications running in the Java virtual machine. This is a relatively advanced feature and should be used only by developers who have a strong grasp of the fundamentals of the language. With that caveat in mind, reflection is a powerful technique and can enable applications to perform operations which would otherwise be impossible.
Figure from: https://techvidvan.com/tutorials/reflection-in-java/
Java Reflection
Java Reflection
The Test class users reflection to get the ReflectionDemo class characteristics and invoke its defined methods.
Java Reflection - Misuse
Example: “java.lang.Runtime” , “1”
Can be used to “hide” suspicious API calls
[PGP.]P_V.cD_EX\T
Return
Class cls = Class.forName(decrypt(“[PGP.]P_V.cD_EX\T”));
Common Malpractices
Dynamic Code Loading - DCL
DCL(Dynamic code loading) allows an application to load code that is not part of its static, initial codebase. The additional code can be retrieved from a remote location and executed at runtime.
Dynamic Code Loading - Implementation
DexClassLoader(String dexPath, String optimizedDirectory, String librarySearchPath, ClassLoader parent)
dexPath | String: the list of jar/apk files containing classes and resources, delimited by File.pathSeparator, which defaults to ":" on Android |
optimizedDirectory | String: this parameter is deprecated and has no effect since API level 26. |
librarySearchPath | String: the list of directories containing native libraries, delimited by File.pathSeparator; may be null |
parent | ClassLoader: the parent class loader |
Dynamic Code Loading - Implementation
Fetch the dex, jar, apk e.t.c
String dexPath = context.getFilesDir().getAbsolutePath() + “/” +"dexPath.dex";
Final DexClassLoader nClazz = new DexClassLoader(dexPath,mContext.getCodeCacheDir().getAbsolutePath(), null,getClass().getClassLoader()).loadClass(clazz);
DexClassLoader(String dexPath, String optimizedDirectory, String librarySearchPath, ClassLoader parent)
Dynamic Code Loading - what is wrong with this ?
Dynamic Code Loading - what is wrong with this ?