コード例 #1
0
ファイル: whatsapp.py プロジェクト: testerclub/pyadb
def main():
    logging.basicConfig(level=logging.WARNING)
    adb = ADB()

    # set ADB path, using a couple of popular addresses.
    try:
        adb.set_adb_path('~/android-sdk-linux/platform-tools/adb')
    except ADB.BadCall:
        adb.set_adb_path(r'C:\Android\android-sdk\platform-tools\adb.exe')

    print("[+] Using PyADB version %s" % adb.pyadb_version())

    # verity ADB path
    print("[+] Verifying ADB path...", end='')
    if not adb.check_path():
        print("ERROR")
        exit(-2)
    print("OK")

    # print ADB Version
    print("[+] ADB Version: %s" % adb.get_version())

    print("")

    # restart server (may be other instances running)
    print("[+] Restarting ADB server...")
    try:
        adb.restart_server()
    except Exception as err:
        print("\t- ERROR\n", err)
        exit(-3)

    # get detected devices
    while True:
        print("[+] Detecting devices...", end=' ')
        try:
            devices = adb.get_devices()
        except adb.PermissionsError:
            devices = None
            print("You haven't enough permissions!")
            exit(-3)

        if devices:
            print("OK")
            break

        # no devices connected
        print("No devices connected")
        print("[+] Waiting for devices...")
        adb.wait_for_device()

    # this should never be reached
    if len(devices) == 0:
        print("[+] No devices detected!")
        exit(-4)

    # show detected devices
    i = 0
    for dev in devices:
        print("\t%d: %s" % (i, dev))
        i += 1

    # if there are more than one devices, ask to the user to choose one of them
    if i > 1:
        dev = i + 1
        while dev < 0 or dev > int(i - 1):
            print("\n[+] Select target device [0-%d]: " % int(i - 1), end=' ')
            dev = int(stdin.readline())
    else:
        dev = 0

    # set target device
    try:
        adb.set_target_device(devices[dev])
    except Exception as e:
        print("\n[!] Error: " % e)
        exit(-5)

    print("\n[+] Using \"%s\" as target device" % devices[dev])

    # check if 'su' binary is available
    print("[+] Looking for 'su' binary: ", end=' ')

    try:
        supath = adb.find_binary("su")
    except ADB.AdbException as err:
        if str(err) != "'su' was not found":
            print("Error: %s" % err)
            exit(-6)
        supath = None

    if supath is not None:
        # 'su' binary has been found

        print("[+] Checking if 'su' binary can give root access:")
        try:
            rootid = adb.shell_command('%s -c id' % supath)
            if 'root' in rootid.replace('(', ')').split(')'):
                # it can provide root privileges
                print("\t- Yes")
                get_whatsapp_root(adb, supath)
            else:
                print("\t- No: %s" % rootid)
                get_whatsapp_nonroot(adb)
        except adb.AdbException as err:
            print("\t- No: %s" % err)
            get_whatsapp_nonroot(adb)
    else:
        print("Not found.")
        get_whatsapp_nonroot(adb)

    exit(0)
