Skip to content

TLS record fragmentation, DPYProxy #308

Open

Description

@wkrp

Circumventing the GFW with TLS Record Fragmentation
Niklas Niere (@JonSnowWhite)
https://github.com/UPB-SysSec/DPYProxy

This blog post explores an interesting idea: fragmenting TLS messages (especially Client Hello) over multiple TLS records. This is different from TCP segmentation, which has been studied in the past by, e.g., Winter & Lindskog 2012 (Section 5.2, brdgrd), Khattak et al. 2013, and Bock et al. 2021 (Section 4.1), and is implemented in tools including GoodbyeDPI. Rather, this research takes advantage of the fact that TLS messages (e.g. Client Hello) are carried in TLS records, and that one message may be fragmented over multiple records:

The TLS Record Protocol is a layered protocol. At each layer, messages may include fields for length, description, and content. The Record Protocol takes messages to be transmitted, fragments the data into manageable blocks, optionally compresses the data, applies a MAC, encrypts, and transmits the result.

The post introduces a tool, DPYProxy, that fragments TLS messages over multiple records (by parsing the user's TLS records and re-wrapping them in multiple shorter records). They test the tool in China and find that when a Client Hello message is fragmented at the TLS record layer, the SNI is not interpreted by the firewall and the connection doesn't get blocked. (Surprisingly, TCP-layer segmentation also worked in their tests—as long as the Client Hello message is broken before the SNI extension.)

Activity

  1. HectorHW commented on Nov 8, 2023

    @HectorHW

    Verified to work (for now at least) against Roskomnadzor blocking https websites in Russia. Nice finding!

  2. JonSnowWhite commented on Nov 9, 2023

    @JonSnowWhite

    @HectorHW Thanks for the info!

  3. klzgrad commented on Nov 9, 2023

    @klzgrad

    It is less likely for realtime systems to handle TCP or TLS reassembly due to its computation or memory cost at scale, in realtime, but this is not a fact that can be relied on in general. During a previous blockage of Cloudflare in #295 I tested various ways of TCP fragmentation of TLS Hello and was able to trigger TCP resets in all variations. I believe in general it is more likely for offline and deeper traffic analysis to perform traffic reassembly as realtime decisions are not required.

  4. RPRX commented on Nov 13, 2023

    @RPRX

    @5e2t 针对河南 GFW 和广州国际出口 GFW 测试过 tlshello 分片:XTLS/Xray-core#2426 (comment)

    我的观点是这些分片 可能可用,但 GFW 并不需要重组它们,目前来说,一个报文只含一部分而不是完整的 client hello 即为异常

    @5e2t tested tlshello fragmentation against Henan GFW and Guangzhou international outbound GFW: XTLS/Xray-core#2426 (comment)

    My view is that these fragments may be usable, but the GFW doesn't need to reconstruct them, and for now, it's an anomaly for a message to contain only a portion of a client hello rather than the full one

  5. JonSnowWhite commented on Nov 13, 2023

    @JonSnowWhite

    Should Record Fragmentation not work standalone, it can hopefully be combined with TCP fragmentation. That might be something to try out for circumvention tools like XRay. Especially when the TCP and TLS Records are of different size/in different order.

  6. fortuna commented on Nov 16, 2023

    @fortuna

    FYI, I tested TLS Record fragmentation with DPYProxy last month and was able to demonstrate that it bypasses SNI-based blocking in an network in Russia and one in Iran.

    I also realized that leaving a single byte of the first message out of the first record was enough to bypass censorship. That suggests to me that they just give up parsing TLS. Perhaps they require the message length to be the record length -5 in their TLS detector. This may help against blocking based on TLS fingerprint because of that.

    See the commands I used for testing at UPB-SysSec/DPYProxy#2 (comment)

    This is how the TCP fragmentation looks like on tshark:

    Transmission Control Protocol, Src Port: 40334, Dst Port: 443, Seq: 1143, Ack: 100, Len: 23
    [21 Reassembled TCP Segments (517 bytes): #28(19), #29(25), #30(25), #31(25), #32(25), #33(25), #34(25), #35(25), #36(25), #37(25), #38(25), #39(25), #40(25), #41(25), #42(25), #43(25), #44(25), #45(25), #46(25), #47(25), #48(23)]
    Transport Layer Security
        TLSv1.3 Record Layer: Handshake Protocol: Client Hello
            Content Type: Handshake (22)
            Version: TLS 1.2 (0x0303)
            Length: 512
            Handshake Protocol: Client Hello
                Handshake Type: Client Hello (1)
                Length: 508
                Version: TLS 1.2 (0x0303)
    

    This is how it looks with TLS record fragmentation only:

    Transmission Control Protocol, Src Port: 58772, Dst Port: 443, Seq: 1, Ack: 1, Len: 642
    Transport Layer Security
        TLSv1 Record Layer: Handshake Protocol: Client Hello (fragment)
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Multiple Handshake Messages
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 20
            Handshake Protocol: Client Hello (fragment)
        TLSv1 Record Layer: Handshake Protocol: Client Hello
            Content Type: Handshake (22)
            Version: TLS 1.0 (0x0301)
            Length: 12
            Handshake Protocol: Client Hello (last fragment)
            [26 Reassembled Handshake Fragments (512 bytes): #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20), #4(20),]
                [Frame: 4, payload: 0-19 (20 bytes)]
                [Frame: 4, payload: 20-39 (20 bytes)]
                [Frame: 4, payload: 40-59 (20 bytes)]
                [Frame: 4, payload: 60-79 (20 bytes)]
                [Frame: 4, payload: 80-99 (20 bytes)]
                [Frame: 4, payload: 100-119 (20 bytes)]
                [Frame: 4, payload: 120-139 (20 bytes)]
                [Frame: 4, payload: 140-159 (20 bytes)]
                [Frame: 4, payload: 160-179 (20 bytes)]
                [Frame: 4, payload: 180-199 (20 bytes)]
                [Frame: 4, payload: 200-219 (20 bytes)]
                [Frame: 4, payload: 220-239 (20 bytes)]
                [Frame: 4, payload: 240-259 (20 bytes)]
                [Frame: 4, payload: 260-279 (20 bytes)]
                [Frame: 4, payload: 280-299 (20 bytes)]
                [Frame: 4, payload: 300-319 (20 bytes)]
                [Frame: 4, payload: 320-339 (20 bytes)]
                [Frame: 4, payload: 340-359 (20 bytes)]
                [Frame: 4, payload: 360-379 (20 bytes)]
                [Frame: 4, payload: 380-399 (20 bytes)]
                [Frame: 4, payload: 400-419 (20 bytes)]
                [Frame: 4, payload: 420-439 (20 bytes)]
                [Frame: 4, payload: 440-459 (20 bytes)]
                [Frame: 4, payload: 460-479 (20 bytes)]
                [Frame: 4, payload: 480-499 (20 bytes)]
                [Frame: 4, payload: 500-511 (12 bytes)]
                [Handshake Fragment count: 26]
            Handshake Protocol: Client Hello
                Handshake Type: Client Hello (1)
                Length: 508
                Version: TLS 1.2 (0x0303)
    

    TCP segmentation

    In Iran, TCP segmentation alone didn't help.

    In Russia, TCP alone could bypass SNI-based censorship, but only on byte 2 (as in [01][2...]), and sometimes on byte 1 (as in [0][1...]). That split is right in the middle of the TLS version, which may confuse the TLS detection and make them give up TLS analysis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions