Class: Rex::Proto::Proxy::Socks4a
- Inherits:
-
Object
- Object
- Rex::Proto::Proxy::Socks4a
- Defined in:
- lib/rex/proto/proxy/socks4a.rb
Overview
A Socks4a proxy server.
Defined Under Namespace
Classes: Client
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #add_client(client) ⇒ Object
-
#initialize(opts = {}) ⇒ Socks4a
constructor
Create a new Socks4a server.
-
#is_running? ⇒ Boolean
Check if the server is running.
-
#join ⇒ Object
Block while the server is running.
- #remove_client(client) ⇒ Object
-
#start ⇒ Object
Start the Socks4a server.
-
#stop ⇒ Object
Stop the Socks4a server.
Constructor Details
#initialize(opts = {}) ⇒ Socks4a
Create a new Socks4a server.
354 355 356 357 358 359 360 361 |
# File 'lib/rex/proto/proxy/socks4a.rb', line 354 def initialize( opts={} ) @opts = { 'ServerHost' => '0.0.0.0', 'ServerPort' => 1080 } @opts = @opts.merge( opts ) @server = nil @clients = ::Array.new @running = false @server_thread = nil end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
435 436 437 |
# File 'lib/rex/proto/proxy/socks4a.rb', line 435 def opts @opts end |
Instance Method Details
#add_client(client) ⇒ Object
427 428 429 |
# File 'lib/rex/proto/proxy/socks4a.rb', line 427 def add_client( client ) @clients << client end |
#is_running? ⇒ Boolean
Check if the server is running.
366 367 368 |
# File 'lib/rex/proto/proxy/socks4a.rb', line 366 def is_running? return @running end |
#join ⇒ Object
Block while the server is running.
402 403 404 |
# File 'lib/rex/proto/proxy/socks4a.rb', line 402 def join @server_thread.join end |
#remove_client(client) ⇒ Object
431 432 433 |
# File 'lib/rex/proto/proxy/socks4a.rb', line 431 def remove_client( client ) @clients.delete( client ) end |
#start ⇒ Object
Start the Socks4a server.
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/rex/proto/proxy/socks4a.rb', line 373 def start begin # create the servers main socket (ignore the context here because we don't want a remote bind) @server = Rex::Socket::TcpServer.create( 'LocalHost' => @opts['ServerHost'], 'LocalPort' => @opts['ServerPort'] ) # signal we are now running @running = true # start the servers main thread to pick up new clients @server_thread = Rex::ThreadFactory.spawn("SOCKS4AProxyServer", false) do while( @running ) do begin # accept the client connection sock = @server.accept # and fire off a new client instance to handle it Client.new( self, sock ).start rescue wlog( "Socks4a.start - server_thread - #{$!}" ) end end end rescue wlog( "Socks4a.start - #{$!}" ) return false end return true end |
#stop ⇒ Object
Stop the Socks4a server.
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/rex/proto/proxy/socks4a.rb', line 409 def stop if( @running ) # signal we are no longer running @running = false # stop any clients we have (create a new client array as client.stop will delete from @clients) clients = [] clients.concat( @clients ) clients.each do | client | client.stop end # close the server socket @server.close if @server # if the server thread did not terminate gracefully, kill it. @server_thread.kill if( @server_thread and @server_thread.alive? ) end return !@running end |