コード例 #2
0
ファイル: apkmole.py プロジェクト: stasvolf/APKMole
def main():
	APKTOOL = "/home/example/Downloads/apktool_2.0.0rc3.jar"  # APKTOOL Directory
	ADBTOOL = "/usr/bin/adb" # ADB Directory
	print "#################################################################################"
	print "#                                APKmole V1.0                                   #"
	print "# ADB & APKTool wrapper for application analysis located on an android device   #"
	print "# Author: Stas Volfus                                                           #"
	print "# the author isn't responsible for any damage caused by using this tool         #"                                                                              #"
	print "#################################################################################"
	print "\nADB Path: "+ADBTOOL
	print "APKtool Path: "+APKTOOL    
	print "\n\n[*] Setting up ADB.."
	adb = ADB()
	adb.set_adb_path(ADBTOOL) 	# path to adb..
	print "[*] Checking APKTool path.." ,
	if os.path.isfile(APKTOOL) is False:
		print R+"\t[FAILED] - path not found."+W
		exit(-1)
	print G+"\t[OK]"+W
	print "[*] Checking ADB path.." ,
	if adb.check_path() is False:
		print "\t"+R+"\t[FAILED] - ADB path doesn't exists..\n"+W
		exit(-2)
	print "\t"+G+"[OK]"+W
	print "[*] Restarting ADB server.." ,
	adb.restart_server()
	if adb.lastFailed():
		print "\t"+R+"[ERROR]"+W
		exit(-3)
	print "\t"+G+"[OK]"+W
	dev = 0
	while dev is 0:
		print "[*] Detecting devices..." ,
		error,devices = adb.get_devices()
		if error is 2:
			print R+"[-] You haven't enought permissions."+W
			exit(-3)
		print "\t"+G+"[OK]"+W
		dev = 1
		if len(devices) == 0:
			print C+"[-] No devices detected! waiting for devices.."+W
			adb.wait_for_device()
			error,devices = adb.get_devices()
			continue
	# devices...
	i = 0
	for dev in devices:
		print "\t%d: %s" % (i,dev)
		i += 1
	#more than one device..
	if i > 1:
		dev = i + 1
		while dev < 0 or dev > int(i - 1):
			print "\n[+] Select target device [0-%d]: " % int(i - 1) ,
			dev = int(stdin.readline())
	else:
		dev = 0
	try:
		adb.set_target_device(devices[dev])
	except Exception,e:
		print R+"\n[-] Error:\t- ADB: %s\t - Python: %s" % (adb.get_error(),e.args)
		exit(-5)
コード例 #3
0
ファイル: whatsapp.py プロジェクト: casschin/pyadb
def main():

    adb = ADB()

    # set ADB path
    adb.set_adb_path('~/android-sdk-linux/platform-tools/adb')

    print("[+] Using PyADB version %s" % adb.pyadb_version())

    # verity ADB path
    print("[+] Verifying ADB path...",)
    if adb.check_path() is False:
        print("ERROR")
        exit(-2)
    print("OK")

    # print(ADB Version)
    print("[+] ADB Version: %s" % adb.get_version())

    print("")

    # restart server (may be other instances running)
    print("[+] Restarting ADB server...")
    adb.restart_server()
    if adb.last_failed():
        print("\t- ERROR\n")
        exit(-3)

    # get detected devices
    dev = 0
    while dev is 0:
        print("[+] Detecting devices..." ,)
        error,devices = adb.get_devices()

        if error is 1:
            # no devices connected
            print("No devices connected")
            print("[+] Waiting for devices...")
            adb.wait_for_device()
            continue
        elif error is 2:
            print("You haven't enought permissions!")
            exit(-3)

        print("OK")
        dev = 1

    # this should never be reached
    if len(devices) == 0:
        print("[+] No devices detected!")
        exit(-4)

    # show detected devices
    i = 0
    for dev in devices:
        print("\t%d: %s" % (i,dev))
        i += 1

    # if there are more than one devices, ask to the user to choose one of them
    if i > 1:
        dev = i + 1
        while dev < 0 or dev > int(i - 1):
            print("\n[+] Select target device [0-%d]: " % int(i - 1) ,)
            dev = int(stdin.readline())
    else:
        dev = 0

    # set target device
    try:
        adb.set_target_device(devices[dev])
    except Exception as e:
        print("\n[!] Error:\t- ADB: %s\t - Python: %s" % (adb.get_error(),e.args))
        exit(-5)

    print("\n[+] Using \"%s\" as target device" % devices[dev])

    # check if 'su' binary is available
    print("[+] Looking for 'su' binary: ",)
    supath = adb.find_binary("su")

    if supath is not None:
        print("%s" % supath)
    else:
        print("Error: %s" % adb.get_error())

    # 'su' binary has been found
    if supath is not None:
        print("[+] Checking if 'su' binary can give root access:")
        rootid = adb.shell_command('%s -c id' % supath)
        if adb.last_failed() is False and 'root' in rootid.replace('(',')').split(')'): # it can provide root privileges
            print("\t- Yes")
            get_whatsapp_root(adb,supath)
        else: # only have normal-user
            print("\t- No: %s" % adb.get_error())
            get_whatsapp_nonroot(adb)
    else:
        get_whatsapp_nonroot(adb)

    exit(0)
