Skip to content

Commit a135b89

Browse files
authored
Merge pull request #1637 from HackTricks-wiki/update_Return_of_ClayRat__Expanded_Features_and_Technique_20251205_182607
Return of ClayRat Expanded Features and Techniques
2 parents 3ddb8ee + 2864fd1 commit a135b89

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

src/mobile-pentesting/android-app-pentesting/accessibility-services-abuse.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,28 @@ Modern Android banking Trojans and Remote-Access-Trojans (RATs) such as **PlayPr
1818

1919
---
2020

21+
### Packed Accessibility droppers
22+
23+
ClayRat v3.0.8 couples its Accessibility RAT with a staged payload hidden under `assets/`. At runtime the host APK:
24+
25+
1. Streams the encrypted blob from `assets/*.dat`.
26+
2. Decrypts it with a hard-coded AES/CBC key + IV embedded inside the Java/Kotlin loader.
27+
3. Writes the plaintext DEX to the app's private dir and loads it via `DexClassLoader`, exposing the actual spyware classes only in memory.
28+
29+
```java
30+
byte[] blob = readAsset("payload.enc");
31+
Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
32+
SecretKeySpec key = new SecretKeySpec(hex("A1..."), "AES");
33+
c.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
34+
byte[] dex = c.doFinal(blob);
35+
DexClassLoader cl = new DexClassLoader(writeTemp(dex), getCodeCacheDir().getPath(), null, getClassLoader());
36+
cl.loadClass("com.clayrat.Core").newInstance();
37+
```
38+
39+
This packing pattern (ATT&CK T1406.002) keeps the Accessibility module off-disk until the dropper executes, defeating static signature scans and Play Protect until the user already granted the dangerous permissions.
40+
41+
---
42+
2143
## Requesting the permission
2244

