Skip to content

Commit 29dd5fc

Browse files
authored
RI-5395: Add Nightly Virustotal Analyze (#4305)
1 parent 880e7c2 commit 29dd5fc

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Nightly Virustotal Analyze
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
file_url:
7+
description: Provide a file URL for manual scanning (optional)
8+
required: false
9+
default: 'https://s3.amazonaws.com/redisinsight.download/public/latest/Redis-Insight-mac-arm64.dmg'
10+
type: string
11+
12+
env:
13+
VIRUSTOTAL_API_KEY: ${{ secrets.VIRUSTOTAL_API_KEY }}
14+
15+
jobs:
16+
analyze:
17+
name: Analyze file
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Use File URL
22+
id: file_url_check
23+
run: |
24+
echo "Using File URL: ${{ github.event.inputs.file_url }}"
25+
echo "FILE_URL=${{ github.event.inputs.file_url }}" >> $GITHUB_ENV
26+
27+
- name: Send URL to scan
28+
run: |
29+
url="${{ env.FILE_URL }}"
30+
echo "URL to check: $url"
31+
32+
# Upload the URL to VirusTotal
33+
analysedId=$(curl -sq -XPOST https://www.virustotal.com/api/v3/urls \
34+
-H "x-apikey: $VIRUSTOTAL_API_KEY" \
35+
--form url=${url} | jq -r '.data.id')
36+
37+
if [ "$analysedId" == "null" ]; then
38+
echo 'Status is null, something went wrong';
39+
exit 1;
40+
fi
41+
42+
echo "ANALYZED_ID=$analysedId" >> $GITHUB_ENV
43+
44+
- name: Check analyze status
45+
run: |
46+
echo "Virustotal Analyzed ID: ${ANALYZED_ID}"
47+
retryAttempts="50"
48+
intervalTime=30
49+
50+
until [ "$retryAttempts" == "0" ]; do
51+
analyzeStatus=$(curl -sq -XGET https://www.virustotal.com/api/v3/analyses/${ANALYZED_ID} \
52+
-H "x-apikey: $VIRUSTOTAL_API_KEY" | jq -r '.data.attributes.status')
53+
54+
if [ "$analyzeStatus" == "completed" ]; then
55+
echo "Current status: ${analyzeStatus}"
56+
break
57+
else
58+
echo "Current status: ${analyzeStatus}, retries left: ${retryAttempts}"
59+
sleep $intervalTime
60+
retryAttempts=$((retryAttempts - 1))
61+
fi
62+
done
63+
64+
if [ "$analyzeStatus" != "completed" ]; then
65+
echo 'Analyze is not completed'
66+
exit 1
67+
fi
68+
69+
- name: Validate analyze
70+
id: validate
71+
run: |
72+
analyzeStats=$(curl -sq -XGET https://www.virustotal.com/api/v3/analyses/${ANALYZED_ID} \
73+
-H "x-apikey: $VIRUSTOTAL_API_KEY" | jq -r '.data.attributes.stats')
74+
75+
analazedMalicious=$(echo ${analyzeStats} | jq '.malicious')
76+
analazedSuspicious=$(echo ${analyzeStats} | jq '.suspicious')
77+
analazedHarmless=$(echo ${analyzeStats} | jq '.harmless')
78+
79+
echo "Results: Malicious: ${analazedMalicious}, Suspicious: ${analazedSuspicious}, Harmless: ${analazedHarmless}"
80+
81+
if [ "$analazedMalicious" != "0" ] || [ "$analazedSuspicious" != "0" ]; then
82+
echo "FAILED=true" >> $GITHUB_ENV
83+
echo 'Found dangers'
84+
else
85+
echo "FAILED=false" >> $GITHUB_ENV
86+
fi

0 commit comments

Comments
 (0)