-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from anikobartos/master
OPSWAT Filescan Sandbox Integration
Showing
9 changed files
with
12,743 additions
and
92 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
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
'fireeye', | ||
'joe', | ||
'triage', | ||
'opswat', | ||
'vmray', | ||
'falcon', | ||
'wildfire', | ||
|
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
5,578 changes: 5,578 additions & 0 deletions
5,578
tests/resources/opswat_submissions_result_benign.json
Large diffs are not rendered by default.
Oops, something went wrong.
2,378 changes: 2,378 additions & 0 deletions
2,378
tests/resources/opswat_submissions_result_likely_malicious.json
Large diffs are not rendered by default.
Oops, something went wrong.
1,421 changes: 1,421 additions & 0 deletions
1,421
tests/resources/opswat_submissions_result_malicious.json
Large diffs are not rendered by default.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
tests/resources/opswat_submissions_result_not_finished.json
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,70 @@ | ||
{ | ||
"flowId": "65316f10ba877ae559118c99", | ||
"allFinished": false, | ||
"allFilesDownloadFinished": false, | ||
"allAdditionalStepsDone": false, | ||
"reportsAmount": 1, | ||
"priority": "max", | ||
"pollPause": 5, | ||
"fileSize": 13370880, | ||
"fileReadProgressBytes": 13370880, | ||
"reports": { | ||
"761590d3-9fec-4ab9-846f-12db39b156b2": { | ||
"finalVerdict": { | ||
"verdict": "UNKNOWN", | ||
"threatLevel": 0, | ||
"confidence": 1 | ||
}, | ||
"allTags": [], | ||
"overallState": "in_progress", | ||
"taskReference": { | ||
"name": "transform-file", | ||
"additionalInfo": { | ||
"submitName": "bad_file.exe", | ||
"submitTime": 1697738514610, | ||
"digests": { | ||
"SHA-256": "834d1dbfab8330ea5f1844f6e905ed0ac19d1033ee9a9f1122ad2051c56783dc" | ||
} | ||
}, | ||
"ID": "84e354e5-4d3c-4790-b6be-6b75c9fa9160", | ||
"state": "IN_PROGRESS", | ||
"opcount": 0, | ||
"processTime": 0 | ||
}, | ||
"subtaskReferences": [], | ||
"allSignalGroups": [], | ||
"iocs": {}, | ||
"filter_errors": [ | ||
"Resource not found: ['osint', 'file']" | ||
], | ||
"file": { | ||
"name": "bad_file.exe", | ||
"hash": "834d1dbfab8330ea5f1844f6e905ed0ac19d1033ee9a9f1122ad2051c56783dc", | ||
"type": null | ||
}, | ||
"filesDownloadFinished": false, | ||
"additionalStepsRunning": [ | ||
"similarity_search" | ||
], | ||
"additionalStepsDone": false, | ||
"created_date": "10/19/2023, 18:01:53", | ||
"defaultOptionsUsed": false, | ||
"scanOptions": { | ||
"rapid_mode": null, | ||
"osint": true, | ||
"extended_osint": true, | ||
"extracted_files_osint": true, | ||
"visualization": true, | ||
"files_download": true, | ||
"resolve_domains": true, | ||
"input_file_yara": true, | ||
"extracted_files_yara": true, | ||
"whois": true, | ||
"ips_meta": true, | ||
"images_ocr": true | ||
}, | ||
"estimatedTime": "8", | ||
"estimated_progress": 0.40424999594688416 | ||
} | ||
} | ||
} |
3,069 changes: 3,069 additions & 0 deletions
3,069
tests/resources/opswat_submissions_result_suspicious.json
Large diffs are not rendered by default.
Oops, something went wrong.
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,108 @@ | ||
import io | ||
from unittest import TestCase | ||
|
||
try: | ||
from unittest.mock import patch | ||
except ImportError: | ||
from mock import patch | ||
|
||
import responses | ||
import sandboxapi.opswat | ||
from . import read_resource | ||
|
||
|
||
URL = "http://filescanio.mock" | ||
|
||
|
||
class TestOPSWAT(TestCase): | ||
def setUp(self): | ||
self.sandbox = sandboxapi.opswat.OPSWATSandboxAPI("key", URL, True) | ||
|
||
# analyze | ||
@responses.activate | ||
def test_analyze(self): | ||
sent_file_response = {"flow_id": "1234"} | ||
|
||
responses.add(responses.POST, f"{URL}/api/scan/file", json=sent_file_response) | ||
self.assertEqual( | ||
self.sandbox.analyze(io.BytesIO("test".encode("ascii")), "filename"), "1234" | ||
) | ||
|
||
# check | ||
@responses.activate | ||
def test_check(self): | ||
flow_id = 1 | ||
finished = [ | ||
("opswat_submissions_result_malicious", True), | ||
("opswat_submissions_result_not_finished", False), | ||
] | ||
for report in finished: | ||
responses.add( | ||
responses.GET, | ||
f"{URL}/api/scan/{flow_id}/report", | ||
json=read_resource(report[0]), | ||
) | ||
self.assertEqual(self.sandbox.check("1"), report[1]) | ||
|
||
# is available | ||
@responses.activate | ||
def test_is_available(self): | ||
response = { | ||
"accountId": "1234", | ||
} | ||
responses.add(responses.GET, f"{URL}/api/users/me", json=response) | ||
self.assertTrue(self.sandbox.is_available()) | ||
|
||
@responses.activate | ||
def test_not_available(self): | ||
response = { | ||
"accountId": "1234", | ||
} | ||
responses.add(responses.GET, f"{URL}/api/users/me", json=response, status=404) | ||
self.assertFalse(self.sandbox.is_available()) | ||
|
||
# report | ||
@responses.activate | ||
def test_report(self): | ||
id = 1 | ||
url = f"{URL}/api/scan/{id}/report?filter=general&filter=finalVerdict&filter=allTags&filter=overallState&filter=taskReference&filter=subtaskReferences&filter=allSignalGroups&filter=iocs" | ||
|
||
responses.add( | ||
responses.GET, | ||
url, | ||
json=read_resource("opswat_submissions_result_malicious"), | ||
) | ||
|
||
response = self.sandbox.report(id) | ||
self.assertEqual( | ||
response, | ||
read_resource("opswat_submissions_result_malicious"), | ||
) | ||
|
||
self.assertEqual( | ||
response["reports"]["f7977db1-6a99-46c3-8567-de1c88c93aa4"]["finalVerdict"][ | ||
"verdict" | ||
], | ||
"MALICIOUS", | ||
) | ||
|
||
# score | ||
@responses.activate | ||
def test_score(self): | ||
id = 1 | ||
files_and_score = [ | ||
("opswat_submissions_result_malicious", 100), | ||
("opswat_submissions_result_suspicious", 50), | ||
("opswat_submissions_result_benign", 0), | ||
("opswat_submissions_result_likely_malicious", 75), | ||
] | ||
|
||
for file_and_score in files_and_score: | ||
responses.add( | ||
responses.GET, | ||
f"{URL}/api/scan/{id}/report?filter=general&filter=finalVerdict&filter=allTags&filter=overallState&filter=taskReference&filter=subtaskReferences&filter=allSignalGroups&filter=iocs", | ||
json=read_resource(file_and_score[0]), | ||
) | ||
self.assertEqual( | ||
self.sandbox.score(self.sandbox.report(id)), file_and_score[1] | ||
) |