-
Notifications
You must be signed in to change notification settings - Fork 3
/
pppoe.go
65 lines (51 loc) · 1.26 KB
/
pppoe.go
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
package main
import (
"encoding/binary"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"log"
)
type PppPAPCode uint8
const (
AuthenticateRequest PppPAPCode = 0x01
//AuthenticateAck PppPAPCode = 0x02
//AuthenticateNack PppPAPCode = 0x03
)
type PppPAP struct {
code PppPAPCode
identifier uint8
length uint16
peerID []byte
password []byte
}
func DecodePppPAP(ppp *layers.PPP) *PppPAP {
peerIdLength := ppp.Payload[4]
passwordLength := ppp.Payload[5+peerIdLength]
return &PppPAP{
code: PppPAPCode(ppp.Payload[0]),
identifier: ppp.Payload[1],
length: binary.BigEndian.Uint16(ppp.Payload[2:4]),
peerID: ppp.Payload[5 : 5+peerIdLength],
password: ppp.Payload[6+peerIdLength : 6+peerIdLength+passwordLength],
}
}
func PrintPapInfoIfPossible(packet gopacket.Packet) {
pppLayer := packet.Layer(layers.LayerTypePPP)
if pppLayer == nil {
return
}
ppp, _ := pppLayer.(*layers.PPP)
if ppp.PPPType != 0xc023 {
return
}
pap := DecodePppPAP(ppp)
if pap.code != AuthenticateRequest {
return
}
log.Printf(`
=================================================
=== PAP Username : %s
=== PAP Password : %s
=================================================
`, string(pap.peerID), string(pap.password))
}