Giter Club home page Giter Club logo

Comments (13)

wkrp avatar wkrp commented on July 28, 2024 2

FOCI paper on Turbo Tunnel

I've had a paper on Turbo Tunnel accepted at the upcoming Free and Open Communications on the Internet (FOCI) workshop. I've written a draft that I will be revising over the next week. I invite your comments. The final revision is due 2020-07-28.

Here is the current draft. This will also be the home of an HTML version of the paper, when I find time to do that.
https://www.bamsoftware.com/papers/turbotunnel/

I'll tag the people who I know have GitHub accounts and are mentioned in the acknowledgements. If I acknowledged you, it probably means here or elsewhere that I found useful.
@cohosh @arlolra @ValdikSS @fortuna @studentmain @ewust @sergeyfrolov @xtaci

from bbs.

wkrp avatar wkrp commented on July 28, 2024 1

Are you aware of https://tools.ietf.org/html/draft-schinazi-masque-01?

It's effectively VPN over QUIC, without doubled guarantees. I believe it addresses some of your concerns.

I know about MASQUE–it's actually linked to in the writeup above. But MASQUE is not really an example of what I'm talking about.

MASQUE observes that QUIC is likely to make a good cover protocol, because of its default encryption and anticipated wide use in HTTP/3. Furthermore, QUIC provides features that are convenient for implementing a proxy, such as multiplexing multiple streams into one connection. I think these observations are correct and I have nothing against the MASQUE proposal.

What I am proposing is orthogonal. Perhaps the best way to explain the difference is that MASQUE puts QUIC on the outside of the protocol stack; i.e., the part exposed to observation by the censor is actual UDP-encapsulated QUIC packets. In contrast, I'm saying that it's a good idea to use QUIC, or something like it, as an inner layer in a circumvention stack, regardless of what the outermost obfuscation layer may be. I am not proposing a specific new circumvention protocol based on QUIC, but a general design principle, that the features of a session/reliability protocol are useful for circumvention purposes, independent of the external tunnel that provides covertness. QUIC is one of these session/reliability protocols, and a promising one, but if QUIC is used in a turbo tunnel design, it will not be in the form of UDP datagrams exposed on the wire, but as packets encoded or encapsulated inside the covert tunnel. See here for an example of QUIC packets encapsulated in HTTP requests, and here for an example of QUIC packets encapsulated in an obfs4 stream.

MASQUE found a single protocol—UDP-based QUIC—that (1) is good for obfsucation; and (2) provides nice features for implementing a proxy, such as operation over lossy channels, stream multiplexing, and connection migration. One way to understand a turbo tunnel design is that it separates these two functions: you have one layer for obfuscation (obfs4, Shadowsocks, meek, etc.), and another layer, more or less independent, that provides those other features. You combine the flexibility to swap out different forms of obfuscation, with the speed and robustness benefits of a session/reliability protocol. UDP-based QUIC suffices if you want your obfuscation layer to look like HTTP/3, but it doesn't help if you want to build a DNS-based tunnel, or a WebRTC-based tunnel, or one that uses HTTP/1.1, for example.

from bbs.

DavidSchinazi avatar DavidSchinazi commented on July 28, 2024 1

Hi there! Just to respond to the points about MASQUE above, I think that right now MASQUE is focusing on enabling proxying over HTTP - which makes it a good candidate for a pluggable transport. However, I think that it would be possible to use MASQUE as a Turbo Tunnel session layer as well - the connection migration property of QUIC allows you to migrate a MASQUE connection across underlying pluggable transports without loss of connectivity. We mentioned this briefly in the Onion Routing section of the MASQUE Obfuscation doc.

from bbs.

ewust avatar ewust commented on July 28, 2024

I think this is a great idea, and something we could definitely use in TapDance/Refraction Networking schemes. We generally multiplex long-lived sessions over many short-lived decoy connections, which works okay but is pretty hacky and can be unreliable (and potentially attackable).

I generally agree with the last question about traffic fingerprinting, but have a few notes, with the understanding that pretty much everyone in practice has punted on dealing with packet sizes/timings. But thinking into the future, it might also make sense to consider splitting the obfsucation layer into two sub-layers, one that deals with the wire protocol (e.g. we look like TLS as in TapDance or we encrypt everything as in obfs4...), and one that deals with the timing/packet sizes (like Slitheen does to mimic realistic web traffic). I think the timing/packet size layer could become tricky if the next layer protocol is this new packet-based session/reliability protocol, because the choice of the session/reliability protocol layer dictates at least a few constraints on the timing/packet size layer.

