-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcvehound.go
61 lines (51 loc) · 1.31 KB
/
cvehound.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
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
)
const cveListRepo = "https://github.com/CVEProject/cvelist.git"
const cveListLocalPath = "cvelist"
var home string
var cveListPath string
func initCVERepo() {
if _, err := os.Stat(cveListPath); os.IsNotExist(err) {
fmt.Println("Cloning cvelist repository...")
err := exec.Command("git", "clone", cveListRepo, cveListPath).Run()
if err != nil {
fmt.Println("Error cloning repository:", err)
os.Exit(1)
}
} else {
fmt.Println("Updating cvelist repository...")
err := exec.Command("git", "-C", cveListPath, "pull", "origin", "master").Run()
if err != nil {
fmt.Println("Error updating repository:", err)
os.Exit(1)
}
}
}
func searchCVEList(searchTerm string) {
fmt.Println("Searching for Search Term...")
regex_string := fmt.Sprintf("(\"TITLE\".*%s\")", searchTerm)
output, err := exec.Command("rg", regex_string, cveListPath).CombinedOutput()
if err != nil {
fmt.Println("Error searching for cvelist searchTerm:", err)
os.Exit(1)
}
fmt.Println(string(output))
}
func init() {
home = os.Getenv("HOME")
cveListPath = filepath.Join(home, cveListLocalPath)
}
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: cvehound searchTerm")
os.Exit(1)
}
searchTerm := os.Args[1]
initCVERepo()
searchCVEList(searchTerm)
}