122 points · by xxbondsxx · 14y ago · 25 comments
To re-implement file transfer, we decided to hijack Facebook's speedy chat service to do our own packet transmission. This is the way it works:
-A python localhost server converts binary data into base64 ASCII and forms packets with uuid's, timestamps, seqnums, and the whole 9 yards.
-These packets get pumped over localhost to a user script (aka a Greasemonkey script) running on Facebook.com.
-This user script handles the scrubbing of incoming chat messages (packets) and populating the chatbox with outgoing packets.
-Facebook does _not_ make sending a chat message easy with custom JS, so in order to actually send a chat message, we signal the python localhost server to run a bash script that tells applescript to emulate a keydown event. Hacked up, I know, but it works! Also, this works for any application (desktop, flash embedded, etc) because it's as legit as a real keypress.
Just pumping the packets was the first challenge which we finished around 2am. The second obstacle was that facebook decides to drop about 50% of our packets after the first 15, so we then implemented a crude TCP style acknowledgement/handshake method that ensures each packet gets delivered. Implementing TCP inside of TCP... as meta as you get.
If you want to watch a video of a nyan cat GIF transmission, go here:
http://www.youtube.com/watch?feature=player_detailpage&v=tk5m0mqsrFs#t=74s
The main point is that despite even the most extreme legal restrictions on the internet, the next generation will always find a way :D
Github: https://github.com/pcottle/emotiface
Happy to answer any questions. Techcrunch also showed up and filmed / walked around the office (which was surprising considering the relationship between the two). I remember the techcrunch guy specifically saying "I feel like I'm at the Deathstar" when he walked through Facebook's double doors.
There are various interesting ways to tunnel TCP inside many other protocols like ICMP, DNS, etc. The underlying principle is that since many protocols run over IP, as long as you're able to route IP, you're pretty much done.
EDIT: I didn't mean to sound pessimistic. :)
Obviously not a scenario that we will see any time soon (hopefully), but it was certainly a fun challenge to work on. It was also extremely hilarious to see two computers, side-by-side, chat each other actual network packets inside a browser.
http://en.wikipedia.org/wiki/Steganography#Digital_steganogr...
If you couldn't inject your own code into the chat plugin (or had trouble faking the packets from your own), you could do the extremely low-tech solution of videochatting a screen of a slowly-changing QR code. It would make encoding super simple and still allow for a decent amount of bandwidth transmission :D
Damnit! That's a good idea. 3k bytes per QR code, a conservative estimate of 15 fps, and you are at decent 45k a second with no code injection!
Yes taking over the inter is a diaster, but even something like that isn't enoughvto close the gates completely.
And the truth is, they can't.
Edit: I mean multiple source, of this is already "broadcasted", so no need to take care of multiple receivers.
The only challenge would be dividing up the packet requesting, but you could do this manually by pasting in two handshake packets, one with startat at 0 and the other with startat at 50:
{"handshake":true,"uuid":"somethingRandom",type:"whichToSend","startAt":0,"filename":"nyancat"}
{"handshake":true,"uuid":"somethingRandom",type:"whichToSend","startAt":50,"filename":"nyancat"}
And then boom! Receive as normal and enjoy your ultra-slow bittorrent-style bandwidth
https://github.com/pcottle/emotiface/blob/master/backend/key...
As you can see, it just keeps hitting return 20 times (for 20 packets). The JS does the majority of the heavy lifting. It continually checks the chat textarea and waits for it to empty (when a keydown happens). When that happens, it loads the next packet and waits again. Code snippet:
//check if it's nothing
console.log('waiting for next return key');
var theVal = $j('.fbNubFlyoutInner').find('textarea').val();
console.log(theVal);
if(theVal)
{
//need to wait
var timeoutStr = "keydownCheck('" + filename + "'," + String(numPacket) + ");";
setTimeout(timeoutStr,keydownSleep);
return;
}
//actually put the next packet in
var packetText = JSON.stringify(files[filename].packetMap[numPacket]);
$j('.fbNubFlyoutInner').find('textarea').val(packetText);
Link:https://github.com/pcottle/emotiface/blob/master/backend/sta...