coderrr

November 6, 2009

SOCKS 4 server with ProxyMachine

Filed under: network, ruby — Tags: , — coderrr @ 4:15 am

I proxy almost all my web traffic through a SOCKS proxy. After going through a bunch of different servers, each with its own issues, I decided to just write my own. I ended up using ProxyMachine and it only took seven lines!

# socks4.rb
proxy do |data|
  next  if data.size < 9
  v, c, port, o1, o2, o3, o4, user = data.unpack("CCnC4a*")
  return { :close => "\x0\x5b\x0\x0\x0\x0\x0\x0" }  if v != 4 or c != 1
  next  if ! idx = user.index("\x0")
  { :remote => "#{[o1,o2,o3,o4]*'.'}:#{port}", :reply => "\x0\x5a\x0\x0\x0\x0\x0\x0", :data => data[idx+9..-1] }
end

run it with:

$ proxymachine -h 127.0.0.1 -p 1080 -c socks4.rb

* note this only actually covers half of the SOCKS4 protocol, but it’s the only half that pretty much anyone uses

1 Comment »

  1. [...] SOCKS 4 server with ProxyMachine « coderrr a few seconds ago from xmpp [...]

    Pingback by Postmodern (postmodern) 's status on Friday, 06-Nov-09 08:00:29 UTC - Identi.ca — November 6, 2009 @ 8:00 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.