Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
[Debug] fix target connect func
Browse files Browse the repository at this point in the history
  • Loading branch information
jweny committed Aug 11, 2021
1 parent f16742a commit 706c36a
Showing 1 changed file with 31 additions and 38 deletions.
69 changes: 31 additions & 38 deletions pkg/util/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,36 +357,37 @@ func VerifyPortConnection(targetAddr string) bool {
return true
}

func VerifyTargetConnection(originalReq *http.Request) bool {
fastReq := fasthttp.AcquireRequest()
fastResp := fasthttp.AcquireResponse()
oriData, err := GetOriginalReqBody(originalReq)
if err != nil {
return false
}
err = CopyRequest(originalReq, fastReq, oriData)
if err != nil {
return false
}
timeout := conf.GlobalConfig.HttpConfig.HttpTimeout
// 检测原始请求
err = fasthttpClient.DoTimeout(fastReq, fastResp, time.Duration(timeout)*time.Second)
if err != nil {
// 检测原始请求 + index.php
uri := string(fastReq.RequestURI())
if uri != "" && strings.HasSuffix(uri, "/") {
uri = fmt.Sprint(uri, "index.php")
} else {
uri = fmt.Sprint(uri, "/index.php")
}
fastReq.SetRequestURI(uri)
err = fasthttpClient.DoTimeout(fastReq, fastResp, time.Duration(timeout)*time.Second)
if err != nil {
return false
}
}
return true
}
// 以后接被动扫描插件的时候用
//func VerifyTargetConnection(originalReq *http.Request) bool {
// fastReq := fasthttp.AcquireRequest()
// fastResp := fasthttp.AcquireResponse()
// oriData, err := GetOriginalReqBody(originalReq)
// if err != nil {
// return false
// }
// err = CopyRequest(originalReq, fastReq, oriData)
// if err != nil {
// return false
// }
// timeout := conf.GlobalConfig.HttpConfig.HttpTimeout
// // 检测原始请求
// err = fasthttpClient.DoTimeout(fastReq, fastResp, time.Duration(timeout)*time.Second)
// if err != nil {
// // 检测原始请求 + index.php
// uri := string(fastReq.RequestURI())
// if uri != "" && strings.HasSuffix(uri, "/") {
// uri = fmt.Sprint(uri, "index.php")
// } else {
// uri = fmt.Sprint(uri, "/index.php")
// }
// fastReq.SetRequestURI(uri)
// err = fasthttpClient.DoTimeout(fastReq, fastResp, time.Duration(timeout)*time.Second)
// if err != nil {
// return false
// }
// }
// return true
//}

func VerifyInputTarget(target string) (bool, string) {
// 连通性校验改到这里
Expand Down Expand Up @@ -438,14 +439,6 @@ func GenOriginalReq(target string) (*http.Request, error) {
originalReq.Header.Set("User-Agent", conf.GlobalConfig.HttpConfig.Headers.UserAgent)
originalReq.Header.Set("Accept-Language","en")
originalReq.Header.Set("Connection","close")

// 检查fixUrl连通性
verify = VerifyTargetConnection(originalReq)
if !verify {
errMsg := fmt.Errorf("util/requests.go:GenOriginalReq %s can not connect", fixTarget)
log.Error(errMsg)
return nil, errMsg
}
return originalReq, nil
}

Expand Down

0 comments on commit 706c36a

Please sign in to comment.