• Python攻防-AndroidMainfest数据自动化解析


    前言

    在前面的一篇文章:Python攻防-APK批量自动反编译与数据分析 中,已经介绍了如何批量拉取手机中的 APK 文件并进行反编译获得源码,同时如何进行简单的数据检索和分析处理。本文将进一步介绍如何从反编译出来批量的 AndroidMainfest.xml 配置文件中,自动化统计出 Android 四大组件的 exported 属性和未定义的权限,同时生成可视化统计表格。

    组件属性

    Android APP 四大组件(Activity、Service、Receiver、Content Provider)存在的攻击面基本上都需要一个前提:组件属性 exported=“true"。下面来看看如何借助 Python 代码,自动化统计出批量 AndroidMainfest.xml 文件中 exported=“true" 的 Android 组件。

    脚本浅析

    1、首先看下数据源,基于我上面提到的 Python攻防-APK批量自动反编译与数据分析 批量反编译后获得的 APK 源码文件夹:
    在这里插入图片描述
    其中,AndroidMainfest.xml 文件位于每个 apk 反编译后的 resources 文件夹下,比如:
    在这里插入图片描述
    2、首先看下如何解析 AndroidMainfest.xml 文件并获得对应的 PackageName 属性(即包名),毕竟一份APP属性的统计数据如果连包名都没有的话是相当离谱的:

    from xml.etree.ElementTree import parse
    ……
    def getPackageName(filePath):
        """
        读取AndroidManifest.xml文件中包名的属性
        :param filePath: AndroidManifest.xml文件路径
        :return: PackageName
        """
        tree = parse(filePath)
        root = tree.getroot()
        packageName = root.attrib['package']
        print(Fore.BLUE + "PackageName: " + packageName)
        return packageName
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    3、接下来提取关键数据,看看如何获取 AndroidMainfest.xml 文件中四大组件的 exported 属性,以下代码将生成某个 APP 的四大组件 "组件名:exported属性值" 的字典:

    from colorama import Fore, init
    from xml.etree.ElementTree import parse
    ……
    def getComponentDict(filePath):
        """
        获取指定AndroidManifest.xml文件中包含的所有四大组件的{组件类型:"组件名:exported属性值"}的字典
        :param filePath: AndroidManifest.xml文件路径
        :return: {组件类型:"组件名:exported属性值"}的字典
        """
        tree = parse(filePath)
        namespace = "{http://schemas.android.com/apk/res/android}"
        componentTypeList = {"activity", "service", "receiver", "provider"}
        componentAllDict = {}  # 存储某个App的所有组件的字典,格式:{组件类型:"组件名:eported属性值"}
        componentOneDict = {}  # 存储某个App某类组件的字典,格式:{"组件名:eported属性值"}
        for componentType in componentTypeList:
            nodelist = tree.findall('application/' + componentType)
            for node in nodelist:
                componentName = node.get(namespace + 'name')
                if node.get(namespace + 'exported') is not None:
                    componentExported = node.get(namespace + 'exported')
                else:
                    componentExported = "true"  # 兼容Android 12以下版本,未设置exported属性,默认True
                componentOneDict[componentName] = componentExported
            print("%s 组件的字典:" % componentType + str(componentOneDict))
            componentAllDict[componentType] = componentOneDict
            componentOneDict = {}  # 将中间字典存储到目标字典后,置空并进入下个循环收集另一类组件的数据
        # print("最终的数据:" + str(intentAllDict))
        print(Fore.GREEN + "****************************************")
        return componentAllDict
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    4、遍历上面提到的反编译后的整个资源文件夹下的所有 AndroidMainfest.xml 文件,统计所有目标 APP 的组件及其属性并存放于全局字典 componentFinallyDict 中,该字典的键值 key 为 "APP名/包名”,value 值为该应用对应的四大组件与其 exported 属性自称的字典(即步骤 3 函数的返回值):

    from colorama import Fore, init
    
    init(autoreset=True)
    componentFinallyDict = {}  # 存储最终所有APK的四大组件属性的字典,格式为:{PackageName:"{组件类型:"组件名:exported属性值"}"}
    
    def analyzeAndroidManifest(file_path):
        """
        生成指定文件夹下所有APP的四大组件属性的字典,格式为:{PackageName:"{组件类型:"组件名:exported属性值"}"}
        :param file_path: 存储反编译后的APP资源文件的路径
        :return: {PackageName:"{组件类型:"组件名:exported属性值"}"}的字典
        """
        global componentFinallyDict
        for file_ls in os.listdir(file_path):
            print(Fore.BLUE + "APPName: " + file_ls)
            path = str(file_path) + "/" + str(file_ls) + "/resources/AndroidManifest.xml"
            packageName = file_ls + "/" + getPackageName(path)  # APP的名称+包名,如“Mms.apk/com.android.mms”
            componentDict = getComponentDict(path)
            componentFinallyDict[packageName] = componentDict
        # print(str(componentFinallyDict))
        print(Fore.BLUE + "[*]Successfully analyze all AndroidManifest!")
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    5、最后,将全局字典 componentFinallyDict 的数据进行解析并生成 xlsx 统计表格:

    def writeDataToXlsx(xlsxPath):
        """
        将字典里面存储的Intent数据转换成xlsx格式的表格
        :param xlsxPath: 输出的xlsx文件路径
        :return: null
        """
        dataSource = {}
        dictCol0List = []
        dictCol1List = []
        dictCol2List = []
        dictCol3List = []
        dictCol4List = []
        global componentFinallyDict
        # 数据源格式为:{PackageName:"{组件类型:"组件名:exported属性值"}"},其中PackageName=APP的名称+包名,如“Mms.apk/com.android.mms”
        for packageName, componentDict in componentFinallyDict.items():
            for componentType, componentDictExported in componentDict.items():
                for componentName, exported in componentDictExported.items():
                    try:
                        dictCol0List.append(str(packageName).split("/")[0])
                        dictCol1List.append(str(packageName).split("/")[1])
                        dictCol2List.append(componentType)
                        dictCol3List.append(componentName)
                        dictCol4List.append(exported)
                    except IndexError as e:
                        print(e)
                        continue
        # 设置xlsx表格每列数据的源数据列表
        dataSource["APPName"] = dictCol0List
        dataSource["PackageName"] = dictCol1List
        dataSource["ComponentType"] = dictCol2List
        dataSource["ComponentName"] = dictCol3List
        dataSource["exported"] = dictCol4List
        # print(dataSource)
        print(Fore.BLUE + "[*]Start generating xlsx…")
        writer = pd.ExcelWriter(xlsxPath)
        dataFrame = pd.DataFrame(dataSource)
        dataFrame.to_excel(writer, sheet_name="sheet1")
        writer.close()  # 保存writer中的数据至excel
        print(Fore.BLUE + "[*]Successfully generated xlsx!")
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    效果演示

    完整代码如下:

    # @File  : intentAnalyze
    # @Time  : 2022/11/12 10:10
    # @Author: Tr0e
    # @Blog  : https://tr0e.github.io/
    
    import os
    import time
    import pandas as pd
    from colorama import Fore, init
    from xml.etree.ElementTree import parse
    from func_timeout import func_set_timeout
    
    init(autoreset=True)
    componentFinallyDict = {}  # 存储最终所有APK的四大组件属性的字典,格式为:{PackageName:"{组件类型:"组件名:exported属性值"}"}
    vulPermissionDict = {}  # 存储最终所有APK未定义的权限的字典,格式为:{PackageName:未定义权限列表},PackageName=“APK名.apk/com.XXX.XXX”
    
    
    def analyzeAndroidManifest(file_path):
        """
        生成指定文件夹下所有APP的四大组件属性的字典,格式为:{PackageName:"{组件类型:"组件名:exported属性值"}"}
        :param file_path: 存储反编译后的APP资源文件的路径
        :return: {PackageName:"{组件类型:"组件名:exported属性值"}"}的字典
        """
        global componentFinallyDict
        for file_ls in os.listdir(file_path):
            print(Fore.BLUE + "APPName: " + file_ls)
            path = str(file_path) + "/" + str(file_ls) + "/resources/AndroidManifest.xml"
            packageName = file_ls + "/" + getPackageName(path)  # APP的名称+包名,如“Mms.apk/com.android.mms”
            componentDict = getComponentDict(path)
            componentFinallyDict[packageName] = componentDict
        # print(str(componentFinallyDict))
        print(Fore.BLUE + "[*]Successfully analyze all AndroidManifest!")
    
    
    def getPackageName(filePath):
        """
        读取AndroidManifest.xml文件中包名的属性
        :param filePath: AndroidManifest.xml文件路径
        :return: PackageName
        """
        tree = parse(filePath)
        root = tree.getroot()
        packageName = root.attrib['package']
        print(Fore.BLUE + "PackageName: " + packageName)
        return packageName
    
    
    def getComponentDict(filePath):
        """
        获取指定AndroidManifest.xml文件中包含的所有四大组件的{组件类型:"组件名:exported属性值"}的字典
        :param filePath: AndroidManifest.xml文件路径
        :return: {组件类型:"组件名:exported属性值"}的字典
        """
        tree = parse(filePath)
        namespace = "{http://schemas.android.com/apk/res/android}"
        componentTypeList = {"activity", "service", "receiver", "provider"}
        componentAllDict = {}  # 存储某个App的所有组件的字典,格式:{组件类型:"组件名:eported属性值"}
        componentOneDict = {}  # 存储某个App某类组件的字典,格式:{"组件名:eported属性值"}
        for componentType in componentTypeList:
            nodelist = tree.findall('application/' + componentType)
            for node in nodelist:
                componentName = node.get(namespace + 'name')
                if node.get(namespace + 'exported') is not None:
                    componentExported = node.get(namespace + 'exported')
                else:
                    componentExported = "true"  # 兼容Android 12以下版本,未设置exported属性,默认True
                componentOneDict[componentName] = componentExported
            print("%s 组件的字典:" % componentType + str(componentOneDict))
            componentAllDict[componentType] = componentOneDict
            componentOneDict = {}  # 将中间字典存储到目标字典后,置空并进入下个循环收集另一类组件的数据
        # print("最终的数据:" + str(intentAllDict))
        print(Fore.GREEN + "****************************************")
        return componentAllDict
    
    
    def writeDataToXlsx(xlsxPath):
        """
        将字典里面存储的Intent数据转换成xlsx格式的表格
        :param xlsxPath: 输出的xlsx文件路径
        :return: null
        """
        dataSource = {}
        dictCol0List = []
        dictCol1List = []
        dictCol2List = []
        dictCol3List = []
        dictCol4List = []
        global componentFinallyDict
        # 数据源格式为:{PackageName:"{组件类型:"组件名:exported属性值"}"},其中PackageName=APP的名称+包名,如“Mms.apk/com.android.mms”
        for packageName, componentDict in componentFinallyDict.items():
            for componentType, componentDictExported in componentDict.items():
                for componentName, exported in componentDictExported.items():
                    try:
                        dictCol0List.append(str(packageName).split("/")[0])
                        dictCol1List.append(str(packageName).split("/")[1])
                        dictCol2List.append(componentType)
                        dictCol3List.append(componentName)
                        dictCol4List.append(exported)
                    except IndexError as e:
                        print(e)
                        continue
        # 设置xlsx表格每列数据的源数据列表
        dataSource["APPName"] = dictCol0List
        dataSource["PackageName"] = dictCol1List
        dataSource["ComponentType"] = dictCol2List
        dataSource["ComponentName"] = dictCol3List
        dataSource["exported"] = dictCol4List
        # print(dataSource)
        print(Fore.BLUE + "[*]Start generating xlsx…")
        writer = pd.ExcelWriter(xlsxPath)
        dataFrame = pd.DataFrame(dataSource)
        dataFrame.to_excel(writer, sheet_name="sheet1")
        writer.close()  # 保存writer中的数据至excel
        print(Fore.BLUE + "[*]Successfully generated xlsx!")
    
    
    def copyRight():
        print(Fore.GREEN + "************** CopyRight ****************")
        print(Fore.GREEN + "             Welcome to use               ")
        print(Fore.GREEN + "     Author: Tr0e                         ")
        print(Fore.GREEN + "     Github: https://github.com/Tr0e      ")
        print(Fore.GREEN + "     Blog  : https://tr0e.github.io       ")
        print(Fore.GREEN + "*****************************************")
    
    
    if __name__ == '__main__':
        copyRight()
        start = time.time()
        # 对批量APP四大组件的exported属性进行收集并生成统计表格
        analyzeAndroidManifest("D:/tmp/Result")
        writeDataToXlsx("data/result/intent.xlsx")
        end = time.time()
        print(Fore.BLUE + "[*]Done.Totally time is " + str(end - start) + "s.Enjoy it!")
        exit(0)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134

    代码运行效果如下图所示:
    在这里插入图片描述
    在这里插入图片描述
    上述脚本在 6 秒钟解析了 449 个 AndroidMainfest.xml 文件并生成 13914 条 Android 组件统计数据。

    权限排查

    Android 应用层组件安全测试基础实战技巧 这篇文章里,我曾介绍过 Android 系统中的权限定义方法,以及如何识别 APP 引用了未定义的权限。下面来介绍如何通过自动化脚本,统计批量的 APP AndroidMainfest.xml 文件中引用的未定义 Permission。

    脚本浅析

    1、数据源依然同上文,AndroidMainfest.xml 文件位于每个 apk 反编译后的 resources 文件夹下,比如:
    在这里插入图片描述
    2、获取某个 AndroidMainfest.xml 文件中未定义的权限的原理很简单:获取 uses-permission 标签里面的权限名 xxx,然后执行 adb shell pm list permissions | findstr xxx,根据返回接口判断权限是否未定义,然后生成并返回一个未定义权限的列表:

    def getPermissionErrorList(filePath):
        """
        读取AndroidManifest.xml文件中的未定义权限列表
        :param filePath: AndroidManifest.xml文件路径
        :return 某个APP的未定义权限列表
        """
        tree = parse(filePath)
        root = tree.getroot()
        namespace = "{http://schemas.android.com/apk/res/android}"
        # packageName = root.attrib['package']
        # print(Fore.BLUE + "PackageName: " + packageName)
        usesPermissionList = []
        undefinePermissionList = []
        for child in root.iter('uses-permission'):
            permissionName = child.get(namespace + 'name')
            usesPermissionList.append(permissionName)
            # print(permissionName)
            cmd = "adb shell pm list permissions | findstr " + permissionName
            if execCommand(cmd) == "":
                if permissionName.startswith("android.permission"):
                    continue
                undefinePermissionList.append(permissionName)
        print(undefinePermissionList)
        print(Fore.GREEN + "****************************************")
        return undefinePermissionList
    
    
    @func_set_timeout(3)
    def execCommand(command):
        return os.popen(command).read().strip('\n')
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    3、对资源文件夹下的所有 AndroidMainfest.xml 文件进行解析,生成一个汇集了所有 APP 未定义权限的字典 vulPermissionDict:

    vulPermissionDict = {}  # 存储最终所有APK未定义的权限的字典,格式为:{PackageName:未定义权限列表},PackageName=“APK名.apk/com.XXX.XXX”
    
    def analyzePermissions(file_path):
        """
        生成指定文件夹下所有APP的未定义组件的字典,格式为:{PackageName:未定义组件列表}
        :param file_path: 存储反编译后的APP资源文件的路径
        :return: {PackageName:未定义组件列表}的字典
        """
        global vulPermissionDict
        for file_ls in os.listdir(file_path):
            print(Fore.BLUE + "APPName: " + file_ls)
            path = str(file_path) + "/" + str(file_ls) + "/resources/AndroidManifest.xml"
            packageName = file_ls + "/" + getPackageName(path)  # APP的名称+包名,如“Mms.apk/com.android.mms”
            permissionList = getPermissionErrorList(path)
            vulPermissionDict[packageName] = permissionList
        # print(str(vulPermissionDict))
        print(Fore.BLUE + "[*]Successfully analyze all Permissions!")
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    4、最后将数据源字典 vulPermissionDict 的数据转换成 xlsx 表格:

    def writePermissionXlsx(xlsxPath):
        """
        将字典里面存储的未定义权限数据转换成xlsx格式的表格
        :param xlsxPath: 输出的xlsx文件路径
        :return: null
        """
        dataSource = {}
        dictCol1List = []
        dictCol2List = []
        dictCol3List = []
        global vulPermissionDict
        # 数据源格式为:{PackageName:未定义权限列表},其中PackageName=APP的名称+包名,如“Mms.apk/com.android.mms”
        for packageName, permissionList in vulPermissionDict.items():
            for vulPermission in permissionList:
                try:
                    dictCol1List.append(str(packageName).split("/")[0])
                    dictCol2List.append(str(packageName).split("/")[1])
                    dictCol3List.append(vulPermission)
                except IndexError as e:
                    print(e)
                    continue
        # 设置xlsx表格每列数据的源数据列表
        dataSource["APPName"] = dictCol1List
        dataSource["PackageName"] = dictCol2List
        dataSource["PermissionName"] = dictCol3List
        # print(dataSource)
        print(Fore.BLUE + "[*]Start generating xlsx…")
        writer = pd.ExcelWriter(xlsxPath)
        dataFrame = pd.DataFrame(dataSource)
        dataFrame.to_excel(writer, sheet_name="sheet1")
        writer.close()  # 保存writer中的数据至excel
        print(Fore.BLUE + "[*]Successfully generated xlsx!")
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    效果演示

    完整代码如下所示:

    # @File  : intentAnalyze
    # @Time  : 2022/11/12 10:10
    # @Author: Tr0e
    # @Blog  : https://tr0e.github.io/
    
    import os
    import time
    import pandas as pd
    from colorama import Fore, init
    from xml.etree.ElementTree import parse
    from func_timeout import func_set_timeout
    
    init(autoreset=True)
    vulPermissionDict = {}  # 存储最终所有APK未定义的权限的字典,格式为:{PackageName:未定义权限列表},PackageName=“APK名.apk/com.XXX.XXX”
    
    def analyzePermissions(file_path):
        """
        生成指定文件夹下所有APP的未定义组件的字典,格式为:{PackageName:未定义组件列表}
        :param file_path: 存储反编译后的APP资源文件的路径
        :return: {PackageName:未定义组件列表}的字典
        """
        global vulPermissionDict
        for file_ls in os.listdir(file_path):
            print(Fore.BLUE + "APPName: " + file_ls)
            path = str(file_path) + "/" + str(file_ls) + "/resources/AndroidManifest.xml"
            packageName = file_ls + "/" + getPackageName(path)  # APP的名称+包名,如“Mms.apk/com.android.mms”
            permissionList = getPermissionErrorList(path)
            vulPermissionDict[packageName] = permissionList
        # print(str(vulPermissionDict))
        print(Fore.BLUE + "[*]Successfully analyze all Permissions!")
    
    
    def getPermissionErrorList(filePath):
        """
        读取AndroidManifest.xml文件中的未定义权限列表
        :param filePath: AndroidManifest.xml文件路径
        :return 某个APP的未定义权限列表
        """
        tree = parse(filePath)
        root = tree.getroot()
        namespace = "{http://schemas.android.com/apk/res/android}"
        # packageName = root.attrib['package']
        # print(Fore.BLUE + "PackageName: " + packageName)
        usesPermissionList = []
        undefinePermissionList = []
        for child in root.iter('uses-permission'):
            permissionName = child.get(namespace + 'name')
            usesPermissionList.append(permissionName)
            # print(permissionName)
            cmd = "adb shell pm list permissions | findstr " + permissionName
            if execCommand(cmd) == "":
                if permissionName.startswith("android.permission"):
                    continue
                undefinePermissionList.append(permissionName)
        print(undefinePermissionList)
        print(Fore.GREEN + "****************************************")
        return undefinePermissionList
    
    
    @func_set_timeout(3)
    def execCommand(command):
        return os.popen(command).read().strip('\n')
    
    
    def writePermissionXlsx(xlsxPath):
        """
        将字典里面存储的未定义权限数据转换成xlsx格式的表格
        :param xlsxPath: 输出的xlsx文件路径
        :return: null
        """
        dataSource = {}
        dictCol1List = []
        dictCol2List = []
        dictCol3List = []
        global vulPermissionDict
        # 数据源格式为:{PackageName:未定义权限列表},其中PackageName=APP的名称+包名,如“Mms.apk/com.android.mms”
        for packageName, permissionList in vulPermissionDict.items():
            for vulPermission in permissionList:
                try:
                    dictCol1List.append(str(packageName).split("/")[0])
                    dictCol2List.append(str(packageName).split("/")[1])
                    dictCol3List.append(vulPermission)
                except IndexError as e:
                    print(e)
                    continue
        # 设置xlsx表格每列数据的源数据列表
        dataSource["APPName"] = dictCol1List
        dataSource["PackageName"] = dictCol2List
        dataSource["PermissionName"] = dictCol3List
        # print(dataSource)
        print(Fore.BLUE + "[*]Start generating xlsx…")
        writer = pd.ExcelWriter(xlsxPath)
        dataFrame = pd.DataFrame(dataSource)
        dataFrame.to_excel(writer, sheet_name="sheet1")
        writer.close()  # 保存writer中的数据至excel
        print(Fore.BLUE + "[*]Successfully generated xlsx!")
    
    
    def copyRight():
        print(Fore.GREEN + "************** CopyRight ****************")
        print(Fore.GREEN + "             Welcome to use               ")
        print(Fore.GREEN + "     Author: Tr0e                         ")
        print(Fore.GREEN + "     Github: https://github.com/Tr0e      ")
        print(Fore.GREEN + "     Blog  : https://tr0e.github.io       ")
        print(Fore.GREEN + "*****************************************")
    
    
    if __name__ == '__main__':
        copyRight()
        start = time.time()
        # 对批量APP排查未定义权限并生成统计表格
        analyzePermissions("D:/tmp/Result")
        writePermissionXlsx("data/result/permission.xlsx")
        end = time.time()
        print(Fore.BLUE + "[*]Done.Totally time is " + str(end - start) + "s.Enjoy it!")
        exit(0)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117

    代码运行效果如下图所示:
    在这里插入图片描述
    在这里插入图片描述
    可以看到由于反复调用 adb shell 命令,导致该部分脚本的运行速度相对较慢,耗时较长。

    总结

    以上对 AndroidMainfest.xml 文件的批量自动化数据解析和提取,生成了可视化的直观统计表格,但是对于安全测试工作而言,这仅仅是完成了信息收集的前期任务,如果借助上述统计表格的数据进行进一步高效的、有针对性的测试,就看各位手握的“攻击面”了。以上完整代码已同步到我的 Giuhub 项目:MyTools,请按需自取。

  • 相关阅读:
    Feature Pyramid Networks for Object Detection(2017.4)
    MySQL性能分析常见方式
    docker笔记7:Docker微服务实战
    SOFA Weekly | 开源人—于雨、本周 QA、本周 Contributor
    【图像处理】使用各向异性滤波器和分割图像处理从MRI图像检测脑肿瘤(Matlab代码实现)
    Element文件上传-解决跨域
    密码学系列7-变幻多端的安全性证明
    Cinema 4D 2024 v2024.0.2
    提高数据科学效率的 8 个Python神库
    IQM的Unimon:一种新的量子比特,可促进量子计算机的实用化
  • 原文地址:https://blog.csdn.net/weixin_39190897/article/details/127826881