-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
116 lines (102 loc) · 2.77 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)
func main() {
if len(os.Args) != 2 {
splash()
os.Exit(0)
}
input := os.Args[1]
info, err := os.Stat(input)
if err != nil {
log.Fatalf("Cannot find '%s'", input)
}
if info.IsDir() {
log.Fatalf("Expected a file, but '%s' is a directory", input)
}
hash, err := hashFile(input)
if err != nil {
log.Fatalf("Failed to hash file located at '%s': %v", input, err)
}
url := fmt.Sprintf("https://virustotal.com/gui/file/%s", hash)
if err := openBrowser(url); err != nil {
log.Fatal(err)
}
}
func splash() {
fmt.Println(`
...:::...
-*#%%%%%%%%%%#*+.
=@@@@@@@@@@@@@@@@@+
-@@@@@%#**++++*%@@@@#.
.@@@@+---=+*##*=--%@%@#
*@%@= -*#%%@@@@%# +@@%@=
:@@@@#:..::----::::%@@@@@.
*@@@@@@#*++====+*#@@@@@%@+
.@@@@@@@@@@@@@@@@@@@@@@@@@%
+@@@@@@@@@@@@@@@@@@@@@@@@@@-
%@@@@@@@@@@@@@@@@@@@@@@@@@@+
=@%@@@@@@@@@@@@@@@@@@@@@@@@@*
#@@@@@@@@@@@@@@@@@@@@@@@@@@@%
:@@@@@@@@@@@@@@@@@@@@@@@@@@@@%
*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.
.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@:
=@%@@@@@@@@@@@@@@@@@@@@@@@@@@@@:
#@@@@@@@%**++++++*%@@@@@@@@@@@@-
.@@@@@@@#. +@@@@@@@@@@@-
+@@@@@@@: ඞ %@@@@@@@@@@-
... %@@@@@@@- sus #@@@@@@@@@@:
-##%%%%**@%@@@%@@- v0.1.0 %@@@@@@@@@@.
*@@@@@@@@@@@@@@@+ -@@@@@@@@@@%.
:=+****##***+-. .=++#@@@@@@@@@%@%
-@@@@@%%%@@@@@@@%-
:#%@@@@@@@@%#*+-
.:-=---::.`)
hash, _ := hashFile(os.Args[0])
fmt.Printf("Usage: %s <file_path>\nRepo: https://github.com/benjammin4dayz/sus-virustotal-cli\nHash: %s",
strings.TrimSuffix(
filepath.Base(os.Args[0]),
filepath.Ext(os.Args[0]),
),
hash,
)
}
func hashFile(filePath string) (string, error) {
f, err := os.Open(filePath)
if err != nil {
return "", err
}
defer f.Close()
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
return "", err
}
return hex.EncodeToString(h.Sum(nil)), nil
}
func openBrowser(url string) error {
var cmd *exec.Cmd
switch runtime.GOOS {
case "windows":
cmd = exec.Command("cmd", "/c", "start", url)
case "darwin":
cmd = exec.Command("open", url)
case "linux":
cmd = exec.Command("xdg-open", url)
default:
return fmt.Errorf("unsupported platform: %s", runtime.GOOS)
}
if err := cmd.Run(); err != nil {
return err
}
return nil
}