Package core :: Package controllers :: Package w3afAgent :: Package client :: Module w3afAgentClient :: Class SocksHandler
[hide private]
[frames] | no frames]

Class SocksHandler




This request handler class handles Socks 4 requests.

Instance Methods [hide private]
  __init__(self, clientSocket, request)
  run(self)
  setBindAddress(self, bindAddy)
  handle(self, req)
This function is the main request handler function.
  validate_socks4a(self, req)
This method verifies the extension to socks4 that allows the client to send 0.0.0.x as IP address to indicate to the server that it should resolve the hostname sent in the ID field and then connect to it.
  handle_bind(self, req)
This function handles a BIND request.
  handle_connect(self, req)
This function handles a CONNECT request.
  answer_granted(self, dst_ip='0.0.0.0', dst_port=0)
This function sends a REQUEST_GRANTED answer to the client.
  answer_rejected(self, reason=REQUEST_REJECTED_FAILED, dst_ip='0.0.0.0', dst_port=0)
This function send a REQUEST_REJECTED answer to the client.
  answer(self, code=REQUEST_GRANTED, ip_str='0.0.0.0', port_int=0)
This function sends an answer to the client.
  forward(self, client_sock, server_sock)
This function makes the forwarding of data by listening to two sockets, and writing to one everything it reads on the other.

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, join, setDaemon, setName, start

Inherited from threading.Thread (private): _set_daemon

Inherited from threading._Verbose (private): _note

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__


Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, clientSocket, request)
(Constructor)

 
None
Overrides: threading.Thread.__init__

run(self)

 
None
Overrides: threading.Thread.run

setBindAddress(self, bindAddy)

 
None

handle(self, req)

 

This function is the main request handler function.

It delegates each step of the request processing to a different function and handles raised exceptions in order to warn the client that its request has been rejected (if needed). The steps are:
  • decode_request: reads the request and splits it into a dictionary. it checks if the request is well-formed (correct socks version, correct command number, well-formed port number.
  • validate_request: checks if the current configuration accepts to handle the request (client identification, authorization rules)
  • handle_connect: handles CONNECT requests
  • handle_bind: handles BIND requests

validate_socks4a(self, req)

 
This method verifies the extension to socks4 that allows the client to send 0.0.0.x as IP address to indicate to the server that it should resolve the hostname sent in the ID field and then connect to it.

handle_bind(self, req)

 

This function handles a BIND request.

The actions taken are:
- create a new socket,
- bind it to the external ip chosen on init of the server,
- listen for a connection on this socket,
- register the bind into the server,
- tell the client the bind is ready,
- accept an incoming connection,
- tell the client the connection is established,
- forward data between the client and the remote peer.

handle_connect(self, req)

 

This function handles a CONNECT request.

The actions taken are:
  • create a new socket,
  • register the connection into the server,
  • connect to the remote host,
  • tell the client the connection is established,
  • forward data between the client and the remote peer.

answer_granted(self, dst_ip='0.0.0.0', dst_port=0)

 
This function sends a REQUEST_GRANTED answer to the client.

answer_rejected(self, reason=REQUEST_REJECTED_FAILED, dst_ip='0.0.0.0', dst_port=0)

 
This function send a REQUEST_REJECTED answer to the client.

answer(self, code=REQUEST_GRANTED, ip_str='0.0.0.0', port_int=0)

 
This function sends an answer to the client. This has been factorised because all answers follow the same format.

forward(self, client_sock, server_sock)

 

This function makes the forwarding of data by listening to two sockets, and writing to one everything it reads on the other.

This is done using select(), in order to be able to listen on both sockets simultaneously and to implement an inactivity timeout.