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
play-integrity-attestation-bypass.mdMarkdown149 lines14.4 KiBsource raw download

title: "Play Integrity Attestation Bypass (SafetyNet Replacement)" section: "Mobile" sectionSlug: "mobile-pentesting" sourcePath: "src/mobile-pentesting/android-app-pentesting/play-integrity-attestation-bypass.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/mobile-pentesting/android-app-pentesting/play-integrity-attestation-bypass.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

Play Integrity Attestation Bypass (SafetyNet Replacement)#

What Play Integrity Does#

Play Integrity is Google’s SafetyNet successor for app attestation. The app requests an integrity token and forwards the encrypted token to its backend. The backend sends it to playintegrity.googleapis.com/v1/PACKAGE_NAME:decodeIntegrityToken (or uses the supported Google API client library), then validates the returned verdict and binds it to the protected request. When Google manages response encryption, the application backend should not attempt to decrypt the token locally.[10][12]

Key verdict flags commonly enforced:[1]

Bypass Model#

Instead of forging Google’s JWT, spoof the signals Google evaluates so they correspond to a different, legitimate device profile. The attack chain:[1]

  1. Hide root so local checks and Play Services probes don’t see Magisk/su.
  2. Replace the key attestation certificate chain (keybox.xml) with one from a genuine device so Play Integrity sees a certified/locked device.
  3. Spoof the security patch level to satisfy MEETS_STRONG_INTEGRITY.

Google mitigates by revoking abused keyboxes; rotation is required when a keybox is blocked.[1]

Prerequisites & Tooling#

Achieve MEETS_BASIC_INTEGRITY + MEETS_DEVICE_INTEGRITY#

  1. Install modules & reboot: Flash TrickyStore and Tricky Addon in Magisk, reboot.[1]
  2. Configure TrickyStore (via KSU Web UI): Select TrickyStore → Select All → Deselect Unnecessary → Save.
  3. Inject a valid keybox: In Keybox, choose Valid to download/apply a new keybox.xml (vendor attestation credentials). This file underpins hardware key attestation and is now spoofed from a certified/locked device.
  4. Verify: Run Play Integrity API Checker → MEETS_BASIC_INTEGRITY and MEETS_DEVICE_INTEGRITY should pass. In Key Attestation the bootloader appears locked because the attestation chain is replaced.

Achieve MEETS_STRONG_INTEGRITY (Patch-Level Spoof)#

STRONG fails on outdated patch levels. TrickyStore can spoof a modern security patch date for all partitions:[1]

  1. In TrickyStore, pick Set Security Patch → Get Security Patch Date → Save.
  2. Re-run Play Integrity API Checker; MEETS_STRONG_INTEGRITY should now pass.

Practical Tester Angles Against Weak Integrations#

Even when you cannot permanently recover DEVICE/STRONG, many app backends still misuse the API. During testing, look for:[10]

Emerging Technique: Remote Key Attestation (RKA)#

A newer evolution is to relay the attestation request to another Android device instead of copying keybox.xml onto every client device. The usual flow is:[11]

  1. Intercept the local Key Attestation / Play Integrity request before it reaches the TEE/KeyStore path.
  2. Forward the nonce / app identity / request details to a remote rooted host.
  3. Let that host generate the attestation response using either an unrevoked legacy keybox or a genuinely vulnerable device whose boot chain still reports a locked state.
  4. Return the attestation blob to the client app/backend.

Why it matters for testers:[11]

This is where the ecosystem is moving: Remote Key Provisioning (RKP) reduces the long-term value of leaked static keyboxes, but it does not fully remove relay-style attacks when the attacker controls a privileged or exploited host device.[11]

Hardware Attestation Clean-Device Relay#

This variant targets applications that treat a valid Android Keystore X.509 attestation chain as a Boolean device-integrity result; it is distinct from forging a Play Integrity token. OID 1.3.6.1.4.1.11129.2.1.17 proves that some acceptable TEE/StrongBox generated the leaf key for attestationChallenge, but it does not bind that hardware to the process or network session presenting the chain. Consequently, even signature validation, Google-root pinning, freshness, revocation, security-level, deviceLocked=true, and verifiedBootState=Verified checks can all pass on relayed evidence because those claims are genuine for the oracle phone.[11][13][15]

A practical clean-device relay works as follows:[13][14]

  1. Instrument the rooted target process and capture the backend's raw challenge before local key generation.
  2. Re-encode it as unpadded Base64URL (android.util.Base64: NO_PADDING | NO_WRAP | URL_SAFE, or 1 | 2 | 8) and send POST /attest with {"nonce":"..."} to a stock, locked phone.
  3. On that phone, generate an ephemeral secp256r1 AndroidKeyStore signing key with SHA-256 and .setAttestationChallenge(challenge); request StrongBox if policy requires it, then export KeyStore.getCertificateChain(alias) as Base64 DER.
  4. Inject that chain into the target using the exact application-specific Java/Kotlin return type. Do not call the original local method, or the rooted phone will generate its own failing RootOfTrust.

The highest-level method that accepts ByteArray and returns an attestation wrapper is usually the safest seam. The following shortened Frida 17-style pattern synchronously relays the challenge and reconstructs the expected object; the controller must always post a response (even an empty array after an HTTP error) or op.wait() deadlocks the application thread.[13][14]

import Java from 'frida-java-bridge';
Java.perform(() => {
  const K = Java.use('com.target.KeystoreAttestation');
  const Result = Java.use('com.target.AttestedKey');
  const B64 = Java.use('android.util.Base64');
  const ArrayList = Java.use('java.util.ArrayList');
  K.generateAttestedKey.overload('[B').implementation = challenge => {
    send({event: 'attestation_request', nonce: B64.encodeToString(challenge, 1 | 2 | 8)});
    let chain = []; const op = recv('response', m => { chain = m.payload ?? []; });
    op.wait();
    const remote = ArrayList.$new(); chain.forEach(cert => remote.add(cert));
    return Result.$new(remote, 'relayed', null);
  };
});

When the application has no convenient wrapper, hook KeyGenParameterSpec.Builder.setAttestationChallenge(byte[]) on input and java.security.KeyStore.getCertificateChain(String) on output. Track the key alias and per-request context so concurrent generations cannot pair one challenge with another chain.[13]

Boundary and backend checks#

A chain-only relay does not copy the oracle's private key. Requiring a signature over fresh session-, challenge-, and transaction-specific data proves possession of the attested leaf key and forces an attacker to proxy every signing operation to the oracle, rather than reuse the initial certificate result.[13]

Also parse attestationApplicationId (authorization tag [709]) and compare the package name and SHA-256 signing-certificate digest with independently configured expected values. This blocks the simple cross-app oracle when it runs a different helper package; pair it with a hardware-enforced locked/Verified boot policy because application identity is platform-supplied rather than an independent physical-device binding.[13][15]

Operational Notes#

References#