forked from circleops/circle-ecosystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.sh
62 lines (53 loc) · 1.7 KB
/
scanner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
#
# Copyright (c) 2022 Circle Internet Financial Trading Company Limited.
# All rights reserved.
#
# Circle Internet Financial Trading Company Limited CONFIDENTIAL
# This file includes unpublished proprietary source code of Circle Internet
# Financial Trading Company Limited, Inc. The copyright notice above does not
# evidence any actual or intended publication of such source code. Disclosure
# of this source code or any related proprietary information is strictly
# prohibited without the express written permission of Circle Internet Financial
# Trading Company Limited.
#
## scanner.sh - Helper script to scan images using VirusTotalAPI.
## Requires VIRUS_TOTAL_API_KEY env var
if [ $# -ne 1 ]
then
echo "Usage: $0 dir to be scanned" >&2
exit 1
fi
if [ -z "${VIRUS_TOTAL_API_KEY}" ]
then
echo "VIRUS_TOTAL_API_KEY env var not defined"
exit 1
fi
check_file_for_malware () {
echo "Uploading file $FILE to Virus total"
request=$(curl -sSL --request POST \
--url "https://www.virustotal.com/vtapi/v2/file/scan" \
--form "apikey=${VIRUS_TOTAL_API_KEY}" \
--form "file=${FILE}")
resource=$(echo $request | jq .resource | tr -d '"')
echo "Checking status of uploaded file"
response=$(curl -sSL --request GET \
--url "https://www.virustotal.com/vtapi/v2/file/report?apikey=${VIRUS_TOTAL_API_KEY}&resource=${resource}")
malware_found=$(echo $response | jq -r .positives | tr -d '"')
if [[ $malware_found -ne 0 ]]
then
echo "Malware Found"
exit 1
else
echo "No malware found"
exit 0
fi
}
DIR="$1"
for FILE in "$DIR"/*
do
if [ -f "$FILE" ]
then
check_file_for_malware
fi
done