Repository navigation
TLS : tls spoofing - #6103
TLS : tls spoofing#6103codewithtamim wants to merge 50 commits into
Conversation
…im/Xray-core into feature/tls-spoofing
|
应当加到 finalmask |
|
将它添加为一个tcpmask(以避免需要修改其他传输) |
|
|
|
|
@Fangliding @RPRX new changes are ready |
|
@Fangliding any update? |
|
@codewithtamim 下个月合并 |
|
this should be merged, in iran TLS spoofing is back (it got blocked before, its alive again!) |
can you try building from my branch and try it? and then give some feedback :) |
Replace TLS ClientHello spoofing with a stateless packet pipe transport. The new implementation builds spoofed IP packets directly (TCP SYN, UDP, ICMPv4 Echo, ICMPv6 Echo over IPv4) and supports configurable send/recv transports with round-robin source IP rotation. - SpoofSender/SpoofReceiver interfaces with TCP/UDP/ICMP/ICMPv6 impls - SpoofConn (net.Conn): Write sends spoofed packets, Read receives responses - Relay: receives spoofed packets, forwards to target, sends responses - Uses raw sockets (SOCK_RAW + IP_HDRINCL) on Unix, WinDivert on Windows - Platform build tags for darwin/freebsd/linux and Windows
|
Interesting approach. I was thinking about a different direction for QUIC that may solve a similar DPI problem without injecting fake packets. The idea is QUICstep: Establish the QUIC connection through an alternate/allowed path, so the Initial packet and TLS handshake are not visible on the direct path. Conceptually: Client handshake complete Client ───── encrypted QUIC 1-RTT ─────► Server The bootstrap relay must be transparent to the QUIC datagrams. It must not terminate QUIC itself, otherwise there is no end-to-end connection to migrate. This is obviously QUIC/UDP-specific and does not replace RawPacket/TLS spoofing for TCP. But for QUIC it has an interesting property: instead of showing DPI a fake first flight, the direct path never sees the first flight at all. The main question is how real-world DPI behaves when the first packets it observes for a flow are already QUIC 1-RTT packets and it never observed the Initial. Has anyone experimented with this kind of bootstrap-path → direct-path QUIC migration? |
Can you explain in human language? I think the message was written with llm |
|
идея QUICstep: сначала установить QUIC-соединение через разрешённый bootstrap-путь, завершить handshake, а затем перенести это же соединение на прямой UDP через QUIC Connection Migration. Тогда DPI на прямом пути не видит Initial и TLS ClientHello, а сразу видит уже установленный зашифрованный QUIC-трафик. делал тесты через нейронку как проверка при разных блокировках. результаты закинул в md. по моим тестам QUICstep вариант только по обходу блокировок по Initial/SNI. Для моих задач он не подошел. а тут как раз то что нужно. |
# Conflicts: # infra/conf/transport_internet.go
9938052 to
bb335c6
Compare
9ade89d to
5d17b87
Compare


