Ejemplo n.º 1
0
def save_file_from_vt(hash_id):
    downloaded_file = download_from_virus_total(hash_id)
    if (downloaded_file == None):
        return None

    data_bin = downloaded_file
    file_id = hashlib.sha1(data_bin).hexdigest()
    # print "file_id="+str(file_id)
    pc = PackageController()
    res = pc.searchFile(file_id)
    if (res == None):  # File not found. Add it to the package.
        pc.append(file_id, data_bin, True)
        print("Added: %s" % (file_id, ))
    return file_id
Ejemplo n.º 2
0
def save_file_from_vt(hash_id):
    downloaded_file=download_from_virus_total(hash_id)
    if(downloaded_file==None):
        return None

    data_bin=downloaded_file
    file_id=hashlib.sha1(data_bin).hexdigest()
   # print "file_id="+str(file_id)
    pc=PackageController()
    res=pc.searchFile(file_id)
    if(res==None): # File not found. Add it to the package.
        pc.append(file_id,data_bin,True)
        print("Added: %s" % (file_id,))
    return file_id
Ejemplo n.º 3
0
def add_file_from_vt(hash_id):
    #return None # FUNCION DESABILITADA - SACAR LA LINEA PARA PONER
    downloaded_file = download_from_virus_total(hash_id)
    if (downloaded_file == None):
        return None

    data_bin = downloaded_file
    file_id = hashlib.sha1(data_bin).hexdigest()
    #print "file_id="+str(file_id)
    pc = PackageController()
    res = pc.searchFile(file_id)
    if (res == None):  # File not found. Add it to the package.
        pc.append(file_id, data_bin, True)
        #print("Added: %s" % (file_id,))
    return file_id
Ejemplo n.º 4
0
def add_file_from_vt(hash_id):
    #return None # FUNCION DESABILITADA - SACAR LA LINEA PARA PONER
    downloaded_file=download_from_virus_total(hash_id)
    if(downloaded_file==None):
        return None

    data_bin=downloaded_file
    file_id=hashlib.sha1(data_bin).hexdigest()
    #print "file_id="+str(file_id)
    pc=PackageController()
    res=pc.searchFile(file_id)
    if(res==None): # File not found. Add it to the package.
        pc.append(file_id,data_bin,True)
        #print("Added: %s" % (file_id,))
    return file_id
Ejemplo n.º 5
0
def load_to_mongo2(folder_path):
    pc=PackageController()
    ram = Ram()
    files=recursive_read(folder_path)
    count=0
    reset=0
    already_loaded=0
    time_start = datetime.datetime.now()
    uploaded=0
    in_mem=0
    loaded_ram_counter=0
    lc=Launcher()
    if(files is None):
        return "No files where found."
    while (uploaded < len(files)):
        loaded_ram_counter=0
        data_vector=[]
        print "loading files to memory"
        while (in_mem < len(files)):
            f=files[in_mem]
            file_cursor=open(f,"r")
            data_vector.append(file_cursor.read())
            in_mem=in_mem+1
            loaded_ram_counter=loaded_ram_counter+1
            if(loaded_ram_counter > 100):
                if(ram.free_percent() < 0.3):
                    print "Ram full"
                    break
        for data in data_vector:
            file_id=hashlib.sha1(data).hexdigest()
            print "loading to db: "+str(file_id)
            res=pc.searchFile(file_id)
            if(res==None):
                pc.append(file_id,data)
                sample=Sample()
                sample.setID(file_id)
                sample.setBinary(data)
                sample.setStorageVersion({}) 
                count+=1
                lc.launchAnalysisByID(sample)
            else:
                already_loaded+=1
            uploaded=uploaded+1

    result=str(already_loaded)+" were already loaded to mongo.\n"
    result+=thetime(time_start,datetime.datetime.now(),count)
    print result
    return result
Ejemplo n.º 6
0
def upload_file(data_bin):
    pc=PackageController()
    file_id=hashlib.sha1(data_bin).hexdigest()
    res=pc.searchFile(file_id)
    if(res==None): # File not found. Add it to the package.
        pc.append(file_id,data_bin)
        print("Added: %s" % (file_id,))
        log_event("file added",str(file_id))
        return "ok"
    else:
        if(res==0):#file already exists
            log_event("file already exists",str(file_id))
            return "already exists"
        else:#existe y esta bloqueado por vt
            log_event("file already exists",str(file_id))
            return "virustotal"
Ejemplo n.º 7
0
def upload_file(data_bin):
    pc = PackageController()
    file_id = hashlib.sha1(data_bin).hexdigest()
    res = pc.searchFile(file_id)
    if (res == None):  # File not found. Add it to the package.
        pc.append(file_id, data_bin)
        print("Added: %s" % (file_id, ))
        log_event("file added", str(file_id))
        return "ok"
    else:
        if (res == 0):  #file already exists
            log_event("file already exists", str(file_id))
            return "already exists"
        else:  #existe y esta bloqueado por vt
            log_event("file already exists", str(file_id))
            return "virustotal"
def save_file_from_vt(hash_id):
    downloaded_file=download_from_virus_total(hash_id)
    if(downloaded_file==None):
        return {"status": "unknown", "hash": None}
    if downloaded_file.get('status') == "out_of_credits":
        return {"status": "out_of_credits", "hash": None}
    if downloaded_file.get('status') == "not_found":
        return {"status": "not_found", "hash": None}
    if downloaded_file.get('status') == 'ok':
        data_bin=downloaded_file.get('file')
        file_id=hashlib.sha1(data_bin).hexdigest()
        pc=PackageController()
        res=pc.searchFile(file_id)
        if(res==None): # File not found. Add it to the package.
            pc.append(file_id,data_bin,True)
            return {"status": "added", "hash": file_id}
        else:
            process_file(file_id)
            return {"status": "inconsistency_found", "hash": file_id}
Ejemplo n.º 9
0
def save_file_from_vt(hash_id):
    downloaded_file = download_from_virus_total(hash_id)
    if(downloaded_file is None):
        return {"status": "unknown", "hash": None}
    if downloaded_file.get('status') == "out_of_credits":
        return {"status": "out_of_credits", "hash": None}
    if downloaded_file.get('status') == "not_found":
        return {"status": "not_found", "hash": None}
    if downloaded_file.get('status') == 'ok':
        data_bin = downloaded_file.get('file')
        file_id = hashlib.sha1(data_bin).hexdigest()
        pc = PackageController()
        res = pc.searchFile(file_id)
        if(res is None):  # File not found. Add it to the package.
            pc.append(file_id, data_bin, True)
            return {"status": "added", "hash": file_id}
        else:
            process_file(file_id)
            return {"status": "inconsistency_found", "hash": file_id}
Ejemplo n.º 10
0
def add_file_from_vt(hash_id):
    downloaded_file=download_from_virus_total(hash_id)
    if(downloaded_file==None):
        print "add_file_from_vt(): "+str(hash_id)+" not found in VT."
        return None

    print "add_file_from_vt(): downloaded_file is not None."+str(hash_id)
    data_bin=downloaded_file
    file_id=hashlib.sha1(data_bin).hexdigest()
    #print "file_id="+str(file_id)
    pc=PackageController()
    res=pc.searchFile(file_id)
    if(res==None): # File not found. Add it to the package.
        pc.append(file_id,data_bin,True)
        print str(hash_id)+" added to DB from VT."
        #print("Added: %s" % (file_id,))
    else:
        print "add_file_from_vt(): "+str(hash_id)+" was found in the DB and asked in VT: BUG. Going to process right now."
        process_file(file_id)
    return file_id