def check_device_compatibility(): """ checks for connected device compatibility with the framework. Quit if connected device is not found or compatible """ ''' DEVICE_CONFIG = "devices.ini" config = ConfigParser.ConfigParser() config.read(DEVICE_CONFIG) serial_numbers = config.sections() ''' serial_numbers = dev.list() adb = Adb() connected_devices = adb.devices() if len(connected_devices) >= 1: print "Total of %d devices connected"%len(connected_devices) else: log.critical("Please connect device before starting droidpot") exit(0) for device in connected_devices: isCompatible = False for serial_number in serial_numbers: if device == serial_number: print "device %s is compatible"%serial_number isCompatible = True break if not isCompatible: log.critical("Found device that is not compatible with droidpot. Please use only compatible devices for malware analysis.") exit(1)
class fastboot_testCase(unittest.TestCase): def setUp(self): self.fastboot = Fastboot() self.adb = Adb() self.adb.reboot_bootloader() def tearDown(self): self.fastboot.reboot() while len(self.adb.devices()) == 0: time.sleep(5) @unittest.skip("skip reboot test") def test_reboot(self): self.fastboot.reboot() result = True print "[!] waiting for phone to reboot..." for i in range(0, 5): if len(self.adb.devices()) == 0: time.sleep(10) result = False else: result = True break if i == 4: print "[!] Reboot time out" self.assertTrue(result, msg="fastboot reboot failed") @unittest.skip("skip reboot bootloader test") def test_reboot_bootloader(self): result = False self.fastboot.reboot_bootloader() devices = self.fastboot.devices() print "[!] waiting for phone to enter bootloader mode..." for i in range(0, 5): devices = self.fastboot.devices() if len(devices) != 0: result = True break else: time.sleep(10) if i == 4: print "[!] Reboot time out" self.assertTrue(result, msg="fastboot reboot-bootloader failed") def test_devices(self): result = False self.fastboot.reboot_bootloader() time.sleep(5) devices = self.fastboot.devices() if len(devices) > 0: result = True self.assertTrue(result, msg="fastboot devices did not detect any devices")
class adb_testcase(unittest.TestCase): def setUp(self): self.adb_c = Adb() self.adb_c.start_server() def tearDown(self): #self.adb_c.kill_server() pass #@unittest.skip("skipping test device") def test_devices(self): devices = self.adb_c.devices() #print devices result = True if len(devices) == 0: result = False self.assertTrue(result, msg="No device detected") def test_push_file(self): path = os.path.dirname(os.path.realpath(__file__)) src = os.path.join(path, TEST_FILE) dest = os.path.join(SDCARD_PATH, TEST_FILE) isSuccessful = self.adb_c.push(source=src, dest=dest) self.assertTrue(isSuccessful, msg="adb push not successful") def test_pull_file(self): path = os.path.dirname(os.path.realpath(__file__)) src = os.path.join(SDCARD_PATH, TEST_FILE) dest = os.path.join(path, "extract.txt") isSuccessful = self.adb_c.pull(source=src, dest=dest) self.assertTrue(isSuccessful, msg="adb pull not successful") os.remove(dest) def test_shell_no_root(self): parameters = "ps" result = self.adb_c.shell(command=parameters) self.assertTrue(result.isSuccess, msg="adb shell ps not successful") print result.std_output def test_shell_with_root(self): parameters = "strace -p 1" result = self.adb_c.shell(needOutput=False, root=True, command=parameters) self.assertTrue(result.isSuccess, msg="adb shell with root not successful") self.adb_c.reboot() sleep(5) while len(self.adb_c.devices()) == 0: print("waiting for device to reboot...") sleep(10) @unittest.skip("skipping reboot test") def test_reboot_commands(self): """ reboot command testcase should be the last :return: """ self.adb_c.reboot() print("device rebooting... Please wait...") sleep(3) devices = self.adb_c.devices() foundDevice = False if devices: foundDevice = True self.assertFalse(foundDevice, msg="adb reboot not successful")