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)
def main(): start = time.time() try: db = DB() except: logging.error("DB error") raise number_of_key = 8 #get all data whitch including sacn :False doc = db.get_all_vt_False() lock = threading.Lock()#thread lock thread_data = spilt(doc,doc.count(),number_of_key) # api_key =['51d63dc8b2860fbd889ea73d564e361e1ec795ce2daadb1046771272336cdadf', # '20f0728b711931ef2f60c8c403e83c20b600a902a12293a7d1fe566f85ca22dd', # '7ec895bab30a273bf6df3e211105f5f2ee45a96ddea57f53d6e4fe2b98f0c7c1', # 'd0fe387a075ca62d0336485641912f1b318240f6132c576fa96dbf81b242da71', # '29b45a9dc40737a7bc894cbacc3da603044e7f3a2651606dfca89de9accab80a', # '51d63dc8b2860fbd889ea73d564e361e1ec795ce2daadb1046771272336cdadf', # '60473b7caf108d05a5f51b9fd7544f6bb7bd0a4d966ca58d0c7b65e43611abc9', # '860011e025932bd8ad550e3174b75ee1c686134543a4635a4e37fef038c0fbec'] thread_pool = [] #deal apk with md5 for i in range(0,number_of_key): p = Thread_mongo(lock,api_key[i],thread_data[i]) thread_pool.append(p) for i in thread_pool: i.start() for i in thread_pool: i.join() # get the remaining data doc = db.get_all_vt_False() v = virustotal.VirusTotal('51d63dc8b2860fbd889ea73d564e361e1ec795ce2daadb1046771272336cdadf') #send apk data by one process for i in doc: print i['name'] time.sleep(20) filename = '/tmp/'+i['pgname']+'.apk'#write down the apk file in the disk with open(filename, 'wb') as f: f.write(db.get_apk_file(i['apkdata'])) av_result = submit_sample(v,filename) os.remove(filename) db.update_av_report(i['_id'], av_result) end = time.time() print 'total used:', end - start,' s'
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
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
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)