
Un tool di analisi malware Android che crea profili runtime completi intercettando il comportamento delle applicazioni attraverso crittografia, file system, database, comunicazioni di rete e operazioni sui processi.
Android Binary API Tracer
Dexray Intercept fa parte della Sandbox dinamica Sandroid. Il suo scopo è creare profili di runtime per tracciare il comportamento di un'applicazione Android. Questo viene fatto utilizzando frida.
Basta installarlo con pip:
python3 -m pip install dexray-intercept
Questo installerà Dexray Intercept come strumento da riga di comando ammm o dexray-intercept.
Inoltre fornirà un pacchetto dexray_intercept. Maggiori informazioni su come utilizzare il pacchetto sono riportate di seguito.
Assicurati che il tuo dispositivo Android sia rootato. Il frida-server verrà installato automaticamente all'ultima versione. Poi puoi utilizzare Dexray Intercept semplicemente invocando il seguente comando:
dexray-intercept <target app>
# or using its old name:
ammm <target app>
Tutti gli hook sono disabilitati per impostazione predefinita per prestazioni ottimali. Abilita gli hook in base alle tue esigenze di analisi:
# Enable specific hooks
dexray-intercept --enable-aes <app_name> # Enable AES crypto hooks
dexray-intercept --enable-web <app_name> # Enable web/HTTP hooks
dexray-intercept --enable-aes --enable-web <app_name> # Enable multiple hooks
# Enable hook groups
dexray-intercept --hooks-crypto <app_name> # Enable all crypto hooks
dexray-intercept --hooks-network <app_name> # Enable all network hooks
dexray-intercept --hooks-filesystem <app_name> # Enable all file system hooks
# Enable all hooks (performance impact)
dexray-intercept --hooks-all <app_name> # Enable all available hooks
# Use package identifier instead of app name
dexray-intercept -s com.example.package --hooks-crypto
--hooks-crypto (AES, encodings, keystore, certificates)--hooks-network (HTTP, sockets, SSL/TLS)--hooks-filesystem (file operations, databases, shared preferences)--hooks-ipc (intents, broadcasts, binder, shared preferences)--hooks-process (DEX unpacking, native libraries, runtime)--hooks-services (camera, location, telephony, bluetooth)Ecco un esempio di monitoraggio dell'app chrome sul nostro AVD:
dexray-intercept Chrome
Dexray Intercept
⠀⠀⠀⠀⢀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠙⢷⣤⣤⣴⣶⣶⣦⣤⣤⡾⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⠾⠛⢉⣉⣉⣉⡉⠛⠷⣦⣄⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⠋⣠⣴⣿⣿⣿⣿⣿⡿⣿⣶⣌⠹⣷⡀⠀⠀
⠀⠀⠀⠀⣼⣿⣿⣉⣹⣿⣿⣿⣿⣏⣉⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠁⣴⣿⣿⣿⣿⣿⣿⣿⣿⣆⠉⠻⣧⠘⣷⠀⠀
⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡇⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⠈⠀⢹⡇⠀
⣠⣄⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⣠⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⢸⣿⠛⣿⣿⣿⣿⣿⣿⡿⠃⠀⠀⠀⠀⢸⡇⠀
⣿⣿⡇⢸⣿⣿⣿Sandroid⣿⣿⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣷⠀⢿⡆⠈⠛⠻⠟⠛⠉⠀⠀⠀⠀⠀⠀⣾⠃⠀
⣿⣿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣧⡀⠻⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⠃⠀⠀
⣿⣿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢼⠿⣦⣄⠀⠀⠀⠀⠀⠀⠀⣀⣴⠟⠁⠀⠀⠀
⣿⣿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣦⠀⠀⠈⠉⠛⠓⠲⠶⠖⠚⠋⠉⠀⠀⠀⠀⠀⠀
⠻⠟⠁⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠈⠻⠟⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠉⠉⣿⣿⣿⡏⠉⠉⢹⣿⣿⣿⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⢀⣄⠈⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠈⠉⠉⠀⠀⠀⠀⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
[*] starting app profiling
[*] press Ctrl+C to stop the profiling ...
[*] Filesystem profiling informations:
[*] [Libc::read] Read FD (anon_inode:[eventfd],0x7ac6b67540,8)
[*] Filesystem profiling informations:
[*] [Libc::read] Read FD (anon_inode:[eventfd],0x7fcb41c990,8
Installa Dexray Intercept come pacchetto e utilizza la nuova architettura modulare:
from dexray_intercept import AppProfiler, setup_frida_device
from dexray_intercept.services.hook_manager import HookManager
# Connect to device and get process
device = setup_frida_device()
process = device.attach("com.example.app")
# Configure hooks (all disabled by default for performance)
hook_config = {
'aes_hooks': True,
'web_hooks': True,
'file_system_hooks': True,
'keystore_hooks': True
}
# Create profiler with new architecture
profiler = AppProfiler(
process,
verbose_mode=True,
output_format="JSON",
hook_config=hook_config,
enable_stacktrace=True
)
# Start profiling
script = profiler.start_profiling()
# ... let app run and collect data ...
# Get results
profile_data = profiler.get_profile_data()
json_output = profiler.get_profiling_log_as_json()
# Runtime hook management
profiler.enable_hook('socket_hooks', True) # Enable more hooks at runtime
enabled_hooks = profiler.get_enabled_hooks() # Check what's enabled
# Stop profiling
profiler.stop_profiling()
Abilita gruppi specifici di hook in base alle tue esigenze di analisi:
# Crypto hooks
hook_config = {
'aes_hooks': True,
'encodings_hooks': True,
'keystore_hooks': True
}
# Network hooks
hook_config = {
'web_hooks': True,
'socket_hooks': True
}
# File system hooks
hook_config = {
'file_system_hooks': True,
'database_hooks': True
}
# Enable all hooks (performance impact)
profiler.enable_all_hooks()
# Enable hook groups
profiler.enable_hook_group('crypto') # Enable all crypto-related hooks
La vecchia API è ancora disponibile per la compatibilità all'indietro:
from dexray_intercept import AppProfilerLegacy
# OR use environment variable: DEXRAY_FORCE_OLD_ARCH=true
profiler = AppProfilerLegacy(process_session, verbose=True, output_format="CMD",
base_path=None, deactivate_unlink=False)
profiler.instrument() # Old method name
# ...
profiler.finish_app_profiling() # Old method name
Per eseguirlo come pacchetto in Sandroid assicurati di aver installato anche il JobManager da AndroidFridaManager. Questo permette di eseguire più sessioni frida in thread diversi.
Tutto ciò che devi fare è eseguire il seguente codice:
from AndroidFridaManager import JobManager
from dexray_intercept import AppProfiler
job_manager = JobManager()
app_package = "net.classwindexampleyear.bookseapiececountry"
profiler = AppProfiler(job_manager.process_session, True, output_format="JSON", base_path=None, deactivate_unlink=False)
frida_script_path = profiler.get_frida_script()
job_manager.setup_frida_session(app_package, profiler.on_appProfiling_message)
job = job_manager.start_job(frida_script_path, custom_hooking_handler_name=profiler.on_appProfiling_message)
# close only the job and the frida session keeps active to run other frida scripts
# job_manager.stop_job_with_id(job.job_id)
job_manager.stop_app_with_closing_frida(app_package) # stops the frida session and the app and all frida jobs
profiler.write_profiling_log() # write the log data to profile.json
# instead of writing it to a file the JSON output will just be returned
# profiler.get_profiling_log_as_JSON()
Assicurati che nessun'altra parte del tuo codice stia tentando di connettersi al server frida (nessun'altra sessione frida).
Per testare questo puoi provare il seguente esempio: catelites_2018_01_19.apk. Il nome del pacchetto è net.classwindexampleyear.bookseapiececountry. Assicurati che il tuo AVD sia in esecuzione su Android 9, in modo che il campione possa eseguire tutto il suo codice malevolo. Puoi installare questo campione semplicemente con adb install samples/unpacking/catelites_2018_01_19.apk.
Per compilare questo progetto assicurati che npm e frida-compile siano in esecuzione sul tuo sistema e installati nel tuo path. Dalla versione 17.0 di frida, frida-compile viene installato tramite pip install frida-tools.
Poi basta invocare il seguente comando per ottenere l'ultimo frida agent compilato:
$ cd <AppProfiling-Project>
> Dexray [email protected] build
> frida-compile agent/hooking_profile_loader.ts -o src/dexray_intercept/profiling.js
$ npm install frida-java-bridge@latest --save
$ npm install --save-dev @types/frida-gum@latest
> Dexray [email protected] prepare
> npm run build
up to date, audited 75 packages in 6s
19 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Questo assicura che gli ultimi script/hook frida vengano utilizzati in dexray-intercept.
Per apportare modifiche al codice python si consiglia di installare dexray-intercept con pip utilizzando la modalità editable:
python3 -m pip install -e .
In questo modo le modifiche locali al codice python vengono riflesse senza creare una nuova versione del pacchetto.
È disponibile una documentazione completa che copre installazione, utilizzo, riferimento API e sviluppo:
Invocando semplicemente il seguente comando in questa directory, setup.py dovrebbe essere utilizzato per installare dexray-intercept come pacchetto python locale sul tuo sistema:
python3 -m pip install .
Per compilare gli hook frida in TypeScript abbiamo bisogno del progetto frida-compile (link). Che sarà incluso in frida-tools.
python3 -m pip install frida-tools
Oltre a questo abbiamo bisogno anche del supporto per frida-java-bridge e i tipi interni di frida:
npm install frida-java-bridge@latest --save
npm install --save-dev @types/frida-gum@latest
Durante l'unpacking, le applicazioni possono caricare DexCode—precedentemente puntato a blocchi di memoria distinti—in un DexFile, che rappresenta il codice in esecuzione. Ad esempio, alcune applicazioni possono ripristinare le istruzioni immediatamente prima dell'esecuzione. In questi casi, Sandroid non è in grado di ripristinare le istruzioni nel DexFile. Sono necessarie ulteriori ricerche per risolvere questo problema
Dexray Intercept si basa sull'eccellente lavoro di vari progetti open-source e ricercatori nella comunità della sicurezza Android e dell'analisi dinamica. Vorremmo ringraziare i seguenti progetti che hanno ispirato o contribuito alla nostra implementazione:
Estendiamo la nostra gratitudine a questi progetti e ai loro manutentori per aver fatto avanzare lo stato dell'analisi della sicurezza Android e per aver reso il loro lavoro disponibile alla comunità.