-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from glaslos/slavikm_merge
Merging the slavikm fork back into master
- Loading branch information
Showing
20 changed files
with
479 additions
and
543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Breaking API changes from version 1.0 | ||
|
||
1. Initialization | ||
----------------- | ||
Previously, initializing the client required creating the client with the relevant API key and other parameters: | ||
``` | ||
// Create the client | ||
c := govt.Client{Apikey: "api key"} | ||
``` | ||
|
||
Now, the initialization is done via the New function with which checks that the client is initialized correctly: | ||
``` | ||
// Create the client | ||
c := govt.New(govt.SetErrorLog(log.New(os.Stderr, "VT: ", log.Lshortfile), govt.SetApikey(apikey), govt.SetUrl(apiurl)) | ||
``` | ||
|
||
You can provide multiple initialization functions of type govt.OptionFunc to help with the initialization. | ||
|
||
| *Function* | *Description* | *Mandatory* | | ||
|---------------|------------------------------------------------|-------------| | ||
| SetApikey | Provide the API key to use | true | | ||
| SetHttpClient | Provide a custom HTTP client | false | | ||
| SetUrl | Provide a different URL from the default one | false | | ||
| SetBasicAuth | Provide proxy credentials | false | | ||
| SetErrorLog | Set error logger to write errors to | false | | ||
| SetTraceLog | Set trace logger to dump requests / replies to | false | | ||
|
||
2. Client implementation details | ||
-------------------------------- | ||
Client implementation details such as internal fields are now private. This move was made so it will be easier to evolve and change the API without breaking compatibility with existing code. | ||
|
||
3. File uploads | ||
--------------- | ||
To improve memory footprint requirements, file uploads are now streaming using a goroutine. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
SampleClients/fileknownbysymantec/vtFileKnownBySymantec.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// vtFileKnownBySymantec.go - checks via VirusTotal if a given file is detected by Symantec AV. | ||
package main | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/williballenthin/govt" | ||
) | ||
|
||
var apikey string | ||
var apiurl string | ||
var rsrc string | ||
var file string | ||
var vtUpload bool | ||
|
||
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", "8ac31b7350a95b0b492434f9ae2f1cde", "resource of file to check VT for. Resource can be md5, sha-1 or sha-2 sum of a file.") | ||
flag.StringVar(&file, "file", "", "submit a file instead of a resource") | ||
flag.BoolVar(&vtUpload, "upload-vt", false, "if 'true' files unknown to VT will be uploaded to VT") | ||
} | ||
|
||
// calculate md5 of a given file | ||
func calcMd5(filename string) (md5sum string) { | ||
f, err := os.Open(filename) | ||
check(err) | ||
defer f.Close() | ||
md5 := md5.New() | ||
_, err = io.Copy(md5, f) | ||
return fmt.Sprintf("%x", md5.Sum(nil)) | ||
} | ||
|
||
func check(e error) { | ||
if e != nil { | ||
panic(e) | ||
} | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
fileForError := "" | ||
if file != "" { | ||
rsrc = calcMd5(file) | ||
fileForError = file | ||
} else { | ||
fileForError = "</path/to/file>" | ||
} | ||
|
||
c, err := govt.New(govt.SetApikey(apikey), govt.SetUrl(apiurl)) | ||
check(err) | ||
|
||
r, err := c.GetFileReport(rsrc) | ||
check(err) | ||
if r.ResponseCode == 0 { | ||
fmt.Println(rsrc + " NOT KNOWN by VirusTotal") | ||
if vtUpload == true && file != "" { | ||
r, err := c.ScanFile(file) | ||
check(err) | ||
j, err := json.MarshalIndent(r, "", " ") | ||
fmt.Printf("FileReport: ") | ||
os.Stdout.Write(j) | ||
} else { | ||
fmt.Printf("For uploading to VT use vtFileScan -file=%s\n", fileForError) | ||
} | ||
} else { | ||
sr := r.Scans["Symantec"] | ||
if sr.Detected == true { | ||
fmt.Printf("%s detected by Symantec Version %s as %s since update %s\n", rsrc, sr.Version, sr.Result, sr.Update) | ||
} else { | ||
fmt.Printf("%s NOT detected by Symantec; Detection Rate: [%d/%d]\n", rsrc, r.Positives, r.Total) | ||
fmt.Printf("If you want to upload this file to VT use: 'vtFileScan -file=%s'\n", fileForError) | ||
fmt.Printf("If you want to submit it to Symantec use: 'symantecUpload -file=%s'\n", fileForError) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.