1 of 32

APPLICATION SECURITY

(Threats and Malpractices)

Speaker: Dimitrios Valsamaras | @Ch0pin

2 of 32

Common Malpractices

  • Webviews
  • Floating Windows
  • Accessibility Service
  • Administration API
  • Reflection
  • Dynamic Code Loading

3 of 32

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.

4 of 32

Accessibility Service from a security perspective

An application for which the accessibility service has been granted can run in the background and…

  • Read the UI of any other application
  • Parse the entire Android UI to check which layouts are in the screen
  • Check whether the screen has changed or the screen content has changed
  • Read notifications coming from/for any application
  • Perform Clicks / Swipes
  • Set text to textviews

… Pretty much, it can act in behalf of the user

5 of 32

Accessibility Service - How to enable (Android 10)

Settings → Accessibility →

Click on the app →

Use Service→ Allow

6 of 32

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

7 of 32

Accessibility Service - Java Code Implementation

Override Required

Class name declared in the Manifest

8 of 32

Accessibility Service - Accessibility Event

  • An accessibility event is fired by an individual view which populates the event with data for its state and requests from its parent to send the event to interested parties. The parent can optionally modify or even block the event based on its broader understanding of the user interface's context.

  • The main purpose of an accessibility event is to communicate changes in the UI to an AccessibilityService.

  • The service may inspect, if needed the user interface by examining the View hierarchy, as represented by a tree of AccessibilityNodeInfo (snapshot of a View state) which can be used for exploring the window content.

9 of 32

Accessibility Service - View Hierarchy Example

10 of 32

Accessibility Service - Event Lifecycle

UI changed

Match ?

Ignore

No

Yes

Trigger Callback

11 of 32

Accessibility Service - Abuse

  • Flutbot Abuses the accessibility service to get the foreground app.

  • If the application is in its target list, it will trigger an overlay which will cover the legitimate application with a fake one

  • After getting the credentials inserted to the fake view, it sends them to a Command and Control server

12 of 32

Accessibility Service - Abuse

  • Overlays targeting legitimate applications

13 of 32

Accessibility Service - Abuse, Overlays

Monitoring the API calls performed by the accessibility service implementation.

14 of 32

Accessibility Service - Abuse

  • Click
  • Home

15 of 32

Accessibility Service - Abuse

  • log typed keys (keyloggers)

  • auto-enable permissions

  • auto-enable access to services

When correctly coordinated it can perform chain of actions to automate more complex tasks (e.g. screen recording)

16 of 32

Common Malpractices

  • Webviews
  • Floating Windows
  • Accessibility Service
  • Administration API
  • Reflection
  • Dynamic Code Loading

17 of 32

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.

18 of 32

Device Admin

  • Set password quality.
  • Specify requirements for the user's password, such as minimum length, the minimum number of numeric characters it must contain, and so on.
  • Set the password. If the password does not conform to the specified policies, the system returns an error.
  • Set how many failed password attempts can occur before the device is wiped (that is, restored to factory settings).
  • Set how long from now the password will expire.
  • Set the password history length (length refers to number of old passwords stored in the history). This prevents users from reusing one of the last n passwords they previously used.
  • Specify that the storage area should be encrypted, if the device supports it.
  • Set the maximum amount of inactive time that can elapse before the device locks.
  • Make the device lock immediately.
  • Wipe the device's data (that is, restore factory settings).
  • Disable the camera.

19 of 32

Device Admin - Implementation

DeviceAdminReceiver subclass

Permission

Filter

20 of 32

Device Admin - Callbacks

Permission

21 of 32

Common Malpractices

  • Webviews
  • Floating Windows
  • Accessibility Service
  • Administration API
  • Reflection
  • Dynamic Code Loading

22 of 32

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.

23 of 32

Java Reflection

24 of 32

Java Reflection

The Test class users reflection to get the ReflectionDemo class characteristics and invoke its defined methods.

25 of 32

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));

26 of 32

Common Malpractices

  • Webviews
  • Floating Windows
  • Accessibility Service
  • Administration API
  • Reflection
  • Dynamic Code Loading

27 of 32

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.

  • Code Reuse

  • Extensibility

  • Self-upgrade

28 of 32

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

29 of 32

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)

30 of 32

Dynamic Code Loading - what is wrong with this ?

31 of 32

Dynamic Code Loading - what is wrong with this ?

  • Name can be encrypted
  • Content can be encrypted

32 of 32

References