Skip to content

Commit cfe8099

Browse files
authored
scan files for virus with command line (#2664)
Signed-off-by: Daniel Hansson <[email protected]>
1 parent 6de5151 commit cfe8099

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

lib.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,35 @@ something is wrong here. Please report this to $ISSUES"
384384
fi
385385
}
386386

387+
metadefender-scan() {
388+
# Usage:
389+
# metadefender-scan.sh $PATH $APIKEY, for example:
390+
hash="$(sha256sum "$1")"
391+
hash="${hash%% *}"
392+
apikey=7283aa9bbcee83132506659a4e5675bb
393+
curl "https://api.metadefender.com/v4/hash/$hash" -H "apikey: $apikey"
394+
}
395+
387396
# Used in geoblock.sh
388397
download_geoip_dat() {
389398
# 1 = IP version 4 or 6
390399
# 2 = v4 or v6
391400
if site_200 https://dl.miyuru.lk/geoip/maxmind/country/maxmind"$1".dat.gz
392401
then
393402
curl_to_dir https://dl.miyuru.lk/geoip/maxmind/country maxmind"$1".dat.gz /tmp
394-
install_if_not gzip
395-
gzip -d /tmp/maxmind"$1".dat.gz
396-
mv /tmp/maxmind"$1".dat /usr/share/GeoIP/GeoIP"$2".dat
397-
chown root:root /usr/share/GeoIP/GeoIP"$2".dat
398-
chmod 644 /usr/share/GeoIP/GeoIP"$2".dat
399-
find "$SCRIPTS" -type f -regex "$SCRIPTS/202[0-9]-[01][0-9]-Maxmind-Country-IP$2\.dat" -delete
403+
# Scan file for virus
404+
if ! metadefender-scan /tmp/maxmind"$1".dat.gz | grep '"scan_all_result_i":0,"current_av_result_i":0,"'
405+
then
406+
msg_box "Potential threat found in .dat file! Please report this to $ISSUES. We will now delete the file!"
407+
rm -f /tmp/maxmind"$1".dat.gz
408+
else
409+
install_if_not gzip
410+
gzip -d /tmp/maxmind"$1".dat.gz
411+
mv /tmp/maxmind"$1".dat /usr/share/GeoIP/GeoIP"$2".dat
412+
chown root:root /usr/share/GeoIP/GeoIP"$2".dat
413+
chmod 644 /usr/share/GeoIP/GeoIP"$2".dat
414+
find "$SCRIPTS" -type f -regex "$SCRIPTS/202[0-9]-[01][0-9]-Maxmind-Country-IP$2\.dat" -delete
415+
fi
400416
fi
401417
}
402418

0 commit comments

Comments
 (0)