mirror of
https://github.com/carlospolop/hacktricks
synced 2025-02-17 06:28:27 +00:00
152 lines
7.8 KiB
Markdown
152 lines
7.8 KiB
Markdown
# Tutorial de Frida 1
|
|
|
|
<details>
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
|
|
|
* ¿Trabajas en una **empresa de ciberseguridad**? ¿Quieres ver tu **empresa anunciada en HackTricks**? ¿O quieres tener acceso a la **última versión de PEASS o descargar HackTricks en PDF**? ¡Consulta los [**PLANES DE SUSCRIPCIÓN**](https://github.com/sponsors/carlospolop)!
|
|
* Descubre [**The PEASS Family**](https://opensea.io/collection/the-peass-family), nuestra colección exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
* Obtén el [**swag oficial de PEASS y HackTricks**](https://peass.creator-spring.com)
|
|
* **Únete al** [**💬**](https://emojipedia.org/speech-balloon/) [**grupo de Discord**](https://discord.gg/hRep4RUj7f) o al [**grupo de Telegram**](https://t.me/peass) o **sígueme** en **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
|
|
* **Comparte tus trucos de hacking enviando PRs al** [**repositorio de hacktricks**](https://github.com/carlospolop/hacktricks) **y al** [**repositorio de hacktricks-cloud**](https://github.com/carlospolop/hacktricks-cloud).
|
|
|
|
</details>
|
|
|
|
<figure><img src="../../../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
|
|
|
|
Si estás interesado en una **carrera de hacking** y hackear lo imposible - ¡**estamos contratando**! (_se requiere fluidez en polaco escrito y hablado_).
|
|
|
|
{% embed url="https://www.stmcyber.com/careers" %}
|
|
|
|
**Desde**: [https://medium.com/infosec-adventures/introduction-to-frida-5a3f51595ca1](https://medium.com/infosec-adventures/introduction-to-frida-5a3f51595ca1)\
|
|
**APK**: [https://github.com/t0thkr1s/frida-demo/releases](https://github.com/t0thkr1s/frida-demo/releases)\
|
|
**Código fuente**: [https://github.com/t0thkr1s/frida-demo](https://github.com/t0thkr1s/frida-demo)
|
|
|
|
## Python
|
|
|
|
Frida te permite **insertar código JavaScript** dentro de las funciones de una aplicación en ejecución. Pero puedes usar **python** para **llamar** los hooks e incluso para **interactuar** con los **hooks**.
|
|
|
|
Este es un script de python sencillo que puedes usar con todos los ejemplos propuestos en este tutorial:
|
|
```python
|
|
#hooking.py
|
|
import frida, sys
|
|
|
|
with open(sys.argv[1], 'r') as f:
|
|
jscode = f.read()
|
|
process = frida.get_usb_device().attach('infosecadventures.fridademo')
|
|
script = process.create_script(jscode)
|
|
print('[ * ] Running Frida Demo application')
|
|
script.load()
|
|
sys.stdin.read()
|
|
```
|
|
Llama al script:
|
|
```bash
|
|
python hooking.py <hookN.js>
|
|
```
|
|
Es útil saber cómo usar Python con Frida, pero para estos ejemplos también puedes llamar directamente a Frida utilizando las herramientas de línea de comandos de Frida:
|
|
```bash
|
|
frida -U --no-pause -l hookN.js -f infosecadventures.fridademo
|
|
```
|
|
## Hook 1 - Bypass de Booleanos
|
|
|
|
Aquí puedes ver cómo **hook** un método **booleano** (_checkPin_) de la clase: _infosecadventures.fridademo.utils.PinUtil_
|
|
```javascript
|
|
//hook1.js
|
|
Java.perform(function() {
|
|
console.log("[ * ] Starting implementation override...")
|
|
var MainActivity = Java.use("infosecadventures.fridademo.utils.PinUtil");
|
|
MainActivity.checkPin.implementation = function(pin){
|
|
console.log("[ + ] PIN check successfully bypassed!")
|
|
return true;
|
|
}
|
|
});
|
|
```
|
|
|
|
```
|
|
python hooking.py hook1.js
|
|
```
|
|
## Hook 2 - Función de Fuerza Bruta
|
|
|
|
### Función no estática
|
|
|
|
Si deseas llamar a una función no estática de una clase, **primero necesitas una instancia** de esa clase. Luego, puedes usar esa instancia para llamar a la función.\
|
|
Para hacerlo, podrías **encontrar una instancia existente** y usarla:
|
|
```javascript
|
|
Java.perform(function() {
|
|
console.log("[ * ] Starting PIN Brute-force, please wait...");
|
|
Java.choose("infosecadventures.fridademo.utils.PinUtil", {
|
|
onMatch: function(instance) {
|
|
console.log("[ * ] Instance found in memory: " + instance);
|
|
for(var i = 1000; i < 9999; i++){
|
|
if(instance.checkPin(i + "") == true){
|
|
console.log("[ + ] Found correct PIN: " + i);
|
|
break;
|
|
}
|
|
}
|
|
},
|
|
onComplete: function() { }
|
|
});
|
|
});
|
|
```
|
|
En este caso no funciona ya que no hay ninguna instancia y la función es estática
|
|
|
|
### Función estática
|
|
|
|
Si la función es estática, simplemente puedes llamarla:
|
|
```javascript
|
|
//hook2.js
|
|
Java.perform(function () {
|
|
console.log("[ * ] Starting PIN Brute-force, please wait...")
|
|
var PinUtil = Java.use("infosecadventures.fridademo.utils.PinUtil");
|
|
|
|
for(var i=1000; i < 9999; i++)
|
|
{
|
|
if(PinUtil.checkPin(i+"") == true){
|
|
console.log("[ + ] Found correct PIN: " + i);
|
|
}
|
|
}
|
|
});
|
|
```
|
|
## Hook 3 - Recuperando argumentos y valor de retorno
|
|
|
|
Puedes enganchar una función y hacer que **imprima** el valor de los **argumentos pasados** y el valor del **valor de retorno:**
|
|
```javascript
|
|
//hook3.js
|
|
Java.perform(function() {
|
|
console.log("[ * ] Starting implementation override...")
|
|
|
|
var EncryptionUtil = Java.use("infosecadventures.fridademo.utils.EncryptionUtil");
|
|
EncryptionUtil.encrypt.implementation = function(key, value){
|
|
console.log("Key: " + key);
|
|
console.log("Value: " + value);
|
|
var encrypted_ret = this.encrypt(key, value); //Call the original function
|
|
console.log("Encrypted value: " + encrypted_ret);
|
|
return encrypted_ret;
|
|
}
|
|
});
|
|
```
|
|
## Importante
|
|
|
|
En este tutorial has enganchado métodos usando el nombre del método y _.implementation_. Pero si hubiera **más de un método** con el mismo nombre, deberás **especificar el método** que deseas enganchar **indicando el tipo de los argumentos**.
|
|
|
|
Puedes ver eso en [el siguiente tutorial](frida-tutorial-2.md).
|
|
|
|
|
|
|
|
<figure><img src="../../../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
|
|
|
|
Si estás interesado en una **carrera de hacking** y hackear lo inhackeable - ¡**estamos contratando!** (_se requiere fluidez en polaco escrito y hablado_).
|
|
|
|
{% embed url="https://www.stmcyber.com/careers" %}
|
|
|
|
<details>
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
|
|
|
* ¿Trabajas en una **empresa de ciberseguridad**? ¿Quieres ver tu **empresa anunciada en HackTricks**? ¿O quieres tener acceso a la **última versión de PEASS o descargar HackTricks en PDF**? ¡Consulta los [**PLANES DE SUSCRIPCIÓN**](https://github.com/sponsors/carlospolop)!
|
|
* Descubre [**The PEASS Family**](https://opensea.io/collection/the-peass-family), nuestra colección exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
|
|
* Obtén el [**swag oficial de PEASS y HackTricks**](https://peass.creator-spring.com)
|
|
* **Únete al** [**💬**](https://emojipedia.org/speech-balloon/) [**grupo de Discord**](https://discord.gg/hRep4RUj7f) o al [**grupo de Telegram**](https://t.me/peass) o **sígueme** en **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
|
|
* **Comparte tus trucos de hacking enviando PRs al** [**repositorio de hacktricks**](https://github.com/carlospolop/hacktricks) **y al** [**repositorio de hacktricks-cloud**](https://github.com/carlospolop/hacktricks-cloud).
|
|
|
|
</details>
|