Skip to content

Instantly share code, notes, and snippets.

@d3vilbug
Created November 2, 2018 06:25
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save d3vilbug/41deacfe52a476d68d6f21587c5f531d to your computer and use it in GitHub Desktop.
Save d3vilbug/41deacfe52a476d68d6f21587c5f531d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from __future__ import print_function
import frida
import sys
import json
import time
def on_message(message, payload):
if(message['type'] == 'send'):
rec_data = json.loads(message['payload'])
if rec_data['my_type'] == 'IV':
print("[$] IvParameterSpec :: {}".format(payload.decode('utf-8')))
elif rec_data['my_type'] == 'KEY':
print("[$] SecretSpecKey :: {}".format(payload.decode('utf-8')))
else:
print(message)
else:
print(message)
js_code = """
console.log("Script loaded");
Java.perform(function x() {
//hooking SecretKeySpec's constructor to get the SecretKeySpec
var secret_key_spec = Java.use("javax.crypto.spec.SecretKeySpec");
secret_key_spec.$init.overload("[B", "java.lang.String").implementation = function (x, y) {
send('{"my_type" : "KEY"}', new Uint8Array(x));
return this.$init(x, y);
}
//hooking IvParameterSpec's constructor to get the IV
var iv_parameter_spec = Java.use("javax.crypto.spec.IvParameterSpec");
iv_parameter_spec.$init.overload("[B").implementation = function (x) {
send('{"my_type" : "IV"}', new Uint8Array(x));
return this.$init(x);
}
});
"""
# device = frida.get_usb_device()
# pid = device.spawn(["com.example.a11x256.frida_test"])
# device.resume(pid)
# time.sleep(1)
# session = device.attach(pid)
session = frida.get_usb_device().attach('com.example.a11x256.frida_test')
script = session.create_script(js_code)
script.on("message", on_message)
script.load()
sys.stdin.read()
@gurtej741
Copy link

i am facing the issues:

File ".\frida-get-AES-keys.py", line 13, in on_message
print("[$] IvParameterSpec :: {}".format(payload.decode('utf-8')))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf8 in position 7: invalid start byte
Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\frida\core.py", line 298, in _on_message
callback(message, data)
File ".\frida-get-AES-keys.py", line 15, in on_message
print("[$] SecretSpecKey :: {}".format(payload.decode('utf-8')))
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 1-2: invalid continuation byte

@d3vilbug
Copy link
Author

@gurtej741
Copy link

gurtej741 commented Oct 10, 2019 via email

@gurtej741
Copy link

The python code at link: https://11x256.github.io/Frida-hooking-android-part-5/

shows below error:
\\\\\\frida-AES-KEY-Script> .\frida-get-AES-keys_1.py
File "D:\Android Testing Stuff\frida-AES-KEY-Script\frida-get-AES-keys_1.py", line 16
print "Key sent to SecretKeySpec()", payload.encode("hex")

@d3vilbug
Copy link
Author

and did you also used the .js file from the same link?

@gurtej741
Copy link

gurtej741 commented Oct 10, 2019 via email

@d3vilbug
Copy link
Author

Can you share your .js and .py files ??

@gurtej741
Copy link

gurtej741 commented Oct 10, 2019 via email

@gurtej741
Copy link

gurtej741 commented Oct 17, 2019 via email

Copy link

ghost commented Nov 13, 2021

Hello,
I was getting unfortunately application has stopped
did you found a solution?

@d3vilbug
Copy link
Author

Hi @Mr4FX

You can find the updated script from my blog post https://n00b.sh/posts/aes-killer-mobile-app-demo/

Copy link

ghost commented Nov 17, 2021 via email

@d3vilbug
Copy link
Author

Ohhh sorry, haven't noticed. Responding on twitter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment