module Rex::Proto::Kademlia

Minimal support for the newer Kademlia protocol, referred to here and often elsewhere as Kademlia2. It is unclear how this differs from the old protocol.

Protocol details are hard to come by because most documentation is academic in nature and glosses over the low-level network details. The best documents I found on the protocol are:

gbmaster.wordpress.com/2013/05/05/botnets-surrounding-us-an-initial-focus-on-kad/ gbmaster.wordpress.com/2013/06/16/botnets-surrounding-us-sending-kademlia2_bootstrap_req-kademlia2_hello_req-and-their-strict-cousins/ gbmaster.wordpress.com/2013/11/23/botnets-surrounding-us-performing-requests-sending-out-kademlia2_req-and-asking-contact-where-art-thou/

Constants

BOOTSTRAP_REQUEST

Opcode for a BOOTSTRAP request

BOOTSTRAP_RESPONSE

Opcode for a bootstrap response

PING

Opcode for a PING request

PONG

Opcode for a PING response

Public Class Methods

decode_peer_id(bytes) click to toggle source

Decodes an on-the-wire representation of a Kademlia peer to its 16-character hex equivalent

@param bytes [String] the on-the-wire representation of a Kademlia peer @return [String] the peer ID if valid, nil otherwise

# File lib/rex/proto/kademlia/util.rb, line 9
def self.decode_peer_id(bytes)
  peer_id = 0
  return nil unless bytes.size == 16
  bytes.unpack('VVVV').map { |p| peer_id = ((peer_id << 32) ^ p) }
  peer_id.to_s(16).upcase
end