-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
110 lines (97 loc) · 2.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
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
package main
import (
"flag"
"fmt"
"juuri/options"
"juuri/output"
"juuri/query"
"net/url"
"os"
"os/exec"
"runtime"
"strings"
)
const BANNER = `
_ _
(_)_ ____ ______(_)
/ / // / // / __/ /
__/ /\_,_/\_,_/_/ /_/
|___/
`
const VOYAGER_URL = "http://apis.guru/graphql-voyager/?url="
func usage() {
fmt.Println("juuri OPTIONS <url>")
flag.PrintDefaults()
}
func printBanner() {
fmt.Println(BANNER)
}
func parseHeaders(headersStr string) map[string]string {
headerMap := map[string]string{}
headers := strings.Split(headersStr, ",")
for _, header := range headers {
headerNameValue := strings.Split(header, ":")
headerMap[headerNameValue[0]] = headerNameValue[1]
}
return headerMap
}
func main() {
printBanner()
var options = options.JuuriOptions{}
var headers string
flag.BoolVar(&options.Debug, "debug", false, "Debug logging")
flag.BoolVar(&options.OpenIntrospectionInVoyager, "open-in-voyager", false, "Open introspection result in GraphQL Voyager")
flag.StringVar(&options.File, "file", "", "Output file")
flag.StringVar(&headers, "headers", "", "List of HTTP headers separated by comma, e.g. headers=accept-encoding:gzip,content-type:application/json")
flag.Usage = usage
flag.Parse()
if len(headers) > 0 {
options.Headers = parseHeaders(headers)
}
if flag.NArg() == 0 {
flag.Usage()
os.Exit(1)
}
urlArg := flag.Arg(0)
_, err := url.ParseRequestURI(urlArg)
if err != nil {
panic("Invalid URL " + urlArg)
}
var printer output.Printer
if len(options.File) > 0 {
printer = output.FileOutPrinter
} else {
printer = output.StdOutPrinter
}
printer.Init(&options)
for _, check := range query.VulnChecks {
vulnerable, text := check.Check(urlArg, options)
if vulnerable {
printer.PrintVulnFound(check.Describe())
if len(text) > 0 {
printer.Print(text)
}
} else {
printer.PrintVulnNotFound(check.Describe())
}
}
printer.Stop()
if options.OpenIntrospectionInVoyager {
fullVoyagerUrl := VOYAGER_URL + urlArg
fmt.Println("Opening API in GraphQL Voyager")
var browserErr error
switch runtime.GOOS {
case "linux":
browserErr = exec.Command("xdg-open", fullVoyagerUrl).Start()
case "windows":
browserErr = exec.Command("rundll32", "url.dll,FileProtocolHandler", fullVoyagerUrl).Start()
case "darwin":
browserErr = exec.Command("open", fullVoyagerUrl).Start()
default:
browserErr = fmt.Errorf("Unsupported platform")
}
if browserErr != nil {
fmt.Printf("Error opening browser for GraphQL Voyager: %s\n", browserErr.Error())
}
}
}