Example #1
0
def _proc_tasks(fw_download_url, g_fw_save_path, ftp_user, ftp_password, task_id):
    print("download task_id", task_id)
    # 检查本地保存路径 没有则创建
    SysUtils.check_filepath(g_fw_save_path)

    # 1 时间消耗总占比30  执行下载操作
    total_percentage = 30.0
    ret_download_info = fw_filename = ""
    file_list = []

    if 'ftp://' in fw_download_url:
        ret_download_info, fw_filename, file_list = Mydownload.ftp_download(fw_download_url, g_fw_save_path, ftp_user,
                                                                            ftp_password, task_id, total_percentage)
    else:
        ret_download_info, fw_filename, file_list = Mydownload.http_download(fw_download_url, g_fw_save_path, task_id,
                                                                             total_percentage)

    print(ret_download_info, fw_filename)
    MyTask.save_exec_info_name(task_id, fw_filename)

    # 2 时间消耗总占比0 保存到 pack_file to mongodb
    pack_id, pack_file_id = _save_pack_db(fw_download_url, os.path.join(g_fw_save_path, fw_filename), ret_download_info,
                                          task_id)
    MyTask.save_exec_info_pack_id(task_id, pack_id)

    # 3 时间消耗总占比0 解压缩固件包->系统镜像文件,提取文件到mongo
    img_filename = _proc_uncompress(os.path.join(g_fw_save_path, fw_filename), g_fw_save_path, task_id)
    if len(img_filename) == 0:
        print("package uncompress error")
        img_filename = fw_filename  # bin文件做为包名(文件名)
        # return "package uncompress error"

    # 4 时间消耗总占比0 保存系统镜像文件 to mongodb
    file_id = _save_file_db(os.path.join(g_fw_save_path, img_filename), pack_id)

    # 5 时间消耗总占比40 BIN提取子文件
    total_percentage = 70.0
    extract_bin_files = MyBinwalk.binwalk_file_extract(os.path.join(g_fw_save_path, img_filename))
    MyTask.save_exec_info(task_id, total_percentage, {'binwalk_file_extract': extract_bin_files})

    for file in extract_bin_files:
        # binwalk解包返回的文件名带全路径
        # 对变量类型进行判断 list 值带[] 如: ['C:\\GIT\\firmware_analyze_serv\\files\\firmware\\_CF-EW71-V2.6.0.bin-2.extracted\\40']
        if isinstance(file, list):
            file_id = _save_file_db(file[0], pack_id)
        else:
            file_id = _save_file_db(file, pack_id)

    # 6 时间消耗总占比30 提取文件系统
    FsImage.start_fs_image_extract_task(pack_id)

    total_percentage = 100.0
    MyTask.save_exec_info(task_id, total_percentage, {'download': "固件下载、提取、入库操作完成"})

    # 7 clear temp files
    return 'ERROR_OK'
Example #2
0
def _check_file(task_id):
    # 枚举目录 获取文件
    # path = "C:\\GIT\\python\\firmware"
    path = "C:\\固件下载\\huawei"
    path = "C:\\固件下载\\ZS7035"
    # path = "C:\\TEMP"
    uncompress_path = "C:\\TEMP"

    dest = []
    enumfiles(path, dest)

    SysUtils.check_filepath(uncompress_path)
    os.chdir(uncompress_path)  # 将当前的目录设置为uncompress_path
    for file in dest:
        print(file)
        # 解压缩固件包->系统镜像文件,提取文件到mongo
        # file_path, file_name = os.path.split(file)
        if '.bin' in file:
            img_filename = file
        elif '.trx' in file:
            img_filename = file
        else:
            img_filename = _proc_uncompress(file, uncompress_path, task_id)
        if len(img_filename) == 0:
            continue
        # BINWALK 提取文件
        extract_bin_files = MyBinwalk._binwalk_file_extract(os.path.join(uncompress_path, img_filename),
                                                            uncompress_path)

        # binwalk解包返回的文件名带全路径 写文件
        with open('c:\\git\\file_tree_info0413.txt', 'a+') as fw:
            fw.write(file)
            fw.write('\r')
            for f in extract_bin_files:
                # print(b'Saving original ' + path.encode() + i.getPath().encode() + i.getName())
                if isinstance(f, list):
                    fw.write(os.path.basename(f[0]))
                else:
                    fw.write(os.path.basename(f))
                fw.write('\r')
            fw.close()

        del_file(uncompress_path)

    return
Example #3
0
def _proc_component_tasks(com_download_url, components_save_path, task_id):
    print("download task_id", task_id)
    # 检查本地保存路径 没有则创建
    SysUtils.check_filepath(components_save_path)

    # 1 时间消耗总占比30  执行下载操作
    total_percentage = 30.0
    ret_download_info = com_filename = ""
    file_list = []

    ret_download_info, com_filename, file_list = Mydownload.http_download(com_download_url, components_save_path, task_id, total_percentage)

    print(ret_download_info, com_filename)
    MyTask.save_exec_info_name(task_id, com_filename)

    # 5 组件源码下载后关联漏洞库
    edb_id, title = associated_vulner_db(com_filename)
    total_percentage = 50.0
    MyTask.save_exec_info(task_id, total_percentage, {'download': "组件源码下载后关联漏洞库"})

    # 2 时间消耗总占比0 保存到 pack_com_file to mongodb
    pack_com_id, pack_com_file_id = _save_pack_com_db(os.path.join(components_save_path, com_filename), ret_download_info, edb_id, title, task_id)
    MyTask.save_exec_info_pack_id(task_id, pack_com_id)

    # 3 时间消耗总占比0 解压缩源码包,提取文件到mongo
    output_dir, file_name = os.path.split(os.path.join(components_save_path, com_filename))
    file_list = _proc_com_uncompress(os.path.join(components_save_path, com_filename), output_dir, task_id)

    total_percentage = 70.0
    MyTask.save_exec_info(task_id, total_percentage, {'download': "下载组件解压缩源码包操作完成"})
    # 4 时间消耗总占比0 保存源码文件 to mongodb
    file_id = _save_source_code_file_db(os.path.join(output_dir, file_name.split('.tar.gz')[0]), pack_com_id, task_id)

    total_percentage = 100.0
    MyTask.save_exec_info(task_id, total_percentage, {'download': "下载组件源码入库操作完成"})

    # 7 clear temp files
    return 'ERROR_OK'