repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
inputmethodservice-ime-abuse.mdMarkdown99 lines4.8 KiBrendered raw download
---
title: "Android IME / InputMethodService Abuse (Malicious Keyboards)"
section: "Mobile"
sectionSlug: "mobile-pentesting"
sourcePath: "src/mobile-pentesting/android-app-pentesting/inputmethodservice-ime-abuse.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/mobile-pentesting/android-app-pentesting/inputmethodservice-ime-abuse.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---

# Android IME / InputMethodService Abuse (Malicious Keyboards)

## Overview

Android allows third-party keyboards through `InputMethodService` (IME). Once a user **enables** a keyboard and selects it as the **current input method**, it participates in text entry across apps and can observe or influence much of the text sent through its input connection. Password fields can request reduced learning/suggestions, but applications must not treat an enabled third-party IME as a trusted boundary.<sup>[[1]](#references)</sup><sup>[[2]](#references)</sup>

This is why some Android banking trojans bundle or enable a custom keyboard: the malicious IME can receive keystrokes from target apps that never embed a `WebView`, including banking, chat, and wallet applications.<sup>[[4]](#references)</sup>

> [!NOTE]
> `android.permission.BIND_INPUT_METHOD` is declared on the IME *service* so only the system can bind to it. Declaring it does not grant the app blanket access by itself; the key step is getting the victim to **enable and select** the keyboard in Settings.<sup>[[1]](#references)</sup>

## Manifest declaration

A keyboard is exposed via a service with the `android.view.InputMethod` intent action and an IME configuration XML:

```xml
<!-- AndroidManifest.xml -->
<service
    android:name=".SpyKeyboard"
    android:permission="android.permission.BIND_INPUT_METHOD"
    android:exported="false">

    <intent-filter>
        <action android:name="android.view.InputMethod" />
    </intent-filter>

    <meta-data
        android:name="android.view.im"
        android:resource="@xml/spy_ime" />
</service>
```

**Hunting tip:** a non-keyboard-looking app that declares an `InputMethodService` is a strong red flag.

## Where the data comes from

At runtime an IME learns:

- The **target app** being typed into (via `EditorInfo`, e.g. `attribute.packageName` in `onStartInput`).
- The text being entered (through the IME’s interaction with the current `InputConnection` and/or key events depending on the implementation).

Minimal (non-functional) sketch of the high-signal hook point:

```java
public class SpyKeyboard extends InputMethodService {
  @Override public void onStartInput(EditorInfo attribute, boolean restarting) {
    // attribute.packageName identifies the foreground app receiving input
  }
}
```

## Common enablement & collection workflow (observed in the wild)

- The APK is marketed as a “secure keyboard” or the keyboard is embedded inside a broader trojan.<sup>[[4]](#references)</sup>
- The malware drives the victim into the system keyboard settings (for example, by launching `Settings.ACTION_INPUT_METHOD_SETTINGS` and/or using UI automation) until the IME is enabled and set as default.<sup>[[3]](#references)</sup>
- Keystrokes are buffered per-app and exfiltrated via the malware’s existing C2 channel, often combined with other data sources (e.g., `WebView` man-in-the-browser telemetry).

## How to detect / triage

### On-device checks

- **Settings**: Installed keyboards / default keyboard (look for unknown IMEs).
- **ADB**:

```bash
adb shell dumpsys input_method
adb shell ime list -a
adb shell ime help
```

### Static triage of an APK

- Look for `InputMethodService` classes and the `android.view.InputMethod` intent filter.
- Inspect `@xml/*` IME config referenced by `android.view.im`.
- Check whether the app’s stated functionality matches shipping a full keyboard UI/resources.

## Mitigations

- **User/MDM**: allowlist trusted keyboards; block unknown IMEs in managed profiles/devices.
- **App-side (high risk apps)**: prefer phishing-resistant auth (passkeys/biometrics) and avoid relying on “secret text entry” as a security boundary (a malicious IME sits below the app UI).

## References

- [1] [Android Developers - Creating an input method](https://developer.android.com/develop/ui/views/touch-and-input/creating-input-method)
- [2] [Android Developers - `EditorInfo.inputType`](https://developer.android.com/reference/android/view/inputmethod/EditorInfo#inputType)
- [3] [Android Developers - `Settings.ACTION_INPUT_METHOD_SETTINGS`](https://developer.android.com/reference/android/provider/Settings#ACTION_INPUT_METHOD_SETTINGS)
- [4] [Intel 471 - BlankBot custom `InputMethodService` keyboard](https://www.intel471.com/blog/blankbot-a-new-android-banking-trojan-with-screen-recording-keylogging-and-remote-control-capabilities)