-
Notifications
You must be signed in to change notification settings - Fork 0
/
sheep.go
134 lines (123 loc) · 3.28 KB
/
sheep.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
package main
import (
"bufio"
"crypto/tls"
"flag"
"fmt"
"net/http"
"net/url"
"os"
"regexp"
"strings"
"sync"
"github.com/PuerkitoBio/goquery"
"github.com/corpix/uarand"
)
func CheckContains(url_t string) bool {
re := regexp.MustCompile(`\?.+=.+`)
return re.MatchString(url_t)
}
func SendHttpRequestReadResponseBody(url_t string) *goquery.Document {
client := &http.Client{}
req, err := http.NewRequest("GET", url_t, nil)
if err != nil {
return nil
}
req.Header.Set("User-Agent", uarand.GetRandom())
resp, err := client.Do(req)
if err != nil {
return nil
}
if resp.StatusCode >= 400 {
return nil
}
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
return nil
}
return doc
}
func FindGetInputInForms(doc *goquery.Document) (url.Values, []string) {
var list_of_input_tags_names []string
complete_input_tags_name := url.Values{}
doc.Find("form").Each(func(_ int, selection *goquery.Selection) {
method, _ := selection.Attr("method")
if strings.ToLower(method) == "get" || method == "" {
selection.Find("input").Each(func(_ int, s *goquery.Selection) {
input_tags_name, _ := s.Attr("name")
if input_tags_name != "" {
list_of_input_tags_names = append(list_of_input_tags_names, input_tags_name)
complete_input_tags_name.Set(input_tags_name, "1")
}
})
}
})
return (complete_input_tags_name), (list_of_input_tags_names)
}
func EncodeInputTagsName(complete_input_tags_name url.Values) string {
return complete_input_tags_name.Encode()
}
func GetInputTagsWithoutForm(doc *goquery.Document, list_of_input_tags_names []string) url.Values {
complete_input_tags_name_s := url.Values{}
doc.Find("input").Each(func(i int, s *goquery.Selection) {
if s.Before("form") != nil {
return
}
input_tags_name, _ := s.Attr("name")
if input_tags_name != "" {
complete_input_tags_name_s.Set(input_tags_name, "1")
}
})
return complete_input_tags_name_s
}
func OrganizeInputTags(url_t string) {
if CheckContains(url_t) {
fmt.Println(url_t)
}
doc := SendHttpRequestReadResponseBody(url_t)
if doc == nil {
return
}
var name_tags_encoded string
var new_url string
complete_input_tags_name, list_of_input_tags_names := FindGetInputInForms(doc)
if len(complete_input_tags_name) == 0 {
return
}
name_tags_encoded = EncodeInputTagsName(complete_input_tags_name)
if CheckContains(url_t) {
new_url = fmt.Sprintf("%s&%s", url_t, name_tags_encoded)
} else {
new_url = fmt.Sprintf("%s?%s", url_t, name_tags_encoded)
}
fmt.Println(new_url)
complete_input_tags_name_s := GetInputTagsWithoutForm(doc, list_of_input_tags_names)
if len(complete_input_tags_name_s) == 0 {
return
}
name_tags_encoded = EncodeInputTagsName(complete_input_tags_name_s)
if CheckContains(url_t) {
new_url = fmt.Sprintf("%s&%s", url_t, name_tags_encoded)
} else {
new_url = fmt.Sprintf("%s?%s", url_t, name_tags_encoded)
}
fmt.Println(new_url)
}
func main() {
var wg sync.WaitGroup
conc := flag.Int("concurrency", 10, "concurrency level")
flag.Parse()
reader := bufio.NewScanner(os.Stdin)
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
for i := 0; i < *conc; i++ {
for reader.Scan() {
url := reader.Text()
wg.Add(1)
go func() {
OrganizeInputTags(url)
wg.Done()
}()
}
wg.Wait()
}
}