This repository was archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
63 lines (58 loc) · 1.52 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"flag"
"fmt"
"os"
"github.com/intercloud/gobinsec/gobinsec"
)
const (
CodeVulnerable = 1
CodeError = 2
)
var Version = "NONE"
func main() {
version := flag.Bool("version", false, "Print gobinsec version")
verbose := flag.Bool("verbose", false, "Print additional information in terminal")
cache := flag.Bool("cache", false, "Print cache information in terminal")
wait := flag.Bool("wait", false, "Wait between NVD API calls")
strict := flag.Bool("strict", false, "Vulnerabilities without version are exposed")
config := flag.String("config", "", "Configuration file")
flag.Parse()
if *version {
fmt.Println(Version)
os.Exit(0)
}
if len(flag.Args()) < 1 {
println("ERROR you must pass binary/ies to analyze on command line")
os.Exit(CodeError)
}
if err := gobinsec.LoadConfig(*config, *strict, *wait, *verbose, *cache); err != nil {
println(fmt.Sprintf("ERROR %v", err))
os.Exit(CodeError)
}
if err := gobinsec.BuildCache(); err != nil {
println(fmt.Sprintf("ERROR building cache: %v", err))
os.Exit(CodeError)
}
issue := false
for _, path := range flag.Args() {
binary, err := gobinsec.NewBinary(path)
if err != nil {
gobinsec.ColorRed.Print("ERROR")
fmt.Printf(" analyzing %s: %v\n", path, err)
issue = true
} else {
binary.Report()
if binary.Vulnerable {
issue = true
}
}
}
if err := gobinsec.CacheInstance.Close(); err != nil {
fmt.Fprintf(os.Stderr, "ERROR closing cache: %v\n", err)
os.Exit(CodeError)
}
if issue {
os.Exit(CodeVulnerable)
}
}