forked from KathanP19/Gxss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
244 lines (210 loc) · 5.08 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package main
import (
"bufio"
"bytes"
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
"regexp"
"strings"
"sync"
"time"
)
var (
concurrency int
verbose bool
outputFile string
payload string
useragent string
proxy string
requestData string
method string
)
type customh []string
func (m *customh) String() string {
return "This is custom flag for getting custom headers."
}
func (m *customh) Set(value string) error {
*m = append(*m, value)
return nil
}
var custhead customh
func banner() {
fmt.Println(`
_____ __ __ _____ _____
| __| | | __| __|
| | |- -|__ |__ |
|_____|__|__|_____|_____|
3.0 - @KathanP19
`)
}
func main() {
flag.IntVar(&concurrency, "c", 50, "Set the Concurrency")
flag.BoolVar(&verbose, "v", false, "Verbose mode")
flag.StringVar(&payload, "p", "Gxss", "Payload you want to Send to Check Reflection")
flag.StringVar(&outputFile, "o", "", "Save Result to OutputFile")
flag.StringVar(&requestData, "d", "", "Request data for POST based reflection testing")
flag.StringVar(&proxy, "x", "", "Proxy URL. Example: http://127.0.0.1:8080")
flag.StringVar(&useragent, "u", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36", "Set Custom User agent. Default is Mozilla")
flag.Var(&custhead, "h", "Set Custom Header.")
flag.Parse()
if verbose {
banner()
}
if payload != "" {
if outputFile != "" {
emptyFile, err := os.Create(outputFile)
if err != nil {
log.Fatal(err)
}
log.Println(emptyFile)
emptyFile.Close()
var wg sync.WaitGroup
for i := 0; i < concurrency; i++ {
wg.Add(1)
go func() {
testref(payload, verbose, outputFile, requestData)
wg.Done()
}()
wg.Wait()
}
} else {
var wg sync.WaitGroup
for i := 0; i < concurrency; i++ {
wg.Add(1)
go func() {
testref(payload, verbose, outputFile, requestData)
wg.Done()
}()
wg.Wait()
}
}
} else {
flag.PrintDefaults()
}
if verbose {
fmt.Println("\nFinished Checking, Thank you for using Gxss.")
}
}
func testref(payload string, verbose bool, outputFile string, requestData string) {
time.Sleep(500 * time.Microsecond)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
link := scanner.Text()
checkreflection(link)
}
}
func checkreflection(link string) {
decoded, _ := url.QueryUnescape(link)
u, err := url.Parse(decoded)
if err != nil {
decoded := url.QueryEscape(link)
v, err := url.Parse(decoded)
if err != nil {
fmt.Printf("Error is %e", err)
}
u = v
}
if verbose {
fmt.Println("[+] Testing URL : " + link)
}
q, err := url.ParseQuery(u.RawQuery)
if err != nil {
fmt.Printf("Error is %e", err)
}
if requestData != "" {
method = "POST"
q, err = url.ParseQuery(requestData)
} else {
method = "GET"
}
if err != nil {
fmt.Println(err)
}
for key, value := range q {
var tm string = value[0]
q.Set(key, payload)
if method == "GET" {
u.RawQuery = q.Encode()
}
if method == "POST" {
requestData = q.Encode()
}
_, body, _ := requestfunc(u.String(), requestData, method)
re := regexp.MustCompile(payload)
match := re.FindStringSubmatch(body)
if match != nil {
if verbose {
fmt.Printf("Url : %q\n", u)
fmt.Printf("Reflected Param : %q\n", key)
} else {
fmt.Println(u.String() + "\n")
}
if outputFile != "" {
f, err := os.OpenFile(outputFile, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
log.Println(err)
}
if _, err := f.WriteString(u.String() + "\n"); err != nil {
log.Fatal(err)
}
f.Close()
}
}
q.Set(key, tm)
}
}
//removed gorequest for more granular access to setting headers.
func requestfunc(u string, requestData string, method string) (resp *http.Response, body string, errs []error) {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
if proxy != "" {
proxyUrl, err := url.Parse(proxy)
http.DefaultTransport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
if err != nil {
fmt.Println(err)
}
}
client := &http.Client{
CheckRedirect: redirectPolicyFunc,
}
req, err := http.NewRequest(method, u, bytes.NewBufferString(requestData))
req.Header.Add("User-Agent", useragent)
if err != nil {
fmt.Println(err)
}
if method == "POST" {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
}
//splitting headers and values by using : as separator
for _, v := range custhead {
s := strings.SplitN(v, ":", 2)
req.Header.Add(s[0], s[1])
}
//Converting request dump to string for verbose mode
requestDump, err := httputil.DumpRequest(req, true)
if err != nil {
fmt.Println(err)
}
if verbose {
fmt.Println(string(requestDump))
}
resp, err = client.Do(req)
if err != nil {
return
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
return resp, bodyString, errs
}
func redirectPolicyFunc(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}