def get_android_sdk_manager(): """ Gets the location of SDK manager through CLI while in interactive mode, or via settings.properties if running headlessly """ print common.term.yellow + str( common.config.get( 'qarkhelper', 'ANDROID_SDK_INFO')).decode('string-escape').format(t=common.term) print common.term.cyan choice = raw_input( common.config.get('qarkhelper', 'GET_ANDROID_SDK_MANAGER_PROMPT')) if str(choice).lower() == 'y': download_sdk() else: AndroidSDKPath = raw_input( common.config.get('qarkhelper', 'ANDROID_SDK_MANAGER_PATH_PROMPT')) if not str(AndroidSDKPath).endswith("/"): AndroidSDKPath = str(AndroidSDKPath).strip() + "/" # common.writeKey('AndroidSDKPath', AndroidSDKPath) while not (os.path.exists(AndroidSDKPath + "tools")): logger.error( str( common.config.get( 'qarkhelper', 'ANDROID_SDK_MANAGER_PATH_PROMPT_AGAIN')).decode( 'string-escape')) print common.term.cyan AndroidSDKPath = raw_input( common.config.get('qarkhelper', 'ANDROID_SDK_MANAGER_PATH_PROMPT')) if not str(AndroidSDKPath).endswith("/"): AndroidSDKPath = str(AndroidSDKPath).strip() + "/" common.writeKey('AndroidSDKPath', AndroidSDKPath) common.AndroidSDKPath = AndroidSDKPath common.logger.debug("Located SDK")
def get_android_sdk_manager(): """ Gets the location of SDK manager through CLI while in interactive mode, or via settings.properties if running headlessly """ print common.term.yellow + str(common.config.get("qarkhelper", "ANDROID_SDK_INFO")).decode("string-escape").format( t=common.term ) print common.term.cyan choice = raw_input(common.config.get("qarkhelper", "GET_ANDROID_SDK_MANAGER_PROMPT")) if str(choice).lower() == "y": download_sdk() else: AndroidSDKPath = raw_input(common.config.get("qarkhelper", "ANDROID_SDK_MANAGER_PATH_PROMPT")) if not str(AndroidSDKPath).endswith("/"): AndroidSDKPath = str(AndroidSDKPath).strip() + "/" # common.writeKey('AndroidSDKPath', AndroidSDKPath) while not (os.path.exists(AndroidSDKPath + "tools")): logger.error( str(common.config.get("qarkhelper", "ANDROID_SDK_MANAGER_PATH_PROMPT_AGAIN")).decode("string-escape") ) print common.term.cyan AndroidSDKPath = raw_input(common.config.get("qarkhelper", "ANDROID_SDK_MANAGER_PATH_PROMPT")) if not str(AndroidSDKPath).endswith("/"): AndroidSDKPath = str(AndroidSDKPath).strip() + "/" common.writeKey("AndroidSDKPath", AndroidSDKPath) common.AndroidSDKPath = AndroidSDKPath common.logger.debug("Located SDK")
def downloadSDK(): """ Download the SDK from Google """ url = " https://dl.google.com/android/android-sdk_r24.0.2-macosx.zip" file_name = url.split('/')[-1] u = urllib2.urlopen(url) f = open(common.getConfig("rootDir") + "/" + file_name, 'wb') meta = u.info() file_size = int(meta.getheaders("Content-Length")[0]) common.logger.debug( "Downloading: %s \r\n FileName: %s \r\n FileSize: \r\n %s" % (url, file_name, file_size)) block_sz = file_size / 100 count = 0 while True: buffer = u.read(block_sz) if not buffer: break f.write(buffer) count = count + 1 if count % 10 == 0: sys.stdout.write('\r[{0}] {1}%'.format('#' * (count / 10), count)) sys.stdout.flush() f.close() androidSDKZIP = f.name print common.term.cyan + str( common.config.get('qarkhelper', 'FILE_DOWNLOADED_TO') ) + androidSDKZIP.decode('string-escape').format(t=common.term) print common.term.cyan + str(common.config.get( 'qarkhelper', 'UNPACKING')) + androidSDKZIP.decode('string-escape').format( t=common.term) zf = zipfile.ZipFile(androidSDKZIP) for filename in [zf.namelist()]: try: if not os.path.exists(androidSDKZIP.rsplit(".", 1)[0]): os.makedirs(androidSDKZIP.rsplit(".", 1)[0]) zf.extractall( androidSDKZIP.rsplit(".", 1)[0] + "/", zf.namelist(), ) except KeyError: logger.error('Oops!! %s doesnt look like a valid APK', filename) else: logger.info('Done') #We dont need the ZIP file anymore os.remove(androidSDKZIP) common.writeKey('AndroidSDKPath', androidSDKZIP.rsplit(".", 1)[0] + "/android-sdk-macosx/") runSDKManager()
def getAndroidSDKManager(): """ Gets the location of SDK manager through CLI while in interactive mode, or via settings.properties if running headlessly """ print common.term.yellow + str(common.config.get('qarkhelper','ANDROID_SDK_INFO')).decode('string-escape').format(t=common.term) print common.term.cyan choice=raw_input(common.config.get('qarkhelper','GET_ANDROID_SDK_MANAGER_PROMPT')) if str(choice).lower()=='y': downloadSDK() else: AndroidSDKPath=raw_input(common.config.get('qarkhelper','ANDROID_SDK_MANAGER_PATH_PROMPT')) common.writeKey('AndroidSDKPath', AndroidSDKPath) while not (os.path.exists(common.getConfig('AndroidSDKPath') + "/tools")): logger.error(str(common.config.get('qarkhelper','ANDROID_SDK_MANAGER_PATH_PROMPT_AGAIN')).decode('string-escape')) print common.term.cyan AndroidSDKPath=raw_input(common.config.get('qarkhelper','ANDROID_SDK_MANAGER_PATH_PROMPT')) common.writeKey('AndroidSDKPath', AndroidSDKPath) common.logger.debug("Located SDK")
def downloadSDK(): """ Download the SDK from Google """ url = " https://dl.google.com/android/android-sdk_r24.0.2-macosx.zip" file_name = url.split('/')[-1] u = urllib2.urlopen(url) f = open(common.getConfig("rootDir") + "/" + file_name, 'wb') meta = u.info() file_size = int(meta.getheaders("Content-Length")[0]) common.logger.debug("Downloading: %s \r\n FileName: %s \r\n FileSize: \r\n %s" % (url, file_name, file_size)) block_sz = file_size/100 count = 0 while True: buffer = u.read(block_sz) if not buffer: break f.write(buffer) count = count + 1 if count%10==0: sys.stdout.write('\r[{0}] {1}%'.format('#'*(count/10), count)) sys.stdout.flush() f.close() androidSDKZIP = f.name print common.term.cyan + str(common.config.get('qarkhelper','FILE_DOWNLOADED_TO')) + androidSDKZIP.decode('string-escape').format(t=common.term) print common.term.cyan + str(common.config.get('qarkhelper','UNPACKING')) + androidSDKZIP.decode('string-escape').format(t=common.term) zf = zipfile.ZipFile(androidSDKZIP) for filename in [ zf.namelist()]: try: if not os.path.exists(androidSDKZIP.rsplit(".",1)[0]): os.makedirs(androidSDKZIP.rsplit(".",1)[0]) zf.extractall(androidSDKZIP.rsplit(".",1)[0] + "/", zf.namelist(), ) except KeyError: logger.error('Oops!! %s doesnt look like a valid APK', filename) else: logger.info('Done') #We dont need the ZIP file anymore os.remove(androidSDKZIP) common.writeKey('AndroidSDKPath', androidSDKZIP.rsplit(".",1)[0] + "/android-sdk-macosx/") runSDKManager()
def download_sdk(): """ Download the SDK from Google """ url = "" url_macosx = "https://dl.google.com/android/android-sdk_r24.0.2-macosx.zip" url_linux = "https://dl.google.com/android/android-sdk_r24.3.4-linux.tgz" if sys.platform == "linux2": url = url_linux else: url = url_macosx file_name = url.split("/")[-1] u = urllib2.urlopen(url) f = open(common.getConfig("rootDir") + "/" + file_name, "wb") meta = u.info() file_size = int(meta.getheaders("Content-Length")[0]) common.logger.debug("Downloading: %s \r\n FileName: %s \r\n FileSize: \r\n %s" % (url, file_name, file_size)) block_sz = file_size / 100 count = 0 while True: buffer = u.read(block_sz) if not buffer: break f.write(buffer) count = count + 1 if count % 10 == 0: sys.stdout.write("\r[{0}] {1}%".format("#" * (count / 10), count)) sys.stdout.flush() f.close() androidSDKZIP = f.name print common.term.cyan + str(common.config.get("qarkhelper", "FILE_DOWNLOADED_TO")) + androidSDKZIP.decode( "string-escape" ).format(t=common.term) print common.term.cyan + str(common.config.get("qarkhelper", "UNPACKING")) + androidSDKZIP.decode( "string-escape" ).format(t=common.term) if sys.platform == "linux2": try: if not os.path.exists(androidSDKZIP.rsplit(".", 1)[0]): os.makedirs(androidSDKZIP.rsplit(".", 1)[0]) extract(androidSDKZIP, androidSDKZIP.rsplit(".", 1)[0]) except Exception as e: logger.error(e.message) common.writeKey("AndroidSDKPath", androidSDKZIP.rsplit(".", 1)[0] + "/android-sdk-linux/") else: zf = zipfile.ZipFile(androidSDKZIP) for filename in [zf.namelist()]: try: if not os.path.exists(androidSDKZIP.rsplit(".", 1)[0]): os.makedirs(androidSDKZIP.rsplit(".", 1)[0]) zf.extractall(androidSDKZIP.rsplit(".", 1)[0] + "/", zf.namelist()) except Exception as e: logger.error(e.message) else: logger.info("Done") common.writeKey("AndroidSDKPath", androidSDKZIP.rsplit(".", 1)[0] + "/android-sdk-macosx/") # We dont need the ZIP file anymore os.remove(androidSDKZIP) run_sdk_manager()
ignore = os.system('clear') f = Figlet(font='colossal') print f.renderText('Q A R K') common.logger = logging.getLogger() common.rootDir = os.path.dirname(os.path.realpath(__file__)) #Initialize system #Verify that settings.properties always exists if not os.path.exists(os.path.dirname(os.path.realpath(__file__)) + "/settings.properties"): f = open(os.path.dirname(os.path.realpath(__file__)) + "/settings.properties",'w') f.close() # common.writeKey("rootDir", common.rootDir) common.initialize_logger() ####################################### parser = argparse.ArgumentParser(description='QARK - Andr{o}id Source Code Analyzer and Exploitation Tool') required = parser.add_argument_group('Required') mode = parser.add_argument_group('Mode') advanced = parser.add_argument_group('When --source=2') auto = parser.add_argument_group('When --source=1') optional = parser.add_argument_group('Optional') exploitmenu = parser.add_argument_group('Exploit Generation') mode.add_argument("-s", "--source", dest="source", metavar='int', type=int, help="1 if you have an APK, 2 if you want to specify the source selectively") advanced.add_argument("-m", "--manifest", dest="manifest", help="Enter the full path to the manifest file. Required only when --source==2") auto.add_argument("-p", "--pathtoapk", dest="apkpath", help="Enter the full path to the APK file. Required only when --source==1") advanced_mutual = advanced.add_mutually_exclusive_group()