mirror of
https://github.com/alexbers/mtprotoproxy.git
synced 2026-03-14 07:13:09 +00:00
Compare commits
11 Commits
v1.1.1
...
34f743858c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34f743858c | ||
|
|
375fee1535 | ||
|
|
e0ea17978c | ||
|
|
8bb885ada5 | ||
|
|
bc841cff48 | ||
|
|
c89479000f | ||
|
|
74711c4212 | ||
|
|
51b2482dec | ||
|
|
87f4370927 | ||
|
|
a978eae922 | ||
|
|
88c8c57a44 |
@@ -1,7 +1,7 @@
|
||||
FROM ubuntu:22.04
|
||||
FROM ubuntu:24.04
|
||||
|
||||
RUN apt-get update && apt-get install --no-install-recommends -y python3 python3-uvloop python3-cryptography python3-socks libcap2-bin ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||
RUN setcap cap_net_bind_service=+ep /usr/bin/python3.10
|
||||
RUN setcap cap_net_bind_service=+ep /usr/bin/python3.12
|
||||
|
||||
RUN useradd tgproxy -u 10000
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ TG_DATACENTERS_V6 = [
|
||||
# This list will be updated in the runtime
|
||||
TG_MIDDLE_PROXIES_V4 = {
|
||||
1: [("149.154.175.50", 8888)], -1: [("149.154.175.50", 8888)],
|
||||
2: [("149.154.162.38", 80)], -2: [("149.154.162.38", 80)],
|
||||
2: [("149.154.161.144", 8888)], -2: [("149.154.161.144", 8888)],
|
||||
3: [("149.154.175.100", 8888)], -3: [("149.154.175.100", 8888)],
|
||||
4: [("91.108.4.136", 8888)], -4: [("149.154.165.109", 8888)],
|
||||
5: [("91.108.56.181", 8888)], -5: [("91.108.56.181", 8888)]
|
||||
5: [("91.108.56.183", 8888)], -5: [("91.108.56.183", 8888)]
|
||||
}
|
||||
|
||||
TG_MIDDLE_PROXIES_V6 = {
|
||||
@@ -47,7 +47,7 @@ TG_MIDDLE_PROXIES_V6 = {
|
||||
2: [("2001:67c:04e8:f002::d", 80)], -2: [("2001:67c:04e8:f002::d", 80)],
|
||||
3: [("2001:b28:f23d:f003::d", 8888)], -3: [("2001:b28:f23d:f003::d", 8888)],
|
||||
4: [("2001:67c:04e8:f004::d", 8888)], -4: [("2001:67c:04e8:f004::d", 8888)],
|
||||
5: [("2001:b28:f23f:f005::d", 8888)], -5: [("2001:67c:04e8:f004::d", 8888)]
|
||||
5: [("2001:b28:f23f:f005::d", 8888)], -5: [("2001:b28:f23f:f005::d", 8888)]
|
||||
}
|
||||
|
||||
PROXY_SECRET = bytes.fromhex(
|
||||
@@ -62,7 +62,6 @@ PREKEY_LEN = 32
|
||||
KEY_LEN = 32
|
||||
IV_LEN = 16
|
||||
HANDSHAKE_LEN = 64
|
||||
TLS_HANDSHAKE_LEN = 1 + 2 + 2 + 512
|
||||
PROTO_TAG_POS = 56
|
||||
DC_IDX_POS = 60
|
||||
|
||||
@@ -658,7 +657,7 @@ class CryptoWrappedStreamReader(LayeredStreamReaderBase):
|
||||
|
||||
needed_till_full_block = -len(data) % self.block_size
|
||||
if needed_till_full_block > 0:
|
||||
data += self.upstream.readexactly(needed_till_full_block)
|
||||
data += await self.upstream.readexactly(needed_till_full_block)
|
||||
return self.decryptor.decrypt(data)
|
||||
|
||||
async def readexactly(self, n):
|
||||
@@ -868,6 +867,7 @@ class ProxyReqStreamReader(LayeredStreamReaderBase):
|
||||
RPC_PROXY_ANS = b"\x0d\xda\x03\x44"
|
||||
RPC_CLOSE_EXT = b"\xa2\x34\xb6\x5e"
|
||||
RPC_SIMPLE_ACK = b"\x9b\x40\xac\x3b"
|
||||
RPC_UNKNOWN = b'\xdf\xa2\x30\x57'
|
||||
|
||||
data = await self.upstream.read(1)
|
||||
|
||||
@@ -886,8 +886,11 @@ class ProxyReqStreamReader(LayeredStreamReaderBase):
|
||||
conn_id, confirm = data[4:12], data[12:16]
|
||||
return confirm, {"SIMPLE_ACK": True}
|
||||
|
||||
if ans_type == RPC_UNKNOWN:
|
||||
return b"", {"SKIP_SEND": True}
|
||||
|
||||
print_err("unknown rpc ans type:", ans_type)
|
||||
return b""
|
||||
return b"", {"SKIP_SEND": True}
|
||||
|
||||
|
||||
class ProxyReqStreamWriter(LayeredStreamWriterBase):
|
||||
@@ -1232,7 +1235,7 @@ async def handle_handshake(reader, writer):
|
||||
global last_client_ips
|
||||
global last_clients_with_same_handshake
|
||||
|
||||
TLS_START_BYTES = b"\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03"
|
||||
TLS_START_BYTES = b"\x16\x03\x01"
|
||||
|
||||
if writer.transport.is_closing() or writer.get_extra_info("peername") is None:
|
||||
return False
|
||||
@@ -1258,7 +1261,13 @@ async def handle_handshake(reader, writer):
|
||||
break
|
||||
|
||||
if is_tls_handshake:
|
||||
handshake += await reader.readexactly(TLS_HANDSHAKE_LEN - len(handshake))
|
||||
handshake += await reader.readexactly(2)
|
||||
tls_handshake_len = int.from_bytes(handshake[-2:], "big")
|
||||
if tls_handshake_len < 512:
|
||||
is_tls_handshake = False
|
||||
|
||||
if is_tls_handshake:
|
||||
handshake += await reader.readexactly(tls_handshake_len)
|
||||
tls_handshake_result = await handle_fake_tls_handshake(handshake, reader, writer, peer)
|
||||
|
||||
if not tls_handshake_result:
|
||||
@@ -1355,7 +1364,7 @@ async def do_direct_handshake(proto_tag, dc_idx, dec_key_and_iv=None):
|
||||
print_err("Got connection refused while trying to connect to", dc, TG_DATACENTER_PORT)
|
||||
return False
|
||||
except ConnectionAbortedError as E:
|
||||
print_err("The Telegram server connection is bad: %d (%s %s) %s" % (dc_idx, addr, port, E))
|
||||
print_err("The Telegram server connection is bad: %d (%s %s) %s" % (dc_idx, dc, TG_DATACENTER_PORT, E))
|
||||
return False
|
||||
except (OSError, asyncio.TimeoutError) as E:
|
||||
print_err("Unable to connect to", dc, TG_DATACENTER_PORT)
|
||||
@@ -1570,6 +1579,9 @@ async def tg_connect_reader_to_writer(rd, wr, user, rd_buf_size, is_upstream):
|
||||
else:
|
||||
extra = {}
|
||||
|
||||
if extra.get("SKIP_SEND"):
|
||||
continue
|
||||
|
||||
if not data:
|
||||
wr.write_eof()
|
||||
await wr.drain()
|
||||
@@ -1918,6 +1930,16 @@ async def get_encrypted_cert(host, port, server_name):
|
||||
if record3_type != 23:
|
||||
return b""
|
||||
|
||||
if len(record3) < MIN_CERT_LEN:
|
||||
record4_type, record4 = await get_tls_record(reader)
|
||||
if record4_type != 23:
|
||||
return b""
|
||||
msg = ("The MASK_HOST %s sent some TLS record before certificate record, this makes the " +
|
||||
"proxy more detectable") % config.MASK_HOST
|
||||
print_err(msg)
|
||||
|
||||
return record4
|
||||
|
||||
return record3
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user