Last active
June 18, 2023 14:35
-
-
Save jcalabres/5ddb83dc01f6c0fcc0fba1228fac6913 to your computer and use it in GitHub Desktop.
Automatic LD_PRELOAD on Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from adb.client import Client as AdbClient | |
from sys import * | |
import os | |
if __name__=="__main__": | |
print("[*] Simple script to automatize LD_PRELOAD process on android applications.") | |
if len(argv)!=3: | |
print("[-] Specify PACKAGE_NAME and PATH_LIB.") | |
exit(0) | |
package=argv[1] | |
path=argv[2] | |
lib=argv[2].split("/")[-1] | |
os.system("adb root") | |
client=AdbClient(host="127.0.0.1",port=5037) | |
device=client.devices()[0] | |
uid=int(device.shell("id").split('=')[1].split('(')[0]) | |
device.shell("setenforce 0") | |
enforce=device.shell("getenforce") | |
device.push(path,"/data/local/tmp/"+lib) | |
device.shell("chmod 777 /data/local/tmp/"+lib) | |
device.shell("chown root:root /data/local/tmp/"+lib) | |
print("[+] uid: "+str(uid)) | |
print("[+] enforce: "+enforce), | |
if uid==0 and "Permissive" in enforce: | |
device.shell("setprop wrap."+argv[1]+" LD_PRELOAD=/data/local/tmp/"+lib) | |
device.shell("stop") | |
device.shell("start") | |
print("[+] Loaded libraries :)") | |
print(device.shell("getprop | grep LD_PRELOAD")), | |
else: | |
print("Check uid and enforce.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment