Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions push.py → frida-server-start
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

""" This script aims to automate the process of starting frida-server
on an Android device (for now). The script is a part of AndroidTamer
project and is based on this issue:
project and is based on this issue:
https://github.com/AndroidTamer/Tools_Repository/issues/234.

This script performs following things:
Expand All @@ -19,6 +19,8 @@
"""

import sys
import os
import os.path as path
import subprocess
import os
import lzma
Expand Down Expand Up @@ -51,7 +53,7 @@ def device_exists():

def get_device_arch():
""" This function tries to determine the architecture of the device, so that
the correct version of Frida-server can be downloaded. The function, first,
the correct version of Frida-server can be downloaded. The function, first,
tries to get the output of `uname -m` and then it tries to matches it against
some known values. If not, then it tries `getprop ro.product.cpu.abi`.

Expand All @@ -76,7 +78,7 @@ def get_device_arch():
getprop_cmd = "{} shell getprop ro.product.cpu.abi".format(adb_path)
getprop_archs = ["armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64"]
# We know shell=True is bad, but should be fine here.
output = subprocess.check_output(getprop_cmd, shell=True).lower().strip()
output = str(subprocess.check_output(getprop_cmd, shell=True).lower().strip(), "utf-8")

if output in getprop_archs:
if output in ["armeabi", "armeabi-v7a"]:
Expand All @@ -96,7 +98,7 @@ def prepare_download_url(arch):
return base_url.format(FRIDA_VERSION, FRIDA_VERSION, arch)

def download_and_extract(url, fname):
""" This function downloads the given URL, extracts .xz archive
""" This function downloads the given URL, extracts .xz archive
as given file name.

:returns True if successful, else False.
Expand Down Expand Up @@ -124,18 +126,19 @@ def download_and_extract(url, fname):
print("\t[+] Writing file as: {}.".format(fname))
with open(fname, "wb") as frida_server:
frida_server.write(data)
os.remove(archive_name)
return True
return False

def push_and_execute(fname):
"""This function pushes the file to device, makes it executable,
and then finally runs the binary. The function also saves the PID
and then finally runs the binary. The function also saves the PID
of process in 'frida.pid' file.
"""
push_cmd = "{} push {} /data/local/tmp/frida-server".format(adb_path, fname)
chmod_cmd = "{} shell chmod 0755 /data/local/tmp/frida-server".format(adb_path)
execute_cmd = "{} shell su 0 '/data/local/tmp/frida-server' &".format(adb_path)
ps_cmd = "%s shell 'su 0 ps' | grep frida-server | awk '{print $2}' > frida.pid" % (adb_path)
ps_cmd = "%s shell 'su 0 ps' | grep frida-server | awk '{print $2}' > .frida.pid" % (adb_path)

status_code = os.system(push_cmd)
if status_code == 0:
Expand Down Expand Up @@ -163,7 +166,10 @@ def main():
print("\t[+] Found arch: {}".format(arch))
url = prepare_download_url(arch)
fname = "frida-server-{}-android-{}".format(FRIDA_VERSION, arch)
if download_and_extract(url, fname):
if path.exists(fname):
print("\t[+] {} already downloaded.".format(fname))
push_and_execute(fname)
elif download_and_extract(url, fname):
push_and_execute(fname)
else:
print("\t[-] Could not determine device's arch. Exiting.")
Expand Down
11 changes: 11 additions & 0 deletions frida-server-stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

if [ -f .frida.pid ]; then
pid=`cat .frida.pid`
echo "frida-server pid: $pid, stop it."
adb shell su 0 kill -9 $pid
rm .frida.pid
echo "frida-server stopped."
else
echo "frida-server not started."
fi