예제 #1
0
def main():

    try:
        db = DB()
    except:
        logging.error("DB error")
        raise

    while(True):
        doc = db.get_apk({'vt_scan': False, 'limit': 1})

        if not doc:
            logging.info("Maybe there's no document without vt_scan:true.")
            break

        av_result = vt().get(doc['md5'])

        if av_result is None:
            time.sleep(20)
            filename = '/tmp/'+doc['pgname']+'.apk'
            with open(filename, 'wb') as f:
                f.write(db.get_apk_file(doc['apkdata']))

            av_result = vt().submit_sample(filename)
            os.remove(filename)

            logging.info("Get av_result again")
            # It will try to get report with several queries,
            # so we take some sleep here.
            time.sleep(60)

        logging.debug("av_result: {}".format(av_result))
        db.update_av_report(doc['_id'], av_result)

        time.sleep(20)
예제 #2
0
def download_apk():
    """Get document Objectid and Download APK file
    """
    from db.Mongo import DB
    from bson.objectid import ObjectId

    my_db = DB()
    apk_id = request.form['download_apk']

    apk_info = my_db.get_apk({'_id': ObjectId(apk_id), 'limit': 1})
    logging.debug(
        'Download {}, {}'.format(apk_info['md5'], apk_info['apkdata']))
    apkdata = my_db.get_apk_file(apk_info['apkdata'])

    response = make_response(apkdata)
    response.headers['Content-Type'] = 'application/vnd.android.package-archive'
    response.headers['Content-Disposition'] = 'attachment; filename='+apk_info['pgname']+".apk"

    return response