Kaynağa Gözat

Update environment variable table

tags/1.0^2
9seconds 6 yıl önce
ebeveyn
işleme
7d1d9007af
1 değiştirilmiş dosya ile 77 ekleme ve 134 silme
  1. 77
    134
      README.md

+ 77
- 134
README.md Dosyayı Görüntüle

39
 
39
 
40
 This proxy supports 2 modes of work: direct connection to Telegram and
40
 This proxy supports 2 modes of work: direct connection to Telegram and
41
 promoted channel mode. If you do not need promoted channels, I would
41
 promoted channel mode. If you do not need promoted channels, I would
42
-recommend you to go with direct mode: this is way more robust.
42
+recommend you to go with direct mode: this way is more robust.
43
 
43
 
44
 To run proxy in direct mode, all you need to do is just provide a
44
 To run proxy in direct mode, all you need to do is just provide a
45
 secret. If you do not provide ADTag as a second parameter, promoted
45
 secret. If you do not provide ADTag as a second parameter, promoted
102
 
102
 
103
 # Configuration
103
 # Configuration
104
 
104
 
105
-Basically, to run this tool you need to configure as less as possible.
105
+Basically, to run this tool you need to configure as less as possible. Telegram
106
+clients support 3 different secret types:
107
+
108
+* Simple - basically, it is just a flow of frames ciphered by AES-CTR stream
109
+  cipher.
110
+* Secured - the same stream as simple but with some random noise to prevent
111
+  statistical analysis of traffic flow.
112
+* FakeTLS - this mode envelops telegram stream in TLS so it looks (in theory)
113
+  the same as any TLS1.3 traffic from DPI point of view.
114
+
115
+If you do not have preferences, go with FakeTLS or at least secured.
116
+Simple mode is a little bit naive and traffic flow can be easily
117
+identified as Telegram one.
118
+
119
+Unlike the rest of implementation, mtg is quite strict about the
120
+execution mode: if you run a proxy instance with FakeTLS secret, you
121
+can't connect to it with simple or secured clients. You can't connect
122
+to the proxy with secured secret with FakeTLS key. It forces one mode
123
+of working. So, unfortunately, there is no way how to connect to the
124
+deployed proxy with another secret (if you know how to construct and
125
+convert them). But at the same time, old clients can't connect so they
126
+won't expose the type of the service.
106
 
127
 
107
 First, you need to generate a secret:
128
 First, you need to generate a secret:
108
 
129
 
109
 ```console
130
 ```console
110
-openssl rand -hex 16
131
+$ mtg generate-secret simple
132
+52a493bdfb90eea55739eabff2d92a14
111
 ```
133
 ```
112
 
134
 
