Class: SSRFProxy::Server
- Inherits:
-
Object
- Object
- SSRFProxy::Server
- Includes:
- Celluloid::IO
- Defined in:
- lib/ssrf_proxy/server.rb
Overview
SSRFProxy::Server takes a SSRFProxy::HTTP object, interface and port, and starts a HTTP proxy server on the specified interface and port. All client HTTP requests are sent via the specified SSRFProxy::HTTP object.
Defined Under Namespace
Modules: Error
Instance Attribute Summary collapse
-
#logger ⇒ Logger
readonly
Logger.
Instance Method Summary collapse
-
#initialize(ssrf, interface = '127.0.0.1', port = 8081) ⇒ Server
constructor
Start the local server and listen for connections.
-
#serve ⇒ Object
Run proxy server asynchronously.
Constructor Details
#initialize(ssrf, interface = '127.0.0.1', port = 8081) ⇒ Server
Start the local server and listen for connections
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ssrf_proxy/server.rb', line 60 def initialize(ssrf, interface = '127.0.0.1', port = 8081) @banner = 'SSRF Proxy' @server = nil @logger = ::Logger.new(STDOUT).tap do |log| log.progname = 'ssrf-proxy-server' log.level = ::Logger::WARN log.datetime_format = '%Y-%m-%d %H:%M:%S ' end # set ssrf unless ssrf.class == SSRFProxy::HTTP raise SSRFProxy::Server::Error::InvalidSsrf.new, 'Invalid SSRF provided' end @ssrf = ssrf # check if the remote proxy server is responsive unless @ssrf.proxy.nil? if @ssrf.proxy.host == interface && @ssrf.proxy.port == port raise SSRFProxy::Server::Error::ProxyRecursion.new, "Proxy recursion error: #{@ssrf.proxy}" end if port_open?(@ssrf.proxy.host, @ssrf.proxy.port) print_good('Connected to remote proxy ' \ "#{@ssrf.proxy.host}:#{@ssrf.proxy.port} successfully") else raise SSRFProxy::Server::Error::RemoteProxyUnresponsive.new, 'Could not connect to remote proxy ' \ "#{@ssrf.proxy.host}:#{@ssrf.proxy.port}" end end # if no upstream proxy is set, check if the remote server is responsive if @ssrf.proxy.nil? if port_open?(@ssrf.url.host, @ssrf.url.port) print_good('Connected to remote host ' \ "#{@ssrf.url.host}:#{@ssrf.url.port} successfully") else raise SSRFProxy::Server::Error::RemoteHostUnresponsive.new, 'Could not connect to remote host ' \ "#{@ssrf.url.host}:#{@ssrf.url.port}" end end # start server logger.info "Starting HTTP proxy on #{interface}:#{port}" begin print_status "Listening on #{interface}:#{port}" @server = TCPServer.new(interface, port.to_i) rescue Errno::EADDRINUSE raise SSRFProxy::Server::Error::AddressInUse.new, "Could not bind to #{interface}:#{port}" \ ' - address already in use' end end |
Instance Attribute Details
#logger ⇒ Logger (readonly)
Returns logger.
19 20 21 |
# File 'lib/ssrf_proxy/server.rb', line 19 def logger @logger end |
Instance Method Details
#serve ⇒ Object
Run proxy server asynchronously
162 163 164 |
# File 'lib/ssrf_proxy/server.rb', line 162 def serve loop { async.handle_connection(@server.accept) } end |