3

I am absolutely novice with the Bittorrent protocols and I tried to request a file to a tracker. To do this, I parsed and printed a working .torrent file with a C# program, then I just requested the tracker with these infos with PostMan

The extracted informations are:

- announce :
http://bt1.archive.org:6969/announce

- announce-list
http://bt1.archive.org:6969/announce
http://bt2.archive.org:6969/announce

- comment :
This content hosted at the Internet Archive at https://archive.org/details/6201484321_f1a88ca2cb_b
Files may have changed, which prevents torrents from downloading correctly or completely; please check for an updated torrent at https://archive.org/download/6201484321_f1a88ca2cb_b/6201484321_f1a88ca2cb_b_archive.torrent
Note: retrieval usually requires a client that supports webseeding (GetRight style).
Note: many Internet Archive torrents contain a 'pad file' directory. This directory and the files within it may be erased once retrieval completes.
Note: the file 6201484321_f1a88ca2cb_b_meta.xml contains metadata about this torrent's contents.

- created by :
ia_make_torrent

- creation date :
1462999235

- info
- collections
org.archive.6201484321_f1a88ca2cb_b

- crc32 :
6dbd08b2

- length :
970

- md5 :
96951c7834ee105660e0447e00ec4b31

- mtime :
1462999235

- path
6201484321_f1a88ca2cb_b_meta.xml

- sha1 :
cc69b6337b4e459ec9428629ca49fb65a6249ee8

- name :
6201484321_f1a88ca2cb_b

- piece length :
524288

- pieces :
üyR¨ÆôO2¿Ù'ù'┼0ö


- locale :
en

- title :
6201484321_f1a88ca2cb_b

- url-list
https://archive.org/download/
http://ia600704.us.archive.org/24/items/
http://ia800704.us.archive.org/24/items/

So I have this request to send:

http://bt1.archive.org:6969/announce?info_hash=cc69b6337b4e459ec9428629ca49fb65a6249ee8&peer_id=ABCDEFGHIJKLMNOPQRST&ip=80.11.255.166&port=6881&downloaded=0&left=970

What is wrong ?

EDIT:

I traked the request made by uTorrent on this torrent with WireShark and the hash_info is : %ac%c3%b2%e43%d7%c7GZ%bbYA%b5h%1c%b7%a1%ea%26%e2

But if I sha1 the bencoded form of the info value which is collectionsl35:org.archive.6201484321_f1a88ca2cb_be5:filesld5:crc328:262eacb06:lengthi346936e3:md532:48ab0840ed6501c37072b261fd52bcde5:mtime10:13176646104:pathl27:6201484321_f1a88ca2cb_b.jpge4:sha140:6ce409c363e038a57c79ed17ee97571058101575ed5:crc328:6dbd08b26:lengthi970e3:md532:96951c7834ee105660e0447e00ec4b315:mtime10:14629992354:pathl32:6201484321_f1a88ca2cb_b_meta.xmle4:sha140:cc69b6337b4e459ec9428629ca49fb65a6249ee8ed5:crc328:f94424566:lengthi5253e3:md532:9d665d42153c0b27b5eb4922c4ddef685:mtime10:13176646704:pathl33:6201484321_f1a88ca2cb_b_thumb.jpge4:sha140:e5e775116512cebdc0ad048ce3a0e3dd100becf0ee4:name23:6201484321_f1a88ca2cb_b12:piece lengthi524288e6:pieces20:üyR¨Æô;O2¿Ù‚ù‘†0ö

I don't have the same hash

Victor Castro
  • 1,232
  • 21
  • 40

2 Answers2

2

There are two problems:

  1. The hash you send is not the info_hash. You have somehow, from the meta data in the .torrent file, instead got the SHA1 hash of one of the files in the torrent.
    Retrieving the .torrent file from: https://archive.org/download/6201484321_f1a88ca2cb_b/6201484321_f1a88ca2cb_b_archive.torrent shows that the hex-encoded info_hash is ACC3B2E433D7C7475ABB5941B5681CB7A1EA26E2
  2. The info_hash you send in the request is hex-encoded. It must be URL-encoded like this:
    %ac%c3%b2%e43%d7%c7GZ%bbYA%b5h%1c%b7%a1%ea%26%e2

Correcting that and sending:
http://bt1.archive.org:6969/announce?info_hash=%ac%c3%b2%e43%d7%c7GZ%bbYA%b5h%1c%b7%a1%ea%26%e2&peer_id=ABCDEFGHIJKLMNOPQRST&ip=80.11.255.166&port=6881&downloaded=0&left=970

gives the answer:
d8:completei0e10:downloadedi2e10:incompletei2e8:intervali1950e12:min intervali975e5:peers12:************e

Encombe
  • 2,003
  • 1
  • 17
  • 26
1

You need to URL encode the hash instead of sending it in raw hex.

From the BitTorrent Tracker Protocol

Basic Tracker Announce Request

info_hash The 20 byte sha1 hash of the bencoded form of the info value from the metainfo file. Note that this is a substring of the metainfo file. Don't forget to URL-encode this.

Update

BencodeNET library seems to be doing what you what why don't you try it out?. The examples clearly show how to calculate a hash of a torrent

// Parse torrent by specifying the file path
var parser = new BencodeParser(); // Default encoding is Encoding.UT8F, but you can specify another if you need to
var torrent = parse.Parse<Torrent>("C:\ubuntu.torrent");

// Alternatively, handle the stream yourself
using (var stream = File.OpenRead("C:\ubuntu.torrent"))
{
    torrent = parse.Parse<Torrent>(stream);
}

// Calculate the info hash
string infoHash = torrent.GetInfoHash();
// "B415C913643E5FF49FE37D304BBB5E6E11AD5101"

// or as bytes instead of a string
byte[] infoHashBytes = torrent.GetInfoHashBytes();

// Get Magnet link
string magnetLink = torrent.GetMagnetLink();
// magnet:?xt=urn:btih:1CA512A4822EDC7C1B1CE354D7B8D2F84EE11C32&dn=ubuntu-14.10-desktop-amd64.iso&tr=http://torrent.ubuntu.com:6969/announce&tr=http://ipv6.torrent.ubuntu.com:6969/announce

// Convert Torrent to it's BDictionary representation
BDictionary bencode = torrent.ToBDictionary();
Miguel Sanchez
  • 434
  • 3
  • 11
  • I already did, and the encoded hash is not different of the not encoded one. Currently, i use the `sha1` field of the file contained in the torrent, BUT after some more research i found that i must use the `pieces` field (http://stackoverflow.com/questions/28348678/what-exactly-is-the-info-hash-in-a-torrent-file) But, look at the field content, this is not well encoded, i dont know what encoding is used EDIT: the charset is UTF-8 – Victor Castro Oct 12 '16 at 11:54
  • @LeCintas the docs say `hash of the bencoded form of the info value from the metainfo file` – Miguel Sanchez Oct 12 '16 at 12:06