Skip to content

Commit df36ac9

Browse files
committed
Mostly complete Kademlia PING / BOOTSTRAP scanner
1 parent f5aa3ec commit df36ac9

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

lib/rex/proto/kademlia.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: binary -*-
22

3-
require 'rex/proto/steam/message'
3+
require 'rex/proto/kademlia/message'

lib/rex/proto/kademlia/message.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ def decode_pong(message)
7777
return nil unless opcode == PONG
7878
# abort if the response is too large/small
7979
return nil unless port && port.size == 2
80-
# the port will be the port the true endpoint is actually listening on,
81-
# which may not be the same as the port you contacted it on (NAT/etc)
80+
# this should always be equivalent to the source port from which the PING was received
8281
port.unpack('v')[0]
8382
end
8483

modules/auxiliary/scanner/kademlia/server_info.rb

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,31 @@ def build_probe
5454
end
5555

5656
def scanner_process(response, src_host, src_port)
57-
info = message_decode(response)
57+
return if response.blank?
58+
peer = "#{src_host}:#{src_port}"
59+
60+
case action.name
61+
when 'BOOTSTRAP'
62+
peer_id, tcp_port, version, peers = decode_bootstrap_res(response)
63+
info = {
64+
peer_id: peer_id,
65+
tcp_port: tcp_port,
66+
version: version,
67+
peers: peers
68+
}
69+
if datastore['VERBOSE']
70+
else
71+
print_good("#{peer} ID #{peer_id}, TCP port #{tcp_port}, version #{version}, #{peers.size} peers")
72+
end
73+
when 'PING'
74+
udp_port = decode_pong(response)
75+
print_good("#{peer} PONG")
76+
# udp_port should match the port we contacted it from. TODO: validate this?
77+
info = { udp_port: udp_port }
78+
end
79+
5880
return unless info
5981
@results[src_host] ||= []
60-
if datastore['VERBOSE']
61-
print_good("#{src_host}:#{src_port} found '#{info.inspect}'")
62-
else
63-
print_good("#{src_host}:#{src_port} found '#{info[:name]}'")
64-
end
6582
@results[src_host] << info
6683
end
6784

0 commit comments

Comments
 (0)