feat: 支持国密 TLS 网站扫描
测试构建 / 代码检查 (push) Has been cancelled
测试构建 / 单元测试和构建 (push) Has been cancelled
测试构建 / 构建验证 (push) Has been cancelled

- 添加 tjfoc/gmsm 依赖,提供 gmtls 国密 TLS 支持
- 新增国密 HTTP 客户端 ClientGM/ClientNoRedirectGM
- DetectHTTPScheme 增加国密 TLS 回退检测,返回 https-gm 协议标识
- webtitle 插件识别并路由到国密客户端
- DoRequest 标准 TLS 失败时自动回退国密客户端
This commit is contained in:
ZacharyZcR
2026-05-13 19:10:37 +08:00
parent b2e91d9fc0
commit d412786228
6 changed files with 161 additions and 17 deletions
+45 -4
View File
@@ -1,6 +1,7 @@
package lib
import (
"context"
"crypto/tls"
"embed"
"fmt"
@@ -13,6 +14,7 @@ import (
"github.com/shadow1ng/fscan/common"
"github.com/shadow1ng/fscan/common/proxy"
gmtls "github.com/tjfoc/gmsm/gmtls"
"gopkg.in/yaml.v2"
)
@@ -29,10 +31,12 @@ const (
// 全局HTTP客户端变量
var (
Client *http.Client // 标准HTTP客户端
ClientNoRedirect *http.Client // 不自动跟随重定向的HTTP客户端
dialTimeout = 5 * time.Second // 连接超时时间
keepAlive = 5 * time.Second // 连接保持时间
Client *http.Client // 标准HTTP客户端
ClientNoRedirect *http.Client // 不自动跟随重定向的HTTP客户端
ClientGM *http.Client // 国密TLS HTTP客户端
ClientNoRedirectGM *http.Client // 国密TLS 不跟随重定向
dialTimeout = 5 * time.Second // 连接超时时间
keepAlive = 5 * time.Second // 连接保持时间
)
// Inithttp 初始化HTTP客户端配置
@@ -166,6 +170,43 @@ func InitHTTPClient(ThreadsNum int, DownProxy string, Timeout time.Duration, max
CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse },
}
// 创建国密TLS客户端(用于连接国密HTTPS站点)
trGM := &http.Transport{
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
dialer := &net.Dialer{
Timeout: dialTimeout,
KeepAlive: keepAlive,
}
return gmtls.DialWithDialer(dialer, network, addr, &gmtls.Config{
GMSupport: gmtls.NewGMSupport(),
InsecureSkipVerify: true,
})
},
MaxConnsPerHost: 20,
MaxIdleConns: 20,
MaxIdleConnsPerHost: 5,
IdleConnTimeout: keepAlive,
TLSHandshakeTimeout: 5 * time.Second,
DisableKeepAlives: false,
}
ClientGM = &http.Client{
Transport: trGM,
Timeout: Timeout,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
if len(via) >= maxRedirects {
return http.ErrUseLastResponse
}
return nil
},
}
ClientNoRedirectGM = &http.Client{
Transport: trGM,
Timeout: Timeout,
CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse },
}
return nil
}
+13
View File
@@ -446,6 +446,19 @@ func DoRequest(req *http.Request, redirect bool) (*Response, error) {
oResp, err = ClientNoRedirect.Do(req)
}
// 标准TLS连接失败时,尝试国密TLS客户端
if err != nil && req.URL.Scheme == "https" {
if redirect {
if oResp2, err2 := ClientGM.Do(req); err2 == nil {
oResp, err = oResp2, nil
}
} else {
if oResp2, err2 := ClientNoRedirectGM.Do(req); err2 == nil {
oResp, err = oResp2, nil
}
}
}
if err != nil {
// HTTP请求失败,计为TCP失败
common.GetGlobalState().IncrementTCPFailedPacketCount()