Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scan link to virus total findings #55

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion agent/process_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
EXCLUDED_SCANNERS = ["K7GW", "TrendMicro-HouseCall"]


def get_technical_details(scans: dict[str, Any], target: str | None) -> str:
def get_technical_details(
scans: dict[str, Any], target: str | None, scans_link: str | None
) -> str:
"""Returns a markdown table of the technical report of the scan.
Each row presents an antivirus with corresponding scan result : Malicious/Safe.

Args:
scans : Dictionary of the scans.
target : target to scan.
scans_link : Link to the scan report.

Returns:
technical_detail : Markdown table of the scans results.
Expand All @@ -26,6 +29,10 @@ def get_technical_details(scans: dict[str, Any], target: str | None) -> str:
if target is not None:
technical_detail = f"Analysis of the target `{target}`:\n"
technical_detail += markdown.table_markdown(formatted_scans)
if scans_link is not None:
technical_detail += (
f"\nFor more details, visit the [scan report]({scans_link})."
)
return technical_detail


Expand Down
5 changes: 4 additions & 1 deletion agent/virus_total_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ def process(self, message: msg.Message) -> None:

def _process_response(self, response: dict[str, Any], target: str | None) -> None:
scans = virustotal.get_scans(response)
scans_link = response.get("results", {}).get("permalink")
try:
if scans is not None:
scans = process_scans.exclude_unreliable_scans(scans)
technical_detail = process_scans.get_technical_details(scans, target)
technical_detail = process_scans.get_technical_details(
scans, target, scans_link
)

if process_scans.is_scan_malicious(scans) is True:
self.report_vulnerability(
Expand Down
23 changes: 20 additions & 3 deletions tests/virus_total_agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def virustotal_url_valid_response(url: str, timeout: int) -> dict[str, Any]:
"sha1": "some_sha1",
"resource": "some_ressource_id",
"response_code": 1,
"permalink": "http://www.virustotal.com/url/1db0ad7dbcec0676710ea0eaacd35d5e471d3e11944d53bcbd31f0cbd11bce31/analysis/1320752364/",
},
"response_code": 200,
}
Expand Down Expand Up @@ -131,6 +132,7 @@ def virustotal_valid_response(message: msg.Message) -> dict[str, Any]:
"sha1": "some_sha1",
"resource": "some_ressource_id",
"response_code": 1,
"permalink": "https://www.virustotal.com/file/52d3df0ed60c46f336c131bf2ca454f73bafdc4b04dfa2aea80746f5ba9e6d1c/analysis/1273894724/",
},
"response_code": 200,
}
Expand Down Expand Up @@ -163,6 +165,10 @@ def testVirusTotalAgent_whenVirusTotalApiReturnsValidResponse_noExceptionRaised(
== "VirusTotal scan flagged malicious asset(s) (MD5 based search)"
)
assert isinstance(agent_mock[0].data["technical_detail"], str)
assert (
"For more details, visit the [scan report](https://www.virustotal.com/file/52d3df0ed60c46f336c131bf2ca454f73bafdc4b04dfa2aea80746f5ba9e6d1c/analysis/1273894724/)."
in agent_mock[0].data["technical_detail"]
)
assert all(
msg.data["short_description"] == "VirusTotal Malware analysis."
for msg in agent_mock
Expand Down Expand Up @@ -228,6 +234,11 @@ def testVirusTotalAgent_whenLinkReceived_virusTotalApiReturnsValidResponse(
== "VirusTotal scan flagged malicious asset(s) (MD5 based search)"
)
assert isinstance(agent_mock[0].data["technical_detail"], str)
assert (
"For more details, visit the [scan report]("
"http://www.virustotal.com/url/1db0ad7dbcec0676710ea0eaacd35d5e471d3e11944d53bcbd31f0cbd11bce31/analysis"
"/1320752364/)."
) in agent_mock[0].data["technical_detail"]
assert all(
msg.data["short_description"] == "VirusTotal Malware analysis."
for msg in agent_mock
Expand Down Expand Up @@ -410,9 +421,15 @@ def testVirusTotalAgent_whenFileHasNoPath_shouldReportWithHash(
virustotal_agent.process(message_without_path)

assert len(agent_mock) == 1
assert agent_mock[0].data["technical_detail"] == (
"Analysis of the target `44d88612fea8a8f36de82e1278abb02f`:\n|Package| Result |"
" \n|-------|----------| \n|Bkav |_Safe_ | \n|Elastic|_Malicous_| \n"
assert (
agent_mock[0].data["technical_detail"]
== """Analysis of the target `44d88612fea8a8f36de82e1278abb02f`:
|Package| Result |
|-------|----------|
|Bkav |_Safe_ |
|Elastic|_Malicous_|

For more details, visit the [scan report](https://www.virustotal.com/file/52d3df0ed60c46f336c131bf2ca454f73bafdc4b04dfa2aea80746f5ba9e6d1c/analysis/1273894724/)."""
)


Expand Down
Loading