~bigbes/shroud

ref: 3394139df40339ebdae50f853d922c14fca77c35 shroud/internal/awgserver/detect.go -rw-r--r-- 1.3 KiB
3394139d — Eugene Blikh docs: update README with VLESS+REALITY, CI/CD site deployment a month ago
                                                                                
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
package awgserver

import "encoding/binary"

// WireGuard message sizes (from noise-protocol.go).
const (
	messageInitiationSize      = 148
	messageResponseSize        = 92
	messageCookieReplySize     = 64
	messageTransportHeaderSize = 16
)

// isAWGPacket checks if the packet matches any AmneziaWG message type
// using the S1-S4 size offsets and H1-H4 header ranges.
func isAWGPacket(pkt []byte, cfg *Config) bool {
	size := len(pkt)

	// Initiation: exact size S1+148, H1 at offset S1.
	if size == cfg.S1+messageInitiationSize && size >= cfg.S1+4 {
		hdr := binary.LittleEndian.Uint32(pkt[cfg.S1:])
		if cfg.H1.Contains(hdr) {
			return true
		}
	}

	// Response: exact size S2+92, H2 at offset S2.
	if size == cfg.S2+messageResponseSize && size >= cfg.S2+4 {
		hdr := binary.LittleEndian.Uint32(pkt[cfg.S2:])
		if cfg.H2.Contains(hdr) {
			return true
		}
	}

	// Cookie Reply: exact size S3+64, H3 at offset S3.
	if size == cfg.S3+messageCookieReplySize && size >= cfg.S3+4 {
		hdr := binary.LittleEndian.Uint32(pkt[cfg.S3:])
		if cfg.H3.Contains(hdr) {
			return true
		}
	}

	// Transport: size >= S4+16, H4 at offset S4.
	if size >= cfg.S4+messageTransportHeaderSize && size >= cfg.S4+4 {
		hdr := binary.LittleEndian.Uint32(pkt[cfg.S4:])
		if cfg.H4.Contains(hdr) {
			return true
		}
	}

	return false
}