4

I'm just trying to get a response from router.utorrent.com to potentially make a DHT service down the track. For example, given a magnet link with:

xt=urn:btih:a78c852bcc0379e612e1bd794e1fd19061b84d11

the hash is:

a78c852bcc0379e612e1bd794e1fd19061b84d11

Then in the terminal I entered this:

nc -u router.utorrent.com 6881


d1:ad2:id20:a78c852bcc0379e612e1bd794e1fd19061b84d11e1:q4:ping1:t1:01:y1:qe

based on this documentation but i dont get any response. I even tried Wireshark to check if any packet at all was coming back and still nothing. Why doesn't μTorrent talk to me?

Jeremy
  • 1
  • 85
  • 340
  • 366
Cadell Christo
  • 3,105
  • 3
  • 21
  • 19

2 Answers2

3

The hash should be in binary. In bencoding the number + colon is the length prefix for a string. A sha1 in hex is 40 bytes long, for it to be actually 20 bytes long it needs to be the raw output of the hash function.

You basically need to conver the hex string to binary (40 hex -> 20 binary) for it to work.

the8472
  • 40,999
  • 5
  • 70
  • 122
  • thanks for your response. expand a bit on this i'm new at this. what do i have to do to the hash i've got above? – Cadell Christo Nov 01 '12 at 04:35
  • so the should send this? d1:ad2:id20:10010100111000011111110100011001000001100001101110000000000000000000e1:q4:ping1:t1:01:y1:qe – Cadell Christo Nov 18 '12 at 13:16
  • no. i already wrote that in my answer: 40bytes hex -> 20 bytes raw binary. – the8472 Nov 18 '12 at 22:25
  • sorry i dont mean to be annoying i just want to understand i converted the hex a78c852bcc0379e612e1bd794e1fd19061b84d11 to binary 10010100111000011111110100011001000001100001101110000000000000000000‌ now is that correct? then what do i do – Cadell Christo Nov 19 '12 at 01:30
  • Binary. 8bit representation. hexdecode. base256 instead of base16 or base2. – the8472 Nov 19 '12 at 22:59
  • http://stackoverflow.com/questions/3844502/how-does-bt-magnet-links-work that helped so the torrents info block is bencoded then sha1 encoded to get an 'info hash'. that info hash is a 20 byte binary. the hash from the magnet link is the base32 encoding of the 'info hash'. so i need to decode the base32 magnet hash to get the 'info hash'? – Cadell Christo Nov 20 '12 at 08:34
  • http://www.unitconversion.org/numbers/base-32-to-binary-conversion.html i used that site. does it look right? a78c852bcc0379e612e1bd794e1fd19061b84d11 to 1010001110100001100010000010100010010110110001100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 – Cadell Christo Nov 20 '12 at 08:36
  • 1
    also, the "id" argument in DHT messages is supposed to be your node ID, which you choose at random. no need to stick the info-hash in there. – Arvid Dec 24 '12 at 19:14
1

As explained in the other answer, bencoding is a binary format, not a text format. You seem to be trying to enter the message body into netcat using a terminal. Terminals are designed for entering textual input to programs, not binary, and so you will not be able to directly enter that sequence into netcat's stdin.

The ID in your ping request should not be the torrent's infohash. It should be a unique ID to identify your client to the DHT network. For testing, you really could just pick an ID made up entirely of 20 ASCII characters, and avoid these encoding issues, but in practice you'll want to use uniformly random binary IDs.

If you want to a binary ID in a terminal, you shouldn't try inputting it directly into netcat. Instead you can use your shell's echo command and hex encoding to produce the data in the intended format, and pipe that into netcat. For example, in bash:

echo -n $'d1:ad2:id20:\x23\x71\x0c\x1c\xb4\x50\x7d\x87\x29\xb8\x3f\x87\x2c\xc6\xa2\xa4\x4c\x39\x73\x67e1:q4:ping1:t1:01:y1:qe' | nc -u router.utorrent.com 6881

Note that the response you get from the node will be unescaped binary, not necessarily text, so displaying it directly in your terminal as we're doing here could result in things appearing strangely or your current terminal session being messed up some way.

Jeremy
  • 1
  • 85
  • 340
  • 366