1+ # -*- coding: binary -*-
12require 'singleton'
23require 'rex/socket'
34require 'rex/socket/tcp'
@@ -365,20 +366,31 @@ def self.proxy(sock, type, host, port)
365366
366367 routes = { shost => sport . to_s , host => port . to_s }
367368
368- ni_packet = packet_type << [ 0 ] . pack ( 'c*' ) << [ route_info_version ] . pack ( 'c*' ) << [ ni_version ] . pack ( 'c*' ) << [ num_of_entries ] . pack ( 'c*' ) << [ talk_mode ] . pack ( 'c*' ) << [ 0 ] . pack ( 'c*' ) << [ 0 ] . pack ( 'c*' ) << [ num_rest_nodes ] . pack ( 'c*' )
369+ ni_packet = [
370+ packet_type ,
371+ 0 ,
372+ route_info_version ,
373+ ni_version ,
374+ num_of_entries ,
375+ talk_mode ,
376+ 0 ,
377+ 0 ,
378+ num_rest_nodes
379+ ] . pack ( "A8c7" )
369380
370381 first = false
371382
372- routes . each do |host , port |
373- route_item = host + [ 0 ] . pack ( "C" ) + port + [ 0 , 0 ] . pack ( "c* " )
374- if first
375- route_data = route_data << [ route_item . length ] . pack ( 'N' ) << route_item
376- first = true
377- else
378- route_data << route_item
379- end
380- end
383+ routes . each do |host , port |
384+ route_item = [ host , 0 , port , 0 , 0 ] . pack ( "A*CA*CC " )
385+ if first
386+ route_data = [ route_data , route_item . length , route_item ] . pack ( "A*NA*" )
387+ first = true
388+ else
389+ route_data << route_item
390+ end
391+ end
381392
393+ # TODO: This is really hard to follow
382394 ni_packet << [ route_data . length - 4 ] . pack ( 'N' )
383395 ni_packet << route_data
384396 ni_packet = [ ni_packet . length ] . pack ( 'N' ) << ni_packet
@@ -390,9 +402,9 @@ def self.proxy(sock, type, host, port)
390402 end
391403
392404 begin
393- ret_len = sock . recv ( 4 ) . unpack ( 'H*' ) [ 0 ]
394- if ret_len !=0
395- ret = sock . recv ( ret_len . to_i )
405+ ret_len = sock . recv ( 4 ) . unpack ( 'H*' ) [ 0 ]
406+ if ret_len !=0
407+ ret = sock . recv ( ret_len . to_i )
396408 end
397409 rescue IOError
398410 raise Rex ::ConnectionProxyError . new ( host , port , type , "Failed to receive a response from the proxy" ) , caller
@@ -415,10 +427,10 @@ def self.proxy(sock, type, host, port)
415427 end
416428 elsif ret =~ /NI_PONG/
417429 # would like to print this "[*] remote native connection to #{host}:#{port} established\n"
418- else
419- raise Rex ::ConnectionProxyError . new ( host , port , type , "Connection to #{ host } :#{ port } failed - #{ ret } \n \n #{ ni_packet } " )
430+ else
431+ raise Rex ::ConnectionProxyError . new ( host , port , type , "Connection to #{ host } :#{ port } failed - #{ ret } \n \n #{ ni_packet } " )
420432 end
421-
433+
422434 when 'http'
423435 setup = "CONNECT #{ host } :#{ port } HTTP/1.0\r \n \r \n "
424436 size = sock . put ( setup )
0 commit comments