Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add bypass mode; fix: add new keys #3

Merged
merged 1 commit into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions gover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ go run main.go

6. Start the game and have fun!

## For your safety
MHY will frequently update their resource files, so our hardcoded checksums are not always available. For your account safety, it is recommended that you enable bypass mode.

1. Install [npcap](https://npcap.com/) on windows or [libpcap](https://www.tcpdump.org/) on linux

2. Run `go build -tags bypass` to build the bypass version

3. Run `gover.exe --bypass` on windows or `.\gover --bypass` on linux to enable runtime bypass

4. (Known issue) Make sure your game was the first startup before login, which means you shouldn't logout then re-login without completely quit the game, or will cause capture failed

## Fiddler Script
```cs
/* Gidra proxy fiddler script */
Expand Down
2 changes: 2 additions & 0 deletions gover/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ require (
require (
github.com/ThreeKing2018/gocolor v0.0.0-20190625094635-394e0e24c0d0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/gopacket v1.1.19 // indirect
golang.org/x/sys v0.0.0-20190412213103-97732733099d // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)
15 changes: 15 additions & 0 deletions gover/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,23 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8=
github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
github.com/yezihack/colorlog v0.0.0-20190312024641-4717a40e9990 h1:62I1TD5lofiBbO3+oS5wVXBCB7hyncP4Ge0UsVKSag0=
github.com/yezihack/colorlog v0.0.0-20190312024641-4717a40e9990/go.mod h1:oeujxvLndaRV//iyjkRt4o71gSTvyf+T4NOt0ZQSWc4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion gover/kcp/kcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func TestKCP(t *testing.T) {
fmt.Println(kcp, err)
kcp.NoDelay(1, 10, 2, 1)
kcp.Send([]byte("hello world"))
kcp.Update()
kcp.Update(0)
kcp.Input([]byte{1, 0, 0, 0, 2, 0, 0, 0, 81, 0, 32, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100})
d := make([]byte, 1500)
n := kcp.Recv(d)
Expand Down
85 changes: 61 additions & 24 deletions gover/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/MoonlightPS/Iridium-gidra/gover/ec2b"
"github.com/MoonlightPS/Iridium-gidra/gover/gen"
"github.com/MoonlightPS/Iridium-gidra/gover/proxy"
"github.com/MoonlightPS/Iridium-gidra/gover/proxy/bypass"
"github.com/MoonlightPS/Iridium-gidra/gover/utils"
"github.com/yezihack/colorlog"
"google.golang.org/protobuf/proto"
Expand All @@ -26,7 +27,7 @@ const HTTP_LST = ":8081"

type serverDesc struct {
addr *net.UDPAddr
sock *proxy.KCPSocket
sock proxy.ProxyInterface
}

type regionRsp struct {
Expand All @@ -35,6 +36,7 @@ type regionRsp struct {
}

var gameServers = map[string]*serverDesc{}
var bypassMode = false

func WaitExit() {
c := make(chan os.Signal, 1)
Expand Down Expand Up @@ -89,8 +91,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
colorlog.Error("failed request dispatch, err: %+v", err)
return
}

regionInfo := &gen.QueryCurrRegionHttpRsp{}
originResp := append(make([]byte, 0, len(result)), result...)

ver := r.URL.Query().Get("version")
v2 := strings.Contains(ver, "2.7.5") || strings.Contains(ver, "2.8.") || strings.Contains(ver, "3.")
Expand Down Expand Up @@ -127,6 +128,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
}
}

regionInfo := &gen.QueryCurrRegionHttpRsp{}
err = proto.Unmarshal(result, regionInfo)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
Expand All @@ -140,7 +142,22 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
IP: net.ParseIP(regionInfo.GetRegionInfo().GetGateserverIp()),
Port: int(regionInfo.GetRegionInfo().GetGateserverPort()),
}
if s, ok := gameServers[target.String()]; ok {
if bypassMode {
keyBytes, err := ec2b.Derive(regionInfo.GetClientSecretKey())
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
colorlog.Error("generate key error, err: %+v", err)
return
}

key := utils.NewPacketKey()
key.SetKey(keyBytes)
sock := proxy.NewBypassSocket(target, key, keyID)
sock.Start()
gameServers[target.String()] = &serverDesc{addr: nil, sock: sock}
colorlog.Info("starting new bypass sniffer on %+v", target)
} else if s, ok := gameServers[target.String()]; ok {
regionInfo.GetRegionInfo().GateserverIp = s.addr.IP.String()
regionInfo.GetRegionInfo().GateserverPort = uint32(s.addr.Port)
} else {
Expand Down Expand Up @@ -173,31 +190,38 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
}
}

result, err = proto.Marshal(regionInfo)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
colorlog.Error("failed marshal region, err: %+v", err)
return
}
if v2 {
result, sign, err := utils.EncryptWithSign(result, keyID)
if bypassMode {
result = originResp
} else {
result, err = proto.Marshal(regionInfo)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
colorlog.Error("failed enc region, err: %+v", err)
colorlog.Error("failed marshal region, err: %+v", err)
return
}
resp := &regionRsp{
Content: base64.StdEncoding.EncodeToString(result),
Sign: base64.StdEncoding.EncodeToString(sign),
}
result, err = json.Marshal(resp)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
colorlog.Error("failed marshal region json, err: %+v", err)
return
}
if v2 {
if !bypassMode {
var sign []byte
result, sign, err = utils.EncryptWithSign(result, keyID)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
colorlog.Error("failed enc region, err: %+v", err)
return
}
resp := &regionRsp{
Content: base64.StdEncoding.EncodeToString(result),
Sign: base64.StdEncoding.EncodeToString(sign),
}
result, err = json.Marshal(resp)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
colorlog.Error("failed marshal region json, err: %+v", err)
return
}
}
w.Header().Set("Content-Length", strconv.Itoa(len(result)))
w.Header().Set("Content-Type", "application/json")
Expand All @@ -212,11 +236,24 @@ func main() {
if err != nil {
panic(err)
}
for _, arg := range os.Args {
if arg == "--bypass" {
bypassMode = true
colorlog.Warn("service is running at bypass mode")
}
}
if bypassMode {
err = bypass.StartBypassService()
if err != nil {
panic(err)
}
}
http.HandleFunc("/query_cur_region", indexHandler)
go http.ListenAndServe(HTTP_LST, nil)
colorlog.Info("running...")
WaitExit()
for _, v := range gameServers {
v.sock.Stop()
}
bypass.StopBypassService()
}
Loading