增加connect host伪装
This commit is contained in:
@@ -2,9 +2,12 @@ package http
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"hash/crc32"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
@@ -53,10 +56,16 @@ func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, add
|
|||||||
})
|
})
|
||||||
log.Debugf("connect %s/%s", address, network)
|
log.Debugf("connect %s/%s", address, network)
|
||||||
|
|
||||||
|
connectHost := address
|
||||||
|
if c.md.host != "" {
|
||||||
|
// 伪装的地址
|
||||||
|
connectHost = c.md.host
|
||||||
|
}
|
||||||
|
|
||||||
req := &http.Request{
|
req := &http.Request{
|
||||||
Method: http.MethodConnect,
|
Method: http.MethodConnect,
|
||||||
URL: &url.URL{Host: address},
|
URL: &url.URL{Host: connectHost},
|
||||||
Host: address,
|
Host: connectHost,
|
||||||
ProtoMajor: 1,
|
ProtoMajor: 1,
|
||||||
ProtoMinor: 1,
|
ProtoMinor: 1,
|
||||||
Header: c.md.header,
|
Header: c.md.header,
|
||||||
@@ -67,6 +76,12 @@ func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, add
|
|||||||
}
|
}
|
||||||
req.Header.Set("Proxy-Connection", "keep-alive")
|
req.Header.Set("Proxy-Connection", "keep-alive")
|
||||||
|
|
||||||
|
// 真实连接的地址
|
||||||
|
if c.md.host != "" {
|
||||||
|
targetAddr := encodeServerName(address)
|
||||||
|
req.Header.Set("Gost-Target", targetAddr)
|
||||||
|
}
|
||||||
|
|
||||||
if user := c.options.Auth; user != nil {
|
if user := c.options.Auth; user != nil {
|
||||||
u := user.Username()
|
u := user.Username()
|
||||||
p, _ := user.Password()
|
p, _ := user.Password()
|
||||||
@@ -129,3 +144,10 @@ func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, add
|
|||||||
|
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func encodeServerName(name string) string {
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
binary.Write(buf, binary.BigEndian, crc32.ChecksumIEEE([]byte(name)))
|
||||||
|
buf.WriteString(base64.RawURLEncoding.EncodeToString([]byte(name)))
|
||||||
|
return base64.RawURLEncoding.EncodeToString(buf.Bytes())
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,15 +11,19 @@ import (
|
|||||||
type metadata struct {
|
type metadata struct {
|
||||||
connectTimeout time.Duration
|
connectTimeout time.Duration
|
||||||
header http.Header
|
header http.Header
|
||||||
|
//伪装混淆用host
|
||||||
|
host string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *httpConnector) parseMetadata(md mdata.Metadata) (err error) {
|
func (c *httpConnector) parseMetadata(md mdata.Metadata) (err error) {
|
||||||
const (
|
const (
|
||||||
connectTimeout = "timeout"
|
connectTimeout = "timeout"
|
||||||
header = "header"
|
header = "header"
|
||||||
|
host = "host"
|
||||||
)
|
)
|
||||||
|
|
||||||
c.md.connectTimeout = mdutil.GetDuration(md, connectTimeout)
|
c.md.connectTimeout = mdutil.GetDuration(md, connectTimeout)
|
||||||
|
c.md.host = mdutil.GetString(md, host)
|
||||||
|
|
||||||
if mm := mdutil.GetStringMapString(md, header); len(mm) > 0 {
|
if mm := mdutil.GetStringMapString(md, header); len(mm) > 0 {
|
||||||
hd := http.Header{}
|
hd := http.Header{}
|
||||||
|
|||||||
Reference in New Issue
Block a user