我无法弄清楚如何编辑此 Radius MSCHAPv2 示例并从 radius 客户端获取密码。我正在使用的 go 库是https://github.com/layeh/radius。
MSCHAPv2 是否发送带有密码的用户名?如何从客户端获取密码到服务器?
package microsoft
import (
"log"
"reflect"
"layeh.com/radius"
"layeh.com/radius/rfc2759"
"layeh.com/radius/rfc2865"
"layeh.com/radius/rfc2868"
"layeh.com/radius/rfc2869"
"layeh.com/radius/rfc3079"
)
const (
radiusSecret = "secret"
)
func RunRadiusServer() {
handler := func(w radius.ResponseWriter, r *radius.Request) {
username := rfc2865.UserName_GetString(r.Packet)
challenge := MSCHAPChallenge_Get(r.Packet)
response := MSCHAP2Response_Get(r.Packet)
// TODO: look up user in local database.
// The password must be stored in the clear for CHAP mechanisms to work.
// In theory, it would be possible to use a password hashed with MD4 as
// all the functions in MSCHAPv2 use the MD4 hash of the password anyway,
// but given that MD4 is so vulerable that breaking a hash is almost as
// fast as computing it, it's just not worth it.
password := "password-from-database"
if len(challenge) == 16 && len(response) == 50 {
// See rfc2548 - 2.3.2. MS-CHAP2-Response
ident := response[0]
peerChallenge := response[2:18]
peerResponse := response[26:50]
ntResponse, err := rfc2759.GenerateNTResponse(challenge, peerChallenge, username, password)
if err != nil {
log.Printf("Cannot generate ntResponse for %s: %v", username, err)
w.Write(r.Response(radius.CodeAccessReject))
return
}
我编辑了函数的顶部:
username := rfc2865.UserName_GetString(r.Packet)
password := rfc2865.UserPassword_GetString(r.Packet)
log.Printf("bytes %+v", r.Get(1), string(r.Get(1)))
log.Printf("bytes %+v", r.Get(2), string(r.Get(2)))
log.Printf("u/p %v, %v\n", username, password)
用户名正确。密码为空。1 是用户名。我无法对 2 进行排序,因为它不会将字节转换为字符串。
这里有一个类似但不是 Go 特定的问题,也没有正确回答。谢谢!
慕妹3242003
绝地无双
相关分类