コード例 #4
0
ファイル: adb.py プロジェクト: bigzz/moniter
def main():

    adb = ADB()

    # set ADB path
    adb.set_adb_path('/home/bigzhang/Android/Sdk/platform-tools/adb')

    print "[+] Using PyADB version %s" % adb.pyadb_version()

    # verity ADB path
    print "[+] Verifying ADB path...",
    if adb.check_path() is False:
        print "ERROR"
        exit(-2)
    print "OK"

    # print ADB Version
    print "[+] ADB Version: %s" % adb.get_version()

    print ""

    # restart server (may be other instances running)
    print "[+] Restarting ADB server..."
    adb.restart_server()
    if adb.lastFailed():
        print "\t- ERROR\n"
        exit(-3)

    # get detected devices
    dev = 0
    while dev is 0:
        print "[+] Detecting devices..." ,
        error,devices = adb.get_devices()

        if error is 1:
            # no devices connected
            print "No devices connected"
            print "[+] Waiting for devices..."
            adb.wait_for_device()
            continue
        elif error is 2:
            print "You haven't enought permissions!"
            exit(-3)

        print "OK"
        dev = 1

    # this should never be reached
    if len(devices) == 0:
        print "[+] No devices detected!"
        exit(-4)

    # show detected devices
    i = 0
    for dev in devices:
        print "\t%d: %s" % (i,dev)
        i += 1

    # if there are more than one devices, ask to the user to choose one of them
    if i > 1:
        dev = i + 1
        while dev < 0 or dev > int(i - 1):
            print "\n[+] Select target device [0-%d]: " % int(i - 1) ,
            dev = int(stdin.readline())
    else:
        dev = 0

    # set target device
    try:
        adb.set_target_device(devices[dev])
    except Exception,e:
        print "\n[!] Error:\t- ADB: %s\t - Python: %s" % (adb.get_error(),e.args)
        exit(-5)
コード例 #5
0
def main():

    adb = ADB()

    # set ADB path
    adb.set_adb_path('~/android-sdk-linux/platform-tools/adb')

    print "[+] Using PyADB version %s" % adb.pyadb_version()

    # verity ADB path
    print "[+] Verifying ADB path...",
    if adb.check_path() is False:
        print "ERROR"
        exit(-2)
    print "OK"

    # print ADB Version
    print "[+] ADB Version: %s" % adb.get_version()

    print ""

    # restart server (may be other instances running)
    print "[+] Restarting ADB server..."
    adb.restart_server()
    if adb.lastFailed():
        print "\t- ERROR\n"
        exit(-3)

    # get detected devices
    dev = 0
    while dev is 0:
        print "[+] Detecting devices...",
        error, devices = adb.get_devices()

        if error is 1:
            # no devices connected
            print "No devices connected"
            print "[+] Waiting for devices..."
            adb.wait_for_device()
            continue
        elif error is 2:
            print "You haven't enought permissions!"
            exit(-3)

        print "OK"
        dev = 1

    # this should never be reached
    if len(devices) == 0:
        print "[+] No devices detected!"
        exit(-4)

    # show detected devices
    i = 0
    for dev in devices:
        print "\t%d: %s" % (i, dev)
        i += 1

    # if there are more than one devices, ask to the user to choose one of them
    if i > 1:
        dev = i + 1
        while dev < 0 or dev > int(i - 1):
            print "\n[+] Select target device [0-%d]: " % int(i - 1),
            dev = int(stdin.readline())
    else:
        dev = 0

    # set target device
    try:
        adb.set_target_device(devices[dev])
    except Exception, e:
        print "\n[!] Error:\t- ADB: %s\t - Python: %s" % (adb.get_error(),
                                                          e.args)
        exit(-5)
