Module: Rex::Proto::Proxy::Socks4a::Client::Relay
- Defined in:
- lib/rex/proto/proxy/socks4a.rb
Overview
A mixin for a socket to perform a relay to another socket.
Instance Method Summary collapse
-
#relay(relay_client, relay_sock) ⇒ Object
Relay data coming in from relay_sock to this socket.
Instance Method Details
#relay(relay_client, relay_sock) ⇒ Object
Relay data coming in from relay_sock to this socket.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/rex/proto/proxy/socks4a.rb', line 164 def relay( relay_client, relay_sock ) @relay_client = relay_client @relay_sock = relay_sock # start the relay thread (modified from Rex::IO::StreamAbstraction) @relay_thread = Rex::ThreadFactory.spawn("SOCKS4AProxyServerRelay", false) do loop do closed = false buf = nil begin s = Rex::ThreadSafe.select( [ @relay_sock ], nil, nil, 0.2 ) if( s == nil || s[0] == nil ) next end rescue closed = true end if( closed == false ) begin buf = @relay_sock.sysread( 32768 ) closed = true if( buf == nil ) rescue closed = true end end if( closed == false ) total_sent = 0 total_length = buf.length while( total_sent < total_length ) begin data = buf[total_sent, buf.length] sent = self.write( data ) if( sent > 0 ) total_sent += sent end rescue closed = true break end end end if( closed ) @relay_client.stop ::Thread.exit end end end end |