Frida Tutorial 3

Reading time: 5 minutes

tip

Jifunze na fanya mazoezi ya AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Jifunze na fanya mazoezi ya GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Jifunze na fanya mazoezi ya Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Support HackTricks

Hii ni muhtasari wa chapisho: https://joshspicer.com/android-frida-1
APK: https://github.com/OWASP/owasp-mstg/blob/master/Crackmes/Android/Level_01/UnCrackable-Level1.apk

Suluhisho 1

Kulingana na https://joshspicer.com/android-frida-1

Hook the _exit()_ function na decrypt function ili iweze kuchapisha bendera kwenye frida console unapobofya verify:

javascript
Java.perform(function () {
send("Starting hooks OWASP uncrackable1...")

function getString(data) {
var ret = ""
for (var i = 0; i < data.length; i++) {
ret += "#" + data[i].toString()
}
return ret
}

var aes_decrypt = Java.use("sg.vantagepoint.a.a")
aes_decrypt.a.overload("[B", "[B").implementation = function (var_0, var_1) {
send(
"sg.vantagepoint.a.a.a([B[B)[B   doFinal(enc)  // AES/ECB/PKCS7Padding"
)
send("Key       : " + getString(var_0))
send("Encrypted : " + getString(var_1))
var ret = this.a.overload("[B", "[B").call(this, var_0, var_1)
send("Decrypted : " + getString(ret))

var flag = ""
for (var i = 0; i < ret.length; i++) {
flag += String.fromCharCode(ret[i])
}
send("Decrypted flag: " + flag)
return ret //[B
}

var sysexit = Java.use("java.lang.System")
sysexit.exit.overload("int").implementation = function (var_0) {
send("java.lang.System.exit(I)V  // We avoid exiting the application  :)")
}

send("Hooks installed.")
})

Solution 2

Based in https://joshspicer.com/android-frida-1

Hook rootchecks na decrypt function ili iweze kuchapisha bendera kwenye frida console unapobofya verify:

javascript
Java.perform(function () {
send("Starting hooks OWASP uncrackable1...")

function getString(data) {
var ret = ""
for (var i = 0; i < data.length; i++) {
ret += "#" + data[i].toString()
}
return ret
}

var aes_decrypt = Java.use("sg.vantagepoint.a.a")
aes_decrypt.a.overload("[B", "[B").implementation = function (var_0, var_1) {
send(
"sg.vantagepoint.a.a.a([B[B)[B   doFinal(enc)  // AES/ECB/PKCS7Padding"
)
send("Key       : " + getString(var_0))
send("Encrypted : " + getString(var_1))
var ret = this.a.overload("[B", "[B").call(this, var_0, var_1)
send("Decrypted : " + getString(ret))

var flag = ""
for (var i = 0; i < ret.length; i++) {
flag += String.fromCharCode(ret[i])
}
send("Decrypted flag: " + flag)
return ret //[B
}

var rootcheck1 = Java.use("sg.vantagepoint.a.c")
rootcheck1.a.overload().implementation = function () {
send("sg.vantagepoint.a.c.a()Z   Root check 1 HIT!  su.exists()")
return false
}

var rootcheck2 = Java.use("sg.vantagepoint.a.c")
rootcheck2.b.overload().implementation = function () {
send("sg.vantagepoint.a.c.b()Z  Root check 2 HIT!  test-keys")
return false
}

var rootcheck3 = Java.use("sg.vantagepoint.a.c")
rootcheck3.c.overload().implementation = function () {
send("sg.vantagepoint.a.c.c()Z  Root check 3 HIT!  Root packages")
return false
}

var debugcheck = Java.use("sg.vantagepoint.a.b")
debugcheck.a.overload("android.content.Context").implementation = function (
var_0
) {
send("sg.vantagepoint.a.b.a(Landroid/content/Context;)Z  Debug check HIT! ")
return false
}

send("Hooks installed.")
})

Solution 3 – frida-trace (Frida ≥ 16)

Ikiwa hutaki kuandika mikono, unaweza kuruhusu Frida izalishe stubs za Java kwako na kisha uzihariri:

bash
# Spawn the application and automatically trace the Java method we care about
aadb shell "am force-stop owasp.mstg.uncrackable1"
frida-trace -U -f owasp.mstg.uncrackable1 \
-j 'sg.vantagepoint.a.a.a("[B","[B")[B' \
-j 'sg.vantagepoint.a.c!*' \
--output ./trace

# The first run will create ./trace/scripts/sg/vantagepoint/a/a/a__B_B_B.js
# Edit that file and add the logic that prints the decrypted flag or
# returns a constant for the root-checks, then:
frida -U -f owasp.mstg.uncrackable1 -l ./trace/_loader.js --no-pause

Na Frida 16+ stub inayozalishwa tayari inatumia sintaksia ya kisasa ya ES6 na itakusanywa na QuickJS runtime iliyojengwa – hauhitaji tena frida-compile.


Suluhisho 4 – Mstari mmoja na Objection (2024)

Ikiwa una Objection >1.12 iliyosakinishwa unaweza kutupa bendera kwa amri moja (Objection inazunguka Frida ndani):

bash
objection -g owasp.mstg.uncrackable1 explore \
--startup-command "android hooking watch class sg.vantagepoint.a.a method a \n  && android hooking set return_value false sg.vantagepoint.a.c * \n  && android hooking invoke sg.vantagepoint.a.a a '[B' '[B'"
  • watch class inachapisha maandiko ya wazi yanayorejeshwa na utaratibu wa AES
  • set return_value false inalazimisha kila ukaguzi wa root / debugger kuripoti false
  • invoke inakuwezesha kuita njia moja kwa moja bila kubonyeza Verify.

KUMBUKA: Kwenye Android 14 (API 34) lazima uendeshe Objection/Frida katika spawn mode (-f) kwa sababu attach imezuiwa na vizuizi vya seccomp-bpf vilivyoanzishwa mnamo Oktoba 2024.


Maelezo ya kisasa ya Android (2023 - 2025)

  • libsu 5.x na Zygisk huficha su vizuri; hata hivyo, ukaguzi wa msingi wa Java katika Kiwango cha 1 bado unashindwa ikiwa faili /system/bin/su ipo. Hakikisha unawasha denylist au tu ung'anishe java.io.File.exists() na Frida.
  • Frida 16.1 ilirekebisha ajali kwenye Android 12/13 iliyosababishwa na mpangilio wa Scudo wa Google. Ikiwa unaona Abort message: 'missing SHADOW_OFFSET', sasisha Frida (au tumia toleo la usiku la 17.0 lililotengenezwa mapema).
  • Kwa sababu Play Integrity ilichukua nafasi ya SafetyNet mnamo 2023, baadhi ya programu mpya zinaita API ya com.google.android.gms.tasks.Task. Kiwango cha 1 HAKIFANYI hivyo, lakini mkakati sawa wa ung'aniko ulioonyeshwa hapa unafanya kazi – ung'anisha com.google.android.gms.safetynet.SafetyNetClient na urudishe EvaluationType iliyotengenezwa.

Marejeleo

  • Tangazo la toleo la Frida – "Frida 16.0 (2023-04-02): Marekebisho ya kuaminika ya Android 12/13 & marekebisho ya API ya spawn"
  • Objection 1.12 – "Hali ya spawn pekee kwa Android 14" (Slides za mazungumzo ya BlackHat USA 2024)

tip

Jifunze na fanya mazoezi ya AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Jifunze na fanya mazoezi ya GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Jifunze na fanya mazoezi ya Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Support HackTricks