移动光猫(如HG8347R,HS8545M5)及部份光猫PPPOE密码获取

我最近搬了新家,房东使用的是华为HG8347R光猫。由于我希望将光猫的工作模式从路由模式更改为桥接模式,以便我可以使用自己的路由器进行拨号,但房东并不清楚PPPOE的密码。因此,我开始寻找获取这个密码的方式。以下是我完成这个过程的详细记录。

获取加密后的PPPOE密码

首先,我使用超级用户的账号密码登录光猫,在网络连接中找到当前使用路由模式的连接。在这里,我发现了被前端代码隐藏的PPPOE密码。我使用一种简单的前端技巧来显示这个密码。这个技巧就是在密码字段上点击右键,进行检查,找到相应的元素,然后将其type属性中的password更改为text,这样就可以显示出密码。我最终获取到了一个64位长的字符串。这个字符串其实是PPPOE密码经过sha256(md5)加密后生成的。由于PPPOE密码长度一般为8位长且为纯数字,密码长度并不长,因此我可以通过穷举的方式获取原始密码。

Golang穷举脚本

我简单地编写了一个Go脚本,只穷举了从10000000到9999999999的可能性。这个范围对大部分场景应该已经足够,如果有其他需求可以自行修改脚本。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main

import (
"context"
"crypto/md5"
"crypto/sha256"
"encoding/hex"
"fmt"
"sync"
"strconv"
"time"
)

const (
startPassword = 10000000 // 设定穷举的起始密码
secret = "将密码粘贴到此处" // 设定你的密码
)

var (
wg sync.WaitGroup
mutex sync.Mutex
result int
buf = make([]byte, 0, 64) // 重用的字节切片,避免内存拷贝
lastTry int
)

func main() {
fmt.Println("Starting password brute force from 8 digits to 13 digits...")
for endPassword := startPassword * 10; endPassword <= 1e13; endPassword *= 10 {
ctx, cancel := context.WithCancel(context.Background())

// 创建一个定时器,每15秒输出一次当前正在尝试的密码
go func() {
ticker := time.NewTicker(15 * time.Second)
for {
select {
case <-ticker.C:
fmt.Printf("Currently trying: %d\n", lastTry)
case <-ctx.Done():
ticker.Stop()
return
}
}
}()

// 使用CPU的每个核心创建一个goroutine
for i := startPassword; i < endPassword; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()

m := md5.New()
s := sha256.New()

// 重用字节切片,避免内存拷贝
buf = buf[:0]
buf = strconv.AppendInt(buf, int64(i), 10)

if sha256Coding(md5Coding(buf, m), s) == secret {
mutex.Lock() // 获得互斥锁
if result == 0 {
result = i
fmt.Printf("Password: %d\n", i)
cancel() // 发送取消信号
}
mutex.Unlock() // 释放互斥锁
}
lastTry = i
}(i)
select {
case <-ctx.Done():
return
default:
}
}
wg.Wait()
if result == 0 {
fmt.Printf("Increased search to %d digits, no match found yet. Continuing...\n", len(strconv.Itoa(endPassword-1)))
} else {
return
}
}
fmt.Println("No match found up to 13 digits. Please check your secret.")
}

func md5Coding(v []byte, m hash.Hash) string {
m.Write(v)
return hex.EncodeToString(m.Sum(nil))
}

func sha256Coding(v string, s hash.Hash) string {
s.Write([]byte(v))
return hex.EncodeToString(s.Sum(nil))
}

运行完毕后即可得到原始密码

Author: Little Twain
Link: https://8.9.6.8/2023/04/28/光猫PPPOE密码获取/
Copyright Notice: All articles in this blog are licensed under GNU General Public License v3.0 unless stating additionally.