Skip to content

Instantly share code, notes, and snippets.

@justsml
Forked from luca-m/virustotal_upload
Last active November 9, 2015 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justsml/ce74c3469dcfaaacdbdf to your computer and use it in GitHub Desktop.
Save justsml/ce74c3469dcfaaacdbdf to your computer and use it in GitHub Desktop.
Upload a sample to VirusTotal and pretty print the report. All in a handy alias.
#!/bin/bash
# Upload a sample to VirusTotal and pretty print the report. All in a handy alias.
#
# Dependecies:
#
# * python > 2.7
# * pip install Pygments==1.4
# * curl
# * VirusTotal API key
#
upload_file=$(which $1)
virustotal_upload() {
apikey=$VT_API_KEY
echo "$(tput setaf 7)Uploading $upload_file to VirusTotal$(tput sgr0)"
vt_hash=$(curl -X POST 'https://www.virustotal.com/vtapi/v2/file/scan' --form apikey=$apikey --form file=@"$(realpath $upload_file)" | grep -o '"[0-9|a-f]{64}"' | head -1 | sed 's/"//g')
echo "GETTING HASH: $vt_hash"
echo "$(tput setaf 4)SHA256:$vt_hash waiting for report..$(tput sgr0)"
if [ "$vt_hash" != "" ]; then
while true; do
response=`curl -X POST 'https://www.virustotal.com/vtapi/v2/file/report' --form apikey=$apikey --form resource=$vt_hash`
echo `echo $response|grep -o '"scans"'`
if [ $(echo -n "$response"|grep -o '"response_code": 1'| wc -l) -eq 1 ]; then
echo "$response" | python -mjson.tool | pygmentize -l javascript -f console | less -r
break;
fi;
echo -e -n "$(tput setaf 7).$(tput sgr0)\r"
sleep 5
done;
else
echo 'FAILED TO GET HASH KEY - RESPONSE FROM VIRUSTOTAL NOT VALID ' $response
fi
}
virustotal_upload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment