Example #1
0
    def refresh_artifacts(self, data=""):
        if data == "":
            coms = self.comments_set.all()

            data = self.description
            for c in coms:
                data += "\n" + c.comment

        found_artifacts = artifacts.find(data)

        artifact_list = []
        for key in found_artifacts:
            for a in found_artifacts[key]:
                artifact_list.append((key, a))

        db_artifacts = Artifact.objects.filter(value__in=[a[1] for a in artifact_list])

        exist = []

        for a in db_artifacts:
            exist.append((a.type, a.value))
            if self not in a.incidents.all():
                a.incidents.add(self)

        new_artifacts = list(set(artifact_list) - set(exist))
        all_artifacts = list(set(artifact_list))

        for a in new_artifacts:
            new = Artifact(type=a[0], value=a[1])
            new.save()
            new.incidents.add(self)

        for a in all_artifacts:
            artifacts.after_save(a[0], a[1], self)
Example #2
0
File: models.py Project: er587/FIR
    def refresh_artifacts(self, data=""):
        if data == "":
            coms = self.comments_set.all()

            data = self.description
            for c in coms:
                data += "\n" + c.comment

        found_artifacts = artifacts.find(data)

        artifact_list = []
        for key in found_artifacts:
            for a in found_artifacts[key]:
                artifact_list.append((key, a))

        db_artifacts = Artifact.objects.filter(value__in=[a[1] for a in artifact_list])

        exist = []

        for a in db_artifacts:
            exist.append((a.type, a.value))
            if self not in a.incidents.all():
                a.incidents.add(self)

        new_artifacts = list(set(artifact_list) - set(exist))
        all_artifacts = list(set(artifact_list))

        for a in new_artifacts:
            new = Artifact(type=a[0], value=a[1])
            new.save()
            new.incidents.add(self)

        for a in all_artifacts:
            artifacts.after_save(a[0], a[1], self)
Example #3
0
def scan_file(file_object, user):
    logger.debug("Scanning uploaded file %s", file_object.getfilename())
    try:
        from fir_artifacts.models import Artifact
        from fir_artifacts import Hash
        code, payload = api.new_scan()
        scan_id = payload['id']
        scan = IrmaScan.objects.create(irma_scan=scan_id, user=user)
        api.upload_files(scan_id, files={'file': file_object.file})
        force = user.has_perm('fir_irma.can_force_scan')
        api.launch_scan(scan_id, force=force)
        hashes = file_object.get_hashes()
        for h in hashes:
            try:
                a = Artifact.objects.get(value=hashes[h])
                a.save()
            except Exception:
                a = Artifact()
                a.type = Hash.key
                a.value = hashes[h]
                a.save()
            a.relations.add(scan)
    except api.APIError as error:
        logger.error("IRMA automatic scan error - %s - %s", error.type, error.message)
    except Exception as error:
        logger.error("IRMA automatic scan error - generic_error - %s", str(error))
Example #4
0
def handle_uploaded_file(file, description, obj):

	f = File()
	f.description = description
	f.file = file
	f.content_object = obj
	f.save()

	hashes = f.get_hashes()
	for h in hashes:
		try:
			a = Artifact.objects.get(value=hashes[h])
			a.save()
		except Exception:
			a = Artifact()
			a.type = Hash.key
			a.value = hashes[h]
			a.save()

		a.relations.add(obj)
		f.hashes.add(a)
	f.save()
Example #5
0
def handle_uploaded_file(file, description, obj):

    f = File()
    f.description = description
    f.file = file
    f.content_object = obj
    f.save()

    hashes = f.get_hashes()
    for h in hashes:
        try:
            a = Artifact.objects.get(value=hashes[h])
            a.save()
        except Exception:
            a = Artifact()
            a.type = Hash.key
            a.value = hashes[h]
            a.save()

        a.relations.add(obj)
        f.hashes.add(a)
    f.save()

    return f