Exemplo n.º 1
0
Arquivo: vt.py Projeto: 18z/abc
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)
Exemplo n.º 2
0
Arquivo: view.py Projeto: 18z/abc
def download_apk():
    """Get document Objectid and Download APK file
    """
    from core.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
Exemplo n.º 3
0
def download_apk():
    """Get document Objectid and Download APK file
    """
    from core.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
Exemplo n.º 4
0
def main():

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

    while (True):
        #find the first data with vt_scan is False
        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'  #write down the apk file in the disk
            with open(filename, 'wb') as f:
                f.write(db.get_apk_file(doc['apkdata']))

            av_result = vt().submit_sample(
                filename)  #send the file to vt for scan
            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)  # insert vt report into db

        time.sleep(20)