Node.js Remove the evil information in the seed (torrent) file

Source: Internet
Author: User
Tags md5 require

The torrent file, also known as the seed, was just a file for recording the information needed in the BT download. But with the great development of the Internet, some people have injected some evil information into the small torrent file, and the seeds have become synonymous with evil.

-->

2012, a Japanese film called ABS-130 caused the network vibration, the network has appeared "at the outset to seek a kind of dog, now * people ugly" phenomenon, became 2012 years of the internet a big thing.

2014, net network action in full swing, the major Internet companies have made an example, the moment between XX cloud, x ray all the seeds of the evil to shut out. Long live NET Action!! (also my teacher!!) )

Each large network disk, download applications from the seeds to extract key information, the seeds shut out. Where is the key information hidden? Let's find out.

SEED file Structure

The following content is from Wikipedia

. torrent seed files are essentially text files that contain two parts of tracker information and file information. Tracker information is mainly used in BT download tracker server address and for the tracker server settings, file information is based on the calculation of the target file generated, the results according to the BitTorrent protocol Bencode rules for coding. The main principle is to divide the files that provide downloads into chunks of equal size, the block size must be 2k of the whole number of times (because it is a virtual chunk, the hard disk does not produce each block file), and the index information and hash code of each block are written into the seed file, so the seed file is the "index" of the downloaded file.

The image above is the structure of a typical seed, and the identified evil keywords are hidden in name and file. Name contains the names of the seeds, such as: abcd-123 sexy xxxx. The path in file contains information about all the files you want to download, such as the Grass X community's newest address, txt, and so on.

Node.js and Parse-torrent Libraries

In order to find out the evil information in the seeds, we have node.js and Parse-torrent library as assistants.

Experimental Preparation:

Seed one installed node.js computer one

First we use NPM to install the Parse-torrent library, which helps us quickly find information within the seed.

NPM Install Parse-torrent
?
1 2 3 4 5 var fs = require ("FS");   var parsetorrent = require (' parse-torrent '); var info = parsetorrent (fs.readfilesync (' my.torrent ')); Console.log (info);

This library will parse the seed information and return it to us in the form of an object.

View results:

Name

Files

You can see that the information for name and files parsed with the Parse-torrent library is stored in Buffer form.

Cleaning seeds

How to clean up the evil information in the seeds, kill the seeds of evil in the cradle, the most important even if you want to clear the name and files inside the path of information.

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19-20 function Cleaninfo (info) {//MD5 the seed name with info.name = MD5 (info.name); info[' name.utf-8 '] = MD5 (info[' name.utf-8 ']); var Files = info.files; for (var i = 0; i < files.length; i++) {var file = Files[i]; for (var key in file) {if (key = = "path" | | key = = "Path" . Utf-8 ") {for (var j = 0; J < File[key].length; J +) {var text = file[key][j].tostring (); var dotindex = Text.lastind Exof ("."); Encrypt the seed name with MD5 file[key][j] = MD5 (Text.slice (0,dotindex)) + Text.slice (dotindex,text.length); }}} return info; }
?
1 2 3 4 5 Regenerate the cleaned info object with a torrent file var buf = Parsetorrent.totorrentfile ({info:cleaninfos[i]}); Fs.writefile (dir + "/" + Cleaninfos[i].name + ". Torrent", buf);

After that, our evil seed file becomes this:

Combat phase

First prepares a seed, carries on the offline downloading of XX cloud.

At first it was rejected.

Then run the script to clean it.

Node Cleantorrent iptd-xxx.torrent

The download was successful!

Script source Stacking Here, I'm going to take a look at my downloads.!!!

(* * * * all off, you show me this!!! )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.