For example, if the session/reliability layer generates a 100 byte QUIC packet, but the timing/packet size layer determines it can only send 25 bytes next, it either has to A) send padding and hope that it will be able to send the 100 byte QUIC packet later or B) fragment the QUIC packet. Option A is tricky because now the timing/packet size layer has to be mindful of what kinds of packets the session/reliability layer spits out. Option B is tricky because now we need at least some kind of fragmentation/defragmentation logic. This is also complicated if the timing/packet size layer tries to play with timings, and your reliability layer has some constraints on retransmissions/ACK timings or tries to do things with RTT estimation.

These challenges and constraints are probably more a function of having a layer that tries to obfuscate packet size/timings, and aren't specific to the session/reliability layer; any protocol you tried to put on top of a packet size/timing-modifying layer might have to consider these. Still, I think it might be good to keep in mind what protocol layer we want to (eventually) be underneath Turbo Tunnel.

from bbs.

wkrp avatar wkrp commented on July 28, 2024

I generally agree with the last question about traffic fingerprinting, but have a few notes, with the understanding that pretty much everyone in practice has punted on dealing with packet sizes/timings. But thinking into the future, it might also make sense to consider splitting the obfsucation layer into two sub-layers, one that deals with the wire protocol (e.g. we look like TLS as in TapDance or we encrypt everything as in obfs4...), and one that deals with the timing/packet sizes (like Slitheen does to mimic realistic web traffic). I think the timing/packet size layer could become tricky if the next layer protocol is this new packet-based session/reliability protocol, because the choice of the session/reliability protocol layer dictates at least a few constraints on the timing/packet size layer.

I think you're right that a separate timing/size protocol is needed. Potentially a lightweight one, though the details may depend on the obfuscation scheme.

I am picturing something like this. Let every run of data within some discrete container (HTTP body, UDP datagram, TLS application record, etc.) be prefixed with a tag indicating whether it's padding or real data, and a length. They key is that the length is represented using a variable-size encoding, so every run length is possible, with no minimum. A strawman proposal is

first byte:  pcxxxxxx
later bytes: cxxxxxxx

The p bit is 1 for data or 0 for padding. The c (continuation) bit is 1 if there are more bytes in the tag, or 0 if this is the last byte in the tag. The x bits get concatenated to form the length. This would allow sending a run of any byte size—containing padding if nothing else, but possibly data if there is enough room. For example,

0 bytes
	(just don't send anything)
1 byte of padding (1 byte of tag prefix followed by 0 bytes)
	00000000
2 bytes of padding (1 byte of tag prefix followed by 1 byte)
	00000001 [1 arbitrary byte]
64 bytes of padding (1 byte of tag prefix followed by 63 bytes)
	00111111 [63 arbitrary bytes]
65 bytes of padding (2 bytes of tag prefix followed by 63 bytes)
	01000000 00111111 [63 arbitrary bytes]
1500 bytes of padding (2 bytes of tag prefix followed by 1498=10111011010₂ bytes)
	01001011 01011010 [1498 arbitrary bytes]
1000+500 bytes of padding
	01000111 01100110 [998 bytes] 01000011 01110010 [498 bytes]

100 bytes of data (total 102 bytes)
	11000000 01100100 [100 data bytes]
100 bytes of data + 26 bytes of padding (total 128 bytes)
	11000000 01100100 [100 data bytes] 00011010 [25 arbitrary bytes]

If your channel is continuous (not chopped up into discrete containers), then you don't even need a variable-length encoding like this. For example, obfs4's frame format is completely adequate for shaping to arbitrary sizes with byte-level precision, despite having a fixed 21-byte prefix on each frame. That's because obfs4 is carried inside a continuous stream, so you can send only a part of the prefix now, and the rest later.

For example, if the session/reliability layer generates a 100 byte QUIC packet, but the timing/packet size layer determines it can only send 25 bytes next, it either has to A) send padding and hope that it will be able to send the 100 byte QUIC packet later or B) fragment the QUIC packet. Option A is tricky because now the timing/packet size layer has to be mindful of what kinds of packets the session/reliability layer spits out. Option B is tricky because now we need at least some kind of fragmentation/defragmentation logic. This is also complicated if the timing/packet size layer tries to play with timings, and your reliability layer has some constraints on retransmissions/ACK timings or tries to do things with RTT estimation.

To me, option A sounds like the right choice here. Send an entire data packet when the packet size scheduler gives you enough room to do so, otherwise just send padding. It may be we can cajole the sequencing/reliability layer to give us a packet of no larger than a specific size on demand, like, "give me a packet whose total size is at most 80 bytes, or else return an error." The libraries I've looked at so far seem not to be architected that way; you don't "pull" packets from them, rather they "push" one on you via a callback, but maybe it's possible to achieve something similar by manipulating the MTU.

