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
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

example.config.toml 16KB

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