コード例 #6
0
ファイル: managers.py プロジェクト: shadeimi/crais
class HotplugManager(threading.Thread):
    _instance = None

    def __init__(self, lock, config_path):
        print config_path
        self.conf = ConfigObj(config_path)
        self.adb = ADB(self.conf['mainConfiguration']
                                ['adbConfiguration']['adbPath'])
        self.adb.restart_server()
        self.lock = lock
        self.storage = ZODB.DB(None)
        self.connection = self.storage.open()
        self.root = self.connection.root
        self.root.devices = BTrees.OOBTree.BTree()

    def __new__(cls, *args, **kwargs):
        if not cls._instance:
            cls._instance = super(HotplugManager,
                                  cls).__new__(cls, *args, **kwargs)
            cls._ins = super(HotplugManager,
                             cls).__new__(cls, *args, **kwargs)
        return cls._instance

    @retry(libusb1.LIBUSB_ERROR_ACCESS, tries=2)
    def _usb_connection(self, device, event):
        """ TODO: Manage missing udev rules """
        
        key = "%04x:%04x" % (device.getVendorID(), device.getProductID())
        if event == 2:
            self.lock.acquire()
            try:
                # Delete key object from ZODB
                del self.root.devices[key]
                transaction.get().commit()
            except Exception as e:
                print str(e.message)
                transaction.abort()
                pass
            self.lock.release()

        elif event == 1 and device.getSerialNumber() is not None:
            self.adb.restart_server()
            devices = list(self.adb.get_devices())[1:][0]
            try:
                if device.getSerialNumber() in devices:
                    self.adb.set_target_device(device.getSerialNumber())
                    version = self.adb.shell_command('getprop ro.build.version.release').rstrip()
                    model = ''.join((self.adb.shell_command('settings get secure android_id')).splitlines())

                    self.lock.acquire()
                    try:
                        dm = DeviceManager(model, version)
                        self.root.devices[str(key)] = dm
                        transaction.commit()
                    except (Exception, AttributeError) as e:
                        print str(e.message)
                        transaction.abort()
                        pass
                    self.lock.release()

            except (IndexError, AttributeError, TypeError, KeyError) as e:
                print str(e.message)
                pass

        self.adb.kill_server()

    def callback(self, context, device, event):
        try:
            print "Device %s: %s" % (
                {
                    libusb1.LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED: 'arrived',
                    libusb1.LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT: 'left',
                }[event],
                device
            )

            self._usb_connection(device, event)

        except (AttributeError, libusb1.USBError) as e:
            print str(e.message)
            pass
