-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckov.go
71 lines (58 loc) · 1.53 KB
/
checkov.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
package main
import (
"flag"
"fmt"
"github.com/PuerkitoBio/goquery"
"net/http"
"os"
"strings"
)
func main() {
var url string
flag.StringVar(&url, "url", "", "The full Checkov Guide URL")
flag.Parse()
// go run checkov.go -url https://docs.bridgecrew.io/docs/s3_16-enable-versioning
// Ensure the URL is not empty
// And contains http:// or https://
if len(url) == 0 || (!strings.Contains(url, "http://") &&
!strings.Contains(url, "https://")) {
fmt.Println("Usage: main.go -url")
fmt.Println("The -url option requires a protocol declaration (https:// or http://)")
os.Exit(1)
}
severity := GetSeverityByURL(url)
// Only return a notification for success
if len(severity) > 0 {
fmt.Printf("[+] Returned: [%s]", severity)
}
}
func GetSeverityByURL(url string) string {
text := ""
res, err := http.Get(url)
if err != nil {
fmt.Printf("[-] Error getting URL: [%s]", url)
}
defer res.Body.Close()
if res.StatusCode != 200 {
fmt.Printf("[-] Status code: [%s] Status: [%s]", res.StatusCode, res.Status)
return ""
}
doc, err := goquery.NewDocumentFromReader(res.Body)
if err != nil {
fmt.Printf("[-] Error Creating Document: [%s]", err)
return ""
}
doc.Find("div.markdown-body").Each(func(i int, s *goquery.Selection) {
p := s.Find("p")
p.Contents().Each(func(i int, s *goquery.Selection) {
if strings.Contains(s.Text(), "Severity:") {
text = s.Text()
}
})
})
if len(text) == 0 {
fmt.Printf("[-] No text found for selector. Url: [%s]", url)
return ""
}
return strings.TrimSpace(text)
}