4 from subprocess import call, check_output
7 FNULL = open(os.devnull, 'w')
9 print("Ensuring device is online")
10 call("adb wait-for-device", shell=True)
12 print("Installing the drozer agent")
13 print("If the device just came online it is likely the package manager hasn't booted.")
14 print("Will try multiple attempts to install.")
15 print("This may need tweaking depending on hardware.")
22 output = check_output('adb shell "pm list packages"', shell=True)
23 print("Checking whether the package manager is up...")
24 if "Could not access the Package Manager" in output:
25 print("Nope. Sleeping for 30 seconds and then trying again.")
36 install_output = check_output("adb install /home/drozer/drozer-agent.apk", shell=True)
38 print("Failed. Trying again.")
42 if "Error: Could not access the Package Manager" not in install_output:
45 print("Install attempted. Checking everything worked")
47 pm_list_output = check_output('adb shell "pm list packages"', shell=True)
49 if "com.mwr.dz" not in pm_list_output:
51 exit("APK didn't install properly. Exiting.")
53 print("Installed ok.")
55 print("Starting the drozer agent main activity: com.mwr.dz/.activities.MainActivity")
56 call('adb shell "am start com.mwr.dz/.activities.MainActivity"', shell=True, stdout=FNULL)
58 print("Starting the service")
60 call("python /home/drozer/enable_service.py", shell=True, stdout=FNULL)
62 print("Forward dem ports mon.")
63 call("adb forward tcp:31415 tcp:31415", shell=True, stdout=FNULL)