A case where option A would not work is when the carrier protocol never produces packets big enough to allow forward progress. I'm thinking here about DNS, which has a maximum upstream payload of about 140 bytes, and the handshake of QUIC, which demands a packet of at least 1200 bytes as an anti-amplification measure. Some kind of simple fragmentation scheme may be required in this case. An alternative would be to use a patched version of QUIC that does not enforce the 1200 bytes requirement, because reflected UDP amplification attacks would not apply in this context.

There's also complexity in how the packet size scheduler interacts with the obfuscation layer. Suppose we are using TLS for obfuscation, and the scheduler calls for a packet of 400 bytes. That doesn't mean that we can just send 400 payload bytes, because the QUIC header will add overhead. But neither can we just send a QUIC packet (+ padding) of 400 bytes including the header, because the TLS record protocol will add its own overhead. For a given packet size, we have to kind of reverse-engineer how much payload to send, that will result in a packet of the desired size. Arguably this requirement, though awkward, is good for obfuscation purposes, because an actual non-circumvention application protocol also does not have direct control over TLS record sizes: it sends chunks of data according to its own logic, and leaves the rest to the TLS library. Just so, a circumvention protocol that wants to avoid dead-parrot distinguishers and therefore tunnels through a real TLS library also should only exert control as far as the sizes of chunks it gives to the TLS library, and let the library take over from there. It's just tricky for us, because the censor is going to be working off of packet sizes from a pcap, which is several abstractions away from the layer which we program.

And I agree we will probably have to tinker with settings such as the default packet retransmit timeout. Interpacket time shaping is likely to give the sequencing/reliability layer the impression that it's running on a pathological network.

from bbs.

wkrp avatar wkrp commented on July 28, 2024
  • Q: You're proposing, in some cases, to run a reliable protocol inside another reliable protocol (e.g. QUIC-in-obfs4-in-TCP). What about the reputed inefficiency TCP-in-TCP?

    • A: Short answer: don't worry about it. I think it would be premature optimization to consider at this point. The fact that the need for a session/reliability layer has been felt for so long by so many systems indicates that we should start experimenting, at least. There's contradictory information online as to whether TCP-in-TCP is as bad as they say, and anyway there are all kinds of performance settings we may tweak if it turns out to be a problem. But again: let's avoid premature optimization and not allow imagined obstacles to prevent us from trying.

I found an IETF Transport Area Working Group draft, draft-pauly-tsvwg-tcp-encapsulation, that touches on this subject, particularly in Section 5.

https://datatracker.ietf.org/doc/html/draft-pauly-tsvwg-tcp-encapsulation-00#section-5

The use of an outer TCP context may cause signals from the network to be hidden from the inner TCP contexts. ... Generally, the main areas of concern are signals that inform loss recovery, Bufferbloat and delay avoidance, and head of line blocking between streams.

https://datatracker.ietf.org/doc/html/draft-pauly-tsvwg-tcp-encapsulation-00#section-5.1.2

Generally, TCP congestion controls and loss recovery algorithms are capable of recovering from loss events very efficiently, and the inner TCP contexts observe brief periods of added delay without much penalty.

A TCP congestion control should be selected and tuned to be able to gracefully handle extremely variable RTT values, which may already the case for some congestion controls, as RTT variance is often greatly increased in mobile and cellular networks.

Additionally, use of a TCP congestion control that considers delay to be a sign of congestion may help the coordination between inner and outer TCP contexts. LEDBAT [RFC6817] and BBR [I-D.cardwell-iccrg-bbr-congestion-control] are two examples of delay based congestion control that an inner TCP context could use to properly interpret loss events experienced by the outer TCP context.

There are further considerations for encapsulated segments that are then meant to be unencapsulated and forwarded verbatim outside the tunnel. These considerations do not apply in the model I envision, because the sequencing/reliability layer is strictly between the two obfuscation endpoints and its details are hidden from whatever protocol that makes use of it.

Care must be taken to ensure that any TCP congestion control in use is also appropriate for an inner context to use on any network segments that are traversed outside of the encapsulation.

Since any losses will be handled by the outer TCP context, it might seem reasonable to modify the the inner TCP contexts' loss recovery algorithms to prevent retransmissions, there are often network segments outside of the encapsulated segments that still rely on the inner contexts' loss recovery algorithms. Instead, spurious retransmissions can be reduced by ensuring that RTO values are tuned such that the outer TCP context will fully time out before any inner TCP contexts.

from bbs.

wkrp avatar wkrp commented on July 28, 2024

I've done a little survey and identified some suitable candidate protocols that also seem to have good Go packages:

My evaluation of these three candidate protocol implementations is in #14.

from bbs.

fortuna avatar fortuna commented on July 28, 2024

Are you aware of https://tools.ietf.org/html/draft-schinazi-masque-01?