113
-or
114
-
115
-```console
116
-head -c 512 /dev/urandom | md5sum | cut -f 1 -d ' '
117
-```
118
-
119
-## Secure mode
120
-
121
-_tl;dr - use secret mode for all new installation of proxy; only clients
122
-with dd-secrets will be able to connect. This mode abuses attempts to
123
-DPI MTPROTO traffic._
124
-
125
-Secure mode is not the best name and of course, it creates a lot of
126
-confusion. To explain what it means, we need to tell you some bits on
127
-dd-secrets.
128
-
129
-MTPROTO proxy protocol requires 16-byte secret. You usually
130
-propagate it as a 32 characters hexadecimal string like
131
-`282831900f371ca182feb0e4e1e1aeef` (if you decode this string
132
-to bytes, you will get a real secret which is used in the
133
-protocol). Everything went quite good until the moment when
134
-developers found an evidence that [protocol is quite weak to
135
-DPI](https://github.com/TelegramMessenger/MTProxy/issues/35) and some
136
-enthusiasts even created simple proofs of concepts on [detecting MTPROTO
137
-traffic](https://github.com/darkk/poormansmtproto).
138
-
139
-Telegram team has introduced a patch called dd-secrets. If you have
140
-a secret `282831900f371ca182feb0e4e1e1aeef` then your dd-secret is
141
-`dd282831900f371ca182feb0e4e1e1aeef`. That is, you just add dd prefix
142
-to the secret, prepend it with dd. In that case, original secret
143
-`282831900f371ca182feb0e4e1e1aeef` is used but client and server start
144
-to act a little bit different: they start to add random noise to the
145
-packets so they can't be detected by their length. In order to keep
146
-backward compatibility, all proxies a quite liberal to the secrets to
147
-use: if the client uses plain secret, without dd prefix, they fall back
148
-to the normal behavior. If dd-secret is used (proxy can extract this
149
-information on the handshake), then more secured, the hardened behavior
150
-is used.
151
-
152
-Yes, it can look like a hack but it is as it is.
153
-
154
-Now going back to the secure mode: if you do not pass `-s` flag to the
155
-mtg, then it checks what mode is requested by the client. If the client
156
-uses plain secret, without dd prefix, then proxy falls back to the
157
-original behavior and do not play with paddings. If dd-secret is used
158
-and client demands this mode, then proxy start to add that random noise
159
-to the packets. But if you pass `-s`, then only clients with dd-secrets
160
-can connect. How to migrate existing clients then? If a client is new
161
-enough, you can just prepend the secret with dd string in the settings.
162
-If it is an old guy, then nothing to do, sorry.
163
-
164
-Why this mode matters? We do not have evidence but there is quite a big
165
-suspicion that some ISPs start to filter MTPROTO traffic. If they detect
166
-the IP address which acts as a proxy, they block it and no clients can
167
-use this proxy. This is an attempt to prevent such a situation.
168
-
169
-General rule of thumb: with all new installation of proxies I would
170
-advise to go with secure mode by default. But please do remember that it
171
-means that clients, which do not pass dd-prefix to their secrets, will
172
-not be able to connect. *Secure mode works only with dd-prefixes!*
173
-
174
-Oneliners to generate such secrets:
175
-
176
 ```console
135
 ```console
177
-echo dd$(openssl rand -hex 16)
136
+$ mtg generate-secret secured
137
+ddf05fb7acb549be047a7c585116581418
178
 ```
138
 ```
179
 
139
 
180
-or
181
-
182
 ```console
140
 ```console
183
-echo dd$(head -c 512 /dev/urandom | md5sum | cut -f 1 -d ' ')
141
+$ mtg generate-secret -c google.com tls
142
+ee852380f362a09343efb4690c4e17862e676f6f676c652e636f6d
184
 ```
143
 ```
185
 
144
 
186
-
187
 ## Antireplay cache
145
 ## Antireplay cache
188
 
146
 
189
 In order to prevent replay attacks, we have internal storage of first
147
 In order to prevent replay attacks, we have internal storage of first
193
 prevent replays.
151
 prevent replays.
194
 
152
 
195
 
153
 
154
+## FakeTLS
155
+
156
+If you run this a proxy in faketls mode, this proxy will try to hide
157
+itself cloaking a host provided as a part of generated secret. It means
158
+that if you cloak google.com then you can curl this proxy and you'll get
159
+a google.com response back.
160
+
161
+mtg proxifies L3 traffic. In other words, only TCP, without interfering
162
+in TLS, HTTP or any other high-level protocol.
163
+
164
+
196
 ## Environment variables
165
 ## Environment variables
197
 
166
 
198
 It is possible to configure this tool using environment variables. You
167
 It is possible to configure this tool using environment variables. You
199
 can configure any flag but not secret or adtag. Here is the list of
168
 can configure any flag but not secret or adtag. Here is the list of
200
 supported environment variables:
169
 supported environment variables:
201
 
170
 
202
-| Environment variable          | Corresponding flags         | Default value                     | Description                                                                                                                                                                                                                                                                |
203
-|-------------------------------|-----------------------------|-----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
204
-| `MTG_DEBUG`                   | `-d`, `--debug`             | `false`                           | Run in debug mode. Usually, you need to run in this mode  only if you develop this tool or its maintainer is asking you to provide  logs with such verbosity.                                                                                                              |
205
-| `MTG_VERBOSE`                 | `-v`, `--verbose`           | `false`                           | Run in verbose mode. This is way less chatty than debug mode.                                                                                                                                                                                                              |
206
-| `MTG_IP`                      | `-b`, `--bind-ip`           | `127.0.0.1`                       | Which IP should we bind to. As usual, `0.0.0.0` means that we want to listen on all interfaces. Also, 4 zeroes will bind to both IPv4 and IPv6.                                                                                                                            |
207
-| `MTG_PORT`                    | `-p`, `--bind-port`         | `3128`                            | Which port should we bind to (listen on).                                                                                                                                                                                                                                  |
208
-| `MTG_IPV4`                    | `-4`, `--public-ipv4`       | [Autodetect](https://ifconfig.co) | IPv4 address of this proxy. This is required if you NAT your proxy or run it in a docker container. In that case, you absolutely need to specify public IPv4 address of the proxy, otherwise either URLs will be broken or proxy could not access Telegram middle proxies. |
209
-| `MTG_IPV4_PORT`               | `--public-ipv4-port`        | Value of `--bind-port`            | Which port should be public of IPv4 interface. This affects only generated links and should be changed only if you NAT your proxy or run it in a docker container.                                                                                                         |
210
-| `MTG_IPV6`                    | `-6`, `--public-ipv6`       | [Autodetect](https://ifconfig.co) | IPv6 address of this proxy. This is required if you NAT your proxy or run it in a docker container. In that case, you absolutely need to specify public IPv6 address of the proxy, otherwise either URLs will be broken or proxy could not access Telegram middle proxies. |
211
-| `MTG_IPV6_PORT`               | `--public-ipv6-port`        | Value of `--bind-port`            | Which port should be public of IPv6 interface. This affects only generated links and should be changed only if you NAT your proxy or run it in a docker container.                                                                                                         |
212
-| `MTG_STATS_IP`                | `-t`, `--stats-ip`          | `127.0.0.1`                       | Which IP should we bind the internal statistics HTTP server.                                                                                                                                                                                                               |
213
-| `MTG_STATS_PORT`              | `-q`, `--stats-port`        | `3129`                            | Which port should we bind the internal statistics HTTP server.                                                                                                                                                                                                             |
214
-| `MTG_STATSD_IP`               | `--statsd-ip`               |                                   | IP/host addresses of statsd service. No defaults, by defaults we do not send anything there.                                                                                                                                                                               |
215
-| `MTG_STATSD_PORT`             | `--statsd-port`             | `8125`                            | Which port should we use to work with statsd.                                                                                                                                                                                                                              |
216
-| `MTG_STATSD_NETWORK`          | `--statsd-network`          | `udp`                             | Which protocol should we use to work with statsd. Possible options are `udp` and `tcp`.                                                                                                                                                                                    |
217
-| `MTG_STATSD_PREFIX`           | `--statsd-prefix`           | `mtg`                             | Which bucket prefix we should use. For example, if you set `mtg`, then metric `traffic.ingress` would be send as `mtg.traffic.ingress`.                                                                                                                                    |
218
-| `MTG_STATSD_TAGS_FORMAT`      | `--statsd-tags-format`      |                                   | Which tags format we should use. By default, we are using default vanilla statsd tags format but if you want to send directly to InfluxDB or Datadog, please specify it there. Possible options are `influxdb` and `datadog`.                                              |
219
-| `MTG_STATSD_TAGS`             | `--statsd-tags`             |                                   | Which tags should we send to statsd with our metrics. Please specify them as `key=value` pairs.                                                                                                                                                                            |
220
-| `MTG_PROMETHEUS_PREFIX`       | `--prometheus-prefix`       | `mtg`                             | Which namespace should be used for prometheus metrics.                                                                                                                                                                                                                     |
221
-| `MTG_BUFFER_WRITE`            | `-w`, `--write-buffer`      | `65536`                           | The size of TCP write buffer in bytes. Write buffer is the buffer for messages which are going from client to Telegram.                                                                                                                                                    |
222
-| `MTG_BUFFER_READ`             | `-r`, `--read-buffer`       | `131072`                          | The size of TCP read buffer in bytes. Read buffer is the buffer for messages from Telegram to client.                                                                                                                                                                      |
223
-| `MTG_SECURE_ONLY`             | `-s`, `--secure-only`       | `false`                           | Support only clients with secure mode (i.e only clients with dd-secrets).                                                                                                                                                                                                  |
224
-| `MTG_ANTIREPLAY_MAXSIZE`      | `anti-replay-max-size`      | `128`                             | Max size of antireplay cache in megabytes.                                                                                                                                                                                                                                 |
225
-| `MTG_ANTIREPLAY_EVICTIONTIME` | `anti-replay-eviction-time` | `168h`                            | Eviction time for antireplay cache entries.                                                                                                                                                                                                                                |
171
+| Environment variable          | Corresponding flags          | Default value                     | Description                                                                                                                                                                                                                                                                     |
172
+|-------------------------------|------------------------------|-----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
173
+| `MTG_DEBUG`                   | `-d`, `--debug`              | `false`                           | Run in debug mode. Usually, you need to run in this mode  only if you develop this tool or its maintainer is asking you to provide  logs with such verbosity.                                                                                                                   |
174
+| `MTG_VERBOSE`                 | `-v`, `--verbose`            | `false`                           | Run in verbose mode. This is way less chatty than debug mode.                                                                                                                                                                                                                   |
175
+| `MTG_BIND`                    | `-b`, `--bind`               | `0.0.0.0:3128`                    | Which host/port pair should we bind to (listen on).                                                                                                                                                                                                                             |
176
+| `MTG_IPV4`                    | `-4`, `--public-ipv4`        | [Autodetect](https://ifconfig.co) | IPv4 address:port of this proxy. This is required if you NAT your proxy or run it in a docker container. In that case, you absolutely need to specify public IPv4 address of the proxy, otherwise either URLs will be broken or proxy could not access Telegram middle proxies. |
177
+| `MTG_IPV6`                    | `-6`, `--public-ipv6`        | [Autodetect](https://ifconfig.co) | IPv6 address:port of this proxy. This is required if you NAT your proxy or run it in a docker container. In that case, you absolutely need to specify public IPv6 address of the proxy, otherwise either URLs will be broken or proxy could not access Telegram middle proxies. |
178
+| `MTG_STATS_BIND`              | `-t`, `--stats-bind`         | `127.0.0.1:3129`                  | Which hist:port should we bind the internal statistics HTTP server (Prometheus).                                                                                                                                                                                                |
179
+| `MTG_STATS_NAMESPACE`         | `--stats-namespace`          | `mtg`                             | Which namespace should be used for prometheus metrics.                                                                                                                                                                                                                          |
180
+| `MTG_STATSD_ADDR`             | `--statsd-addr`              |                                   | IP:host addresses of statsd service. No defaults, by defaults we do not send anything there.                                                                                                                                                                                    |
181
+| `MTG_STATSD_PORT`             | `--statsd-port`              | `8125`                            | Which port should we use to work with statsd.                                                                                                                                                                                                                                   |
182
+| `MTG_STATSD_NETWORK`          | `--statsd-network`           | `udp`                             | Which protocol should we use to work with statsd. Possible options are `udp` and `tcp`.                                                                                                                                                                                         |
183
+| `MTG_STATSD_PREFIX`           | `--statsd-prefix`            | `mtg`                             | Which bucket prefix we should use. For example, if you set `mtg`, then metric `traffic.ingress` would be send as `mtg.traffic.ingress`.                                                                                                                                         |
184
+| `MTG_STATSD_TAGS_FORMAT`      | `--statsd-tags-format`       |                                   | Which tags format we should use. By default, we are using default vanilla statsd tags format but if you want to send directly to InfluxDB or Datadog, please specify it there. Possible options are `influxdb` and `datadog`.                                                   |
185
+| `MTG_STATSD_TAGS`             | `--statsd-tags`              |                                   | Which tags should we send to statsd with our metrics. Please specify them as `key=value` pairs.                                                                                                                                                                                 |
186
+| `MTG_BUFFER_WRITE`            | `-w`, `--write-buffer`       | `65536`                           | The size of TCP write buffer in bytes. Write buffer is the buffer for messages which are going from client to Telegram.                                                                                                                                                         |
187
+| `MTG_BUFFER_READ`             | `-r`, `--read-buffer`        | `131072`                          | The size of TCP read buffer in bytes. Read buffer is the buffer for messages from Telegram to client.                                                                                                                                                                           |
188
+| `MTG_ANTIREPLAY_MAXSIZE`      | `--anti-replay-max-size`     | `128MB`                           | Max size of antireplay cache.                                                                                                                                                                                                                                                   |
189
+| `MTG_CLOAK_PORT`              | `--cloak-port`               | `443`                             | Which port we should use to connect to cloaked host in FakeTLS mode.                                                                                                                                                                                                            |
190
+| `MTG_MULTIPLEX_PERCONNECTION` | `--multiplex-per-connection` | `50`                              | How many client connections can share a single Telegram connection in adtag mode                                                                                                                                                                                                |
226
 
191
 
227
 Usually you want to modify only read/write buffer sizes. If you feel
192
 Usually you want to modify only read/write buffer sizes. If you feel
228
 that proxy is slow, try to increase both sizes giving more priority to
193
 that proxy is slow, try to increase both sizes giving more priority to
237
 Now run the tool:
202
 Now run the tool:
238
 
203
 
239
 ```console
204
 ```console
240
-mtg <secret>
205
+$ mtg run <secret>
241
 ```
206
 ```
242
 
207
 
243
 How to run the tool with ADTag:
208
 How to run the tool with ADTag:
244
 
209
 
245
 ```console
210
 ```console
246
-mtg <secret> <adtag>
211
+$ mtg run <secret> <adtag>
247
 ```
212
 ```
248
 
213
 
249
 This tool will listen on port 3128 by default with the given secret.
214
 This tool will listen on port 3128 by default with the given secret.
250
 
215
 
251
-# One-line runner
252
-
253
-```console
254
-docker run --name mtg --restart=unless-stopped -p 3128:3128 -p 3129:3129 -d nineseconds/mtg:stable $(openssl rand -hex 16)
255
-```
256
-
257
-or in secret mode:
258
-
259
-```console
260
-docker run --name mtg --restart=unless-stopped -p 3128:3128 -p 3129:3129 -d nineseconds/mtg:stable dd$(openssl rand -hex 16)
261
-```
262
-
263
-You will have this tool up and running on port 3128. Now curl
264
-`localhost:3129` to get `tg://` links or do `docker logs mtg`. Also,
265
-port 3129 will show you some statistics if you are interested in.
266
-
267
-Also, you can use [run-mtg.sh](https://github.com/9seconds/mtg/blob/master/run-mtg.sh) script
268
-
269
 
216
 
270
 # statsd integration
217
 # statsd integration
271
 
218
 
278
 
225
 
279
 All metrics are gauges. Here is the list of metrics and their meaning:
226
 All metrics are gauges. Here is the list of metrics and their meaning:
280
 
227
 
281
-| Metric name                     | Unit    | Description                                               |
282
-|---------------------------------|---------|-----------------------------------------------------------|
283
-| `connections.abridged.ipv4`     | number  | The number of active abridged IPv4 connections            |
284
-| `connections.abridged.ipv6`     | number  | The number of active abridged IPv6 connections            |
285
-| `connections.intermediate.ipv4` | number  | The number of active intermediate IPv4 connections        |
286
-| `connections.intermediate.ipv6` | number  | The number of active intermediate IPv6 connections        |
287
-| `connections.secure.ipv4`       | number  | The number of active secure intermediate IPv4 connections |
288
-| `connections.secure.ipv6`       | number  | The number of active secure intermediate IPv6 connections |
289
-| `crashes`                       | number  | An amount of crashes in client handlers                   |
290
-| `traffic.ingress`               | bytes   | Ingress traffic from the start of application (incoming)  |
291
-| `traffic.egress`                | bytes   | Egress traffic from the start of application (outgoing)   |
292
-| `speed.ingress`                 | bytes/s | Ingress bandwidth of the latest second (incoming traffic) |
293
-| `speed.egress`                  | bytes/s | Egress bandwidth of the latest second (outgoing traffic)  |
228
+| Metric name                      | Unit    | Description                                               |
229
+|----------------------------------|---------|-----------------------------------------------------------|
230
+| `connections.abridged.ipv4`      | number  | The number of active abridged IPv4 connections            |
231
+| `connections.abridged.ipv6`      | number  | The number of active abridged IPv6 connections            |
232
+| `connections.intermediate.ipv4`  | number  | The number of active intermediate IPv4 connections        |
233
+| `connections.intermediate.ipv6`  | number  | The number of active intermediate IPv6 connections        |
234
+| `connections.secure.ipv4`        | number  | The number of active secure intermediate IPv4 connections |
235
+| `connections.secure.ipv6`        | number  | The number of active secure intermediate IPv6 connections |
236
+| `telegram_connections.[dc].ipv4` | number  | The number of active abridged IPv4 connections            |
237
+| `telegram_connections.[dc].ipv6` | number  | The number of active abridged IPv6 connections            |
238
+| `crashes`                        | number  | An amount of crashes in client handlers                   |
239
+| `traffic.ingress`                | bytes   | Ingress traffic from the start of application (incoming)  |
240
+| `traffic.egress`                 | bytes   | Egress traffic from the start of application (outgoing)   |
241
+| `replay_attacks`                 | number  | A number of prevented replay attacks.                     |
294
 
242
 
295
 All metrics are prefixed with given prefix. Default prefix is `mtg`.
243
 All metrics are prefixed with given prefix. Default prefix is `mtg`.
296
 With such prefix metric name `traffic.ingress`, for example, would be
244
 With such prefix metric name `traffic.ingress`, for example, would be
300
 # Prometheus integration
248
 # Prometheus integration
301
 
249
 
302
 [Prometheus](https://prometheus.io) integration comes out of
250
 [Prometheus](https://prometheus.io) integration comes out of
303
-the box, you do not need to setup anything special. Prometheus
304
-scrape endpoint lives on the same IP/port where generic stats
305
-service (`http://${MTG_STATS_IP}:${MTG_STATS_PORT}`) but on
306
-`/prometheus` path. So, if you access http stats service as `curl
307
-http://localhost:3129/`, then your prometheus endpoint is `curl
308
-http://localhost:3129/prometheus/`.
251
+the box, you do not need to setup anything special.

Loading…
İptal
Kaydet