1
0
mirror of https://github.com/fumiama/go-nd-portal.git synced 2026-06-20 01:20:41 +08:00

support dx login

This commit is contained in:
源文雨
2022-12-06 12:56:12 +08:00
parent 10639b07ec
commit ca72da0c06
5 changed files with 33 additions and 18 deletions

View File

@@ -15,10 +15,11 @@ $ go install github.com/fumiama/go-nd-portal@latest
> 也可不带参数运行,会在启动时询问参数
```bash
./go-nd-portal -n 20xxxxxxxxxxx -p password
./go-nd-portal -n 20xxxxxxxxxxx -p password [-x]
```
默认值:
* `ip`: 本机公网出口,可自定义
* `-ip`: 本机公网出口,可自定义
* `-x`: 是否使用电信登陆(否)
## 效果

View File

@@ -7,7 +7,6 @@ import (
"net/netip"
"os"
"runtime"
"time"
"golang.org/x/term"
@@ -50,6 +49,7 @@ func Main() {
h := flag.Bool("h", false, "display this help")
w := flag.Bool("w", false, "only display warn-or-higher-level log")
d := flag.Bool("d", false, "display debug-level log")
x := flag.Bool("x", false, "do dx login")
flag.Parse()
if *h {
fmt.Println("Usage:")
@@ -96,18 +96,27 @@ func Main() {
*p = helper.BytesToString(data)
fmt.Println()
}
portal, err := portal.NewPortal(*n, *p, ip)
ptl, err := portal.NewPortal(*n, *p, ip)
if err != nil {
logrus.Errorln(err)
os.Exit(line())
}
challenge, err := portal.GetChallenge()
u := portal.PortalGetChallenge
if *x {
u = portal.PortalGetChallengeDX
}
challenge, err := ptl.GetChallenge(u)
if err != nil {
logrus.Errorln(err)
os.Exit(line())
}
time.Sleep(time.Second + time.Duration(time.Now().Unix()%1000)*time.Millisecond)
err = portal.Login(challenge)
u = portal.PortalLogin
dm := portal.PortalDomain
if *x {
u = portal.PortalLoginDX
dm = portal.PortalDomainDX
}
err = ptl.Login(u, dm, challenge)
if err != nil {
logrus.Errorln(err)
os.Exit(line())

View File

@@ -44,8 +44,8 @@ func NewPortal(name, password string, ipv4 net.IP) (*Portal, error) {
}, nil
}
func (p *Portal) GetChallenge() (string, error) {
u := fmt.Sprintf(PortalGetChallenge, "gondportal", url.QueryEscape(p.nam), p.ip, time.Now().UnixMilli())
func (p *Portal) GetChallenge(u string) (string, error) {
u = fmt.Sprintf(u, "gondportal", url.QueryEscape(p.nam), p.ip, time.Now().UnixMilli())
logrus.Debugln("GET", u)
data, err := requestDataWith(u, "GET", PortalHeaderUA)
if err != nil {
@@ -74,10 +74,10 @@ func (p *Portal) PasswordHMd5(challenge string) string {
return hex.EncodeToString(h.Sum(buf[:0]))
}
func (p *Portal) Login(challenge string) error {
func (p *Portal) Login(u, domain, challenge string) error {
info := EncodeUserInfo(p.String(), challenge)
hmd5 := p.PasswordHMd5(challenge)
u := fmt.Sprintf(PortalLogin, "gondportal", url.QueryEscape(p.nam), hmd5, p.ip, p.CheckSum(challenge, hmd5, info), url.QueryEscape(info), time.Now().UnixMilli())
u = fmt.Sprintf(u, "gondportal", url.QueryEscape(p.nam), hmd5, p.ip, p.CheckSum(domain, challenge, hmd5, info), url.QueryEscape(info), time.Now().UnixMilli())
logrus.Debugln("GET", u)
data, err := requestDataWith(u, "GET", PortalHeaderUA)
if err != nil {

View File

@@ -10,10 +10,13 @@ import (
)
const (
PortalServerIP = "10.253.0.237"
PortalDomain = "@dx-uestc"
PortalGetChallenge = "http://" + PortalServerIP + "/cgi-bin/get_challenge?callback=%s&username=%s" + PortalDomain + "&ip=%v&_=%d"
PortalLogin = "http://" + PortalServerIP + "/cgi-bin/srun_portal?callback=%s&action=login&username=%s" + PortalDomain + "&password={MD5}%s&ac_id=1&ip=%v&chksum=%s&info={SRBX1}%s&n=200&type=1&os=Windows+10&name=Windows&double_stack=0&_=%d"
PortalServerIP = "10.253.0.237"
PortalDomain = "@dx-uestc"
PortalDomainDX = "@dx"
PortalGetChallenge = "http://" + PortalServerIP + "/cgi-bin/get_challenge?callback=%s&username=%s" + PortalDomain + "&ip=%v&_=%d"
PortalGetChallengeDX = "http://" + PortalServerIP + "/cgi-bin/get_challenge?callback=%s&username=%s" + PortalDomainDX + "&ip=%v&_=%d"
PortalLogin = "http://" + PortalServerIP + "/cgi-bin/srun_portal?callback=%s&action=login&username=%s" + PortalDomain + "&password={MD5}%s&ac_id=1&ip=%v&chksum=%s&info={SRBX1}%s&n=200&type=1&os=Windows+10&name=Windows&double_stack=0&_=%d"
PortalLoginDX = "http://" + PortalServerIP + "/cgi-bin/srun_portal?callback=%s&action=login&username=%s" + PortalDomainDX + "&password={MD5}%s&ac_id=1&ip=%v&chksum=%s&info={SRBX1}%s&n=200&type=1&os=Windows+10&name=Windows&double_stack=0&_=%d"
)
const (
@@ -21,7 +24,8 @@ const (
)
const (
PortalUserInfo = `{"username":"%s` + PortalDomain + `","password":"%s","ip":"%v","acid":"1","enc_ver":"srun_bx1"}`
PortalUserInfo = `{"username":"%s` + PortalDomain + `","password":"%s","ip":"%v","acid":"1","enc_ver":"srun_bx1"}`
PortalUserInfoDX = `{"username":"%s` + PortalDomainDX + `","password":"%s","ip":"%v","acid":"1","enc_ver":"srun_bx1"}`
)
func EncodeUserInfo(info, challenge string) string {
@@ -76,12 +80,12 @@ func EncodeUserInfo(info, challenge string) string {
return base64.Base64Encoding.EncodeToString(lv)
}
func (p *Portal) CheckSum(challenge, hmd5, info string) string {
func (p *Portal) CheckSum(domain, challenge, hmd5, info string) string {
var buf [20]byte
h := sha1.New()
_, _ = h.Write(helper.StringToBytes(challenge))
_, _ = h.Write(helper.StringToBytes(p.nam))
_, _ = h.Write([]byte(PortalDomain))
_, _ = h.Write([]byte(domain))
_, _ = h.Write(helper.StringToBytes(challenge))
_, _ = h.Write(helper.StringToBytes(hmd5))
_, _ = h.Write(helper.StringToBytes(challenge))

View File

@@ -71,6 +71,7 @@ func TestCheckSum(t *testing.T) {
t.Log(u.String())
challenge := "d26466d4036507dadb17e87e23358126e0210cb289d19151f59bcfcefdcf345e"
s := u.CheckSum(
PortalDomain,
challenge,
u.PasswordHMd5(challenge),
EncodeUserInfo(