added ability to set target host and port using path
This commit is contained in:
parent
f36877c684
commit
8675580f1c
|
|
@ -15,6 +15,7 @@ require 'optparse'
|
||||||
# encoded/decoded to allow binary data to be sent/received to/from
|
# encoded/decoded to allow binary data to be sent/received to/from
|
||||||
# the target.
|
# the target.
|
||||||
class WebSocketProxy < WebSocketServer
|
class WebSocketProxy < WebSocketServer
|
||||||
|
attr_accessor :target_host, :target_port
|
||||||
|
|
||||||
@@Traffic_legend = "
|
@@Traffic_legend = "
|
||||||
Traffic Legend:
|
Traffic Legend:
|
||||||
|
|
@ -40,6 +41,17 @@ Traffic Legend:
|
||||||
|
|
||||||
# Echo back whatever is received
|
# Echo back whatever is received
|
||||||
def new_websocket_client(client)
|
def new_websocket_client(client)
|
||||||
|
path = Thread.current[:path]
|
||||||
|
if path =~ /:/
|
||||||
|
msg "Path has a ip and port specified. Using those for target"
|
||||||
|
possible_target_host = path[/(\d+\.\d+\.\d+\.\d+):(\d+)/,1]
|
||||||
|
possible_target_port = path[/(\d+\.\d+\.\d+\.\d+):(\d+)/,2].to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
if possible_target_host and possible_target_port
|
||||||
|
@target_host = possible_target_host
|
||||||
|
@target_port = possible_target_port
|
||||||
|
end
|
||||||
|
|
||||||
msg "connecting to: %s:%s" % [@target_host, @target_port]
|
msg "connecting to: %s:%s" % [@target_host, @target_port]
|
||||||
tsock = TCPSocket.open(@target_host, @target_port)
|
tsock = TCPSocket.open(@target_host, @target_port)
|
||||||
|
|
@ -122,50 +134,50 @@ Traffic Legend:
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse parameters
|
# Parse parameters
|
||||||
opts = {}
|
#opts = {}
|
||||||
parser = OptionParser.new do |o|
|
#parser = OptionParser.new do |o|
|
||||||
o.on('--verbose', '-v') { |b| opts['verbose'] = b }
|
# o.on('--verbose', '-v') { |b| opts['verbose'] = b }
|
||||||
o.parse!
|
# o.parse!
|
||||||
end
|
#end
|
||||||
|
#
|
||||||
if ARGV.length < 2
|
#if ARGV.length < 2
|
||||||
puts "Too few arguments"
|
# puts "Too few arguments"
|
||||||
exit 2
|
# exit 2
|
||||||
end
|
#end
|
||||||
|
#
|
||||||
# Parse host:port and convert ports to numbers
|
## Parse host:port and convert ports to numbers
|
||||||
if ARGV[0].count(":") > 0
|
#if ARGV[0].count(":") > 0
|
||||||
opts['listen_host'], _, opts['listen_port'] = ARGV[0].rpartition(':')
|
# opts['listen_host'], _, opts['listen_port'] = ARGV[0].rpartition(':')
|
||||||
else
|
#else
|
||||||
opts['listen_host'], opts['listen_port'] = nil, ARGV[0]
|
# opts['listen_host'], opts['listen_port'] = nil, ARGV[0]
|
||||||
end
|
#end
|
||||||
|
#
|
||||||
begin
|
#begin
|
||||||
opts['listen_port'] = opts['listen_port'].to_i
|
# opts['listen_port'] = opts['listen_port'].to_i
|
||||||
rescue
|
#rescue
|
||||||
puts "Error parsing listen port"
|
# puts "Error parsing listen port"
|
||||||
exit 2
|
# exit 2
|
||||||
end
|
#end
|
||||||
|
#
|
||||||
if ARGV[1].count(":") > 0
|
#if ARGV[1].count(":") > 0
|
||||||
opts['target_host'], _, opts['target_port'] = ARGV[1].rpartition(':')
|
# opts['target_host'], _, opts['target_port'] = ARGV[1].rpartition(':')
|
||||||
else
|
#else
|
||||||
puts "Error parsing target"
|
# puts "Error parsing target"
|
||||||
exit 2
|
# exit 2
|
||||||
end
|
#end
|
||||||
|
#
|
||||||
begin
|
#begin
|
||||||
opts['target_port'] = opts['target_port'].to_i
|
# opts['target_port'] = opts['target_port'].to_i
|
||||||
rescue
|
#rescue
|
||||||
puts "Error parsing target port"
|
# puts "Error parsing target port"
|
||||||
exit 2
|
# exit 2
|
||||||
end
|
#end
|
||||||
|
#
|
||||||
puts "Starting server on #{opts['listen_host']}:#{opts['listen_port']}"
|
#puts "Starting server on #{opts['listen_host']}:#{opts['listen_port']}"
|
||||||
server = WebSocketProxy.new(opts)
|
#server = WebSocketProxy.new(opts)
|
||||||
server.start(100)
|
#server.start(100)
|
||||||
server.join
|
#server.join
|
||||||
|
#
|
||||||
puts "Server has been terminated"
|
#puts "Server has been terminated"
|
||||||
|
|
||||||
# vim: sw=2
|
# vim: sw=2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue