@@ -3,84 +3,137 @@ name: Nightly Virustotal Analyze
3
3
on :
4
4
workflow_dispatch :
5
5
inputs :
6
+ mode :
7
+ description : " Choose 'single' or 'all'"
8
+ required : true
9
+ default : ' all'
10
+ type : string
6
11
file_url :
7
- description : Provide a file URL for manual scanning (optional)
12
+ description : " Provide a file URL for single file scanning (required for 'single' mode) "
8
13
required : false
9
14
default : ' https://s3.amazonaws.com/redisinsight.download/public/latest/Redis-Insight-mac-arm64.dmg'
10
15
type : string
16
+ schedule :
17
+ - cron : ' 0 0 * * *'
11
18
12
19
env :
13
20
VIRUSTOTAL_API_KEY : ${{ secrets.VIRUSTOTAL_API_KEY }}
21
+ DEFAULT_FILES : |
22
+ https://s3.amazonaws.com/redisinsight.download/public/latest/Redis-Insight-mac-x64.dmg
23
+ https://s3.amazonaws.com/redisinsight.download/public/latest/Redis-Insight-mac-arm64.dmg
24
+ https://s3.amazonaws.com/redisinsight.download/public/latest/Redis-Insight-win-installer.exe
25
+ https://s3.amazonaws.com/redisinsight.download/public/latest/Redis-Insight-linux-x86_64.AppImage
26
+ https://s3.amazonaws.com/redisinsight.download/public/latest/Redis-Insight-linux-amd64.deb
14
27
15
28
jobs :
16
29
analyze :
17
- name : Analyze file
30
+ name : VirusTotal Analyze
31
+ runs-on : ubuntu-latest
32
+ outputs :
33
+ files : ${{ steps.setup_matrix.outputs.files }}
34
+ steps :
35
+ - name : Determine mode and files
36
+ id : setup_matrix
37
+ run : |
38
+ mode="${{ github.event.inputs.mode }}"
39
+ file_url="${{ github.event.inputs.file_url }}"
40
+
41
+ if [ "$mode" == "single" ] && [ -z "$file_url" ]; then
42
+ echo "Error: For 'single' mode, a file URL must be provided."
43
+ exit 1
44
+ fi
45
+
46
+ if [ "$mode" == "single" ]; then
47
+ echo "files=[\"$file_url\"]" >> $GITHUB_OUTPUT
48
+ else
49
+ files_json=$(echo "${{ env.DEFAULT_FILES }}" | sed '/^$/d' | jq -R -s -c 'split("\n")[:-1]')
50
+ echo "files=$files_json" >> $GITHUB_OUTPUT
51
+ fi
52
+
53
+ analyze_files :
54
+ name : Analyze each file
55
+ needs : analyze
18
56
runs-on : ubuntu-latest
19
57
58
+ strategy :
59
+ matrix :
60
+ file : ${{ fromJson(needs.analyze.outputs.files) }}
61
+
20
62
steps :
21
- - name : Use File URL
22
- id : file_url_check
63
+ - name : Download file
23
64
run : |
24
- echo "Using File URL : ${{ github.event.inputs.file_url }}"
25
- echo "FILE_URL= ${{ github.event.inputs.file_url }}" >> $GITHUB_ENV
65
+ echo "Downloading : ${{ matrix.file }}"
66
+ curl -sLo file_to_analyze " ${{ matrix.file }}"
26
67
27
- - name : Send URL to scan
68
+ - name : Get upload URL
69
+ id : get_upload_url
28
70
run : |
29
- url="${{ env.FILE_URL }}"
30
- echo "URL to check: $url"
71
+ upload_url=$(curl -sq -XGET https://www.virustotal.com/api/v3/files/upload_url \
72
+ -H "x-apikey: $VIRUSTOTAL_API_KEY" | jq -r '.data')
73
+
74
+ if [ -z "$upload_url" ] || [ "$upload_url" == "null" ]; then
75
+ echo "Failed to retrieve upload URL for ${{ matrix.file }}"
76
+ exit 1
77
+ fi
78
+
79
+ echo "UPLOAD_URL=$upload_url" >> $GITHUB_ENV
31
80
32
- # Upload the URL to VirusTotal
33
- analysedId=$(curl -sq -XPOST https://www.virustotal.com/api/v3/urls \
81
+ - name : Upload file to VirusTotal
82
+ id : upload_file
83
+ run : |
84
+ upload_url="${{ env.UPLOAD_URL }}"
85
+ analyzed_id=$(curl -sq -XPOST "$upload_url" \
34
86
-H "x-apikey: $VIRUSTOTAL_API_KEY" \
35
- --form url=${url} | jq -r '.data.id')
87
+ --form "file=@file_to_analyze" | jq -r '.data.id')
36
88
37
- if [ "$analysedId " == "null" ]; then
38
- echo 'Status is null, something went wrong';
39
- exit 1;
89
+ if [ -z "$analyzed_id" ] || [ "$analyzed_id " == "null" ]; then
90
+ echo "Failed to upload file: ${{ matrix.file }}"
91
+ exit 1
40
92
fi
41
93
42
- echo "ANALYZED_ID=$analysedId " >> $GITHUB_ENV
94
+ echo "ANALYZED_ID=$analyzed_id " >> $GITHUB_ENV
43
95
44
96
- name : Check analyze status
45
97
run : |
46
- echo "Virustotal Analyzed ID: ${ ANALYZED_ID}"
47
- retryAttempts="50"
48
- intervalTime =30
98
+ analyzed_id="${{ env. ANALYZED_ID } }"
99
+ retry_attempts=50
100
+ interval_time =30
49
101
50
- until [ "$retryAttempts " == "0" ]; do
51
- analyzeStatus =$(curl -sq -XGET https://www.virustotal.com/api/v3/analyses/${ANALYZED_ID } \
102
+ until [ "$retry_attempts " == "0" ]; do
103
+ analyze_status =$(curl -sq -XGET https://www.virustotal.com/api/v3/analyses/${analyzed_id } \
52
104
-H "x-apikey: $VIRUSTOTAL_API_KEY" | jq -r '.data.attributes.status')
53
105
54
- if [ "$analyzeStatus" == "completed" ]; then
55
- echo "Current status: ${analyzeStatus}"
106
+ if [ "$analyze_status" == "completed" ]; then
56
107
break
57
- else
58
- echo "Current status: ${analyzeStatus}, retries left: ${retryAttempts}"
59
- sleep $intervalTime
60
- retryAttempts=$((retryAttempts - 1))
61
108
fi
109
+
110
+ echo "Current status: $analyze_status, retries left: $retry_attempts"
111
+ sleep $interval_time
112
+ retry_attempts=$((retry_attempts - 1))
62
113
done
63
114
64
- if [ "$analyzeStatus " != "completed" ]; then
65
- echo 'Analyze is not completed'
115
+ if [ "$analyze_status " != "completed" ]; then
116
+ echo "Analysis not completed for ${{ matrix.file }}"
66
117
exit 1
67
118
fi
68
119
69
120
- name : Validate analyze
70
- id : validate
71
121
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')
122
+ analyzed_id="${{ env.ANALYZED_ID }}"
123
+ analysis=$(curl -sq -XGET "https://www.virustotal.com/api/v3/analyses/${analyzed_id}" \
124
+ -H "x-apikey: $VIRUSTOTAL_API_KEY")
74
125
75
- analazedMalicious=$(echo ${analyzeStats} | jq '.malicious')
76
- analazedSuspicious=$(echo ${analyzeStats} | jq '.suspicious')
77
- analazedHarmless=$(echo ${analyzeStats} | jq '.harmless')
126
+ analyze_stats=$(echo "$analysis" | jq -r '.data.attributes.stats')
78
127
79
- echo "Results: Malicious: ${analazedMalicious}, Suspicious: ${analazedSuspicious}, Harmless: ${analazedHarmless}"
128
+ malicious=$(echo "$analyze_stats" | jq '.malicious')
129
+ suspicious=$(echo "$analyze_stats" | jq '.suspicious')
130
+ suspicious=$(echo "$analyze_stats" | jq '.suspicious')
131
+ harmless=$(echo "$analyze_stats" | jq '.harmless')
80
132
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
133
+ echo "Results for ${{ matrix.file }}: Malicious: $malicious, Suspicious: $suspicious, Harmless: $harmless"
134
+
135
+ if [ "$malicious" != "0" ] || [ "$suspicious" != "0" ]; then
136
+ echo "File ${{ matrix.file }} is flagged as potentially harmful."
137
+ echo "$analysis" | jq -r '.data.attributes.results[] | select(.result == "malicious" or .result == "suspicious")'
138
+ exit 1
86
139
fi
0 commit comments