|
|
@@ -33,7 +33,39 @@ type Network interface {
|
|
33
|
33
|
MakeHTTPClient(func(ctx context.Context, network, address string) (net.Conn, error)) *http.Client
|
|
34
|
34
|
}
|
|
35
|
35
|
|
|
|
36
|
+// AntiReplayCache is an interface that is used to detect replay attacks
|
|
|
37
|
+// based on some traffic fingerprints.
|
|
|
38
|
+//
|
|
|
39
|
+// Replay attacks are probe attacks whose main goal is to identify if
|
|
|
40
|
+// server software can be classified in some way. For example, if you
|
|
|
41
|
+// send some HTTP request to a web server, then you can expect that this
|
|
|
42
|
+// server will respond with HTTP response back.
|
|
|
43
|
+//
|
|
|
44
|
+// There is a problem though. Let's imagine, that connection is
|
|
|
45
|
+// encrypted. Let's imagine, that it is encrypted with some static key
|
|
|
46
|
+// like ShadowSocks (https://shadowsocks.org/assets/whitepaper.pdf).
|
|
|
47
|
+// In that case, in theory, if you repeat the same bytes, you can get
|
|
|
48
|
+// the same responses. Let's imagine, that you've cracked the key. then
|
|
|
49
|
+// if you send the same bytes, you can decrypt a response and see its
|
|
|
50
|
+// structure. Based on its structure you can identify if this server is
|
|
|
51
|
+// SOCKS5, MTPROTO proxy etc.
|
|
|
52
|
+//
|
|
|
53
|
+// This is just one example, maybe not the best or not the most
|
|
|
54
|
+// relevant. In real life, different organizations use such replay
|
|
|
55
|
+// attacks to perform some reverse engineering of the proxy, do some
|
|
|
56
|
+// statical analysis to identify server software.
|
|
|
57
|
+//
|
|
|
58
|
+// There are many ways how to protect your proxy against them. One
|
|
|
59
|
+// is domain fronting which is a core part of mtg. Another one is to
|
|
|
60
|
+// collect some 'handshake fingerprints' and forbid duplication.
|
|
|
61
|
+//
|
|
|
62
|
+// So, it one is sending the same byte flow right after you (or a couple
|
|
|
63
|
+// of hours after), mtg should detect that and reject this connection
|
|
|
64
|
+// (or redirect to fronting domain).
|
|
36
|
65
|
type AntiReplayCache interface {
|
|
|
66
|
+ // Seen before checks if this set of bytes was observed before or
|
|
|
67
|
+ // not. If it is required to store this information somewhere else,
|
|
|
68
|
+ // then it has to do that.
|
|
37
|
69
|
SeenBefore(data []byte) bool
|
|
38
|
70
|
}
|
|
39
|
71
|
|