-
Notifications
You must be signed in to change notification settings - Fork 18
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 ability to check issues against Virus Total #945
Open
AdmiringWorm
wants to merge
4
commits into
chocolatey-community:master
Choose a base branch
from
AdmiringWorm:virus-total
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
730f106
(maint) Added ability to report on existing VirusTotal reports
AdmiringWorm 6b1a1ad
(maint) Add virus total environment variables
AdmiringWorm 80ebe78
(maint) Added special handling for file details section
AdmiringWorm 8fb1267
(maint) Changed how to calculate anti-virus count
AdmiringWorm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ jobs: | |
runs-on: windows-latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
VIRUS_TOTAL_API_KEY: ${{ secrets.VIRUS_TOTAL_API_KEY }} | ||
|
||
steps: | ||
- uses: actions/[email protected] | ||
|
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,72 @@ | ||
function Get-JsonResults { | ||
param( | ||
$inputObject | ||
) | ||
|
||
try { | ||
# we first try normal serialization | ||
return $inputObject | ConvertFrom-Json | ||
} | ||
catch {} | ||
|
||
try { | ||
# next we try to serialize as hash table | ||
return $inputObject | ConvertFrom-Json -AsHashtable | ||
} | ||
catch {} | ||
|
||
# at the end we just return the object as is | ||
$inputObject | ||
} | ||
|
||
function Get-VirusTotalResults { | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[string]$filePath | ||
) | ||
|
||
if (!(Test-Path Env:\VIRUS_TOTAL_API_KEY)) { | ||
return @{ | ||
Status = "NoApiKey" | ||
Flagged = 0 | ||
TotalCount = 0 | ||
Url = $null | ||
} | ||
} | ||
|
||
Write-Host ([StatusCheckMessages]::virusTotalCheck) | ||
$checksum = (Get-FileHash $filePath -Algorithm SHA256 | % Hash).ToLowerInvariant() | ||
$apiUrl = "https://www.virustotal.com/api/v3/files/{0}" -f $checksum | ||
$headers = @{ | ||
"x-apikey" = $env:VIRUS_TOTAL_API_KEY | ||
} | ||
|
||
try { | ||
$response = Invoke-RestMethod -UseBasicParsing -Uri $apiUrl -Method Get -Headers $headers | ||
$response = Get-JsonResults -inputObject $response | ||
|
||
$stats = $response.data.attributes.last_analysis_stats | ||
|
||
Write-Host ([StatusMessages]::virusTotalResultsAvailable) | ||
|
||
[int]$antiVirusCount = $stats.malicious + $stats.suspecious + $stats.harmless + $stats.undetected + $stats.timeout + $stats.failure + $stats.'confirmed-timout' | ||
|
||
@{ | ||
Status = "Found" | ||
Flagged = ($stats.malicious + $stats.suspecious) | ||
TotalCount = $antiVirusCount | ||
Url = "https://www.virustotal.com/gui/file/{0}" -f $checksum | ||
} | ||
} | ||
catch { | ||
# We will assume this means that no virus results are available. | ||
# VirusTotal seems to return 404 when none are uploaded | ||
Write-Host ([StatusMessages]::noVirusTotalStatusAvailable) | ||
@{ | ||
Status = "NotFound" | ||
Flagged = 0 | ||
TotalCount = 0 | ||
Url = "https://www.virustotal.com/gui/file/{0}" -f $checksum | ||
} | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-AsHashtable
may not be supported in PS5. We're usingwindows-latest
in our tasks, but I think the way we're running it may take us to PowerShell rather than Pwsh. May be wrong! I don't know what we're targetting here, just noting as we normally dive into backwards compatibility.That may also be fine, as this is being used post-IRM, which (I thought) should convert from JSON anyway, and this may just fall down to returning the object as-is. Looking at the API, though, it's... hm, fun.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, it is not supported in PS5. We are however explicitly telling GitHub action to use Pwsh, so that is fine. Backwards compatibility is not a concern as these files aren't supposed to be ran on a users computer.
Also to mention, from what I remember when this was added the entire thing would fall over if
-AsHashtable
wasn't used.