fix #5964
RawPacket aka TLS Spoofing
So first lets talk about the idea,
when you connect to a xray server, the censors can see your TLS ClientHello, read the SNI, and figure out what you are doing and block :)
The RawPacket aka TLS spoofing fixes that by injecting a fake TLS ClientHello before the real one Hits.
The fake one carries like a decoy domain (ex. baidu.com) and then the real one carries your actual destination (ex. www.example.com).
A sensor that captures the first packet sees baidu.com and think that you are just browsing, and everything is okay with that, but in reality your connection goes through :)
It can be configured in the
finalmask.tcpokay? and its only for client side.How everything works
When Xray dials a TCP connection and the first
Write()happens (which also triggers the real TLS handshake) , our Raw Packet setup does the following.1.builds a fake Tls ClientHello with whatever SNI you want or you have option to provide the raw bytes (b64).
2.Then we. wrap it in a raw TCP/ip packet.
3.Then deliberately we corrupt the TCP header using whatever method is selected okay?
Then we shoot it out via a raw socket
Then immediately let the real
Write()go through normallyIn short : two packets arrive at the server back to back and the fake one gets dropped by the servers TCP stack because of the corruption and then the real handshake proceeds like nothing happened.
Config Example
{ "streamSettings": { "finalmask": { "tcp": [ { "type": "rawpacket", "settings": { "sni": "baidu.com", "payload": "", "method": "wrong-sequence", "ttl": 3, "count": 1 } } ] } } }Available Fields
sni: The domain to put in the fake ClientHello. If you set this, it will auto generate a valid TLS ClientHello for you automatically. If you setpayloadandsnisame time , sni wins here.payload: If you don't want an auto gnrated ClientHello, then just encode your raw bytes that you want into base64 and put them here. I have added an option to do it from command line also. Do like thisIt will out the thing and then just copy paste.
Note : If
sniand payload are empty or not set , the raw packet does nothing and the connection goes through normally.method: It defines how we corrupt the fake packet so the server drops it.wrong-sequence: It duplicates the sequence number (looks like a retransmission so server drops it)So we grab the kernels
snd_nxt( the next sequence number the kernel expects to send), then subtract the length of the fake payload and then use that as the sequence number of the injected packet. The results then is a duplicate of the. last segment, so the receivers TCP stack sees it as a retransmit at best, or like out of window at worst and then drops it.wrong-checksum: It flips all the bits in the TCP checksum (so server sees a bad checksum and drops it)We build the packet with a correct checksum and then flip every bit(^0xFFFF). The receiver then validates the checksum and its wrong, so the packet goes in trash.
wrong-ack: It sets ACK number way outside the receive window (so server sends dup ACK then drops it)It sets the ACK number to
rcv_nxt - window/2and that's way outside of the receivers window, and the kernel responds with a dup ACK containing the correct sequence number, then drops it.wrong-md5: This adds a fake TCP MD5 signature option and server without MD5 drops itHere we append a TCP option with kind=19 and length=18 to the TCP header. The kind 19 is the MD5 signature option (RFC 2385), if the receiver doesn't use TCP MD5 (which is basically everything except some BGP routers), it sees an unknown option and drops the packet.
wrong-timestamp: Backdates the tcp timestamp by 1 hour (paws detects regression and then drops)Just backdate the TCP timestamp option value by 3600000 MS (1 HR), The receivers paws mechanism checks if the timestamp went backwards, If it did the packet is then dropped.
Note :
wrong-timestampmethod only works on Linux, it doesn't work on MacOS and Free BSD because kernel doesn't expose the per connection timestamp offset, so we can't really tell what to value undercut.ttl: it defines the IP time to live for the fake packet. Default is 3 but the idea is to keep it lower so the packet dies before reaching the server or can but still reaches the probe, you can change it if needed.count: Defines how many writes should trigger an injection. Default is set to 1 means that only the first write gets fake packet treatment, after that the raw socket closes itself and all the subsequent writes goes directly to the TCP connection with zero overhead.Platform Support
How to run it
Linux :
Macos/FreeBSD :
Windows : Run a terminal with Admin rights .
If you miss that , you will get the following error.
transport/internet/tcp: mask err > open AF_INET SOCK_RAW: operation not permitted Hint: run as root, or grant capabilities: sudo setcap cap_net_raw,cap_net_admin+ep /path/to/xrayA Sample Client Example
TESTING I DID
I tested the implementation myself on an Ubuntu 24.0.4 and it works. Here is the process I followed.
First ran xray on the server normally with my config,
Example (that's what I used) :
Then run the server
Client Example :
Cases :
Output
With capabilities everything works. I tested all 5 methods and it worked.
Proof from wire capture, I ran a tcpdump on loopback and saw both packets :
Packet 1 (fake one , the one we injected)
Here look at
0x0090:... 0000 0962 6169 6475 2e63 6f 6d 62 61 69 64 75 2e 63 6f 6d= baidu.com and that's the decoy SNI in the fake ClientHelloPacket 2 (real one, a normal TCP socket) :
Now look at
0x0240:7777 772e 6d69 6372 6f73 6f66 742e 636f 6d= www.microsoft.com, that's the real SNI the server processes.So a probe that only grabs packet 1 sees Baidu.com and moves on. Packet 2 with real SNI goes through the server and the connection works fine.
So that's basically All. Feel free to ask any questions I will try to give ans, Thanks