Saturday, March 08, 2008

Web2Torrent : Let web pages host your files...

This is for research and fun purpose only. Don't contaminate the web using this technique. Use the tool at your own risk.

I just finished a POC implementation of what I call as Web2Torrent. It is not exactly a torrent as you will know after reading this post. It is just a funny way of storing your files on blogs, message forums, mailing lists etc. (Note: This is no rocket science)

It consists of a php file uploader.php, a Javascript file fetch.js and a bookmarklet that uses this Javascript file. The idea is the following:

  1. A binary file is converted to a base64 representation.
  2. It is then divided into suitable number of segments.
  3. Each of these segments is hosted on a different web page. Appropriate delimiters are used to identify the file contents correctly.
  4. Each page also contains the link(s) of the next segment. If one link is down for example, others could be used.
  5. Since each page could come from a domain that you may not control, a bookmarklet needs to be manually loaded after the page is loaded. This bookmarklet (which uses fetch.js) reads the page content and submits it to uploader.php
  6. Uploader then stores the contents in a file and redirects the browser to the next url to be loaded.
  7. Again you manually click the bookmarklet and the process repeats until all segments are downloaded.
  8. After all of them are downloaded, uploader.php creates the output file and redirects the browser to that file.

Note: Now there is a greasemonkey script included that takes care of clicking this bookmarklet for you! Just install the script, edit the URL to point to uploader.php, and just load the address of the first segment. You will have the file downloaded automatically! The code has to undergo lots of improvements though.

Each segment looks like following,

One or more hrefs to the next segment with id linkid (Actually this could be anywhere on the page) ->
_begin_wt_ (The beginning delimiter)
base64 data possibly with tags and whitespaces

Link on the last segment points to 'http://final/' and thats how the segment chain ends.
Rest of it is probably self explanatory.

  1. You don't need a hosting service anymore, web pages start hosting files for you.
  2. The upload/download process can be automated.
  3. Spamming is first time being used for a good cause (Depends on what you share)
Disadvantages and possible solutions:
  1. Web pages start to look ugly ;) (Soln: use divs and display:none)
  2. base64 expands the data (Who cares, its not stored on your hard disk anyway :) )
  3. Legal issues may be involved (No solution)
  4. Security?

You can grab the files here.

Usage (Also includes a sample example):
  1. Extract the files so that they are accessible from http://localhost:8080/web2torrent/ (Otherwise change first url lines in bookmarklet and fetch.js)
  2. Allow php scripts to create files in the directory
  3. Load http://localhost:8080/web2torrent/uploader.php in the browser
  4. Enter the url in the text box and submit the form
  5. The page containing segment will load, then press the bookmarklet you just saved (copy it from bookmarklet.js)
  6. Now new segment will load automatically, use bookmarklet after every page load.
  7. After the third segment is processed, you will be redirected to a wav file (Borrowed from
  8. The zip file also contains filesplit.php which lets you split files in specified number of segments. Before posting it, you will need to properly format it by adding delimiters etc described above. Its good to start from the last segment.

Other variants are possible, e.g. saving data in the images.

Note: This tool was created just for fun. Use it at your own risk. Don't use it for bad purposes. It has no security built in it. May have XSS, may have command injection. Shut it down as soon as you are done. ENABLE JAVASCRIPT otherwise this tool won't work.

Let's see if I can get a research topic for my thesis from this idea... Maybe- distinguishing between good and bad spam? How to protect applications from web2torrent? ...

1 comment:

addiv said...

Excellent idea, Kishor.

I've been thinking about ways to distribute webpage hosting among peer groups, too. I'm going to download your code and play with it. I think it could work very well for hosting GWT webapplications, as they are almost entirely self contained in one javascript file.