forked from williballenthin/govt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtFileReport.go
49 lines (42 loc) · 1.21 KB
/
vtFileReport.go
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
// vtFileReport - fetches a report from VirusTotal for the given resource. A resource can be MD5, SHA-1 or SHA-2 of a file.
// vtFileReport -rsrc=8ac31b7350a95b0b492434f9ae2f1cde
//
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"github.com/williballenthin/govt"
)
var apikey string
var apiurl string
var rsrc string
// init - initializes flag variables.
func init() {
flag.StringVar(&apikey, "apikey", os.Getenv("VT_API_KEY"), "Set environment variable VT_API_KEY to your VT API Key or specify on prompt")
flag.StringVar(&apiurl, "apiurl", "https://www.virustotal.com/vtapi/v2/", "URL of the VirusTotal API to be used.")
flag.StringVar(&rsrc, "rsrc", "", "resource of file to retrieve report for. A resource can be md5, sha-1 or sha-2 sum of a file.")
}
// check - an error checking function
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
flag.Parse()
if rsrc == "" {
fmt.Println("-rsrc=<md5|sha-1|sha-2> not given!")
os.Exit(1)
}
c, err := govt.New(govt.SetApikey(apikey), govt.SetUrl(apiurl))
check(err)
// get a file report
r, err := c.GetFileReport(rsrc)
check(err)
j, err := json.MarshalIndent(r, "", " ")
check(err)
fmt.Printf("FileReport: ")
os.Stdout.Write(j)
}