Ejemplo n.º 1
0
def doAllAppInstall(method):
    # get all apks which are linked in the database
    # will come with [0] package [1] path_to_apk
    appsList = Apps().getAllApps()

    for apk in appsList:
        app = Apps()
        app.path_to_apk = apk[1]
        app.package = apk[0]
        if method is "INSTALL":  #install apps
            installapk(app)
        elif method is "UNINSTALL":  #uninstall apps
            uninstallapk(app)
Ejemplo n.º 2
0
def callMallodroid(appsList):
    existingRecords = Mallodroid.getPackages()

    for apk in appsList:
        if apk[0] in existingRecords:
            continue
        app = Apps()
        app.path_to_apk = apk[1]
        app.package = apk[0]

        res = runMallodroid(app)
        # result will be empty if app doesn't require internet permission
        if res:
            parseXML(res.strip(), app)
Ejemplo n.º 3
0
def assemble_and_install(context):
    """
    reassemble the apk file and install it to the device
    :param context:
    :return:
    """
    app = Apps.getApp(context.package)
    logger.info("%s starting reassembling to apk", app.package)

    newapk = path + app.package + "/" + app.package + "-new.apk"
    newalignedapk = path + app.package + "/" + app.package + "-aligned.apk"

    logger.info("%s reassembling to apk", context.package)
    cmd = ["apktool", "b", path + app.package + "/smali/", "-o", newapk]
    logger.debug(" ".join(cmd))
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()
    if err:
        logger.error(err)
        return
    else:
        logger.debug(out)

    logger.info("%s signing apk", context.package)
    cmd = ["jarsigner", "-verbose", "-sigalg", "SHA1withRSA", "-digestalg", "SHA1", "-keystore", "my-release-key.keystore", "--store-pass", "123456", "-keypass", "123456", newapk, "alias_name"]
    logger.debug(" ".join(cmd))
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()
    if err:
        logger.error(err)
        return
    else:
        logger.debug(out)

    logger.info("%s aligning apk", context.package)
    cmd = [zipalign, "-f", "-v", "4", newapk, newalignedapk]
    logger.debug(" ".join(cmd))
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()
    if err:
        logger.error(err)
        return
    else:
        logger.debug(out)

    app = Apps()
    app.package = context.package
    app.path_to_apk = newalignedapk
    deviceHelper.uninstallapk(app)
    deviceHelper.installapk(app)
Ejemplo n.º 4
0
def evicheck(appslist):
    """
    runs the EviCheck tool on a list of apps and stores results
    as log files and database entries
    :param appslist:
    :return:
    """

    p_result = re.compile(".*Policy valid!.*")

    for apk in appslist:
        app = Apps()
        app.path_to_apk = apk[1]
        app.package = apk[0]
        certFile = path + app.package + "/EviCheck.cert"
        logFile = path + app.package + "/EviCheck.log"
        logger.info("%s running EviCheck", app.package)

        malware = Malware()
        malware.package = app.package
        malware.logfile = logFile
        malware.tool = "EviCheck"

        cmd = ["python", eviscript, "-f", app.path_to_apk, "-g", "-p", evipolicy, "-t", certFile,
               "-m"]  # there are RSA and DSA certificates; cater for both

        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = p.communicate()

        if err:
            logger.error(err)
            continue
        else:
            lines = out.splitlines()
            log = open(logFile, 'w')
            log.writelines(lines)
            log.close()

            global a # init variable
            for line in lines:
                a = p_result.match(line)
                if a:
                    malware.result = "valid"
                    logger.info("%s is valid", app.package)
                    break
            if not a:
                malware.result = "invalid"
                logger.info("%s is not valid", app.package)
            malware.insert()
Ejemplo n.º 5
0
def allApksToJar():
    """
    extracts all apk files to jar
    :return:
    """
    # get all apks which are linked in the database
    # will come with [0] package [1] path_to_apk
    appsList = Apps().getAllApps()

    for apk in appsList:
        app = Apps()
        app.path_to_apk = apk[1]
        app.package = apk[0]

        apkTorJar(app)
Ejemplo n.º 6
0
def explaindroid(appsList):
    """
    running Explain Droid on a list of apps
    :param appsList:
    :return:
    """
    p_result = re.compile(".*LABEL: BENIGN.*")

    for apk in appsList:
        app = Apps()
        app.path_to_apk = apk[1]
        app.package = apk[0]
        logFile = path + app.package + "/ExplainDroid.log"
        logger.info("%s running ExplainDroid", app.package)

        malware = Malware()
        malware.package = app.package
        malware.logfile = logFile
        malware.tool = "ExplainDroid"

        cmd = [expdroidscript, "-mod", "linux", "-apk", app.path_to_apk
               ]  # there are RSA and DSA certificates; cater for both
        p = subprocess.Popen(cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        out, err = p.communicate()

        if err:
            logger.error(err)
            continue
        else:
            lines = out.splitlines()
            log = open(logFile, 'w')
            log.writelines(lines)
            log.close()

            global a  # init variable
            for line in lines:
                a = p_result.match(line)
                if a:
                    malware.result = "benign"
                    logger.info("%s is benign", app.package)
                    break
            if not a:
                malware.result = "malicious"
                logger.info("%s is malicious", app.package)

            malware.insert()
Ejemplo n.º 7
0
def allApksToSmali():
    """
    extracting smali code for all apk files
    :return:
    """

    # get all apks which are linked in the database
    # will come with [0] package [1] path_to_apk
    appsList = Apps().getAllApps()

    for apk in appsList:
        app = Apps()
        app.path_to_apk = apk[1]
        app.package = apk[0]

        allApksToSmali()
Ejemplo n.º 8
0
def install():
    with open(app_list) as lines:
        packages = [line.rstrip('\n') for line in lines]
        packages.insert(0, "ALL")
        packages.append("quit")
        package, index = pick(packages, "choose package")
        if package == "ALL":
            apps = Apps.getAllApps()
            for a in apps:
                app = Apps()
                app.package = a[0]
                app.path_to_apk = a[1]
                deviceHelper.installapk(app)
        else:
            app = Apps.getApp(package)
            deviceHelper.installapk(app)
Ejemplo n.º 9
0
def do():
    if checkInstall():
        forwardPort()
        #startApp()

        # get all apks which are linked in the database
        # will come with [0] package [1] path_to_apk
        appsList = Apps().getAllApps()

        for apk in appsList:
            app = Apps()
            app.path_to_apk = apk[1]
            app.package = apk[0]
            logger.info("%s running drozer", app.package)

            out, err = runDrozerCmd(app, "app.service.info -a")
            if err:
                logger.error(err.strip())
                logger.error(
                    "Probably client app is not running or app not installed ..."
                )
            else:
                if "No exported" in out:
                    pass
                else:
                    writeToDb("service", out, app)

            out, err = runDrozerCmd(app, "app.broadcast.info -a")
            if err:
                logger.error(err.strip())
                logger.error(
                    "Probably client app is not running or app not installed ..."
                )
            else:
                if "No matching" in out:
                    pass
                else:
                    writeToDb("broadcast", out, app)

            out, err = runDrozerCmd(app, "app.provider.info -a")
            if err:
                logger.error(err.strip())
                logger.error(
                    "Probably client app is not running or app not installed ..."
                )
            else:
                if "No matching" in out:
                    pass
                else:
                    writeToDb("provider", out, app)

            out, err = runDrozerCmd(app, "app.activity.info -a")
            if err:
                logger.error(err.strip())
                logger.error(
                    "Probably client app is not running or app not installed ..."
                )
            else:
                if "No exported" in out:
                    pass
                else:
                    writeToDb("activity", out, app)

            out, err = runDrozerCmd(app, "app.package.attacksurface")
            if err:
                logger.error(err.strip())
                logger.error(
                    "Probably client app is not running or app not installed ..."
                )
            else:
                cal = CodeAnalysis()
                cal.package = app.package
                if "is debuggable" in out:
                    cal.debuggable = 'y'
                else:
                    cal.debuggable = 'n'
                cal.insert()

    else:
        logger.warning("Install Drozer Client application first")