2021-05-30 19:03:01 -07:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"github.com/shadow1ng/fscan/common"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
Client *http.Client
|
|
|
|
ClientNoRedirect *http.Client
|
|
|
|
dialTimout = 5 * time.Second
|
2022-01-07 00:59:05 -08:00
|
|
|
keepAlive = 5 * time.Second
|
2021-05-30 19:03:01 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func Inithttp(PocInfo common.PocInfo) {
|
|
|
|
//PocInfo.Proxy = "http://127.0.0.1:8080"
|
|
|
|
err := InitHttpClient(PocInfo.Num, PocInfo.Proxy, time.Duration(PocInfo.Timeout)*time.Second)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitHttpClient(ThreadsNum int, DownProxy string, Timeout time.Duration) error {
|
|
|
|
dialer := &net.Dialer{
|
|
|
|
Timeout: dialTimout,
|
|
|
|
KeepAlive: keepAlive,
|
|
|
|
}
|
|
|
|
|
|
|
|
tr := &http.Transport{
|
|
|
|
DialContext: dialer.DialContext,
|
|
|
|
MaxConnsPerHost: 0,
|
|
|
|
MaxIdleConns: 0,
|
|
|
|
MaxIdleConnsPerHost: ThreadsNum * 2,
|
|
|
|
IdleConnTimeout: keepAlive,
|
|
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
|
|
TLSHandshakeTimeout: 5 * time.Second,
|
2022-01-07 00:54:23 -08:00
|
|
|
DisableKeepAlives: true,
|
2021-05-30 19:03:01 -07:00
|
|
|
}
|
|
|
|
if DownProxy != "" {
|
|
|
|
if DownProxy == "1" {
|
|
|
|
DownProxy = "http://127.0.0.1:8080"
|
|
|
|
} else if !strings.Contains(DownProxy, "://") {
|
|
|
|
DownProxy = "http://127.0.0.1:" + DownProxy
|
|
|
|
}
|
|
|
|
u, err := url.Parse(DownProxy)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
tr.Proxy = http.ProxyURL(u)
|
|
|
|
}
|
|
|
|
|
|
|
|
Client = &http.Client{
|
|
|
|
Transport: tr,
|
|
|
|
Timeout: Timeout,
|
|
|
|
}
|
|
|
|
ClientNoRedirect = &http.Client{
|
2021-06-08 20:16:23 -07:00
|
|
|
Transport: tr,
|
|
|
|
Timeout: Timeout,
|
|
|
|
CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse },
|
2021-05-30 19:03:01 -07:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|