Skip to content

Instantly share code, notes, and snippets.

@H4niz
Created July 16, 2019 13:59
Show Gist options
  • Save H4niz/8676442de1575de9f43b209c33c94642 to your computer and use it in GitHub Desktop.
Save H4niz/8676442de1575de9f43b209c33c94642 to your computer and use it in GitHub Desktop.
#python code
import frida
import time
#========= INIT ============
_PACKAGE_ = "owasp.mstg.uncrackable1"
_HOOKINGSCRIPT_ = "hooking_script.js"
def on_message(message, data):
if message['type'] == 'send':
print("[%s][%s] => %s" % (message['type'], message, data))
if message['type'] == 'error':
for k in message.keys():
print("\t[%s]: %s"%(k, message[k]))
while(True):
try:
print("==== Initialing ====")
device = frida.get_usb_device()
print("[+] Device: {}".format(device))
try:
pid = device.spawn([_PACKAGE_])
except Exception as ex:
print ex
print("[+] PID: {}".format(pid))
device.resume(pid)
time.sleep(1) #Without it Java.perform silently fails
session = device.attach(pid)
print("[+] Attaching session")
# session = frida.get_usb_device().attach(_PACKAGE_)
print("[+] Loading hooking script")
script = session.create_script(open(_HOOKINGSCRIPT_).read())
script.on('message', on_message)
script.load()
print("[*] Initialing successful\n")
break
except Exception as e:
print("[-] Error: {}".format(e))
raw_input("Try again?")
pass
#prevent the python script from terminating
raw_input("[Frida-Hooking]\nContinue?[Enter]\n")
console.log("Script loaded successfully ");
Java.perform(function x(){ //Silently fails without the sleep from the python code
console.log("Inside java perform function");
return 1;
}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment