环境准备
配置Go编译环境
1.下载go依赖包
$ wget https://go.dev/dl/go1.19.5.linux-amd64.tar.gz
2.安装并配置环境变量
$ rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.5.linux-amd64.tar.gz
$ vi /etc/profile
##在末尾添加
export GOROOT=/usr/local/go
export GOPATH=/home/work/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT/bin:GOBIN
$ source /etc/profile
3.检查go版本号
$ go version
go version go1.19.5 linux/amd64
编译FRP
1.下载源码包
从https://github.com/fatedier/frp下载最新版本,并上传到服务器。当前最新版本为0.46.1,所以本次编译以此版本为准。
2.解压源码包
$ unzip frp-0.46.1.zip
$ cd frp-0.46.1
3.修改流量特征
消息JSON特征
$ vi pkg/msg/msg.go
……
type Login struct {
Version string `json:"version,omitempty"`
Hostname string `json:"hostname,omitempty"`
Os string `json:"os,omitempty"`
Arch string `json:"arch,omitempty"`
User string `json:"user,omitempty"`
PrivilegeKey string `json:"privilege_key,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
RunID string `json:"run_id,omitempty"`
Metas map[string]string `json:"metas,omitempty"`
// Some global configures.
PoolCount int `json:"pool_count,omitempty"`
}
……
#将json后面双引号的中内容修改为其他字符串,比如如下所示:
type Login struct {
Version string `json:"vy"`
Hostname string `json:"hy"`
Os string `json:"oty"`
Arch string `json:"aty"`
User string `json:"uty"`
PrivilegeKey string `json:"pty"`
Timestamp int64 `json:"tmpty"`
RunID string `json:"rpty"`
Metas map[string]string `json:"mty"`
// Some global configures.
PoolCount int `json:"poy"`
}
#修改完成后保存文件
TLS连接特征
$ vi pkg/util/net/tls.go
//var FRPTLSHeadByte = 0x17
//修改为
var FRPTLSHeadByte = 0x88
func CheckAndEnableTLSServerConnWithTimeout(
c net.Conn, tlsConfig *tls.Config, tlsOnly bool, timeout time.Duration,
) (out net.Conn, isTLS bool, custom bool, err error) {
//sc, r := gnet.NewSharedConnSize(c, 2)
//buf := make([]byte, 1)
//修改为
sc, r := gnet.NewSharedConnSize(c, 4)
buf := make([]byte, 3)
var n int
_ = c.SetReadDeadline(time.Now().Add(timeout))
n, err = r.Read(buf)
_ = c.SetReadDeadline(time.Time{})
if err != nil {
return
}
switch {
//case n == 1 && int(buf[0]) == FRPTLSHeadByte:
//修改为
case n == 3 && int(buf[0]) == FRPTLSHeadByte:
out = tls.Server(c, tlsConfig)
isTLS = true
custom = true
case n == 1 && int(buf[0]) == 0x16:
out = tls.Server(sc, tlsConfig)
isTLS = true
default:
if tlsOnly {
err = fmt.Errorf("non-TLS connection received on a TlsOnly server")
return
}
out = sc
}
return
}
#修改完成后保存
# vi pkg/util/net/dial.go
func DialHookCustomTLSHeadByte(enableTLS bool, disableCustomTLSHeadByte bool) libdial.AfterHookFunc {
return func(ctx context.Context, c net.Conn, addr string) (context.Context, net.Conn, error) {
if enableTLS && !disableCustomTLSHeadByte {
//_, err := c.Write([]byte{byte(FRPTLSHeadByte)})
//修改为
_, err := c.Write([]byte{byte(FRPTLSHeadByte), byte(0x61), byte(0x63)})
if err != nil {
return nil, nil, err
}
}
return ctx, c, nil
}
}
4.编译
$ make -f Makefile.cross-compiles
至此,手动修改源码特征后编译完成,可以根据部署系统需要在release目录下找到对应操作系统的版本。
参考:
https://www.cnblogs.com/N0r4h/p/15848541.html
https://www.talaxy.site/lets-use-frp/