コード例 #7
0
def main():

    adb = ADB()

    # set ADB path
    adb.set_adb_path('~/android-sdk-linux/platform-tools/adb')

    print("[+] Using PyADB version %s" % adb.pyadb_version())

    # verity ADB path
    print("[+] Verifying ADB path...", )
    if adb.check_path() is False:
        print("ERROR")
        exit(-2)
    print("OK")

    # print(ADB Version)
    print("[+] ADB Version: %s" % adb.get_version())

    print("")

    # restart server (may be other instances running)
    print("[+] Restarting ADB server...")
    adb.restart_server()
    if adb.last_failed():
        print("\t- ERROR\n")
        exit(-3)

    # get detected devices
    dev = 0
    while dev is 0:
        print("[+] Detecting devices...", )
        error, devices = adb.get_devices()

        if error is 1:
            # no devices connected
            print("No devices connected")
            print("[+] Waiting for devices...")
            adb.wait_for_device()
            continue
        elif error is 2:
            print("You haven't enought permissions!")
            exit(-3)

        print("OK")
        dev = 1

    # this should never be reached
    if len(devices) == 0:
        print("[+] No devices detected!")
        exit(-4)

    # show detected devices
    i = 0
    for dev in devices:
        print("\t%d: %s" % (i, dev))
        i += 1

    # if there are more than one devices, ask to the user to choose one of them
    if i > 1:
        dev = i + 1
        while dev < 0 or dev > int(i - 1):
            print("\n[+] Select target device [0-%d]: " % int(i - 1), )
            dev = int(stdin.readline())
    else:
        dev = 0

    # set target device
    try:
        adb.set_target_device(devices[dev])
    except Exception as e:
        print("\n[!] Error:\t- ADB: %s\t - Python: %s" %
              (adb.get_error(), e.args))
        exit(-5)

    print("\n[+] Using \"%s\" as target device" % devices[dev])

    # check if 'su' binary is available
    print("[+] Looking for 'su' binary: ", )
    supath = adb.find_binary("su")

    if supath is not None:
        print("%s" % supath)
    else:
        print("Error: %s" % adb.get_error())

    # 'su' binary has been found
    if supath is not None:
        print("[+] Checking if 'su' binary can give root access:")
        rootid = adb.shell_command('%s -c id' % supath)
        if adb.last_failed() is False and 'root' in rootid.replace(
                '(', ')').split(')'):  # it can provide root privileges
            print("\t- Yes")
            get_whatsapp_root(adb, supath)
        else:  # only have normal-user
            print("\t- No: %s" % adb.get_error())
            get_whatsapp_nonroot(adb)
    else:
        get_whatsapp_nonroot(adb)

    exit(0)
コード例 #8
0
ファイル: apkmole.py プロジェクト: firebitsbr/APKMole
def main():
    APKTOOL = "/home/example/Downloads/apktool_2.0.0rc3.jar"  # APKTOOL Directory
    ADBTOOL = "/usr/bin/adb"  # ADB Directory
    print "#################################################################################"
    print "#                                APKmole V1.0                                   #"
    print "# ADB & APKTool wrapper for application analysis located on an android device   #"
    print "# Author: Stas Volfus                                                           #"
    print "# the author isn't responsible for any damage caused by using this tool         #"  #"
    print "#################################################################################"
    print "\nADB Path: " + ADBTOOL
    print "APKtool Path: " + APKTOOL
    print "\n\n[*] Setting up ADB.."
    adb = ADB()
    adb.set_adb_path(ADBTOOL)  # path to adb..
    print "[*] Checking APKTool path..",
    if os.path.isfile(APKTOOL) is False:
        print R + "\t[FAILED] - path not found." + W
        exit(-1)
    print G + "\t[OK]" + W
    print "[*] Checking ADB path..",
    if adb.check_path() is False:
        print "\t" + R + "\t[FAILED] - ADB path doesn't exists..\n" + W
        exit(-2)
    print "\t" + G + "[OK]" + W
    print "[*] Restarting ADB server..",
    adb.restart_server()
    if adb.lastFailed():
        print "\t" + R + "[ERROR]" + W
        exit(-3)
    print "\t" + G + "[OK]" + W
    dev = 0
    while dev is 0:
        print "[*] Detecting devices...",
        error, devices = adb.get_devices()
        if error is 2:
            print R + "[-] You haven't enought permissions." + W
            exit(-3)
        print "\t" + G + "[OK]" + W
        dev = 1
        if len(devices) == 0:
            print C + "[-] No devices detected! waiting for devices.." + W
            adb.wait_for_device()
            error, devices = adb.get_devices()
            continue
    # devices...
    i = 0
    for dev in devices:
        print "\t%d: %s" % (i, dev)
        i += 1
    #more than one device..
    if i > 1:
        dev = i + 1
        while dev < 0 or dev > int(i - 1):
            print "\n[+] Select target device [0-%d]: " % int(i - 1),
            dev = int(stdin.readline())
    else:
        dev = 0
    try:
        adb.set_target_device(devices[dev])
    except Exception, e:
        print R + "\n[-] Error:\t- ADB: %s\t - Python: %s" % (adb.get_error(),
                                                              e.args)
        exit(-5)