Beispiel #1
0
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)
Beispiel #2
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)
Beispiel #3
0
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)
Beispiel #4
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)
Beispiel #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.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)
Beispiel #6
0
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)
Beispiel #7
0
class ADBFS(Fuse):
    opened = {}

    def __init__(self, *args, **kw):
        Fuse.__init__(self, *args, **kw)
        self.adb = ADB('adb')

    def connect(self):
        print 'Connect device to computer...'
        self.adb.wait_for_device()
        err = self.adb.get_error()
        if err:
            print 'ADB error:', err.strip()
            exit(5)

        print 'Driver enabled!'

    def _sh(self, cmd):
        try:
            return self.adb.shell_command("'%s'" % cmd) or ""
        except Exception as e:
            print 'Command ', cmd, 'failed:', self.adb.get_error()
            raise e
    
    def _ls(self, path):
        if USE_LS:
            return self._sh('ls "%s"' % path).split()
        return self._sh('ls -a "%s"' % path).splitlines()

    # ---- DIRECTORIES ----
    def readdir(self, path, offset):
        if self._sh('test -d "%s"&&echo true' % path).strip() == 'true':
            if path[:-1] != '/':
                path += '/'
            dd = self._ls(path)
            for i in dd:
                yield Direntry(i)

    def rmdir(self, path):
        self.adb.shell_command('rmdir "%s"' % path)
        non_cached(path)

    def mkdir(self, path, mode):
        self.adb.shell_command('mkdir "%s"' % path)
        self.adb.shell_command('chmod %s "%s"' % (oct(mode), path))
        non_cached(path)

    # ---- FILES ----
    def create(self, path, mode):
        self.adb.shell_command('echo "" >"%s"' % path)
        self.adb.shell_command('chmod %s "%s"' % (oct(mode), path))
        non_cached(path)

    def mknod(self, path, mode, dev):
        self.adb.shell_command('touch "%s"' % path)
        self.adb.shell_command('chmod %s "%s"' % (oct(mode), path))
        non_cached(path)

    def open(self, path, flags):
        if self._sh('test -e "%s"&&echo true' % path).strip() != 'true':
            return -ENOENT

        if path in self.opened:
            self.opened[path][1] += 1
        else:
            rfn = cached(path, lambda x: self.adb.get_remote_file(path, x))
            self.opened[path] = [open(rfn, 'rb+'), 1]

    def release(self, path, flags):
        f = self.opened[path]
        f[1] -= 1
        if f[1] == 0:
            f[0].close()
            del self.opened[path]

    def read(self, path, size, offset):
        f = self.opened[path][0]
        f.seek(0, 2)
        slen = f.tell()
        if offset < slen:
            if offset + size > slen:
                size = slen - offset

            f.seek(offset)
            return f.read(size)
        return ''

    def write(self, path, data, offset):
        f = self.opened[path][0]
        f.seek(0, 2)
        slen = f.tell()
        if offset < slen:

            f.seek(offset)
            l = f.write(data)

            rfn = cached(path, lambda x: self.adb.get_remote_file(path, x))
            self.adb.push_local_file(rfn, path)
            return l
        return 0

    def fsync(self, path):
        if path in FILES_CACHE:
            rfn = FILES_CACHE[path]
            self.adb.push_local_file(rfn, path)
            non_cached(path)

    def unlink(self, path):
        self.adb.shell_command('rm "%s"' % path)
        non_cached(path)

    # ---- OTHER ----
    @lru_cache
    def getattr(self, path):
        st = Stat()
        st.st_nlink = 1
        if self._sh('test -e "%s"&&echo true' % path).strip() != 'true':
            return -ENOENT

        elif self._sh('test -h "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFLNK

        elif self._sh('test -d "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFDIR

        elif self._sh('test -f "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFREG

        elif self._sh('test -c "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFCHR

        elif self._sh('test -b "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFBLK

        elif self._sh('test -p "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFIFO

        elif self._sh('test -s "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFSOCK

        else:
            st.st_mode = 0

        st.st_mode |= int(self._sh('stat -c%%a "%s"' % path) or '0', 8)
        st.st_size = int(self._sh('stat -c%%s "%s"' % path) or '0')
        print "file:", path, "size: ", st.st_size, "mode:", oct(st.st_mode)

        return st

    def chmod(self, path, mode):
        self._sh('chmod %s "%s"' % (oct(mode), path))
        non_cached(path)

    def chown(self, oid, gid, path):
        pass # TODO: chown

    def rename(self, path, new):
        self._shd('mv "%s" "%s"' % (path, new))
        non_cached(path)
        non_cached(new)

    def statfs(self):
        st = StatVfs()
        st.f_bsize = 1024
        st.f_frsize = 1024
        st.f_bfree = 0
        st.f_bavail = 0
        st.f_files = 2
        st.f_blocks = 4
        st.f_ffree = 0
        st.f_favail = 0
        st.f_namelen = 255
        return st