-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
220 lines (208 loc) · 5.74 KB
/
util.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
package pkg
import (
"crypto/tls"
"fmt"
"github.com/corpix/uarand"
"io/ioutil"
"math/rand"
"net/http"
"net/http/cookiejar"
"net/url"
"sort"
"strings"
"time"
)
type Response struct {
Status string
StatusCode int
Body string
Header http.Header
ContentLength int
RequestUrl string
Location string
}
var (
HttpProxy string
CeyeApi string
CeyeDomain string
Fuzzthreads = 20
)
func HttpRequsetBasic(username string, password string, urlstring string, method string, postdata string, isredirect bool, headers map[string]string) (*Response, error) {
var tr *http.Transport
if HttpProxy != "" {
uri, _ := url.Parse(HttpProxy)
tr = &http.Transport{
MaxIdleConnsPerHost: -1,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DisableKeepAlives: true,
Proxy: http.ProxyURL(uri),
}
} else {
tr = &http.Transport{
MaxIdleConnsPerHost: -1,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DisableKeepAlives: true,
}
}
client := &http.Client{
Timeout: time.Duration(10) * time.Second,
Transport: tr,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}}
if isredirect {
jar, _ := cookiejar.New(nil)
client = &http.Client{
Timeout: time.Duration(10) * time.Second,
Transport: tr,
Jar: jar,
}
}
req, err := http.NewRequest(strings.ToUpper(method), urlstring, strings.NewReader(postdata))
if err != nil {
return nil, err
}
req.SetBasicAuth(username, password)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
req.Header.Set("User-Agent", uarand.GetRandom())
for v, k := range headers {
req.Header[v] = []string{k}
}
resp, err := client.Do(req)
if err != nil {
//防止空指针
return &Response{"999", 999, "", nil, 0, "", ""}, err
}
var location string
var reqbody string
defer resp.Body.Close()
if body, err := ioutil.ReadAll(resp.Body); err == nil {
reqbody = string(body)
}
if resplocation, err := resp.Location(); err == nil {
location = resplocation.String()
}
return &Response{resp.Status, resp.StatusCode, reqbody, resp.Header, len(reqbody), resp.Request.URL.String(), location}, nil
}
func HttpRequset(urlstring string, method string, postdata string, isredirect bool, headers map[string]string) (*Response, error) {
var tr *http.Transport
if HttpProxy != "" {
uri, _ := url.Parse(HttpProxy)
tr = &http.Transport{
MaxIdleConnsPerHost: -1,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DisableKeepAlives: true,
Proxy: http.ProxyURL(uri),
}
} else {
tr = &http.Transport{
MaxIdleConnsPerHost: -1,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DisableKeepAlives: true,
}
}
client := &http.Client{
Timeout: time.Duration(10) * time.Second,
Transport: tr,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}}
if isredirect {
jar, _ := cookiejar.New(nil)
client = &http.Client{
Timeout: time.Duration(10) * time.Second,
Transport: tr,
Jar: jar,
}
}
req, err := http.NewRequest(strings.ToUpper(method), urlstring, strings.NewReader(postdata))
if err != nil {
return nil, err
}
if headers["Content-Type"] == "" && headers["Content-type"] == "" {
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
}
req.Header.Set("User-Agent", uarand.GetRandom())
for v, k := range headers {
req.Header[v] = []string{k}
}
resp, err := client.Do(req)
if err != nil {
//防止空指针
return &Response{"999", 999, "", nil, 0, "", ""}, err
}
var location string
var reqbody string
defer resp.Body.Close()
if body, err := ioutil.ReadAll(resp.Body); err == nil {
reqbody = string(body)
}
if resplocation, err := resp.Location(); err == nil {
location = resplocation.String()
}
return &Response{resp.Status, resp.StatusCode, reqbody, resp.Header, len(reqbody), resp.Request.URL.String(), location}, nil
}
func Dnslogchek(randomstr string) bool {
urlStr := fmt.Sprintf("http://api.ceye.io/v1/records?token=%s&type=dns&filter=%s", CeyeApi, randomstr)
if resp, err := HttpRequset(urlStr, "GET", "", false, nil); err == nil {
if !strings.Contains(resp.Body, `"data": []`) && strings.Contains(resp.Body, `{"code": 200, "message": "OK"}`) { // api返回结果不为空
return true
}
}
return false
}
func RandomStr() string {
lowercase := "1234567890abcdefghijklmnopqrstuvwxyz"
randSource := rand.New(rand.NewSource(time.Now().Unix()))
var (
letterIdxBits = 6 // 6 bits to represent a letter index
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
)
randBytes := make([]byte, 8)
for i, cache, remain := 8-1, randSource.Int63(), letterIdxMax; i >= 0; {
if remain == 0 {
cache, remain = randSource.Int63(), letterIdxMax
}
if idx := int(cache) & int(letterIdxMask); idx < len(lowercase) {
randBytes[i] = lowercase[idx]
i--
}
cache >>= letterIdxBits
remain--
}
return string(randBytes)
}
func IntInSlice(i int, slice []int) bool {
if slice == nil {
return false
}
sort.Ints(slice)
index := sort.SearchInts(slice, i)
if index < len(slice) && slice[index] == i {
return true
}
return false
}
func StringInSlice(str string, slice []string) bool {
if slice == nil {
return false
}
sort.Strings(slice)
index := sort.SearchStrings(slice, str)
if index < len(slice) && slice[index] == str {
return true
}
return false
}
func SliceInString(str string, slice []string) bool {
if slice == nil {
return false
}
for _, v := range slice {
if strings.Contains(str, v) {
return true
}
}
return false
}