mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-09-14 14:06:44 +08:00
减少http client初始化次数
This commit is contained in:
parent
583e51d479
commit
51b8b2c0e2
@ -1,21 +1,19 @@
|
|||||||
package Plugins
|
package Plugins
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/shadow1ng/fscan/WebScan"
|
"github.com/shadow1ng/fscan/WebScan"
|
||||||
|
"github.com/shadow1ng/fscan/WebScan/lib"
|
||||||
"github.com/shadow1ng/fscan/common"
|
"github.com/shadow1ng/fscan/common"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func WebTitle(info *common.HostInfo) error {
|
||||||
var CheckData []WebScan.CheckDatas
|
var CheckData []WebScan.CheckDatas
|
||||||
|
|
||||||
func WebTitle(info *common.HostInfo) error {
|
|
||||||
if info.Ports == "80" {
|
if info.Ports == "80" {
|
||||||
info.Url = fmt.Sprintf("http://%s", info.Host)
|
info.Url = fmt.Sprintf("http://%s", info.Host)
|
||||||
} else if info.Ports == "443" {
|
} else if info.Ports == "443" {
|
||||||
@ -24,18 +22,18 @@ func WebTitle(info *common.HostInfo) error {
|
|||||||
info.Url = fmt.Sprintf("http://%s:%s", info.Host, info.Ports)
|
info.Url = fmt.Sprintf("http://%s:%s", info.Host, info.Ports)
|
||||||
}
|
}
|
||||||
|
|
||||||
err, result := geturl(info, true)
|
err, result, CheckData := geturl(info, true, CheckData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if result == "https" {
|
if result == "https" {
|
||||||
err, _ := geturl(info, true)
|
err, _, CheckData = geturl(info, true, CheckData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err, _ = geturl(info, false)
|
err, _, CheckData = geturl(info, false, CheckData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -49,41 +47,22 @@ func WebTitle(info *common.HostInfo) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func geturl(info *common.HostInfo, flag bool) (err error, result string) {
|
func geturl(info *common.HostInfo, flag bool, CheckData []WebScan.CheckDatas) (error, string, []WebScan.CheckDatas) {
|
||||||
Url := info.Url
|
Url := info.Url
|
||||||
if flag == false {
|
if flag == false {
|
||||||
Url += "/favicon.ico"
|
Url += "/favicon.ico"
|
||||||
}
|
}
|
||||||
tr := &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
||||||
DisableKeepAlives: false,
|
|
||||||
DialContext: (&net.Dialer{
|
|
||||||
Timeout: time.Duration(info.WebTimeout) * time.Second,
|
|
||||||
KeepAlive: time.Duration(info.WebTimeout+3) * time.Second,
|
|
||||||
}).DialContext,
|
|
||||||
MaxIdleConns: 1000,
|
|
||||||
MaxIdleConnsPerHost: 1000,
|
|
||||||
IdleConnTimeout: time.Duration(info.WebTimeout+3) * time.Second,
|
|
||||||
TLSHandshakeTimeout: 5 * time.Second,
|
|
||||||
}
|
|
||||||
//u, err := url.Parse("http://127.0.0.1:8080")
|
|
||||||
//if err != nil {
|
|
||||||
// return err,result
|
|
||||||
//}
|
|
||||||
//tr.Proxy = http.ProxyURL(u)
|
|
||||||
|
|
||||||
var client = &http.Client{Timeout: time.Duration(info.WebTimeout) * time.Second, Transport: tr}
|
|
||||||
res, err := http.NewRequest("GET", Url, nil)
|
res, err := http.NewRequest("GET", Url, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
res.Header.Add("User-agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36")
|
res.Header.Set("User-agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36")
|
||||||
res.Header.Add("Accept", "*/*")
|
res.Header.Set("Accept", "*/*")
|
||||||
res.Header.Add("Accept-Language", "zh-CN,zh;q=0.9")
|
res.Header.Set("Accept-Language", "zh-CN,zh;q=0.9")
|
||||||
res.Header.Add("Accept-Encoding", "gzip, deflate")
|
res.Header.Set("Accept-Encoding", "gzip, deflate")
|
||||||
if flag == true {
|
if flag == true {
|
||||||
res.Header.Add("Cookie", "rememberMe=1")
|
res.Header.Set("Cookie", "rememberMe=1")
|
||||||
}
|
}
|
||||||
res.Header.Add("Connection", "close")
|
res.Header.Set("Connection", "close")
|
||||||
resp, err := client.Do(res)
|
resp, err := lib.Client.Do(res)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
var title string
|
var title string
|
||||||
@ -99,7 +78,7 @@ func geturl(info *common.HostInfo, flag bool) (err error, result string) {
|
|||||||
title = "None"
|
title = "None"
|
||||||
}
|
}
|
||||||
if flag == true {
|
if flag == true {
|
||||||
result = fmt.Sprintf("WebTitle:%-25v %-3v %v", Url, resp.StatusCode, title)
|
result := fmt.Sprintf("WebTitle:%-25v %-3v %v", Url, resp.StatusCode, title)
|
||||||
common.LogSuccess(result)
|
common.LogSuccess(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,11 +86,11 @@ func geturl(info *common.HostInfo, flag bool) (err error, result string) {
|
|||||||
|
|
||||||
if resp.StatusCode == 400 && info.Url[:5] != "https" {
|
if resp.StatusCode == 400 && info.Url[:5] != "https" {
|
||||||
info.Url = strings.Replace(info.Url, "http://", "https://", 1)
|
info.Url = strings.Replace(info.Url, "http://", "https://", 1)
|
||||||
return err, "https"
|
return err, "https", CheckData
|
||||||
}
|
}
|
||||||
return err, result
|
return err, "", CheckData
|
||||||
}
|
}
|
||||||
return err, ""
|
return err, "", CheckData
|
||||||
}
|
}
|
||||||
return err, ""
|
return err, "", CheckData
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user