-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
226 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
from django.core.files import File | ||
|
||
from colander.core.models import Artifact | ||
from colander.core.utils import hash_file | ||
|
||
|
||
def import_file_as_artifact(input_file, owner, case, artifact_type, name, mimetype, tlp, pap) -> Artifact: | ||
sha256, sha1, md5, size = hash_file(input_file) | ||
input_file.seek(0) | ||
input_file.seek(0, os.SEEK_END) | ||
size_in_bytes = input_file.tell() | ||
input_file.seek(0) | ||
artifact = Artifact( | ||
type=artifact_type, | ||
name=name, | ||
original_name=name, | ||
owner=owner, | ||
case=case, | ||
tlp=tlp, | ||
pap=pap, | ||
mime_type=mimetype, | ||
sha1=sha1, | ||
sha256=sha256, | ||
md5=md5, | ||
size_in_bytes=size_in_bytes, | ||
file=File(file=input_file, name=name) | ||
) | ||
artifact.save() | ||
return artifact |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from tempfile import NamedTemporaryFile | ||
from zipfile import ZipFile | ||
|
||
import requests | ||
|
||
from colander.core.artifact_utils import import_file_as_artifact | ||
from colander.core.models import Observable, EntityRelation, ArtifactType | ||
|
||
|
||
def capture_url(observable_id): | ||
url_object = Observable.objects.get(id=observable_id) | ||
payload = { | ||
'url': url_object.name | ||
} | ||
response = requests.post('http://playwright:80/capture', json=payload) | ||
if response.status_code == 200: | ||
with NamedTemporaryFile() as out: | ||
out.write(response.content) | ||
with ZipFile(out.name, 'r') as archive: | ||
with archive.open('screenshot.png') as screenshot_file: | ||
screenshot = import_file_as_artifact( | ||
screenshot_file, | ||
url_object.owner, | ||
url_object.case, | ||
ArtifactType.objects.get(short_name='IMAGE'), | ||
'webpage_screenshot.png', | ||
'image/png', | ||
url_object.tlp, | ||
url_object.pap, | ||
) | ||
relation = EntityRelation( | ||
name='screenshot of', | ||
owner=url_object.owner, | ||
case=url_object.case, | ||
obj_from=screenshot, | ||
obj_to=url_object | ||
) | ||
relation.save() | ||
with archive.open('capture.har') as screenshot_file: | ||
har = import_file_as_artifact( | ||
screenshot_file, | ||
url_object.owner, | ||
url_object.case, | ||
ArtifactType.objects.get(short_name='HAR'), | ||
'webpage_traffic.har', | ||
'application/json', | ||
url_object.tlp, | ||
url_object.pap, | ||
) | ||
relation = EntityRelation( | ||
name='HTTP traffic of', | ||
owner=url_object.owner, | ||
case=url_object.case, | ||
obj_from=har, | ||
obj_to=url_object | ||
) | ||
relation.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{% load i18n %} | ||
|
||
{% with targets=entity.out_relations origins=entity.in_relations %} | ||
{% if origins or targets %} | ||
<div class="col-md-12 mt-2"> | ||
<h3>{% translate "Related entities" %}</h3> | ||
<table class="table table-sm"> | ||
<thead class="bg-secondary-light"> | ||
<tr> | ||
<td>Type</td> | ||
<td>Entity</td> | ||
<td></td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for relation in origins %} | ||
{% include "entity_relation/table_item.html" with direction="from" %} | ||
{% endfor %} | ||
{% for relation in targets %} | ||
{% include "entity_relation/table_item.html" with direction="to" %} | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
{% endif %} | ||
{% endwith %} |
Oops, something went wrong.