2345
```xml
@@ -53,6 +75,9 @@ The companion XML defines how the fake dialog will look like:
5375

5476
## Remote UI automation primitives
5577

78+
<details>
79+
<summary>Accessibility service automation skeleton</summary>
80+
5681
```java
5782
public class EvilService extends AccessibilityService {
5883
@Override
@@ -74,6 +99,8 @@ public class EvilService extends AccessibilityService {
7499
}
75100
```
76101

102+
</details>
103+
77104
With only these two APIs an attacker can:
78105
* Unlock the screen, open the banking app, navigate its UI tree and submit a transfer form.
79106
* Accept every permission dialog that pops up.
@@ -99,11 +126,62 @@ The victim types credentials into the fake form while the background app receive
99126

100127
> Detailed example: the *Accessibility Overlay Phishing* section inside the Tapjacking page.
101128
129+
ClayRat exposes this capability with the `show_block_screen` / `hide_block_screen` commands that download overlay templates from the C2. Operators can switch layouts on the fly to:
130+
131+
- **Black out** the panel so the victim assumes the handset is off or frozen while automated gestures disable Play Protect or grant more permissions.
132+
- Display fake **system update / battery optimization** panels that justify why the device is “busy” while background automation continues.
133+
- Show an **interactive PIN pad** overlay that mirrors the system lock screen—the malware captures every digit and streams it to the operator as soon as a 4‑digit code is entered.
134+
135+
Because TYPE_ACCESSIBILITY_OVERLAY windows never raise the `SYSTEM_ALERT_WINDOW` permission prompt, the victim only sees the decoy UI while the RAT keeps interacting with the real apps underneath.
136+
102137
### 2. On-Device Fraud automation
103138
Malware families such as **PlayPraetor** maintain a persistent WebSocket channel where the operator can issue high-level commands (`init`, `update`, `alert_arr`, `report_list`, …). The service translates those commands into the low-level gestures above, achieving real-time unauthorized transactions that easily bypass multi-factor-authentication tied to that very device.
104139

105140
### 3. Screen streaming & monitoring
106-
By combining the **MediaProjection API** with an RTMP client library, the RAT can broadcast the live framebuffer to `rtmp://<c2>:1935/live/<device_id>`, giving the adversary perfect situational awareness while the Accessibility engine drives the UI.
141+
ClayRat upgrades the usual MediaProjection trick into a remote desktop stack:
142+
143+
1. `turbo_screen` triggers the MediaProjection consent dialog; the Accessibility service clicks “Start now” so the victim never intervenes.
144+
2. With the resulting `MediaProjection` token it creates a `VirtualDisplay` backed by an `ImageReader`, keeps a `ForegroundService` alive, and drains frames on worker threads.
145+
3. Frames are JPEG/PNG encoded according to the operator-supplied `set_quality` parameter (defaults to `60` when missing) and shipped over an HTTP→WebSocket upgrade advertising the custom `ClayRemoteDesktop` user-agent.
146+
4. `start_desktop` / `stop_desktop` manage the capture threads while `screen_tap`, `screen_swipe`, `input_text`, `press_home`, `press_back` and `press_recents` replay gestures against the live framebuffer.
147+
148+
The result is a VNC-like feed delivered entirely through sanctioned APIs—no root or kernel exploits—yet it hands the attacker live situational awareness with millisecond latency.
149+
150+
### 4. Lock-screen credential theft & auto-unlock
151+
ClayRat subscribes to `TYPE_WINDOW_CONTENT_CHANGED` / `TYPE_VIEW_TEXT_CHANGED` events emitted by `com.android.systemui` (`Keyguard`). It reconstructs whatever guard is active:
152+
153+
- **PIN** – watches keypad button presses until the locker reports completion.
154+
- **Password** – concatenates strings seen in the focused password field for each `AccessibilityEvent`.
155+
- **Pattern** – records the ordered node indices inferred from gesture coordinates across the 3×3 grid.
156+
157+
Secrets plus metadata (lock type + timestamp) are serialized into `SharedPreferences` under `lock_password_storage`. When the operator pushes `auto_unlock`, the service wakes the device with `unlock_device` / `screen_on`, replays the stored digits or gestures through `dispatchGesture`, and silently bypasses the keyguard so subsequent ODF workflows can continue.
158+
159+
### 5. Notification phishing & harvesting
160+
A companion Notification Listener turns the shade into a phishing surface:
161+
162+
- `get_push_notifications` dumps every currently visible notification, including OTP / MFA messages.
163+
- The `notifications` command toggles a `notifications_enabled` flag so each future `onNotificationPosted()` payload is streamed to the C2 in real time.
164+
- `send_push_notification` lets operators craft fake, interactive notifications that impersonate banking or chat apps; any text the victim submits is parsed as credentials and exfiltrated immediately.
165+
166+
Because Accessibility can open/dismiss the notification shade programmatically, this method harvests secrets without touching the targeted apps.
167+
168+
### 6. Telephony & SMS command channel
169+
After coercing the user into setting the RAT as the default SMS app, the following commands provide complete modem control:
170+
171+
- `send_sms` and `retransmishion` send arbitrary or replayed messages to attacker-controlled numbers.
172+
- `messsms` iterates over the entire contacts database to spam phishing links for worm-like propagation.
173+
- `make_call` initiates voice calls that support social-engineering workflows.
174+
- `get_sms_list` / `get_sms` and `get_call_log` / `get_calls` dump inboxes and call history so MFA codes or call metadata can be abused instantly.
175+
176+
Combined with Accessibility-driven UI navigation, ClayRat can receive an OTP via notification/SMS and immediately input it inside the target banking or enterprise app.
177+
178+
### 7. Discovery, collection & proxying
179+
Additional ClayRat commands map the environment and keep C2 resilient:
180+
181+
- `get_apps` / `get_apps_list` enumerate installed packages (ATT&CK T1418).
182+
- `get_device_info` reports model, OS version and battery state (T1426).
183+
- `get_cam` / `get_camera` capture front-camera stills, while `get_keylogger_data` serializes lock PINs plus passwords, view descriptions and hints scraped from sensitive fields.
184+
- `get_proxy_data` fetches a proxy WebSocket URL, appends the unique device ID and spins a job that tunnels HTTP/HTTPS over the same bidirectional channel (T1481.002 / T1646).
107185

108186
---
109187

@@ -149,6 +227,9 @@ The **AccessibilityService** is the local engine that turns those cloud commands
149227
## ATS automation cheat-sheet (Accessibility-driven)
150228
Malware can fully automate a bank app with only Accessibility APIs. Generic primitives:
151229

230+
<details>
231+
<summary>Helper methods for ATS automation</summary>
232+
152233
```java
153234
// Helpers inside your AccessibilityService
154235
private List<AccessibilityNodeInfo> byText(String t){
@@ -174,6 +255,8 @@ private void tap(float x, float y){
174255
}
175256
```
176257

258+
</details>
259+
177260
Example flow (Czech → English labels):
178261
- "Nová platba" (New payment) → click
179262
- "Zadat platbu" (Enter payment) → click
@@ -238,6 +321,8 @@ Background and TTPs: https://www.threatfabric.com/blogs/ghost-tap-new-cash-out-t
238321
---
239322

240323
## References
324+
* [Return of ClayRat: Expanded Features and Techniques](https://zimperium.com/blog/return-of-clayrat-expanded-features-and-techniques)
325+
* [ClayRat v3 IoCs (Zimperium)](https://github.com/Zimperium/IOC/tree/master/2025-12-ClayRatv3)
241326
* [PlayPraetor’s evolving threat: How Chinese-speaking actors globally scale an Android RAT](https://www.cleafy.com/cleafy-labs/playpraetors-evolving-threat-how-chinese-speaking-actors-globally-scale-an-android-rat)
242327
* [Android accessibility documentation – Automating UI interaction](https://developer.android.com/guide/topics/ui/accessibility/service)
243328
* [The Rise of RatOn: From NFC heists to remote control and ATS (ThreatFabric)](https://www.threatfabric.com/blogs/the-rise-of-raton-from-nfc-heists-to-remote-control-and-ats)

0 commit comments

Comments
 (0)