Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

example.config.toml 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. # This is an example of the configuration file for mtg. You actually can
  2. # run mtg with it. It starts a proxy on all interfaces with a secret
  3. # ee367a189aee18fa31c190054efd4a8e9573746f726167652e676f6f676c65617069732e636f6d
  4. #
  5. # It has all possible options with default values. So, a real world
  6. # configuration file should contain only those options you are going to
  7. # use. You do not need to enumerate all of them. In other words, each
  8. # option here has a default value. If you comment a key-value pair, it
  9. # should not make any effect.
  10. #
  11. # stats is the only exception.
  12. # Debug starts application in debug mode. It starts to be quite verbose
  13. # in output. Actually, the idea is that you run it in debug mode only if
  14. # you have any issue.
  15. debug = true
  16. # A secret. Please remember that mtg supports only FakeTLS mode, legacy
  17. # simple and secured mode are prohibited. For you it means that secret
  18. # should either be base64-encoded or starts with ee.
  19. secret = "ee367a189aee18fa31c190054efd4a8e9573746f726167652e676f6f676c65617069732e636f6d"
  20. # Host:port pair to bind the built-in stats HTTP API server.
  21. # GET /stats returns per-user connection counts and traffic.
  22. # If not set, the stats API is not started.
  23. # api-bind-to = "127.0.0.1:9090"
  24. # Host:port pair to run proxy on.
  25. bind-to = "0.0.0.0:3128"
  26. # This defines what types of traffic mtg listens to. If you are not sure,
  27. # then definitely keep it disable. Enable it only and only if incoming traffic
  28. # is coming from some sort of load-balancer like HAProxy or ELB.
  29. # https://www.haproxy.org/download/2.3/doc/proxy-protocol.txt
  30. #
  31. # mtg uses a library that supports v1 and v2 versions of ProxyProtocol.
  32. # default value is false.
  33. # proxy-protocol-listener = false
  34. # Defines how many concurrent connections are allowed to this proxy.
  35. # All other incoming connections are going to be dropped.
  36. concurrency = 8192
  37. # Sometimes you want to enforce mtg to use some types of
  38. # IP connectivity to Telegram. We have 4 modes:
  39. # - prefer-ipv6:
  40. # We can use both ipv4 and ipv6 but ipv6 has a preference
  41. # - prefer-ipv4:
  42. # We can use both ipv4 and ipv6 but ipv4 has a preference
  43. # - only-ipv6:
  44. # Only ipv6 connectivity is used
  45. # - only-ipv4:
  46. # Only ipv4 connectivity is used
  47. prefer-ip = "prefer-ipv6"
  48. # Public IP addresses of this server. Used by 'mtg access' to generate
  49. # proxy links and by 'mtg doctor' to validate SNI-DNS match.
  50. # If not set, mtg tries to detect them automatically via ifconfig.co.
  51. # Set these if ifconfig.co is unreachable from your server.
  52. # public-ipv4 = "1.2.3.4"
  53. # public-ipv6 = "2001:db8::1"
  54. # If this setting is set, then mtg will try to get proxy updates from Telegram
  55. # Usually this is completely fine to have it disabled, because mtg has a list
  56. # of some core proxies hardcoded.
  57. auto-update = false
  58. # FakeTLS uses domain fronting protection. So it needs to know a port to
  59. # access.
  60. #
  61. # Deprecated: use [domain-fronting] configuration block. If relevant option
  62. # is defined there, this one would be ignored.
  63. # domain-fronting-port = 443
  64. # By default, mtg resolves the fronting hostname (from the secret) via DNS
  65. # to establish a TCP connection. If DNS resolution of that hostname is blocked,
  66. # you can specify an IP address to connect to directly. The hostname is still
  67. # used for SNI in the TLS handshake.
  68. #
  69. # default value is not set (DNS resolution is used).
  70. #
  71. # Deprecated: use [domain-fronting] configuration block. If relevant option
  72. # is defined there, this one would be ignored.
  73. # domain-fronting-ip = "10.0.0.10"
  74. # This makes a communication between both fronting website and mtg to use
  75. # proxy protocol.
  76. #
  77. # Deprecated: use [domain-fronting] configuration block. If relevant option
  78. # is defined there, this one would be ignored.
  79. # domain-fronting-proxy-protocol = false
  80. # FakeTLS can compare timestamps to prevent probes. Each message has
  81. # encrypted timestamp. So, mtg can compare this timestamp and decide if
  82. # we need to proceed with connection or not.
  83. #
  84. # Sometimes time can be skewed so we accept all messages within a
  85. # time range of this parameter.
  86. tolerate-time-skewness = "5s"
  87. # Telegram has a concept of DC. You can think about DC as a number of a cluster
  88. # with a certain purpose. Some clusters serve media, some - messages, some rule
  89. # channels and so on. But sometimes unknown DC number is requested by client.
  90. # It could be a bug or some global reconfiguration of the Telegram.
  91. #
  92. # By default, proxy rejects such requests. But it is also possible to fallback
  93. # this request to any DC. Telegram works in a way that any DC is able to serve
  94. # any request but sacrificing a latency.
  95. #
  96. # If this setting is disabled (default), mtg will reject a connection.
  97. # Otherwise, chose a new DC.
  98. allow-fallback-on-unknown-dc = false
  99. # For multi-user support, use the [secrets] section instead of "secret".
  100. # Each key is a user name, used for per-user stats tracking.
  101. # All secrets must use the same hostname.
  102. #
  103. # IMPORTANT: [secrets] must appear after all global keys (like bind-to,
  104. # api-bind-to) — in TOML, keys after a [section] belong to that table.
  105. # [secrets]
  106. # alice = "ee367a189aee18fa31c190054efd4a8e9573746f726167652e676f6f676c65617069732e636f6d"
  107. # bob = "ee0123456789abcdef0123456789abcd9573746f726167652e676f6f676c65617069732e636f6d"
  108. # This section is relevant to communication with fronting domain. Usually
  109. # you do not need to setup anything here but there are plenty of cases, especially
  110. # if you put mtg behind load balancer, when some specific configuration is
  111. # required.
  112. [domain-fronting]
  113. # By default, mtg resolves the fronting hostname (from the secret) via DNS
  114. # to establish a TCP connection. If DNS resolution of that hostname is blocked,
  115. # you can specify an IP address to connect to directly. The hostname is still
  116. # used for SNI in the TLS handshake.
  117. #
  118. # default value is not set (DNS resolution is used).
  119. # ip = "10.10.10.11"
  120. # FakeTLS uses domain fronting protection. So it needs to know a port to
  121. # access. Default value is 443
  122. # port = 443
  123. # This makes a communication between both fronting website and mtg to use
  124. # proxy protocol.
  125. # proxy-protocol = false
  126. # network defines different network-related settings
  127. [network]
  128. # please be aware that mtg needs to do some external requests. For
  129. # example, if you do not pass public ips, it will request your public ip
  130. # address from some external service.
  131. #
  132. # As for 2.0, if you set a public-ip on your own, mtg won't issue any
  133. # network requests except of those required for Telegram.
  134. #
  135. # so, in order of doing them, it needs to do DNS lookup. mtg ignores DNS
  136. # resolver of the operating system and uses DOH instead. This is a host
  137. # it has to access.
  138. #
  139. # By default we use Cloudflare.
  140. #
  141. # DEPRECATED option:
  142. # If dns option is specified, it will be used instead. No default is defined
  143. # anymore. But if you set this option, this is literally the same providing
  144. # https:// URL to `dns`.
  145. #
  146. # In other words:
  147. #
  148. # doh-ip = "1.1.1.1"
  149. #
  150. # is literally the same as
  151. #
  152. # dns = "https://1.1.1.1"
  153. # doh-ip = "1.1.1.1"
  154. # Starting from mtg v2.1.12 we have changed a configuration for DNS. Now it
  155. # supports DNS-over-HTTPS, DNS-over-TLS, custom UDP resolver and system
  156. # resolver.
  157. #
  158. # Here is how to define DNS-over-HTTPS:
  159. # - https://1.1.1.1
  160. # - https://1.1.1.1/dns-query
  161. # - https://cloudflare-dns.com/dns-query
  162. # - https://cloudflare-dns.com
  163. #
  164. # Here is how to define DNS-over-TLS:
  165. # - tls://1.1.1.1
  166. # - tls://cloudflare-dns.com
  167. #
  168. # Here is how to define a custom UDP resolver (we support only IPs here)
  169. # - 1.1.1.1
  170. # - udp://1.1.1.1
  171. #
  172. # If you set it to empty string, default resolver will be used.
  173. # But please comment out doh-ip
  174. dns = "https://1.1.1.1"
  175. # mtg can work via proxies (for now, we support only socks5). Proxy
  176. # configuration is done via list. So, you can specify many proxies
  177. # there.
  178. #
  179. # Actually, if you supply an empty list, then no proxies are going to be
  180. # used. If you supply a single proxy, then mtg will use it exclusively.
  181. # If you supply >= 2, then mtg will load balance between them.
  182. #
  183. # If you add an empty string here, this is an equivalent of 'plain network',
  184. # with no proxy usage.
  185. #
  186. # Proxy configuration is done via ordinary URI schema:
  187. #
  188. # socks5://user:password@host:port
  189. #
  190. # Only socks5 proxy is used. user/password is optional. As you can
  191. # see, you can specify some parameters in GET query. These parameters
  192. # configure circuit breaker.
  193. proxies = [
  194. # "socks5://user:password@host:port"
  195. ]
  196. # network timeouts define different settings for timeouts. tcp timeout
  197. # define a global timeout on establishing of network connections. idle
  198. # means a timeout on pumping data between sockset when nothing is
  199. # happening.
  200. #
  201. # please be noticed that handshakes have no timeouts intentionally. You can
  202. # find a reasoning here:
  203. # https://www.ndss-symposium.org/wp-content/uploads/2020/02/23087-paper.pdf
  204. [network.timeout]
  205. tcp = "5s"
  206. http = "10s"
  207. idle = "5m"
  208. # mtg has to mimic real websites. It does not mean domain fronting, it also
  209. # means that traffic characteristics should be similar to real world traffic.
  210. # websites and applications behave differently, their traffic patterns are also
  211. # different. Applications do bursts of RPC-style messages (or JSON communication,
  212. # does not really matter), while websites pump heavy content in HTTP2 streams
  213. #
  214. # It means that statistically there is a different between traffic shape:
  215. # delays between packets are also different.
  216. # In order to avoid censorship detection based on these patterns, there is a
  217. # mtg subsystem called "Doppelganger" that aims to mimic website statistics
  218. # as close as it could.
  219. #
  220. # Delays between TLS packets are not constant. There are many factors
  221. # that come in play. Application should generate some response, it could
  222. # send some headers first and stream content with chunked encoding. So
  223. # some first packets could come as soon as possible, with some delays
  224. # after first ones. Such phenomenon is described by different statistic
  225. # distribution. There are 2 distribution that describe it: lognormal
  226. # distribution and Weibul distribution. Lognormal is all about steady streams
  227. # of heavy content like a video. Weibul is great about short bursts like
  228. # user who requested a static page an a couple of images.
  229. [defense.doppelganger]
  230. # This is a list of URLs that would be crawled by mtg to approximate delay
  231. # statistics. They MUST be HTTPS urls.
  232. #
  233. # You can come to the website and collect different URLs, with light and
  234. # heavy content. We recommend to search for CDNs.
  235. urls = [
  236. # "https://st-ok.cdn-vk.ru/res/react/vendor/clsx-2.1.1-amd.js"
  237. ]
  238. # A collection is done in raids. Each raid makes this number of requests to
  239. # each URL in this list. Do not use a huge number, 10 is probably ok.
  240. repeats-per-raid = 10
  241. # This is a duration between each raid. It makes no sense to have a small number
  242. # here as you would start to make a noticeable activity. Usually traffic patterns
  243. # do not change a lot, so do not expect different results if you request
  244. # each 10 minutes.
  245. raid-each = "6h"
  246. # This enables dynamic tls record sizing.
  247. #
  248. # Some modern stacks and platforms start to use the technique that is called
  249. # DRS. They start with small TLS packets and ramp up eventually. First packets
  250. # are usually about MTU size, after that we get 4k and eventually max size.
  251. # This is done with a good intention: to minimize a time to the first byte,
  252. # so application could start doing something with the data right after first
  253. # RTT.
  254. #
  255. # Apparently, about 90% of application do not employ this technique, they use
  256. # max size always: nginx, apache, java stuff. But Golang tools, angie and
  257. # some specific patches activate this technique.
  258. #
  259. # In order to mimic a real website we need to know something about software
  260. # it uses. Usually nobody cares: openssl does 16384, Python does it, nginx
  261. # does it. So this setting is disabled by default.
  262. #
  263. # https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency/
  264. # https://aws.github.io/s2n-tls/usage-guide/ch08-record-sizes.html
  265. # https://github.com/cloudflare/sslconfig/blob/master/patches/nginx__dynamic_tls_records.patch
  266. drs = false
  267. # Some countries do active probing on Telegram connections. This technique
  268. # allows to protect from such effort.
  269. #
  270. # mtg has a cache of some connection fingerprints. Actually, first bytes
  271. # of each connection. So, it stores them in some in-memory LRU+TTL cache.
  272. # You can configure this cache here.
  273. [defense.anti-replay]
  274. # You can enable/disable this feature.
  275. enabled = true
  276. # max size of such a cache. Please be aware that this number is
  277. # approximate we try hard to store data quite dense but it is possible
  278. # that we can go over this limit for 10-20% under some conditions and
  279. # architectures.
  280. max-size = "1mib"
  281. # we use stable bloom filters for anti-replay cache. This helps
  282. # to maintain a desired error ratio.
  283. error-rate = 0.001
  284. # You can protect proxies by using different blocklists. If client has
  285. # ip from the given range, we do not try to do a proper handshake. We
  286. # actually route it to fronting domain. So, this client will never ever
  287. # have a chance to use mtg to access Telegram.
  288. #
  289. # Please remember that blocklists are initialized in async way. So,
  290. # when you start a proxy, blocklists are empty, they are populated and
  291. # processed in backgrounds. An error in any URL is ignored.
  292. [defense.blocklist]
  293. # You can enable/disable this feature.
  294. enabled = true
  295. # This is a limiter for concurrency. In order to protect website
  296. # from overloading, we download files in this number of threads.
  297. download-concurrency = 2
  298. # A list of URLs in FireHOL format (https://iplists.firehol.org/)
  299. # You can provider links here (starts with https:// or http://) or
  300. # path to a local file, but in this case it should be absolute.
  301. urls = [
  302. "https://iplists.firehol.org/files/firehol_level1.netset",
  303. # "/local.file"
  304. ]
  305. # How often do we need to update a blocklist set.
  306. update-each = "24h"
  307. # Allowlist is an opposite to a blocklist. Only those IPs that are coming from
  308. # subnets defined in these lists are allowed. All others will be rejected.
  309. #
  310. # If this feature is disabled, then there won't be any check performed by this
  311. # validator. It is possible to combine both blocklist and whitelist.
  312. [defense.allowlist]
  313. # You can enable/disable this feature.
  314. enabled = false
  315. # This is a limiter for concurrency. In order to protect website
  316. # from overloading, we download files in this number of threads.
  317. download-concurrency = 2
  318. # A list of URLs in FireHOL format (https://iplists.firehol.org/)
  319. # You can provider links here (starts with https:// or http://) or
  320. # path to a local file, but in this case it should be absolute.
  321. urls = [
  322. # "https://iplists.firehol.org/files/firehol_level1.netset",
  323. # "/local.file"
  324. ]
  325. update-each = "24h"
  326. # statsd statistics integration.
  327. [stats.statsd]
  328. # enabled/disabled
  329. enabled = false
  330. # host:port for UDP endpoint of statsd
  331. address = "127.0.0.1:8888"
  332. # prefix of metric for statsd
  333. metric-prefix = "mtg"
  334. # tag format to use
  335. # supported values are 'datadog', 'influxdb' and 'graphite'
  336. # default format is graphite.
  337. tag-format = "datadog"
  338. # prometheus metrics integration.
  339. [stats.prometheus]
  340. # enabled/disabled
  341. enabled = true
  342. # host:port where to start http server for endpoint
  343. bind-to = "127.0.0.1:3129"
  344. # prefix of http path
  345. http-path = "/"
  346. # prefix for metrics for prometheus
  347. metric-prefix = "mtg"