It's effectively VPN over QUIC, without doubled guarantees. I believe it addresses some of your concerns.

from bbs.

fortuna avatar fortuna commented on July 28, 2024

UDP-based QUIC suffices if you want your obfuscation layer to look like HTTP/3, but it doesn't help if you want to build a DNS-based tunnel, or a WebRTC-based tunnel, or one that uses HTTP/1.1, for example.

This explanation made your proposal a lot clearer to me. Thanks!

from bbs.

wkrp avatar wkrp commented on July 28, 2024

I am picturing something like this. Let every run of data within some discrete container (HTTP body, UDP datagram, TLS application record, etc.) be prefixed with a tag indicating whether it's padding or real data, and a length. They key is that the length is represented using a variable-size encoding, so every run length is possible, with no minimum.

I've got an implementation of this scheme in the meek turbotunnel branch.

The public API is

func WriteData(w io.Writer, data []byte) (int, error)
func WritePadding(w io.Writer, n int) (int, error)
func ReadData(r io.Reader) ([]byte, error)

WriteData writes a data block of n bytes and returns the number of bytes written, which will be n+1, n+2, or n+3 because of the length prefix. WritePadding writes exactly n bytes of padding, including the length prefix as part of the padding. ReadData skips over padding and returns the first data block.

Although the length prefix encoding would allow for integers of any size, I decided to limit the range to [0, 0xfffff], which means that a length prefix will never consist of more than 3 bytes, and that decoded lengths will fit in a uint32.

There's another public function

func MaxDataForSize(n int) int

MaxDataForSize returns the largest size a data block passed to WriteData can be, without exceeding n bytes in encoded length. The intent here is to allow you to fill a buffer to an exact size by putting an as many data packets as possible, then padding to fill up the rest. Something like:

var buffer bytes.Buffer
requestedSize := 500
var size int
var err error
for err == nil && size < requestedSize {
    max := encapsulation.MaxDataForSize(requestedSize - size)
    var n int
    if max > 0 {
        var p [1024]byte
        n, err = source.Read(p[:])
        if err == nil {
            n, err = encapsulation.WriteData(buffer, p[:n])
        }
    } else {
        n, err = encapsulation.WritePadding(buffer, requestedSize - size)
    }
    size += n
}

However I think the MaxDataForSize design needs a rethink, because while it's fine when you can Read up to a maximum number of bytes, it's more awkward when you are dealing with discrete packets of determined sizes. See here in meek-client. What you want to do is keep reading packets and doing WriteData into the buffer until you read a packet that's bigger than MaxDataForSize on the remaining space in the buffer. Then "unread" that packet so it will be available again in the future, WritePadding up to the remaining size, and send your burst. In the meek branch I'm reading packets from a channel, and you can't "unread" a channel. You would need to build a data structure around the channel that yields a packet only if it doesn't exceed a given size.

from bbs.

klzgrad avatar klzgrad commented on July 28, 2024

If TCP-in-TCP performance is not a concern, why not Tor over TCP/IP over HTTP? This setup seems to satisfy the described requirements and there are good userspace TCP/IP stacks already.

I think the reason QUIC came to be is to take the control of the reliability layer back from kernel, because they wanted to do something interesting at this level but found it impossible to co-exist with existing reliable protocols in kernel and also chose not to do it in the TCP-in-TCP way. H/2 is already an attempt at reinventing 1/2 of TCP (and smux mentioned above reinvents the same part). It would be quite hard to create something different from QUIC and functionally as good as QUIC.

from bbs.

wkrp avatar wkrp commented on July 28, 2024

If TCP-in-TCP performance is not a concern, why not Tor over TCP/IP over HTTP? This setup seems to satisfy the described requirements and there are good userspace TCP/IP stacks already.

Yes, userspace TCP would work fine as an inner session/reliability layer. I am trying to emphasize that the specific choice of an inner session protocol does not matter so much--the really important idea is decoupling the session from the outer network connection. I did a lot of testing with KCP and QUIC, but there are probably many more equivalent options.

I think I considered userspace TCP early on, but did not find a good Go package for it, and for practical reasons I wanted the session protocol to be written in Go. Stream multiplexing turns out to be a really nice feature, though that could equally be accomplished with smux-in-TCP as with smux-in-KCP.

The "Tor over TCP/IP over HTTP" layering is basically what Turbo Tunnel in meek implements.

from bbs.

ignoramous avatar ignoramous commented on July 28, 2024

I think I considered userspace TCP early on, but did not find a good Go package for it

Assuming you aren't aware, gvisor/netstack (in-use by tailscale, outline-go-tun2socks, libsagernet, xjasonlyu's tun2socks, and firestack that I co-develop) is a pretty flexible golang TCP/IP implementation.

from bbs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.