From 90b581283a24e21859a252c5c0ac7093aacf256c Mon Sep 17 00:00:00 2001 From: Sen Date: Mon, 14 Jan 2013 16:22:56 +0800 Subject: [PATCH 01/48] make local easier to understand --- local.rb | 139 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 72 insertions(+), 67 deletions(-) diff --git a/local.rb b/local.rb index d828160..97bff1b 100644 --- a/local.rb +++ b/local.rb @@ -25,7 +25,6 @@ require 'json' require './encrypt' - cfg_file = File.open('config.json') config = JSON.parse(cfg_file.read) cfg_file.close @@ -38,10 +37,6 @@ $encrypt_table, $decrypt_table = get_table(key) -def inet_ntoa(n) - n.unpack("C*").join "." -end - module LocalServer class LocalConnector < EventMachine::Connection def initialize server @@ -50,7 +45,7 @@ def initialize server end def post_init - p "connecting #{@server.remote_addr} via #{@server.server_using}" + p "connecting #{@server.remote_addr[3..-1]} via #{$server}" addr_to_send = @server.addr_to_send.clone encrypt $encrypt_table, addr_to_send send_data addr_to_send @@ -59,7 +54,7 @@ def post_init encrypt $encrypt_table, piece send_data piece end - @server.cached_pieces = nil + @server.cached_pieces = [] @server.stage = 5 end @@ -74,96 +69,106 @@ def unbind end end - attr_accessor :remote_addr - attr_accessor :remote_port - attr_accessor :stage - attr_accessor :addr_to_send - attr_accessor :server_using - attr_accessor :cached_pieces + @@connected_clients = Array.new + + attr_accessor :stage, :remote_addr, :addr_to_send, :cached_pieces + + def initialize + super + end + + def receive_data data + data_handler data + end def post_init - puts "local connected" @stage = 0 - @header_length = 0 - @remote = 0 + @@connected_clients.push(self) @cached_pieces = [] - @remote_addr = nil - @remote_port = nil - @connector = nil - @addr_to_send = "" - @server_using = $server + puts "A client has connected..." end - def receive_data data + def unbind + @@connected_clients.delete(self) + puts "A client has left..." + end + + private + + def data_handler data if @stage == 5 encrypt $encrypt_table, data - @connector.send_data data - return - end - if @stage == 0 + @connector.send_data(data) and return + elsif @stage == 0 send_data "\x05\x00" @stage = 1 - return - end - if @stage == 1 + elsif @stage == 1 begin - addr_len = 0 - cmd = data[1] - addrtype = data[3] - if cmd != "\x01" - warn "unsupported cmd: " + cmd.unpack('c')[0].to_s - close_connection - return - end - if addrtype == "\x03" - addr_len = data[4].unpack('c')[0] - elsif addrtype != "\x01" - warn "unsupported addrtype: " + addrtype.unpack('c')[0].to_s - close_connection - return + unless data[1] == "\x01" + send_data "\x05\x07\x00\x01" + self.close_connection and return end + @addr_to_send = data[3] - if addrtype == "\x01" - @addr_to_send += data[4..9] - @remote_addr = inet_ntoa data[4..7] - @remote_port = data[8, 2].unpack('s>')[0] - @header_length = 10 - else - @remote_addr = data[5, addr_len] - @addr_to_send += data[4..5 + addr_len + 2] - @remote_port = data[5 + addr_len, 2].unpack('s>')[0] - @header_length = 5 + addr_len + 2 - end - #p @remote_addr, @remote_port - #p @addr_to_send - send_data "\x05\x00\x00\x01\x00\x00\x00\x00" + [@remote_port].pack('s>') + + resolve_addrtype(data) + + send_data "\x05\x00\x00\x01\x00\x00\x00\x00" + [$remote_port].pack('s>') + @stage = 4 + @connector = EventMachine.connect $server, $remote_port, LocalConnector, self + if data.size > @header_length @cached_pieces.push data[@header_length, data.size] end - - @connector = EventMachine.connect $server, $remote_port, LocalConnector, self rescue Exception => e warn e - if @connector != nil - @connector.close_connection - end + @connector.close_connection unless @connector.nil? close_connection end elsif @stage == 4 @cached_pieces.push data end - end - def unbind - if @connector != nil - @connector.close_connection_after_writing + def resolve_addrtype(data) + addrtype = data[3] + if addrtype == "\x01" + ip_address(data) + elsif addrtype == "\x03" + domain_adress(data) + else + warn "unsupported addrtype: " + addrtype.unpack('c')[0].to_s + close_connection and return end + end + def domain_adress(data) + addr_len = data[4].unpack('c')[0] + @addr_to_send += data[4..5 + addr_len + 2] + @remote_addr = data[2, addr_len] + @remote_port = data[2 + addr_len, 2].unpack('s>')[0] + @header_length = 2 + addr_len + 2 end + + def ip_address(data) + @addr_to_send += data[4..9] + @remote_addr = inet_ntoa data[1..4] + @remote_port = data[5, 2].unpack('s>')[0] + @header_length = 7 + end + + def inet_ntoa(n) + n.unpack("C*").join "." + end + end EventMachine::run { + Signal.trap("INT") { EventMachine.stop } + Signal.trap("TERM") { EventMachine.stop } + + puts "*** Local side is up, port:#{$port}" + puts "*** Hit Ctrl+c to stop" EventMachine::start_server "0.0.0.0", $port, LocalServer -} \ No newline at end of file +} From da9b3a6320565dd13021fa7c8df93c87aa0a6499 Mon Sep 17 00:00:00 2001 From: Sen Date: Mon, 14 Jan 2013 16:24:16 +0800 Subject: [PATCH 02/48] i juse don't like while --- encrypt.rb | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/encrypt.rb b/encrypt.rb index c817e42..fd76fc2 100644 --- a/encrypt.rb +++ b/encrypt.rb @@ -28,35 +28,21 @@ def get_table (key) decrypt_table = Array.new(256, 0) a = Digest::MD5.digest(key).unpack('Q<')[0] - i = 0 - while i < 256 - table[i] = i - i += 1 - end - i = 1 + 0.upto(255).each{ |i| table[i] = i } - while i < 1024 + 1.upto(1023).each do |i| table = merge_sort(table, lambda { |x, y| a % (x + i) - a % (y + i) }) - i += 1 - end - i = 0 - while i < 256 - decrypt_table[table[i]] = i - i += 1 end + + 0.upto(255).each{ |i| decrypt_table[table[i]] = i } + [table, decrypt_table] end def encrypt (table, buf) - i = 0 - - while i < buf.length - buf[i] = table[buf[i].ord].chr - i += 1 - end + 0.upto(buf.length - 1).each{ |i| buf[i] = table[buf[i].ord].chr } end - From b86bc823a1bc169db5041c4880199142568b9209 Mon Sep 17 00:00:00 2001 From: Sen Date: Mon, 14 Jan 2013 21:12:05 +0800 Subject: [PATCH 03/48] use FFI to get better performance --- .gitignore | 2 ++ Rakefile | 8 ++++++++ encrypt.rb | 19 +++++++++++++++++-- ext/ext.c | 13 +++++++++++++ local.rb | 12 ++++-------- 5 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 .gitignore create mode 100644 Rakefile create mode 100644 ext/ext.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc78368 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.so +*.o diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..73bb8f7 --- /dev/null +++ b/Rakefile @@ -0,0 +1,8 @@ +require 'rake' + +task :default => 'compile' + +task :compile do + `rm ./ext/*.o ./ext/*.so` + `cd ./ext && gcc -fPIC -c ext.c && gcc -shared -o ext.so ext.o` +end diff --git a/encrypt.rb b/encrypt.rb index fd76fc2..2fff12c 100644 --- a/encrypt.rb +++ b/encrypt.rb @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +require "ffi" require "digest" require "./merge_sort" @@ -42,7 +43,21 @@ def get_table (key) [table, decrypt_table] end -def encrypt (table, buf) - 0.upto(buf.length - 1).each{ |i| buf[i] = table[buf[i].ord].chr } +module Ext + extend FFI::Library + ffi_lib "ext/ext.so" + attach_function "encrypt", [:pointer, :pointer, :int], :pointer end +def encrypt (table, buf) + table_ptr = FFI::MemoryPointer.new(:int, table.length) + table_ptr.put_array_of_int32(0, table) + + buf_ptr = FFI::MemoryPointer.new(:string, buf.length) + buf_ptr.put_bytes(0, buf) + + r = Ext.encrypt(table_ptr, buf_ptr, buf.length).get_bytes(0, buf.length) + table_ptr.free + buf_ptr.free + r +end diff --git a/ext/ext.c b/ext/ext.c new file mode 100644 index 0000000..d8eae53 --- /dev/null +++ b/ext/ext.c @@ -0,0 +1,13 @@ +#include + +char* encrypt(int table[], char buf[], int len) +{ + int j = 0; + char *end = buf + len; + while (buf < end) { + *buf = (char)table[(unsigned char)*buf]; + buf++; + } + + return buf - len; +} diff --git a/local.rb b/local.rb index 97bff1b..456782b 100644 --- a/local.rb +++ b/local.rb @@ -47,12 +47,10 @@ def initialize server def post_init p "connecting #{@server.remote_addr[3..-1]} via #{$server}" addr_to_send = @server.addr_to_send.clone - encrypt $encrypt_table, addr_to_send - send_data addr_to_send + send_data encrypt($encrypt_table, addr_to_send) for piece in @server.cached_pieces - encrypt $encrypt_table, piece - send_data piece + send_data encrypt($encrypt_table, piece) end @server.cached_pieces = [] @@ -60,8 +58,7 @@ def post_init end def receive_data data - encrypt $decrypt_table, data - @server.send_data data + @server.send_data encrypt($decrypt_table, data) end def unbind @@ -97,8 +94,7 @@ def unbind def data_handler data if @stage == 5 - encrypt $encrypt_table, data - @connector.send_data(data) and return + @connector.send_data(encrypt($encrypt_table, data)) and return elsif @stage == 0 send_data "\x05\x00" @stage = 1 From 66622c0ba3dd68a895732a42da137666f5479452 Mon Sep 17 00:00:00 2001 From: Sen Date: Mon, 14 Jan 2013 21:24:54 +0800 Subject: [PATCH 04/48] fix for FFI --- server.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server.rb b/server.rb index b4af8c9..732d5da 100644 --- a/server.rb +++ b/server.rb @@ -58,8 +58,7 @@ def post_init end def receive_data data - encrypt $encrypt_table, data - @server.send_data data + @server.send_data encrypt($encrypt_table, data) end def unbind @@ -88,7 +87,7 @@ def post_init end def receive_data data - encrypt $decrypt_table, data + data = encrypt $decrypt_table, data if @stage == 5 @connector.send_data data return @@ -142,4 +141,4 @@ def unbind EventMachine::run { EventMachine::start_server "0.0.0.0", $remote_port, LocalServer -} \ No newline at end of file +} From fbbb1d08b0158774964683b03cd8be96c14ffafa Mon Sep 17 00:00:00 2001 From: Sen Date: Tue, 15 Jan 2013 21:29:04 -0800 Subject: [PATCH 05/48] Create README.md --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..256a82d --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +shadowsocks-ruby +================ + +a Ruby EventMachine port of shadowsocks-nodejs (not stable yet). use shadowsocks-nodejs instead + +install + +``` ruby +gem install eventmachine +gem install ffi +rake +``` + +server side + +``` ruby +nohup ruby server.rb > log & +``` + +then enjoy! From f671880e4f78c772d84a6ce9647f6b82b855b5e1 Mon Sep 17 00:00:00 2001 From: Sen Date: Thu, 26 Sep 2013 12:45:31 +0800 Subject: [PATCH 06/48] bin dir --- bin/ss-local | 3 +++ bin/ss-server | 3 +++ 2 files changed, 6 insertions(+) create mode 100755 bin/ss-local create mode 100755 bin/ss-server diff --git a/bin/ss-local b/bin/ss-local new file mode 100755 index 0000000..55da95d --- /dev/null +++ b/bin/ss-local @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby + +p 'hello, i am client' diff --git a/bin/ss-server b/bin/ss-server new file mode 100755 index 0000000..461e559 --- /dev/null +++ b/bin/ss-server @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby + +p 'hello, i am server' From 37d6b6e1ec81ee92d632ae81a06025208bb61da6 Mon Sep 17 00:00:00 2001 From: Sen Date: Tue, 1 Oct 2013 17:54:27 +0800 Subject: [PATCH 07/48] gem should work --- .gitignore | 5 + Gemfile | 3 + Gemfile.lock | 24 +++++ Rakefile | 9 +- bin/ss-local | 18 +++- bin/ss-server | 18 +++- config.json | 6 +- encrypt.rb | 63 ------------ ext/{ext.c => encrypt/encrypt.c} | 2 - ext/encrypt/extconf.rb | 3 + lib/shadowsocks.rb | 9 ++ lib/shadowsocks/cli.rb | 51 ++++++++++ lib/shadowsocks/config.rb | 50 +++++++++ lib/shadowsocks/listener.rb | 58 +++++++++++ lib/shadowsocks/local.rb | 79 ++++++++++++++ lib/shadowsocks/server.rb | 62 +++++++++++ lib/shadowsocks/table.rb | 84 +++++++++++++++ lib/shadowsocks/tunnel.rb | 19 ++++ lib/shadowsocks/version.rb | 3 + local.rb | 170 ------------------------------- merge_sort.rb | 41 -------- server.rb | 144 -------------------------- shadowsocks.gemspec | 25 +++++ tasks/compile.rake | 9 ++ tasks/dev.rake | 7 ++ test.rb | 15 --- 26 files changed, 531 insertions(+), 446 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock delete mode 100644 encrypt.rb rename ext/{ext.c => encrypt/encrypt.c} (91%) create mode 100644 ext/encrypt/extconf.rb create mode 100644 lib/shadowsocks.rb create mode 100644 lib/shadowsocks/cli.rb create mode 100644 lib/shadowsocks/config.rb create mode 100644 lib/shadowsocks/listener.rb create mode 100644 lib/shadowsocks/local.rb create mode 100644 lib/shadowsocks/server.rb create mode 100644 lib/shadowsocks/table.rb create mode 100644 lib/shadowsocks/tunnel.rb create mode 100644 lib/shadowsocks/version.rb delete mode 100644 local.rb delete mode 100644 merge_sort.rb delete mode 100644 server.rb create mode 100644 shadowsocks.gemspec create mode 100644 tasks/compile.rake create mode 100644 tasks/dev.rake delete mode 100644 test.rb diff --git a/.gitignore b/.gitignore index cc78368..9963cbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ *.so *.o +.DS_Store +*.gem +tmp +*.bundle +Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..c80ee36 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "http://rubygems.org" + +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..ea75f46 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,24 @@ +PATH + remote: . + specs: + shadowsocks (0.1) + eventmachine (~> 1.0.3) + json (~> 1.8.0) + +GEM + remote: http://rubygems.org/ + specs: + eventmachine (1.0.3) + json (1.8.0) + metaclass (0.0.1) + mocha (0.14.0) + metaclass (~> 0.0.1) + rake (10.1.0) + +PLATFORMS + ruby + +DEPENDENCIES + mocha (~> 0.14.0) + rake + shadowsocks! diff --git a/Rakefile b/Rakefile index 73bb8f7..7bb616b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,5 @@ +# encoding: UTF-8 require 'rake' -task :default => 'compile' - -task :compile do - `rm ./ext/*.o ./ext/*.so` - `cd ./ext && gcc -fPIC -c ext.c && gcc -shared -o ext.so ext.o` -end +# Load custom tasks +Dir['tasks/*.rake'].sort.each { |f| load f } diff --git a/bin/ss-local b/bin/ss-local index 55da95d..16259c3 100755 --- a/bin/ss-local +++ b/bin/ss-local @@ -1,3 +1,19 @@ #!/usr/bin/env ruby -p 'hello, i am client' +lib = File.expand_path(File.dirname(__FILE__) + '/../lib') +$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) + +require 'shadowsocks' +require 'shadowsocks/cli' +require 'shadowsocks/config' + +begin + config = Shadowsocks::Config.new ARGV + cli = Shadowsocks::Cli.new({side: :local, config: config}) + cli.run +rescue => e + raise e if $DEBUG + STDERR.puts e.message + STDERR.puts e.backtrace.join("\n") + exit 1 +end diff --git a/bin/ss-server b/bin/ss-server index 461e559..cf70d24 100755 --- a/bin/ss-server +++ b/bin/ss-server @@ -1,3 +1,19 @@ #!/usr/bin/env ruby -p 'hello, i am server' +lib = File.expand_path(File.dirname(__FILE__) + '/../lib') +$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) + +require 'shadowsocks' +require 'shadowsocks/cli' +require 'shadowsocks/config' + +begin + config = Shadowsocks::Config.new ARGV + cli = Shadowsocks::Cli.new({side: :server, config: config}) + cli.run +rescue => e + raise e if $DEBUG + STDERR.puts e.message + STDERR.puts e.backtrace.join("\n") + exit 1 +end diff --git a/config.json b/config.json index 0548439..8353b2d 100644 --- a/config.json +++ b/config.json @@ -2,6 +2,6 @@ "server":"127.0.0.1", "server_port":8388, "local_port":1080, - "password":"barfoo!", - "timeout":60 -} \ No newline at end of file + "password":"foobar!", + "timeout":600 +} diff --git a/encrypt.rb b/encrypt.rb deleted file mode 100644 index 2fff12c..0000000 --- a/encrypt.rb +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/ruby - -# Copyright (c) 2012 clowwindy -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -require "ffi" -require "digest" -require "./merge_sort" - -def get_table (key) - table = Array.new(256, 0) - decrypt_table = Array.new(256, 0) - - a = Digest::MD5.digest(key).unpack('Q<')[0] - - 0.upto(255).each{ |i| table[i] = i } - - 1.upto(1023).each do |i| - table = merge_sort(table, lambda { |x, y| - a % (x + i) - a % (y + i) - }) - end - - 0.upto(255).each{ |i| decrypt_table[table[i]] = i } - - [table, decrypt_table] -end - -module Ext - extend FFI::Library - ffi_lib "ext/ext.so" - attach_function "encrypt", [:pointer, :pointer, :int], :pointer -end - -def encrypt (table, buf) - table_ptr = FFI::MemoryPointer.new(:int, table.length) - table_ptr.put_array_of_int32(0, table) - - buf_ptr = FFI::MemoryPointer.new(:string, buf.length) - buf_ptr.put_bytes(0, buf) - - r = Ext.encrypt(table_ptr, buf_ptr, buf.length).get_bytes(0, buf.length) - table_ptr.free - buf_ptr.free - r -end diff --git a/ext/ext.c b/ext/encrypt/encrypt.c similarity index 91% rename from ext/ext.c rename to ext/encrypt/encrypt.c index d8eae53..85010e0 100644 --- a/ext/ext.c +++ b/ext/encrypt/encrypt.c @@ -1,5 +1,3 @@ -#include - char* encrypt(int table[], char buf[], int len) { int j = 0; diff --git a/ext/encrypt/extconf.rb b/ext/encrypt/extconf.rb new file mode 100644 index 0000000..7cda835 --- /dev/null +++ b/ext/encrypt/extconf.rb @@ -0,0 +1,3 @@ +require 'mkmf' + +create_makefile('encrypt') diff --git a/lib/shadowsocks.rb b/lib/shadowsocks.rb new file mode 100644 index 0000000..ffa5468 --- /dev/null +++ b/lib/shadowsocks.rb @@ -0,0 +1,9 @@ +require 'eventmachine' + +module Shadowsocks + autoload :Server, 'shadowsocks/server' + autoload :Local, 'shadowsocks/local' + autoload :Table, 'shadowsocks/table' + autoload :Tunnel, 'shadowsocks/tunnel' + autoload :Listener, 'shadowsocks/listener' +end diff --git a/lib/shadowsocks/cli.rb b/lib/shadowsocks/cli.rb new file mode 100644 index 0000000..dfbf59c --- /dev/null +++ b/lib/shadowsocks/cli.rb @@ -0,0 +1,51 @@ +require 'optparse' +require 'pp' + +require File.expand_path('../version', __FILE__) + +module Shadowsocks + class Cli + include ::Shadowsocks::Table + + attr_accessor :side, :args, :config, :table + + def initialize(options) + @side = options[:side] + @config = options[:config] + @table = get_table(config.password) + end + + def run + case side + when :local + EventMachine::run { + Signal.trap("INT") { EventMachine.stop } + Signal.trap("TERM") { EventMachine.stop } + + puts "*** Local side is up, port:#{config.local_port}" + puts "*** Hit Ctrl+c to stop" + EventMachine::start_server "0.0.0.0", config.local_port, Shadowsocks::Local::LocalListener, &method(:initialize_connection) + } + when :server + EventMachine::run { + Signal.trap("INT") { EventMachine.stop } + Signal.trap("TERM") { EventMachine.stop } + + puts "*** Server side is up, port:#{config.server_port}" + puts "*** Hit Ctrl+c to stop" + + EventMachine::start_server "0.0.0.0", config.server_port, Shadowsocks::Server::ServerListener, &method(:initialize_connection) + } + end + end + + private + + def initialize_connection connection + connection.config = @config + connection.table = @table + connection.pending_connect_timeout = @config.timeout + end + + end +end diff --git a/lib/shadowsocks/config.rb b/lib/shadowsocks/config.rb new file mode 100644 index 0000000..b378740 --- /dev/null +++ b/lib/shadowsocks/config.rb @@ -0,0 +1,50 @@ +require 'json' + +module Shadowsocks + class Config + attr_reader :args, :server, :server_port, :local_port, :password, :timeout, :config_path + + def initialize(_args) + @args = _args || [] + + parse_args + read_config + end + + def read_config + @config_path = File.expand_path('../..', File.dirname(__FILE__)) + '/config.json' unless @config_file + cfg_file = File.open @config_path + json = JSON.parse cfg_file.read + cfg_file.close + + @server = json["server"] if @server.nil? + @password = json["password"] if @password.nil? + @server_port = json["server_port"].to_i if @server_port.nil? + @local_port = json["local_port"].to_i if @local_port.nil? + @timeout = json["timeout"].to_i if @timeout.nil? + end + + private + + def parse_args + opt_parser = OptionParser.new do |opts| + opts.banner = "Usage: ss-server [options]" + + opts.separator "" + opts.separator "Specific options:" + + opts.on("-s", "--server ADDR", "Remote server, IP address or domain") { |c| @server = c } + opts.on("-k", "--password PASSWORD", "Password, should be same in client and server sides") { |c| @password = c } + opts.on("-c", "--config PATH", "config.json path") { |c| @config_path = c } + opts.on("-p", "--port PORT", Integer, "Remote server port") { |c| @server_port = c } + opts.on("-l", "--local_port PORT", Integer,"Local client port") { |c| @local_port = c } + opts.on("-t", "--timeout NUMBER", Integer, "connection timeout") { |c| @timeout = c } + + opts.on_tail("-v", "--version", "Show shadowsocks gem version") { puts Shadowsocks::VERSION; exit } + opts.on_tail("-h", "--help", "Show this message") { puts opts; exit } + end + + opt_parser.parse!(args) + end + end +end diff --git a/lib/shadowsocks/listener.rb b/lib/shadowsocks/listener.rb new file mode 100644 index 0000000..6114549 --- /dev/null +++ b/lib/shadowsocks/listener.rb @@ -0,0 +1,58 @@ +module Shadowsocks + class Listener < EventMachine::Connection + include ::Shadowsocks::Table + + attr_accessor :stage, :remote_addr, :remote_port, :addr_to_send, :cached_pieces, + :header_length, :connector, :config, :table + + def receive_data data + data_handler data + end + + def post_init + @stage = 0 + @cached_pieces = [] + puts "A client has connected..." + end + + def unbind + puts "A client has left..." + connection_cleanup + end + + private + + def connection_cleanup + connector.close_connection if connector + self.close_connection + end + + def resolve_addrtype data + case @addrtype + when "\x01" + ip_address data + when "\x03" + domain_address data + else + warn "unsupported addrtype: " + @addrtype.unpack('c')[0].to_s + connection_cleanup + end + end + + def domain_address data + @remote_addr = data[2, @addr_len] + @remote_port = data[2 + @addr_len, 2].unpack('s>')[0] + @header_length = 2 + @addr_len + 2 + end + + def ip_address data + @remote_addr = inet_ntoa data[1..4] + @remote_port = data[5, 2].unpack('s>')[0] + @header_length = 7 + end + + def inet_ntoa n + n.unpack("C*").join "." + end + end +end diff --git a/lib/shadowsocks/local.rb b/lib/shadowsocks/local.rb new file mode 100644 index 0000000..3c36430 --- /dev/null +++ b/lib/shadowsocks/local.rb @@ -0,0 +1,79 @@ +module Shadowsocks + module Local + class ServerConnector < ::Shadowsocks::Tunnel + def post_init + p "connecting #{server.remote_addr[3..-1]} via #{server.config.server}" + addr_to_send = server.addr_to_send.clone + + send_data encrypt(table[:encrypt_table], addr_to_send) + server.cached_pieces.each { |piece| send_data encrypt(table[:encrypt_table], piece) } + server.cached_pieces = [] + + server.stage = 5 + end + + def receive_data data + server.send_data encrypt(table[:decrypt_table], data) + end + end + + class LocalListener < ::Shadowsocks::Listener + private + + def data_handler data + case stage + when 0 + send_data "\x05\x00" + @stage = 1 + when 1 + fireup_tunnel data + when 4 + cached_pieces.push data + when 5 + connector.send_data(encrypt(table[:encrypt_table], data)) and return + end + end + + def fireup_tunnel(data) + begin + unless data[1] == "\x01" + send_data "\x05\x07\x00\x01" + connection_cleanup and return + end + + @addr_to_send = data[3] + + resolve_addrtype data + + send_data "\x05\x00\x00\x01\x00\x00\x00\x00" + [config.server_port].pack('s>') + + @stage = 4 + @connector = EventMachine.connect config.server, config.server_port, ServerConnector, self, @table + + if data.size > header_length + cached_pieces.push data[header_length, data.size] + end + rescue Exception => e + warn e + connection_cleanup + end + end + + def resolve_addrtype data + @addrtype = data[3] + super + end + + def domain_address data + @addr_len = data[4].unpack('c')[0] + @addr_to_send += data[4..5 + @addr_len + 2] + super + end + + def ip_address data + @addr_to_send += data[4..9] + super + end + end + end +end diff --git a/lib/shadowsocks/server.rb b/lib/shadowsocks/server.rb new file mode 100644 index 0000000..bc69de8 --- /dev/null +++ b/lib/shadowsocks/server.rb @@ -0,0 +1,62 @@ +module Shadowsocks + module Server + class RequestConnector < ::Shadowsocks::Tunnel + def post_init + p "connecting #{server.remote_addr} via #{server.config.server}" + + server.cached_pieces.each { |piece| send_data piece } + server.cached_pieces = nil + + server.stage = 5 + end + + def receive_data data + server.send_data encrypt(table[:encrypt_table], data) + end + end + + class ServerListener < ::Shadowsocks::Listener + private + + def data_handler data + data = encrypt table[:decrypt_table], data + case stage + when 0 + fireup_tunnel data + when 4 + cached_pieces.push data + when 5 + connector.send_data(data) and return + end + end + + def fireup_tunnel data + begin + resolve_addrtype data + + @stage = 4 + + if data.size > header_length + cached_pieces.push data[header_length, data.size] + end + + @connector = EventMachine.connect @remote_addr, @remote_port, RequestConnector, self, table + rescue Exception => e + warn e + connection_cleanup + end + end + + def resolve_addrtype data + @addrtype = data[0] + super + end + + def domain_address data + @addr_len = data[1].unpack('c')[0] + super + end + end + end +end + diff --git a/lib/shadowsocks/table.rb b/lib/shadowsocks/table.rb new file mode 100644 index 0000000..a2f15ca --- /dev/null +++ b/lib/shadowsocks/table.rb @@ -0,0 +1,84 @@ +require "digest" +require 'ffi' + +module Ext + def self.binary_path + path = '' + %w( so bundle dll ).each do |ext| + path = File.expand_path('..', File.dirname(__FILE__)) + "/encrypt.#{ext}" + break if File.exists? path + end + + path + end + + extend FFI::Library + ffi_lib binary_path + attach_function "encrypt", [:pointer, :pointer, :int], :pointer +end + +module Shadowsocks + module Table + include Ext + + def get_table key + table = Array.new(256, 0) + decrypt_table = Array.new(256, 0) + + a = Digest::MD5.digest(key).unpack('Q<')[0] + i = 0 + + while i < 256 + table[i] = i + i += 1 + end + i = 1 + + while i < 1024 + table = merge_sort(table, lambda { |x, y| + a % (x + i) - a % (y + i) + }) + i += 1 + end + i = 0 + while i < 256 + decrypt_table[table[i]] = i + i += 1 + end + { encrypt_table: table, decrypt_table: decrypt_table } + end + + def encrypt (table, buf) + table_ptr = FFI::MemoryPointer.new(:int, table.length) + table_ptr.put_array_of_int32(0, table) + + buf_ptr = FFI::MemoryPointer.new(:string, buf.length) + buf_ptr.put_bytes(0, buf) + + r = Ext.encrypt(table_ptr, buf_ptr, buf.length).get_bytes(0, buf.length) + table_ptr.free + buf_ptr.free + r + end + + def merge (left, right, comparison) + result = [] + while (left.length > 0) and (right.length > 0) + if comparison.call(left[0], right[0]) <= 0 + result.push left.shift() + else + result.push right.shift() + end + end + result.push left.shift() while left.length > 0 + result.push right.shift() while right.length > 0 + result + end + + def merge_sort (array, comparison) + return array if array.size < 2 + middle = (array.size / 2).ceil + merge(merge_sort(array.slice(0, middle), comparison), merge_sort(array.slice(middle .. array.size), comparison), comparison) + end + end +end diff --git a/lib/shadowsocks/tunnel.rb b/lib/shadowsocks/tunnel.rb new file mode 100644 index 0000000..ff1c453 --- /dev/null +++ b/lib/shadowsocks/tunnel.rb @@ -0,0 +1,19 @@ +module Shadowsocks + class Tunnel < EventMachine::Connection + attr_accessor :server, :table + + def initialize server, table + @server = server + @table = table + super + end + + def unbind + server.close_connection_after_writing + end + + def encrypt table, data + server.encrypt table, data + end + end +end diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb new file mode 100644 index 0000000..3c2dd25 --- /dev/null +++ b/lib/shadowsocks/version.rb @@ -0,0 +1,3 @@ +module Shadowsocks + VERSION = '0.1' +end diff --git a/local.rb b/local.rb deleted file mode 100644 index 456782b..0000000 --- a/local.rb +++ /dev/null @@ -1,170 +0,0 @@ -#!/usr/bin/ruby - -# Copyright (c) 2012 clowwindy -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -require 'rubygems' -require 'eventmachine' -require 'json' -require './encrypt' - -cfg_file = File.open('config.json') -config = JSON.parse(cfg_file.read) -cfg_file.close - -key = config['password'] - -$server = config['server'] -$remote_port = config['server_port'].to_i -$port = config['local_port'].to_i - -$encrypt_table, $decrypt_table = get_table(key) - -module LocalServer - class LocalConnector < EventMachine::Connection - def initialize server - @server = server - super - end - - def post_init - p "connecting #{@server.remote_addr[3..-1]} via #{$server}" - addr_to_send = @server.addr_to_send.clone - send_data encrypt($encrypt_table, addr_to_send) - - for piece in @server.cached_pieces - send_data encrypt($encrypt_table, piece) - end - @server.cached_pieces = [] - - @server.stage = 5 - end - - def receive_data data - @server.send_data encrypt($decrypt_table, data) - end - - def unbind - @server.close_connection_after_writing - end - end - - @@connected_clients = Array.new - - attr_accessor :stage, :remote_addr, :addr_to_send, :cached_pieces - - def initialize - super - end - - def receive_data data - data_handler data - end - - def post_init - @stage = 0 - @@connected_clients.push(self) - @cached_pieces = [] - puts "A client has connected..." - end - - def unbind - @@connected_clients.delete(self) - puts "A client has left..." - end - - private - - def data_handler data - if @stage == 5 - @connector.send_data(encrypt($encrypt_table, data)) and return - elsif @stage == 0 - send_data "\x05\x00" - @stage = 1 - elsif @stage == 1 - begin - unless data[1] == "\x01" - send_data "\x05\x07\x00\x01" - self.close_connection and return - end - - @addr_to_send = data[3] - - resolve_addrtype(data) - - send_data "\x05\x00\x00\x01\x00\x00\x00\x00" + [$remote_port].pack('s>') - - @stage = 4 - @connector = EventMachine.connect $server, $remote_port, LocalConnector, self - - if data.size > @header_length - @cached_pieces.push data[@header_length, data.size] - end - rescue Exception => e - warn e - @connector.close_connection unless @connector.nil? - close_connection - end - elsif @stage == 4 - @cached_pieces.push data - end - end - - def resolve_addrtype(data) - addrtype = data[3] - if addrtype == "\x01" - ip_address(data) - elsif addrtype == "\x03" - domain_adress(data) - else - warn "unsupported addrtype: " + addrtype.unpack('c')[0].to_s - close_connection and return - end - end - - def domain_adress(data) - addr_len = data[4].unpack('c')[0] - @addr_to_send += data[4..5 + addr_len + 2] - @remote_addr = data[2, addr_len] - @remote_port = data[2 + addr_len, 2].unpack('s>')[0] - @header_length = 2 + addr_len + 2 - end - - def ip_address(data) - @addr_to_send += data[4..9] - @remote_addr = inet_ntoa data[1..4] - @remote_port = data[5, 2].unpack('s>')[0] - @header_length = 7 - end - - def inet_ntoa(n) - n.unpack("C*").join "." - end - -end - -EventMachine::run { - Signal.trap("INT") { EventMachine.stop } - Signal.trap("TERM") { EventMachine.stop } - - puts "*** Local side is up, port:#{$port}" - puts "*** Hit Ctrl+c to stop" - EventMachine::start_server "0.0.0.0", $port, LocalServer -} diff --git a/merge_sort.rb b/merge_sort.rb deleted file mode 100644 index e06da1a..0000000 --- a/merge_sort.rb +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/ruby - -# Copyright (c) 2012 clowwindy -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -def merge (left, right, comparison) - result = [] - while (left.length > 0) and (right.length > 0) - if comparison.call(left[0], right[0]) <= 0 - result.push left.shift() - else - result.push right.shift() - end - end - result.push left.shift() while left.length > 0 - result.push right.shift() while right.length > 0 - result -end - -def merge_sort (array, comparison) - return array if array.size < 2 - middle = (array.size / 2).ceil - merge(merge_sort(array.slice(0, middle), comparison), merge_sort(array.slice(middle .. array.size), comparison), comparison) -end diff --git a/server.rb b/server.rb deleted file mode 100644 index 732d5da..0000000 --- a/server.rb +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/ruby - -# Copyright (c) 2012 clowwindy -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -require 'rubygems' -require 'eventmachine' -require 'json' -require './encrypt' - -cfg_file = File.open('config.json') -config = JSON.parse(cfg_file.read) -cfg_file.close - -key = config['password'] - -$remote_port = config['server_port'].to_i - -$encrypt_table, $decrypt_table = get_table(key) - -def inet_ntoa(n) - n.unpack("C*").join "." -end - -module LocalServer - class LocalConnector < EventMachine::Connection - def initialize server - @server = server - super - end - - def post_init - p "connecting #{@server.remote_addr} via #{@server.server_using}" - - for piece in @server.cached_pieces - send_data piece - end - @server.cached_pieces = nil - - @server.stage = 5 - end - - def receive_data data - @server.send_data encrypt($encrypt_table, data) - end - - def unbind - @server.close_connection_after_writing - end - end - - attr_accessor :remote_addr - attr_accessor :remote_port - attr_accessor :stage - attr_accessor :addr_to_send - attr_accessor :server_using - attr_accessor :cached_pieces - - def post_init - puts "local connected" - @stage = 0 - @header_length = 0 - @remote = 0 - @cached_pieces = [] - @remote_addr = nil - @remote_port = nil - @connector = nil - @addr_to_send = "" - @server_using = $server - end - - def receive_data data - data = encrypt $decrypt_table, data - if @stage == 5 - @connector.send_data data - return - end - if @stage == 0 - begin - addr_len = 0 - addrtype = data[0] - if addrtype == "\x03" - addr_len = data[1].unpack('c')[0] - elsif addrtype != "\x01" - warn "unsupported addrtype: " + addrtype.unpack('c')[0].to_s - close_connection - return - end - if addrtype == "\x01" - @remote_addr = inet_ntoa data[1..4] - @remote_port = data[5, 2].unpack('s>')[0] - @header_length = 7 - else - @remote_addr = data[2, addr_len] - @remote_port = data[2 + addr_len, 2].unpack('s>')[0] - @header_length = 2 + addr_len + 2 - end - @stage = 4 - if data.size > @header_length - @cached_pieces.push data[@header_length, data.size] - end - - @connector = EventMachine.connect @remote_addr, @remote_port, LocalConnector, self - rescue Exception => e - warn e - if @connector != nil - @connector.close_connection - end - close_connection - end - elsif @stage == 4 - @cached_pieces.push data - end - - end - - def unbind - if @connector != nil - @connector.close_connection_after_writing - end - - end -end - -EventMachine::run { - EventMachine::start_server "0.0.0.0", $remote_port, LocalServer -} diff --git a/shadowsocks.gemspec b/shadowsocks.gemspec new file mode 100644 index 0000000..e0573aa --- /dev/null +++ b/shadowsocks.gemspec @@ -0,0 +1,25 @@ +require File.expand_path('../lib/shadowsocks/version', __FILE__) + +Gem::Specification.new do |s| + s.name = 'shadowsocks' + s.version = Shadowsocks::VERSION + s.date = '2013-09-26' + s.summary = "ruby version of shadowsocks" + s.description = "Fuck GFW" + s.authors = ["Sen"] + s.email = 'sen9ob@gmail.com' + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- test/{functional,unit}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.homepage = 'http://rubygems.org/gems/shadowsocks' + s.license = 'MIT' + s.extensions = %w[ext/encrypt/extconf.rb] + + s.add_dependency "eventmachine", "~> 1.0.3" + s.add_dependency "json", "~> 1.8.0" + s.add_dependency "ffi", "~> 1.9.0" + + s.add_development_dependency "rake-compiler", "~> 0.9.1" + s.add_development_dependency "mocha", "~> 0.14.0" + s.add_development_dependency "rake" +end diff --git a/tasks/compile.rake b/tasks/compile.rake new file mode 100644 index 0000000..c38bf4b --- /dev/null +++ b/tasks/compile.rake @@ -0,0 +1,9 @@ +require 'rake/extensiontask' + +def gemspec + @clean_gemspec ||= eval(File.read(File.expand_path('../../shadowsocks.gemspec', __FILE__))) +end + +Rake::ExtensionTask.new('encrypt', gemspec) do |ext| + ext.ext_dir = 'ext/encrypt' +end diff --git a/tasks/dev.rake b/tasks/dev.rake new file mode 100644 index 0000000..7132f31 --- /dev/null +++ b/tasks/dev.rake @@ -0,0 +1,7 @@ +task :gem do + `gem build ./shadowsocks.gemspec` +end + +task :install do + `gem install ./shadowsocks-#{Shadowsocks::VERSION}.gem` +end diff --git a/test.rb b/test.rb deleted file mode 100644 index 44baaba..0000000 --- a/test.rb +++ /dev/null @@ -1,15 +0,0 @@ -require "./encrypt" - -target = [ - [ 60, 53, 84, 138, 217, 94, 88, 23, 39, 242, 219, 35, 12, 157, 165, 181, 255, 143, 83, 247, 162, 16, 31, 209, 190, 171, 115, 65, 38, 41, 21, 245, 236, 46, 121, 62, 166, 233, 44, 154, 153, 145, 230, 49, 128, 216, 173, 29, 241, 119, 64, 229, 194, 103, 131, 110, 26, 197, 218, 59, 204, 56, 27, 34, 141, 221, 149, 239, 192, 195, 24, 155, 170, 183, 11, 254, 213, 37, 137, 226, 75, 203, 55, 19, 72, 248, 22, 129, 33, 175, 178, 10, 198, 71, 77, 36, 113, 167, 48, 2, 117, 140, 142, 66, 199, 232, 243, 32, 123, 54, 51, 82, 57, 177, 87, 251, 150, 196, 133, 5, 253, 130, 8, 184, 14, 152, 231, 3, 186, 159, 76, 89, 228, 205, 156, 96, 163, 146, 18, 91, 132, 85, 80, 109, 172, 176, 105, 13, 50, 235, 127, 0, 189, 95, 98, 136, 250, 200, 108, 179, 211, 214, 106, 168, 78, 79, 74, 210, 30, 73, 201, 151, 208, 114, 101, 174, 92, 52, 120, 240, 15, 169, 220, 182, 81, 224, 43, 185, 40, 99, 180, 17, 212, 158, 42, 90, 9, 191, 45, 6, 25, 4, 222, 67, 126, 1, 116, 124, 206, 69, 61, 7, 68, 97, 202, 63, 244, 20, 28, 58, 93, 134, 104, 144, 227, 147, 102, 118, 135, 148, 47, 238, 86, 112, 122, 70, 107, 215, 100, 139, 223, 225, 164, 237, 111, 125, 207, 160, 187, 246, 234, 161, 188, 193, 249, 252 ], - [ 151, 205, 99, 127, 201, 119, 199, 211, 122, 196, 91, 74, 12, 147, 124, 180, 21, 191, 138, 83, 217, 30, 86, 7, 70, 200, 56, 62, 218, 47, 168, 22, 107, 88, 63, 11, 95, 77, 28, 8, 188, 29, 194, 186, 38, 198, 33, 230, 98, 43, 148, 110, 177, 1, 109, 82, 61, 112, 219, 59, 0, 210, 35, 215, 50, 27, 103, 203, 212, 209, 235, 93, 84, 169, 166, 80, 130, 94, 164, 165, 142, 184, 111, 18, 2, 141, 232, 114, 6, 131, 195, 139, 176, 220, 5, 153, 135, 213, 154, 189, 238, 174, 226, 53, 222, 146, 162, 236, 158, 143, 55, 244, 233, 96, 173, 26, 206, 100, 227, 49, 178, 34, 234, 108, 207, 245, 204, 150, 44, 87, 121, 54, 140, 118, 221, 228, 155, 78, 3, 239, 101, 64, 102, 17, 223, 41, 137, 225, 229, 66, 116, 171, 125, 40, 39, 71, 134, 13, 193, 129, 247, 251, 20, 136, 242, 14, 36, 97, 163, 181, 72, 25, 144, 46, 175, 89, 145, 113, 90, 159, 190, 15, 183, 73, 123, 187, 128, 248, 252, 152, 24, 197, 68, 253, 52, 69, 117, 57, 92, 104, 157, 170, 214, 81, 60, 133, 208, 246, 172, 23, 167, 160, 192, 76, 161, 237, 45, 4, 58, 10, 182, 65, 202, 240, 185, 241, 79, 224, 132, 51, 42, 126, 105, 37, 250, 149, 32, 243, 231, 67, 179, 48, 9, 106, 216, 31, 249, 19, 85, 254, 156, 115, 255, 120, 75, 16 ] -] -tables = get_table("foobar!") -p tables -i = 0 - -while i < 256 - fail unless tables[0][i] == target[0][i] - fail unless tables[1][i] == target[1][i] - i += 1 -end From e51eede204fad409075d221b4c875aacc0b933d2 Mon Sep 17 00:00:00 2001 From: Sen Date: Tue, 1 Oct 2013 20:19:11 +0800 Subject: [PATCH 08/48] fix a config file path bug --- lib/shadowsocks/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shadowsocks/config.rb b/lib/shadowsocks/config.rb index b378740..dd7c479 100644 --- a/lib/shadowsocks/config.rb +++ b/lib/shadowsocks/config.rb @@ -12,7 +12,7 @@ def initialize(_args) end def read_config - @config_path = File.expand_path('../..', File.dirname(__FILE__)) + '/config.json' unless @config_file + @config_path = File.expand_path('../..', File.dirname(__FILE__)) + '/config.json' unless @config_path cfg_file = File.open @config_path json = JSON.parse cfg_file.read cfg_file.close From 38771c2c646c86660763946756892cffa64657b0 Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 2 Oct 2013 12:57:39 +0800 Subject: [PATCH 09/48] update read me --- README.md | 70 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 256a82d..f8d892d 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,66 @@ shadowsocks-ruby ================ -a Ruby EventMachine port of shadowsocks-nodejs (not stable yet). use shadowsocks-nodejs instead +Current version: 0.2 -install +shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks). -``` ruby -gem install eventmachine -gem install ffi -rake -``` +Usage +----------- -server side +First, make sure you have Ruby 2.0. -``` ruby -nohup ruby server.rb > log & -``` + $ ruby -v + ruby 2.0.0p247 -then enjoy! +Install Shadowsocks. + + gem install shadowsocks + +Create a file named `config.json`, with the following content. + + { + "server":"my_server_ip", + "server_port":8388, + "local_port":1080, + "password":"barfoo!", + "timeout":600 + } + +Explanation of the fields: + + server your server IP (IPv4/IPv6), notice that your server will listen to this IP + server_port server port + local_port local port + password a password used to encrypt transfer + timeout in seconds + +`cd` into the directory of `config.json`. Run `ss-server` on your server. To run it in the background, run +`nohup ss-server -c ./config.json > log &`. + +On your client machine, `cd` into the directory of `config.json` also, run `ss-local -c config.json`. + +Change the proxy settings in your browser to + + protocol: socks5 + hostname: 127.0.0.1 + port: your local_port + +It's recommended to use shadowsocks with AutoProxy or Proxy SwitchySharp. + +Command line args +------------------ + +You can use args to override settings from `config.json`. + + ss-local -s server_name -p server_port -l local_port -k password + ss-server -p server_port -k password + ss-server -c /etc/shadowsocks/config.json + +License +------- +MIT + +Bugs and Issues +---------------- +Please visit [issue tracker](https://github.com/Sen/shadowsocks-ruby/issues?state=open) From 27c3796e51202ec106d2127bb4cbe89def123730 Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 2 Oct 2013 12:58:50 +0800 Subject: [PATCH 10/48] update gem spec --- shadowsocks.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shadowsocks.gemspec b/shadowsocks.gemspec index e0573aa..d55898b 100644 --- a/shadowsocks.gemspec +++ b/shadowsocks.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.version = Shadowsocks::VERSION s.date = '2013-09-26' s.summary = "ruby version of shadowsocks" - s.description = "Fuck GFW" + s.description = "shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls." s.authors = ["Sen"] s.email = 'sen9ob@gmail.com' s.files = `git ls-files`.split("\n") From 499eb8c63adceb866bf963de51bfca48cfd59f04 Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 2 Oct 2013 12:59:48 +0800 Subject: [PATCH 11/48] methods parameters --- lib/shadowsocks/config.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/shadowsocks/config.rb b/lib/shadowsocks/config.rb index dd7c479..3b97a30 100644 --- a/lib/shadowsocks/config.rb +++ b/lib/shadowsocks/config.rb @@ -2,7 +2,7 @@ module Shadowsocks class Config - attr_reader :args, :server, :server_port, :local_port, :password, :timeout, :config_path + attr_reader :args, :server, :server_port, :local_port, :password, :timeout, :method, :config_path def initialize(_args) @args = _args || [] @@ -37,7 +37,8 @@ def parse_args opts.on("-k", "--password PASSWORD", "Password, should be same in client and server sides") { |c| @password = c } opts.on("-c", "--config PATH", "config.json path") { |c| @config_path = c } opts.on("-p", "--port PORT", Integer, "Remote server port") { |c| @server_port = c } - opts.on("-l", "--local_port PORT", Integer,"Local client port") { |c| @local_port = c } + opts.on("-l", "--local_port PORT", Integer, "Local client port") { |c| @local_port = c } + opts.on("-m", "--method METHOD", Integer, "Encryption method") { |c| @method = c } opts.on("-t", "--timeout NUMBER", Integer, "connection timeout") { |c| @timeout = c } opts.on_tail("-v", "--version", "Show shadowsocks gem version") { puts Shadowsocks::VERSION; exit } From f4c7fd2e03caa2f6eb19e49cdb22c24f6c44abda Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 2 Oct 2013 13:01:16 +0800 Subject: [PATCH 12/48] method in config.json --- config.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index 8353b2d..c699287 100644 --- a/config.json +++ b/config.json @@ -2,6 +2,7 @@ "server":"127.0.0.1", "server_port":8388, "local_port":1080, - "password":"foobar!", - "timeout":600 + "password":"barfoo!", + "timeout":600, + "method":"table" } From b49ece1b4adb8fff210c8829e92bf2d52e7c6e73 Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 2 Oct 2013 13:01:38 +0800 Subject: [PATCH 13/48] method file --- lib/shadowsocks/method.rb | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 lib/shadowsocks/method.rb diff --git a/lib/shadowsocks/method.rb b/lib/shadowsocks/method.rb new file mode 100644 index 0000000..d57bbd4 --- /dev/null +++ b/lib/shadowsocks/method.rb @@ -0,0 +1,50 @@ +require 'openssl' + +module Shadowsocks + class Method + include ::Shadowsocks::Table + + attr_accessor :encrypt_table, :decrypt_table, :password, :method + + def initialize(options = {}) + @password = options[:password] + @method = options[:method] + + unless %w(talbe bf-cfb aes-256-cfb des-cfb).include?(method) + raise "Encrypt method not support" + end + + if method == 'table' + generate_table + end + end + + def encrypt buf + case method + when 'table' + calculate encrypt_table, buf + when 'bf-cfb' + when 'aes-256-cfb' + when 'des-cfb' + cipher = OpenSSL::Cipher.new method.upcase + + end + end + + def decrypt buf + case method + when 'table' + calculate decrypt_table, buf + when 'bf-cfb' + when 'aes-256-cfb' + when 'des-cfb' + end + end + + private + + def generate_table + @encrypt_table, @decrypt_table = get_table password + end + end +end From c0e92782a8acd5977c6cc424c44654d86c4abb17 Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 2 Oct 2013 13:02:30 +0800 Subject: [PATCH 14/48] common config.json --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 8353b2d..a4cdabb 100644 --- a/config.json +++ b/config.json @@ -2,6 +2,6 @@ "server":"127.0.0.1", "server_port":8388, "local_port":1080, - "password":"foobar!", + "password":"barfoo!", "timeout":600 } From ccb730ee2fba4d9971e0c5ae82c205f3547307d3 Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 2 Oct 2013 13:03:15 +0800 Subject: [PATCH 15/48] bump version 0.2 --- lib/shadowsocks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb index 3c2dd25..564df31 100644 --- a/lib/shadowsocks/version.rb +++ b/lib/shadowsocks/version.rb @@ -1,3 +1,3 @@ module Shadowsocks - VERSION = '0.1' + VERSION = '0.2' end From d53ef41fcffcec035113f0f24b662321374d5bc5 Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 2 Oct 2013 13:29:10 +0800 Subject: [PATCH 16/48] code climate --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f8d892d..5e1bb51 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ shadowsocks-ruby ================ +[![Code Climate](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/badges/9dd6c11b6a17c3a55631/gpa.png)](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/feed) + Current version: 0.2 shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks). From 4c7f212ba072bba4c94331781878a628a40ca1da Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 30 Oct 2013 10:49:08 +0800 Subject: [PATCH 17/48] BackpressureLevel for memory usage control --- lib/shadowsocks.rb | 11 ++++++----- lib/shadowsocks/connection.rb | 20 ++++++++++++++++++++ lib/shadowsocks/listener.rb | 7 ++++++- lib/shadowsocks/local.rb | 1 + lib/shadowsocks/server.rb | 1 + lib/shadowsocks/tunnel.rb | 6 +++++- 6 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 lib/shadowsocks/connection.rb diff --git a/lib/shadowsocks.rb b/lib/shadowsocks.rb index ffa5468..0e4de5c 100644 --- a/lib/shadowsocks.rb +++ b/lib/shadowsocks.rb @@ -1,9 +1,10 @@ require 'eventmachine' module Shadowsocks - autoload :Server, 'shadowsocks/server' - autoload :Local, 'shadowsocks/local' - autoload :Table, 'shadowsocks/table' - autoload :Tunnel, 'shadowsocks/tunnel' - autoload :Listener, 'shadowsocks/listener' + autoload :Connection, 'shadowsocks/connection' + autoload :Server, 'shadowsocks/server' + autoload :Local, 'shadowsocks/local' + autoload :Table, 'shadowsocks/table' + autoload :Tunnel, 'shadowsocks/tunnel' + autoload :Listener, 'shadowsocks/listener' end diff --git a/lib/shadowsocks/connection.rb b/lib/shadowsocks/connection.rb new file mode 100644 index 0000000..25c91be --- /dev/null +++ b/lib/shadowsocks/connection.rb @@ -0,0 +1,20 @@ +module Shadowsocks + class Connection < EventMachine::Connection + BackpressureLevel = 2097152 # 2m + + private + + def over_pressure? + remote.get_outbound_data_size > BackpressureLevel + end + + def outbound_checker + if over_pressure? + pause unless paused? + EM.add_timer(1) { outbound_checker } + else + resume if paused? + end + end + end +end diff --git a/lib/shadowsocks/listener.rb b/lib/shadowsocks/listener.rb index 6114549..ab777d1 100644 --- a/lib/shadowsocks/listener.rb +++ b/lib/shadowsocks/listener.rb @@ -1,5 +1,5 @@ module Shadowsocks - class Listener < EventMachine::Connection + class Listener < ::Shadowsocks::Connection include ::Shadowsocks::Table attr_accessor :stage, :remote_addr, :remote_port, :addr_to_send, :cached_pieces, @@ -7,6 +7,7 @@ class Listener < EventMachine::Connection def receive_data data data_handler data + outbound_checker if connector end def post_init @@ -20,6 +21,10 @@ def unbind connection_cleanup end + def remote + connector + end + private def connection_cleanup diff --git a/lib/shadowsocks/local.rb b/lib/shadowsocks/local.rb index 3c36430..b040f8e 100644 --- a/lib/shadowsocks/local.rb +++ b/lib/shadowsocks/local.rb @@ -14,6 +14,7 @@ def post_init def receive_data data server.send_data encrypt(table[:decrypt_table], data) + outbound_checker end end diff --git a/lib/shadowsocks/server.rb b/lib/shadowsocks/server.rb index bc69de8..a8b05de 100644 --- a/lib/shadowsocks/server.rb +++ b/lib/shadowsocks/server.rb @@ -12,6 +12,7 @@ def post_init def receive_data data server.send_data encrypt(table[:encrypt_table], data) + outbound_checker end end diff --git a/lib/shadowsocks/tunnel.rb b/lib/shadowsocks/tunnel.rb index ff1c453..e8eec74 100644 --- a/lib/shadowsocks/tunnel.rb +++ b/lib/shadowsocks/tunnel.rb @@ -1,5 +1,5 @@ module Shadowsocks - class Tunnel < EventMachine::Connection + class Tunnel < ::Shadowsocks::Connection attr_accessor :server, :table def initialize server, table @@ -12,6 +12,10 @@ def unbind server.close_connection_after_writing end + def remote + server + end + def encrypt table, data server.encrypt table, data end From cd3b217242ede3a40b89d6fb75d91d715ab8a214 Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 30 Oct 2013 10:49:57 +0800 Subject: [PATCH 18/48] set default timeout to 60s --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index a4cdabb..f4d7ef6 100644 --- a/config.json +++ b/config.json @@ -3,5 +3,5 @@ "server_port":8388, "local_port":1080, "password":"barfoo!", - "timeout":600 + "timeout":60 } From e233a00866206123f5b9953a0b248b35dceaf83a Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 30 Oct 2013 10:53:04 +0800 Subject: [PATCH 19/48] bump version to 0.3 --- lib/shadowsocks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb index 564df31..6d3da37 100644 --- a/lib/shadowsocks/version.rb +++ b/lib/shadowsocks/version.rb @@ -1,3 +1,3 @@ module Shadowsocks - VERSION = '0.2' + VERSION = '0.3' end From 04c99c558d551fffde8ad56a045473317f933d3b Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 30 Oct 2013 11:11:10 +0800 Subject: [PATCH 20/48] fix readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e1bb51..e8ded5b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ shadowsocks-ruby [![Code Climate](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/badges/9dd6c11b6a17c3a55631/gpa.png)](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/feed) -Current version: 0.2 +Current version: 0.3 shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks). From 5f7b65ea93a3af95b536ce5c756c85092298e7e3 Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 10 Nov 2013 01:38:22 +0800 Subject: [PATCH 21/48] add more encrypt methods --- config.json | 4 +- lib/shadowsocks.rb | 1 + lib/shadowsocks/cli.rb | 18 ++++- lib/shadowsocks/config.rb | 1 + lib/shadowsocks/crypto.rb | 133 ++++++++++++++++++++++++++++++++++++ lib/shadowsocks/listener.rb | 12 +++- lib/shadowsocks/local.rb | 10 +-- lib/shadowsocks/method.rb | 50 -------------- lib/shadowsocks/server.rb | 6 +- lib/shadowsocks/table.rb | 4 +- lib/shadowsocks/tunnel.rb | 16 +++-- 11 files changed, 182 insertions(+), 73 deletions(-) create mode 100644 lib/shadowsocks/crypto.rb delete mode 100644 lib/shadowsocks/method.rb diff --git a/config.json b/config.json index c699287..e8e57e2 100644 --- a/config.json +++ b/config.json @@ -3,6 +3,6 @@ "server_port":8388, "local_port":1080, "password":"barfoo!", - "timeout":600, - "method":"table" + "timeout":60, + "method":"aes-256-cfb" } diff --git a/lib/shadowsocks.rb b/lib/shadowsocks.rb index ffa5468..ca5ffea 100644 --- a/lib/shadowsocks.rb +++ b/lib/shadowsocks.rb @@ -1,6 +1,7 @@ require 'eventmachine' module Shadowsocks + autoload :Crypto, 'shadowsocks/crypto' autoload :Server, 'shadowsocks/server' autoload :Local, 'shadowsocks/local' autoload :Table, 'shadowsocks/table' diff --git a/lib/shadowsocks/cli.rb b/lib/shadowsocks/cli.rb index dfbf59c..923d12d 100644 --- a/lib/shadowsocks/cli.rb +++ b/lib/shadowsocks/cli.rb @@ -7,12 +7,24 @@ module Shadowsocks class Cli include ::Shadowsocks::Table - attr_accessor :side, :args, :config, :table + attr_accessor :side, :args, :config def initialize(options) @side = options[:side] @config = options[:config] - @table = get_table(config.password) + + @method_options = { + method: config.method, + password: config.password + } + + if @config.method == 'table' + table = get_table(config.password) + @method_options.merge!( + encrypt_table: table[:encrypt], + decrypt_table: table[:decrypt] + ) + end end def run @@ -43,7 +55,7 @@ def run def initialize_connection connection connection.config = @config - connection.table = @table + connection.crypto = Shadowsocks::Crypto.new @method_options connection.pending_connect_timeout = @config.timeout end diff --git a/lib/shadowsocks/config.rb b/lib/shadowsocks/config.rb index 3b97a30..a085227 100644 --- a/lib/shadowsocks/config.rb +++ b/lib/shadowsocks/config.rb @@ -22,6 +22,7 @@ def read_config @server_port = json["server_port"].to_i if @server_port.nil? @local_port = json["local_port"].to_i if @local_port.nil? @timeout = json["timeout"].to_i if @timeout.nil? + @method = json["method"] if @method.nil? end private diff --git a/lib/shadowsocks/crypto.rb b/lib/shadowsocks/crypto.rb new file mode 100644 index 0000000..f851d89 --- /dev/null +++ b/lib/shadowsocks/crypto.rb @@ -0,0 +1,133 @@ +require 'securerandom' +require 'openssl' +require 'digest/md5' + +module Shadowsocks + class Crypto + include ::Shadowsocks::Table + + attr_accessor :encrypt_table, :decrypt_table, :password, :method, + :cipher, :bytes_to_key_results, :iv_sent + + def method_supported + case method + when 'aes-128-cfb' then [16, 16] + when 'aes-192-cfb' then [24, 16] + when 'aes-256-cfb' then [32, 16] + when 'bf-cfb' then [16, 8 ] + when 'camellia-128-cfb' then [16, 16] + when 'camellia-192-cfb' then [24, 16] + when 'camellia-256-cfb' then [32, 16] + when 'cast5-cfb' then [16, 8 ] + when 'des-cfb' then [8, 8 ] + when 'idea-cfb' then [16, 8 ] + when 'rc2-cfb' then [16, 8 ] + when 'rc4' then [16, 0 ] + when 'seed-cfb' then [16, 16] + end + end + alias_method :get_cipher_len, :method_supported + + def initialize(options = {}) + @password = options[:password] + @method = options[:method].downcase + @iv_sent = false + if method == 'table' + @encrypt_table = options[:encrypt_table] + @decrypt_table = options[:decrypt_table] + else + if method_supported.nil? + raise "Encrypt method not support" + end + end + + if method != 'table' + @cipher = get_cipher(1, SecureRandom.hex(32)) + end + end + + def encrypt buf + return buf if buf.length == 0 + if method == 'table' + translate @encrypt_table, buf + else + if iv_sent + @cipher.update(buf) + else + @iv_sent = true + @cipher_iv + @cipher.update(buf) + end + end + end + + def decrypt buf + return buf if buf.length == 0 + if method == 'table' + translate @decrypt_table, buf + else + if @decipher.nil? + decipher_iv_len = get_cipher_len[1] + decipher_iv = buf[0..decipher_iv_len ] + @iv = decipher_iv + @decipher = get_cipher(0, @iv) + buf = buf[decipher_iv_len..-1] + return buf if buf.length == 0 + end + @decipher.update(buf) + end + end + + private + + def iv_len + @cipher_iv.length + end + + def get_cipher(op, iv) + m = get_cipher_len + unless m.nil? + key, _iv = EVP_BytesToKey(m[0], m[1]) + + iv = _iv[0..m[1] - 1] + @iv = iv unless @iv + @cipher_iv = iv if op == 1 + + cipher = OpenSSL::Cipher.new method + + op == 1 ? cipher.encrypt : cipher.decrypt + + cipher.key = key + cipher.iv = @iv + cipher + end + end + + def EVP_BytesToKey key_len, iv_len + if bytes_to_key_results + return bytes_to_key_results + end + + m = [] + i = 0 + + len = key_len + iv_len + + code = password.unpack('H*').first + + while m.join.length < len do + data = if i > 0 + m[i - 1] + password + else + password + end + m.push Digest::MD5.digest data + i += 1 + end + ms = m.join + key = ms[0, key_len] + iv = ms[key_len, key_len + iv_len] + bytes_to_key_results = [key, iv] + bytes_to_key_results + end + end +end diff --git a/lib/shadowsocks/listener.rb b/lib/shadowsocks/listener.rb index 6114549..640dc39 100644 --- a/lib/shadowsocks/listener.rb +++ b/lib/shadowsocks/listener.rb @@ -1,9 +1,7 @@ module Shadowsocks class Listener < EventMachine::Connection - include ::Shadowsocks::Table - attr_accessor :stage, :remote_addr, :remote_port, :addr_to_send, :cached_pieces, - :header_length, :connector, :config, :table + :header_length, :connector, :config, :crypto def receive_data data data_handler data @@ -22,6 +20,14 @@ def unbind private + def encrypt(buf) + crypto.encrypt(buf) + end + + def decrypt(buf) + crypto.decrypt(buf) + end + def connection_cleanup connector.close_connection if connector self.close_connection diff --git a/lib/shadowsocks/local.rb b/lib/shadowsocks/local.rb index 3c36430..c2e85da 100644 --- a/lib/shadowsocks/local.rb +++ b/lib/shadowsocks/local.rb @@ -5,15 +5,15 @@ def post_init p "connecting #{server.remote_addr[3..-1]} via #{server.config.server}" addr_to_send = server.addr_to_send.clone - send_data encrypt(table[:encrypt_table], addr_to_send) - server.cached_pieces.each { |piece| send_data encrypt(table[:encrypt_table], piece) } + send_data encrypt(addr_to_send) + server.cached_pieces.each { |piece| send_data encrypt(piece) } server.cached_pieces = [] server.stage = 5 end def receive_data data - server.send_data encrypt(table[:decrypt_table], data) + server.send_data decrypt(data) end end @@ -30,7 +30,7 @@ def data_handler data when 4 cached_pieces.push data when 5 - connector.send_data(encrypt(table[:encrypt_table], data)) and return + connector.send_data(encrypt(data)) and return end end @@ -48,7 +48,7 @@ def fireup_tunnel(data) send_data "\x05\x00\x00\x01\x00\x00\x00\x00" + [config.server_port].pack('s>') @stage = 4 - @connector = EventMachine.connect config.server, config.server_port, ServerConnector, self, @table + @connector = EventMachine.connect config.server, config.server_port, ServerConnector, self, crypto if data.size > header_length cached_pieces.push data[header_length, data.size] diff --git a/lib/shadowsocks/method.rb b/lib/shadowsocks/method.rb deleted file mode 100644 index d57bbd4..0000000 --- a/lib/shadowsocks/method.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'openssl' - -module Shadowsocks - class Method - include ::Shadowsocks::Table - - attr_accessor :encrypt_table, :decrypt_table, :password, :method - - def initialize(options = {}) - @password = options[:password] - @method = options[:method] - - unless %w(talbe bf-cfb aes-256-cfb des-cfb).include?(method) - raise "Encrypt method not support" - end - - if method == 'table' - generate_table - end - end - - def encrypt buf - case method - when 'table' - calculate encrypt_table, buf - when 'bf-cfb' - when 'aes-256-cfb' - when 'des-cfb' - cipher = OpenSSL::Cipher.new method.upcase - - end - end - - def decrypt buf - case method - when 'table' - calculate decrypt_table, buf - when 'bf-cfb' - when 'aes-256-cfb' - when 'des-cfb' - end - end - - private - - def generate_table - @encrypt_table, @decrypt_table = get_table password - end - end -end diff --git a/lib/shadowsocks/server.rb b/lib/shadowsocks/server.rb index bc69de8..83810ef 100644 --- a/lib/shadowsocks/server.rb +++ b/lib/shadowsocks/server.rb @@ -11,7 +11,7 @@ def post_init end def receive_data data - server.send_data encrypt(table[:encrypt_table], data) + server.send_data encrypt(data) end end @@ -19,7 +19,7 @@ class ServerListener < ::Shadowsocks::Listener private def data_handler data - data = encrypt table[:decrypt_table], data + data = decrypt data case stage when 0 fireup_tunnel data @@ -40,7 +40,7 @@ def fireup_tunnel data cached_pieces.push data[header_length, data.size] end - @connector = EventMachine.connect @remote_addr, @remote_port, RequestConnector, self, table + @connector = EventMachine.connect @remote_addr, @remote_port, RequestConnector, self, crypto rescue Exception => e warn e connection_cleanup diff --git a/lib/shadowsocks/table.rb b/lib/shadowsocks/table.rb index a2f15ca..e482352 100644 --- a/lib/shadowsocks/table.rb +++ b/lib/shadowsocks/table.rb @@ -45,10 +45,10 @@ def get_table key decrypt_table[table[i]] = i i += 1 end - { encrypt_table: table, decrypt_table: decrypt_table } + { encrypt: table, decrypt: decrypt_table } end - def encrypt (table, buf) + def translate(table, buf) table_ptr = FFI::MemoryPointer.new(:int, table.length) table_ptr.put_array_of_int32(0, table) diff --git a/lib/shadowsocks/tunnel.rb b/lib/shadowsocks/tunnel.rb index ff1c453..0b74476 100644 --- a/lib/shadowsocks/tunnel.rb +++ b/lib/shadowsocks/tunnel.rb @@ -1,10 +1,10 @@ module Shadowsocks class Tunnel < EventMachine::Connection - attr_accessor :server, :table + attr_accessor :server, :crypto - def initialize server, table + def initialize server, crypto @server = server - @table = table + @crypto = crypto super end @@ -12,8 +12,14 @@ def unbind server.close_connection_after_writing end - def encrypt table, data - server.encrypt table, data + private + + def encrypt(buf) + crypto.encrypt(buf) + end + + def decrypt(buf) + crypto.decrypt(buf) end end end From 459c0990166dba7431cd19d679e83fa6922b78d4 Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 10 Nov 2013 01:46:57 +0800 Subject: [PATCH 22/48] refactor --- lib/shadowsocks/connection.rb | 10 ++++++++++ lib/shadowsocks/listener.rb | 12 +----------- lib/shadowsocks/tunnel.rb | 12 +----------- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/lib/shadowsocks/connection.rb b/lib/shadowsocks/connection.rb index 25c91be..4b7e762 100644 --- a/lib/shadowsocks/connection.rb +++ b/lib/shadowsocks/connection.rb @@ -2,8 +2,18 @@ module Shadowsocks class Connection < EventMachine::Connection BackpressureLevel = 2097152 # 2m + attr_accessor :crypto + private + def encrypt(buf) + crypto.encrypt(buf) + end + + def decrypt(buf) + crypto.decrypt(buf) + end + def over_pressure? remote.get_outbound_data_size > BackpressureLevel end diff --git a/lib/shadowsocks/listener.rb b/lib/shadowsocks/listener.rb index bc4bbe4..dfc9007 100644 --- a/lib/shadowsocks/listener.rb +++ b/lib/shadowsocks/listener.rb @@ -1,9 +1,7 @@ module Shadowsocks class Listener < ::Shadowsocks::Connection - include ::Shadowsocks::Table - attr_accessor :stage, :remote_addr, :remote_port, :addr_to_send, :cached_pieces, - :header_length, :connector, :config, :crypto + :header_length, :connector, :config def receive_data data data_handler data @@ -27,14 +25,6 @@ def remote private - def encrypt(buf) - crypto.encrypt(buf) - end - - def decrypt(buf) - crypto.decrypt(buf) - end - def connection_cleanup connector.close_connection if connector self.close_connection diff --git a/lib/shadowsocks/tunnel.rb b/lib/shadowsocks/tunnel.rb index 81b9d30..3a39ce1 100644 --- a/lib/shadowsocks/tunnel.rb +++ b/lib/shadowsocks/tunnel.rb @@ -1,6 +1,6 @@ module Shadowsocks class Tunnel < ::Shadowsocks::Connection - attr_accessor :server, :table + attr_accessor :server def initialize server, crypto @server = server @@ -15,15 +15,5 @@ def unbind def remote server end - - private - - def encrypt(buf) - crypto.encrypt(buf) - end - - def decrypt(buf) - crypto.decrypt(buf) - end end end From cce85f9dafd839afb0edbf907e576bb79b79f382 Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 10 Nov 2013 01:49:32 +0800 Subject: [PATCH 23/48] bump version 0.4 --- README.md | 6 ++++-- lib/shadowsocks/version.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e8ded5b..a0f5962 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ shadowsocks-ruby [![Code Climate](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/badges/9dd6c11b6a17c3a55631/gpa.png)](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/feed) -Current version: 0.3 +Current version: 0.4 shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks). @@ -26,7 +26,8 @@ Create a file named `config.json`, with the following content. "server_port":8388, "local_port":1080, "password":"barfoo!", - "timeout":600 + "timeout":60, + "method":"aes-256-cfb" } Explanation of the fields: @@ -36,6 +37,7 @@ Explanation of the fields: local_port local port password a password used to encrypt transfer timeout in seconds + method encryption method, "bf-cfb", "aes-256-cfb", "des-cfb", "rc4", etc. Default is aes-256-cfb `cd` into the directory of `config.json`. Run `ss-server` on your server. To run it in the background, run `nohup ss-server -c ./config.json > log &`. diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb index 6d3da37..b440d29 100644 --- a/lib/shadowsocks/version.rb +++ b/lib/shadowsocks/version.rb @@ -1,3 +1,3 @@ module Shadowsocks - VERSION = '0.3' + VERSION = '0.4' end From 116893130db10bc513716a87026527e8e2bf55e7 Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 10 Nov 2013 01:53:36 +0800 Subject: [PATCH 24/48] date bug in gemspec --- shadowsocks.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shadowsocks.gemspec b/shadowsocks.gemspec index d55898b..9848a20 100644 --- a/shadowsocks.gemspec +++ b/shadowsocks.gemspec @@ -3,7 +3,7 @@ require File.expand_path('../lib/shadowsocks/version', __FILE__) Gem::Specification.new do |s| s.name = 'shadowsocks' s.version = Shadowsocks::VERSION - s.date = '2013-09-26' + s.date = Date.today s.summary = "ruby version of shadowsocks" s.description = "shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls." s.authors = ["Sen"] From 668f13153bd1c1503e3a9054c15f0d4b4f550510 Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 10 Nov 2013 02:05:38 +0800 Subject: [PATCH 25/48] params bug fix --- lib/shadowsocks/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shadowsocks/config.rb b/lib/shadowsocks/config.rb index a085227..d4c640a 100644 --- a/lib/shadowsocks/config.rb +++ b/lib/shadowsocks/config.rb @@ -39,7 +39,7 @@ def parse_args opts.on("-c", "--config PATH", "config.json path") { |c| @config_path = c } opts.on("-p", "--port PORT", Integer, "Remote server port") { |c| @server_port = c } opts.on("-l", "--local_port PORT", Integer, "Local client port") { |c| @local_port = c } - opts.on("-m", "--method METHOD", Integer, "Encryption method") { |c| @method = c } + opts.on("-m", "--method METHOD", "Encryption method") { |c| @method = c } opts.on("-t", "--timeout NUMBER", Integer, "connection timeout") { |c| @timeout = c } opts.on_tail("-v", "--version", "Show shadowsocks gem version") { puts Shadowsocks::VERSION; exit } From 16691ae876d839122c014343bf2e0d663174dd7d Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 10 Nov 2013 02:06:50 +0800 Subject: [PATCH 26/48] bump version 0.5 --- README.md | 2 +- lib/shadowsocks/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a0f5962..c2bdce6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ shadowsocks-ruby [![Code Climate](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/badges/9dd6c11b6a17c3a55631/gpa.png)](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/feed) -Current version: 0.4 +Current version: 0.5 shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks). diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb index b440d29..811cdc1 100644 --- a/lib/shadowsocks/version.rb +++ b/lib/shadowsocks/version.rb @@ -1,3 +1,3 @@ module Shadowsocks - VERSION = '0.4' + VERSION = '0.5' end From 26cf7fdb9edb090636660ed2c666a6b89c0e41b2 Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 10 Nov 2013 12:48:44 +0800 Subject: [PATCH 27/48] crypto refactor --- lib/shadowsocks/crypto.rb | 63 +++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/lib/shadowsocks/crypto.rb b/lib/shadowsocks/crypto.rb index f851d89..1490c71 100644 --- a/lib/shadowsocks/crypto.rb +++ b/lib/shadowsocks/crypto.rb @@ -9,6 +9,23 @@ class Crypto attr_accessor :encrypt_table, :decrypt_table, :password, :method, :cipher, :bytes_to_key_results, :iv_sent + def initialize(options = {}) + @password = options[:password] + @method = options[:method].downcase + if method == 'table' + @encrypt_table = options[:encrypt_table] + @decrypt_table = options[:decrypt_table] + else + if method_supported.nil? + raise "Encrypt method not support" + end + end + + if method != 'table' + @cipher = get_cipher(1, SecureRandom.hex(32)) + end + end + def method_supported case method when 'aes-128-cfb' then [16, 16] @@ -28,24 +45,6 @@ def method_supported end alias_method :get_cipher_len, :method_supported - def initialize(options = {}) - @password = options[:password] - @method = options[:method].downcase - @iv_sent = false - if method == 'table' - @encrypt_table = options[:encrypt_table] - @decrypt_table = options[:decrypt_table] - else - if method_supported.nil? - raise "Encrypt method not support" - end - end - - if method != 'table' - @cipher = get_cipher(1, SecureRandom.hex(32)) - end - end - def encrypt buf return buf if buf.length == 0 if method == 'table' @@ -71,6 +70,7 @@ def decrypt buf @iv = decipher_iv @decipher = get_cipher(0, @iv) buf = buf[decipher_iv_len..-1] + return buf if buf.length == 0 end @decipher.update(buf) @@ -85,21 +85,20 @@ def iv_len def get_cipher(op, iv) m = get_cipher_len - unless m.nil? - key, _iv = EVP_BytesToKey(m[0], m[1]) - iv = _iv[0..m[1] - 1] - @iv = iv unless @iv - @cipher_iv = iv if op == 1 + key, _iv = EVP_BytesToKey(m[0], m[1]) - cipher = OpenSSL::Cipher.new method + iv = _iv[0..m[1] - 1] + @iv = iv unless @iv + @cipher_iv = iv if op == 1 - op == 1 ? cipher.encrypt : cipher.decrypt + cipher = OpenSSL::Cipher.new method - cipher.key = key - cipher.iv = @iv - cipher - end + op == 1 ? cipher.encrypt : cipher.decrypt + + cipher.key = key + cipher.iv = @iv + cipher end def EVP_BytesToKey key_len, iv_len @@ -112,21 +111,19 @@ def EVP_BytesToKey key_len, iv_len len = key_len + iv_len - code = password.unpack('H*').first - while m.join.length < len do data = if i > 0 m[i - 1] + password else password end - m.push Digest::MD5.digest data + m.push Digest::MD5.digest(data) i += 1 end ms = m.join key = ms[0, key_len] iv = ms[key_len, key_len + iv_len] - bytes_to_key_results = [key, iv] + @bytes_to_key_results = [key, iv] bytes_to_key_results end end From 30ca08fefa5787ddbe22d5d5f6c49e3a05cdeb6b Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 10 Nov 2013 12:50:05 +0800 Subject: [PATCH 28/48] optimize outbound scheduler --- lib/shadowsocks/connection.rb | 6 +++--- lib/shadowsocks/listener.rb | 2 +- lib/shadowsocks/local.rb | 2 +- lib/shadowsocks/server.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/shadowsocks/connection.rb b/lib/shadowsocks/connection.rb index 4b7e762..69c3d13 100644 --- a/lib/shadowsocks/connection.rb +++ b/lib/shadowsocks/connection.rb @@ -1,6 +1,6 @@ module Shadowsocks class Connection < EventMachine::Connection - BackpressureLevel = 2097152 # 2m + BackpressureLevel = 524288 # 512k attr_accessor :crypto @@ -18,10 +18,10 @@ def over_pressure? remote.get_outbound_data_size > BackpressureLevel end - def outbound_checker + def outbound_scheduler if over_pressure? pause unless paused? - EM.add_timer(1) { outbound_checker } + EM.add_timer(0.2) { outbound_scheduler } else resume if paused? end diff --git a/lib/shadowsocks/listener.rb b/lib/shadowsocks/listener.rb index dfc9007..43dfa30 100644 --- a/lib/shadowsocks/listener.rb +++ b/lib/shadowsocks/listener.rb @@ -5,7 +5,7 @@ class Listener < ::Shadowsocks::Connection def receive_data data data_handler data - outbound_checker if connector + outbound_scheduler if connector end def post_init diff --git a/lib/shadowsocks/local.rb b/lib/shadowsocks/local.rb index 461d5d8..0188998 100644 --- a/lib/shadowsocks/local.rb +++ b/lib/shadowsocks/local.rb @@ -14,7 +14,7 @@ def post_init def receive_data data server.send_data decrypt(data) - outbound_checker + outbound_scheduler end end diff --git a/lib/shadowsocks/server.rb b/lib/shadowsocks/server.rb index 9f1255f..47a84ab 100644 --- a/lib/shadowsocks/server.rb +++ b/lib/shadowsocks/server.rb @@ -12,7 +12,7 @@ def post_init def receive_data data server.send_data encrypt(data) - outbound_checker + outbound_scheduler end end From d2a23faf8337ac9ece34aa8578559f9e74d516db Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 10 Nov 2013 12:52:03 +0800 Subject: [PATCH 29/48] try to set comm_inactivity_timeout --- lib/shadowsocks/cli.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/shadowsocks/cli.rb b/lib/shadowsocks/cli.rb index 923d12d..e2ddb73 100644 --- a/lib/shadowsocks/cli.rb +++ b/lib/shadowsocks/cli.rb @@ -57,6 +57,7 @@ def initialize_connection connection connection.config = @config connection.crypto = Shadowsocks::Crypto.new @method_options connection.pending_connect_timeout = @config.timeout + connection.comm_inactivity_timeout = @config.timeout end end From 55691ff963ff635615ab0c9489362c1a554b41d0 Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 10 Nov 2013 12:53:07 +0800 Subject: [PATCH 30/48] default encrypt method --- README.md | 4 ++-- config.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c2bdce6..4b229af 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Create a file named `config.json`, with the following content. "local_port":1080, "password":"barfoo!", "timeout":60, - "method":"aes-256-cfb" + "method":"aes-128-cfb" } Explanation of the fields: @@ -37,7 +37,7 @@ Explanation of the fields: local_port local port password a password used to encrypt transfer timeout in seconds - method encryption method, "bf-cfb", "aes-256-cfb", "des-cfb", "rc4", etc. Default is aes-256-cfb + method encryption method, "bf-cfb", "aes-256-cfb", "des-cfb", "rc4", etc. Default is "aes-128-cfb" `cd` into the directory of `config.json`. Run `ss-server` on your server. To run it in the background, run `nohup ss-server -c ./config.json > log &`. diff --git a/config.json b/config.json index e8e57e2..b1a2a94 100644 --- a/config.json +++ b/config.json @@ -4,5 +4,5 @@ "local_port":1080, "password":"barfoo!", "timeout":60, - "method":"aes-256-cfb" + "method":"aes-128-cfb" } From 815fd8d2847404b6918d1889d39f77ff8229a13f Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 10 Nov 2013 13:36:08 +0800 Subject: [PATCH 31/48] bump version 0.6 --- README.md | 2 +- lib/shadowsocks/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4b229af..c487e3f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ shadowsocks-ruby [![Code Climate](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/badges/9dd6c11b6a17c3a55631/gpa.png)](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/feed) -Current version: 0.5 +Current version: 0.6 shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks). diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb index 811cdc1..ee99875 100644 --- a/lib/shadowsocks/version.rb +++ b/lib/shadowsocks/version.rb @@ -1,3 +1,3 @@ module Shadowsocks - VERSION = '0.5' + VERSION = '0.6' end From 370be51598e4fee9db69be70f054efab088a8bf6 Mon Sep 17 00:00:00 2001 From: Sen Date: Thu, 23 Jan 2014 16:12:01 +0800 Subject: [PATCH 32/48] data without encrypt --- lib/shadowsocks/crypto.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/shadowsocks/crypto.rb b/lib/shadowsocks/crypto.rb index 1490c71..a0d7082 100644 --- a/lib/shadowsocks/crypto.rb +++ b/lib/shadowsocks/crypto.rb @@ -15,13 +15,11 @@ def initialize(options = {}) if method == 'table' @encrypt_table = options[:encrypt_table] @decrypt_table = options[:decrypt_table] - else - if method_supported.nil? - raise "Encrypt method not support" - end + elsif method_supported.nil? + raise "Encrypt method not support" end - if method != 'table' + if method != 'table' and method != 'none' @cipher = get_cipher(1, SecureRandom.hex(32)) end end @@ -41,12 +39,13 @@ def method_supported when 'rc2-cfb' then [16, 8 ] when 'rc4' then [16, 0 ] when 'seed-cfb' then [16, 16] + when 'none' then [0, 0] end end alias_method :get_cipher_len, :method_supported def encrypt buf - return buf if buf.length == 0 + return buf if buf.length == 0 or method == 'none' if method == 'table' translate @encrypt_table, buf else @@ -60,7 +59,7 @@ def encrypt buf end def decrypt buf - return buf if buf.length == 0 + return buf if buf.length == 0 or method == 'none' if method == 'table' translate @decrypt_table, buf else From 95173fb65796bf0e727e4e7ef7e4a980aec51c51 Mon Sep 17 00:00:00 2001 From: Sen Date: Thu, 23 Jan 2014 17:18:55 +0800 Subject: [PATCH 33/48] data parser --- lib/shadowsocks.rb | 8 +++- lib/shadowsocks/listener.rb | 35 +++++----------- lib/shadowsocks/local.rb | 20 +-------- lib/shadowsocks/parser/base.rb | 71 ++++++++++++++++++++++++++++++++ lib/shadowsocks/parser/local.rb | 15 +++++++ lib/shadowsocks/parser/server.rb | 15 +++++++ lib/shadowsocks/server.rb | 12 +----- 7 files changed, 121 insertions(+), 55 deletions(-) create mode 100644 lib/shadowsocks/parser/base.rb create mode 100644 lib/shadowsocks/parser/local.rb create mode 100644 lib/shadowsocks/parser/server.rb diff --git a/lib/shadowsocks.rb b/lib/shadowsocks.rb index 71976ce..41019bb 100644 --- a/lib/shadowsocks.rb +++ b/lib/shadowsocks.rb @@ -1,11 +1,17 @@ require 'eventmachine' module Shadowsocks - autoload :Crypto, 'shadowsocks/crypto' + autoload :Crypto, 'shadowsocks/crypto' autoload :Connection, 'shadowsocks/connection' autoload :Server, 'shadowsocks/server' autoload :Local, 'shadowsocks/local' autoload :Table, 'shadowsocks/table' autoload :Tunnel, 'shadowsocks/tunnel' autoload :Listener, 'shadowsocks/listener' + + module Parser + autoload :Base, 'shadowsocks/parser/base' + autoload :Local, 'shadowsocks/parser/local' + autoload :Server, 'shadowsocks/parser/server' + end end diff --git a/lib/shadowsocks/listener.rb b/lib/shadowsocks/listener.rb index 43dfa30..87652ce 100644 --- a/lib/shadowsocks/listener.rb +++ b/lib/shadowsocks/listener.rb @@ -25,37 +25,24 @@ def remote private - def connection_cleanup - connector.close_connection if connector - self.close_connection - end + def parse_data parser + @addrtype = parser.addr_type - def resolve_addrtype data - case @addrtype - when "\x01" - ip_address data - when "\x03" - domain_address data - else + if parser.mode == :unsupported warn "unsupported addrtype: " + @addrtype.unpack('c')[0].to_s connection_cleanup end - end - def domain_address data - @remote_addr = data[2, @addr_len] - @remote_port = data[2 + @addr_len, 2].unpack('s>')[0] - @header_length = 2 + @addr_len + 2 + @addr_len = parser.addr_len + @addr_to_send = parser.addr_to_send + @remote_addr = parser.remote_addr + @remote_port = parser.remote_port + @header_length = parser.header_length end - def ip_address data - @remote_addr = inet_ntoa data[1..4] - @remote_port = data[5, 2].unpack('s>')[0] - @header_length = 7 - end - - def inet_ntoa n - n.unpack("C*").join "." + def connection_cleanup + connector.close_connection if connector + self.close_connection end end end diff --git a/lib/shadowsocks/local.rb b/lib/shadowsocks/local.rb index 0188998..e21a8e0 100644 --- a/lib/shadowsocks/local.rb +++ b/lib/shadowsocks/local.rb @@ -42,9 +42,7 @@ def fireup_tunnel(data) connection_cleanup and return end - @addr_to_send = data[3] - - resolve_addrtype data + parse_data Shadowsocks::Parser::Local.new(data) send_data "\x05\x00\x00\x01\x00\x00\x00\x00" + [config.server_port].pack('s>') @@ -59,22 +57,6 @@ def fireup_tunnel(data) connection_cleanup end end - - def resolve_addrtype data - @addrtype = data[3] - super - end - - def domain_address data - @addr_len = data[4].unpack('c')[0] - @addr_to_send += data[4..5 + @addr_len + 2] - super - end - - def ip_address data - @addr_to_send += data[4..9] - super - end end end end diff --git a/lib/shadowsocks/parser/base.rb b/lib/shadowsocks/parser/base.rb new file mode 100644 index 0000000..ffbff4a --- /dev/null +++ b/lib/shadowsocks/parser/base.rb @@ -0,0 +1,71 @@ +module Shadowsocks + module Parser + class Base + attr_accessor :data, :mode + + def initialize(data) + @data = data + + @mode = \ + case addr_type + when "\x01" + :ip + when "\x03" + :domain + else + :unsupported + end + end + + def addr_type + raise 'Called abstract method: addr_type' + end + + def addr_len + raise 'Called abstract method: addr_len' + end + + def addr_to_send + case mode + when :domain + data[3..5 + addr_len + 2] + when :ip + data[3..9] + end + end + + def remote_addr + case mode + when :domain + data[2, addr_len] + when :ip + inet_ntoa data[1..4] + end + end + + def remote_port + case mode + when :domain + data[2 + addr_len, 2].unpack('s>')[0] + when :ip + data[5, 2].unpack('s>')[0] + end + end + + def header_length + case mode + when :domain + 4 + addr_len + when :ip + 7 + end + end + + private + + def inet_ntoa n + n.unpack("C*").join "." + end + end + end +end diff --git a/lib/shadowsocks/parser/local.rb b/lib/shadowsocks/parser/local.rb new file mode 100644 index 0000000..2964979 --- /dev/null +++ b/lib/shadowsocks/parser/local.rb @@ -0,0 +1,15 @@ +module Shadowsocks + module Parser + class Local < Base + def addr_type + data[3] + end + + def addr_len + if mode == :domain + data[4].unpack('c')[0] + end + end + end + end +end diff --git a/lib/shadowsocks/parser/server.rb b/lib/shadowsocks/parser/server.rb new file mode 100644 index 0000000..4c5fe17 --- /dev/null +++ b/lib/shadowsocks/parser/server.rb @@ -0,0 +1,15 @@ +module Shadowsocks + module Parser + class Server < Base + def addr_type + data[0] + end + + def addr_len + if mode == :domain + data[1].unpack('c')[0] + end + end + end + end +end diff --git a/lib/shadowsocks/server.rb b/lib/shadowsocks/server.rb index 47a84ab..fa49780 100644 --- a/lib/shadowsocks/server.rb +++ b/lib/shadowsocks/server.rb @@ -33,7 +33,7 @@ def data_handler data def fireup_tunnel data begin - resolve_addrtype data + parse_data Shadowsocks::Parser::Server.new(data) @stage = 4 @@ -47,16 +47,6 @@ def fireup_tunnel data connection_cleanup end end - - def resolve_addrtype data - @addrtype = data[0] - super - end - - def domain_address data - @addr_len = data[1].unpack('c')[0] - super - end end end end From 29bd77b2248f38c3119d0381076390df0281e553 Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 24 Jan 2014 01:20:50 +0800 Subject: [PATCH 34/48] add chnroute --- .gitignore | 1 + Gemfile.lock | 15 +- config.json | 7 +- data/gfwlist.txt | 3737 ++++++++++++++++++++++++++++++++ lib/shadowsocks.rb | 1 + lib/shadowsocks/cli.rb | 7 +- lib/shadowsocks/config.rb | 6 +- lib/shadowsocks/ip_detector.rb | 30 + lib/shadowsocks/listener.rb | 2 +- lib/shadowsocks/local.rb | 36 +- lib/shadowsocks/parser/base.rb | 4 +- shadowsocks.gemspec | 4 +- tasks/chnroutes.rake | 61 + 13 files changed, 3891 insertions(+), 20 deletions(-) create mode 100644 data/gfwlist.txt create mode 100644 lib/shadowsocks/ip_detector.rb create mode 100644 tasks/chnroutes.rake diff --git a/.gitignore b/.gitignore index 9963cbb..7f69c2b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ tmp *.bundle Gemfile.lock +delegated-apnic-latest diff --git a/Gemfile.lock b/Gemfile.lock index ea75f46..5847d7a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,24 +1,29 @@ PATH remote: . specs: - shadowsocks (0.1) + shadowsocks (0.6) eventmachine (~> 1.0.3) + ffi (~> 1.9.0) json (~> 1.8.0) GEM remote: http://rubygems.org/ specs: eventmachine (1.0.3) - json (1.8.0) - metaclass (0.0.1) - mocha (0.14.0) + ffi (1.9.3) + json (1.8.1) + metaclass (0.0.2) + mocha (1.0.0) metaclass (~> 0.0.1) rake (10.1.0) + rake-compiler (0.9.2) + rake PLATFORMS ruby DEPENDENCIES - mocha (~> 0.14.0) + mocha (~> 1.0.0) rake + rake-compiler (~> 0.9.2) shadowsocks! diff --git a/config.json b/config.json index b1a2a94..ed71280 100644 --- a/config.json +++ b/config.json @@ -1,8 +1,9 @@ { - "server":"127.0.0.1", + "server":"162.243.140.72", "server_port":8388, "local_port":1080, - "password":"barfoo!", + "password":"be_tough", "timeout":60, - "method":"aes-128-cfb" + "method":"aes-128-cfb", + "chnroutes":true } diff --git a/data/gfwlist.txt b/data/gfwlist.txt new file mode 100644 index 0000000..dfe6040 --- /dev/null +++ b/data/gfwlist.txt @@ -0,0 +1,3737 @@ +1.0.1.0/24 +1.0.2.0/23 +1.0.8.0/21 +1.0.32.0/19 +1.1.0.0/24 +1.1.2.0/23 +1.1.4.0/22 +1.1.8.0/21 +1.1.16.0/20 +1.1.32.0/19 +1.2.0.0/23 +1.2.2.0/24 +1.2.4.0/24 +1.2.5.0/24 +1.2.6.0/23 +1.2.8.0/24 +1.2.9.0/24 +1.2.10.0/23 +1.2.12.0/22 +1.2.16.0/20 +1.2.32.0/19 +1.2.64.0/18 +1.3.0.0/16 +1.4.1.0/24 +1.4.2.0/23 +1.4.4.0/24 +1.4.5.0/24 +1.4.6.0/23 +1.4.8.0/21 +1.4.16.0/20 +1.4.32.0/19 +1.4.64.0/18 +1.8.0.0/16 +1.10.0.0/21 +1.10.8.0/23 +1.10.11.0/24 +1.10.12.0/22 +1.10.16.0/20 +1.10.32.0/19 +1.10.64.0/18 +1.12.0.0/14 +1.24.0.0/13 +1.45.0.0/16 +1.48.0.0/15 +1.50.0.0/16 +1.51.0.0/16 +1.56.0.0/13 +1.68.0.0/14 +1.80.0.0/13 +1.88.0.0/14 +1.92.0.0/15 +1.94.0.0/15 +1.116.0.0/14 +1.180.0.0/14 +1.184.0.0/15 +1.188.0.0/14 +1.192.0.0/13 +1.202.0.0/15 +1.204.0.0/14 +14.0.0.0/21 +14.0.12.0/22 +14.1.0.0/22 +14.16.0.0/12 +14.102.128.0/22 +14.102.156.0/22 +14.103.0.0/16 +14.104.0.0/13 +14.112.0.0/12 +14.130.0.0/15 +14.134.0.0/15 +14.144.0.0/12 +14.192.60.0/22 +14.192.76.0/22 +14.196.0.0/15 +14.204.0.0/15 +14.208.0.0/12 +27.8.0.0/13 +27.16.0.0/12 +27.34.232.0/21 +27.36.0.0/14 +27.40.0.0/13 +27.50.40.0/21 +27.50.128.0/17 +27.54.72.0/21 +27.54.152.0/21 +27.54.192.0/18 +27.98.208.0/20 +27.98.224.0/19 +27.99.128.0/17 +27.103.0.0/16 +27.106.128.0/18 +27.106.204.0/22 +27.109.32.0/19 +27.112.0.0/18 +27.112.80.0/20 +27.113.128.0/18 +27.115.0.0/17 +27.116.44.0/22 +27.121.72.0/21 +27.121.120.0/21 +27.128.0.0/15 +27.131.220.0/22 +27.144.0.0/16 +27.148.0.0/14 +27.152.0.0/13 +27.184.0.0/13 +27.192.0.0/11 +27.224.0.0/14 +36.0.0.0/22 +36.0.8.0/21 +36.0.16.0/20 +36.0.32.0/19 +36.0.64.0/18 +36.0.128.0/17 +36.1.0.0/16 +36.4.0.0/14 +36.16.0.0/12 +36.32.0.0/14 +36.36.0.0/16 +36.37.0.0/19 +36.37.36.0/23 +36.37.39.0/24 +36.37.40.0/21 +36.37.48.0/20 +36.40.0.0/13 +36.48.0.0/15 +36.51.0.0/16 +36.56.0.0/13 +36.96.0.0/11 +36.128.0.0/10 +36.192.0.0/11 +36.248.0.0/14 +36.254.0.0/16 +39.0.0.0/24 +39.0.2.0/23 +39.0.4.0/22 +39.0.8.0/21 +39.0.16.0/20 +39.0.32.0/19 +39.0.64.0/18 +39.0.128.0/17 +39.64.0.0/11 +39.128.0.0/10 +42.0.0.0/22 +42.0.8.0/21 +42.0.16.0/21 +42.0.24.0/22 +42.0.32.0/19 +42.0.128.0/17 +42.1.0.0/19 +42.1.32.0/20 +42.1.48.0/21 +42.1.56.0/22 +42.1.128.0/17 +42.4.0.0/14 +42.48.0.0/15 +42.50.0.0/16 +42.51.0.0/16 +42.52.0.0/14 +42.56.0.0/14 +42.62.0.0/17 +42.62.128.0/19 +42.62.160.0/20 +42.62.180.0/22 +42.62.184.0/21 +42.63.0.0/16 +42.80.0.0/15 +42.83.64.0/20 +42.83.80.0/22 +42.83.88.0/21 +42.83.96.0/19 +42.83.128.0/17 +42.84.0.0/14 +42.88.0.0/13 +42.96.64.0/19 +42.96.96.0/21 +42.96.108.0/22 +42.96.112.0/20 +42.96.128.0/17 +42.97.0.0/16 +42.99.0.0/18 +42.99.64.0/19 +42.99.96.0/20 +42.99.112.0/22 +42.99.120.0/21 +42.100.0.0/14 +42.120.0.0/15 +42.122.0.0/16 +42.123.0.0/19 +42.123.36.0/22 +42.123.40.0/21 +42.123.48.0/20 +42.123.64.0/18 +42.123.128.0/17 +42.128.0.0/12 +42.156.0.0/19 +42.156.36.0/22 +42.156.40.0/21 +42.156.48.0/20 +42.156.64.0/18 +42.156.128.0/17 +42.157.0.0/16 +42.158.0.0/15 +42.160.0.0/12 +42.176.0.0/13 +42.184.0.0/15 +42.186.0.0/16 +42.187.0.0/18 +42.187.64.0/19 +42.187.96.0/20 +42.187.112.0/21 +42.187.120.0/22 +42.187.128.0/17 +42.192.0.0/15 +42.194.0.0/21 +42.194.8.0/22 +42.194.12.0/22 +42.194.16.0/20 +42.194.32.0/19 +42.194.64.0/18 +42.194.128.0/17 +42.195.0.0/16 +42.196.0.0/14 +42.201.0.0/17 +42.202.0.0/15 +42.204.0.0/14 +42.208.0.0/12 +42.224.0.0/12 +42.240.0.0/17 +42.240.128.0/17 +42.242.0.0/15 +42.244.0.0/14 +42.248.0.0/13 +49.4.0.0/14 +49.51.0.0/16 +49.52.0.0/14 +49.64.0.0/11 +49.112.0.0/13 +49.120.0.0/14 +49.128.0.0/24 +49.128.2.0/23 +49.140.0.0/15 +49.152.0.0/14 +49.208.0.0/15 +49.210.0.0/15 +49.220.0.0/14 +49.232.0.0/14 +49.239.0.0/18 +49.239.192.0/18 +49.246.224.0/19 +54.222.0.0/15 +58.14.0.0/15 +58.16.0.0/16 +58.17.0.0/17 +58.17.128.0/17 +58.18.0.0/16 +58.19.0.0/16 +58.20.0.0/16 +58.21.0.0/16 +58.22.0.0/15 +58.24.0.0/15 +58.30.0.0/15 +58.32.0.0/13 +58.40.0.0/15 +58.42.0.0/16 +58.43.0.0/16 +58.44.0.0/14 +58.48.0.0/13 +58.56.0.0/15 +58.58.0.0/16 +58.59.0.0/17 +58.59.128.0/17 +58.60.0.0/14 +58.65.232.0/21 +58.66.0.0/15 +58.68.128.0/17 +58.82.0.0/17 +58.83.0.0/16 +58.87.64.0/18 +58.99.128.0/17 +58.100.0.0/15 +58.116.0.0/14 +58.128.0.0/13 +58.144.0.0/16 +58.154.0.0/15 +58.192.0.0/15 +58.194.0.0/15 +58.196.0.0/15 +58.198.0.0/15 +58.200.0.0/13 +58.208.0.0/12 +58.240.0.0/15 +58.242.0.0/15 +58.244.0.0/15 +58.246.0.0/15 +58.248.0.0/13 +59.32.0.0/13 +59.40.0.0/15 +59.42.0.0/16 +59.43.0.0/16 +59.44.0.0/14 +59.48.0.0/16 +59.49.0.0/17 +59.49.128.0/17 +59.50.0.0/16 +59.51.0.0/17 +59.51.128.0/17 +59.52.0.0/14 +59.56.0.0/14 +59.60.0.0/15 +59.62.0.0/15 +59.64.0.0/14 +59.68.0.0/14 +59.72.0.0/15 +59.74.0.0/15 +59.76.0.0/16 +59.77.0.0/16 +59.78.0.0/15 +59.80.0.0/14 +59.107.0.0/17 +59.107.128.0/17 +59.108.0.0/15 +59.110.0.0/15 +59.151.0.0/17 +59.155.0.0/16 +59.172.0.0/15 +59.174.0.0/15 +59.191.0.0/17 +59.191.240.0/20 +59.192.0.0/10 +60.0.0.0/13 +60.8.0.0/15 +60.10.0.0/16 +60.11.0.0/16 +60.12.0.0/16 +60.13.0.0/18 +60.13.64.0/18 +60.13.128.0/17 +60.14.0.0/15 +60.16.0.0/13 +60.24.0.0/14 +60.28.0.0/15 +60.30.0.0/16 +60.31.0.0/16 +60.55.0.0/16 +60.63.0.0/16 +60.160.0.0/15 +60.162.0.0/15 +60.164.0.0/15 +60.166.0.0/15 +60.168.0.0/13 +60.176.0.0/12 +60.194.0.0/15 +60.200.0.0/14 +60.204.0.0/16 +60.205.0.0/16 +60.206.0.0/15 +60.208.0.0/13 +60.216.0.0/15 +60.218.0.0/15 +60.220.0.0/14 +60.232.0.0/15 +60.235.0.0/16 +60.245.128.0/17 +60.247.0.0/16 +60.252.0.0/16 +60.253.128.0/17 +60.255.0.0/16 +61.4.80.0/22 +61.4.84.0/22 +61.4.88.0/21 +61.4.176.0/20 +61.8.160.0/20 +61.28.0.0/20 +61.28.16.0/20 +61.28.32.0/19 +61.28.64.0/18 +61.29.128.0/18 +61.29.192.0/19 +61.29.224.0/20 +61.29.240.0/20 +61.45.128.0/18 +61.45.224.0/20 +61.47.128.0/18 +61.48.0.0/14 +61.52.0.0/15 +61.54.0.0/16 +61.55.0.0/16 +61.87.192.0/18 +61.128.0.0/15 +61.130.0.0/15 +61.132.0.0/16 +61.133.0.0/17 +61.133.128.0/17 +61.134.0.0/18 +61.134.64.0/19 +61.134.96.0/19 +61.134.128.0/18 +61.134.192.0/18 +61.135.0.0/16 +61.136.0.0/18 +61.136.64.0/18 +61.136.128.0/17 +61.137.0.0/17 +61.137.128.0/17 +61.138.0.0/18 +61.138.64.0/18 +61.138.128.0/18 +61.138.192.0/18 +61.139.0.0/17 +61.139.128.0/18 +61.139.192.0/18 +61.140.0.0/14 +61.144.0.0/14 +61.148.0.0/15 +61.150.0.0/15 +61.152.0.0/16 +61.153.0.0/16 +61.154.0.0/15 +61.156.0.0/16 +61.157.0.0/16 +61.158.0.0/17 +61.158.128.0/17 +61.159.0.0/18 +61.159.64.0/18 +61.159.128.0/17 +61.160.0.0/16 +61.161.0.0/18 +61.161.64.0/18 +61.161.128.0/17 +61.162.0.0/16 +61.163.0.0/16 +61.164.0.0/16 +61.165.0.0/16 +61.166.0.0/16 +61.167.0.0/16 +61.168.0.0/16 +61.169.0.0/16 +61.170.0.0/15 +61.172.0.0/14 +61.176.0.0/16 +61.177.0.0/16 +61.178.0.0/16 +61.179.0.0/16 +61.180.0.0/17 +61.180.128.0/17 +61.181.0.0/16 +61.182.0.0/16 +61.183.0.0/16 +61.184.0.0/14 +61.188.0.0/16 +61.189.0.0/17 +61.189.128.0/17 +61.190.0.0/15 +61.232.0.0/14 +61.236.0.0/15 +61.240.0.0/14 +101.0.0.0/22 +101.1.0.0/22 +101.2.172.0/22 +101.4.0.0/14 +101.16.0.0/12 +101.32.0.0/12 +101.48.0.0/15 +101.50.56.0/22 +101.52.0.0/16 +101.53.100.0/22 +101.54.0.0/16 +101.55.224.0/21 +101.64.0.0/13 +101.72.0.0/14 +101.76.0.0/15 +101.78.0.0/22 +101.78.32.0/19 +101.80.0.0/12 +101.96.0.0/21 +101.96.8.0/22 +101.96.16.0/20 +101.96.128.0/17 +101.99.96.0/19 +101.101.64.0/19 +101.101.100.0/24 +101.101.102.0/23 +101.101.104.0/21 +101.101.112.0/20 +101.102.64.0/19 +101.102.100.0/23 +101.102.102.0/24 +101.102.104.0/21 +101.102.112.0/20 +101.104.0.0/14 +101.110.64.0/19 +101.110.96.0/20 +101.110.116.0/22 +101.110.120.0/21 +101.120.0.0/14 +101.124.0.0/15 +101.126.0.0/16 +101.128.0.0/22 +101.128.8.0/21 +101.128.16.0/20 +101.128.32.0/19 +101.129.0.0/16 +101.130.0.0/15 +101.132.0.0/14 +101.144.0.0/12 +101.192.0.0/14 +101.196.0.0/14 +101.200.0.0/15 +101.203.128.0/19 +101.203.160.0/21 +101.203.172.0/22 +101.203.176.0/20 +101.204.0.0/14 +101.224.0.0/13 +101.232.0.0/15 +101.234.64.0/21 +101.234.76.0/22 +101.234.80.0/20 +101.234.96.0/19 +101.236.0.0/14 +101.240.0.0/14 +101.244.0.0/14 +101.248.0.0/15 +101.251.0.0/22 +101.251.8.0/21 +101.251.16.0/20 +101.251.32.0/19 +101.251.64.0/18 +101.251.128.0/17 +101.252.0.0/15 +101.254.0.0/16 +103.1.8.0/22 +103.1.20.0/22 +103.1.24.0/22 +103.1.72.0/22 +103.1.88.0/22 +103.1.168.0/22 +103.2.108.0/22 +103.2.156.0/22 +103.2.164.0/22 +103.2.200.0/22 +103.2.204.0/22 +103.2.208.0/22 +103.2.212.0/22 +103.3.84.0/22 +103.3.88.0/22 +103.3.92.0/22 +103.3.96.0/22 +103.3.100.0/22 +103.3.104.0/22 +103.3.108.0/22 +103.3.112.0/22 +103.3.116.0/22 +103.3.120.0/22 +103.3.124.0/22 +103.3.128.0/22 +103.3.132.0/22 +103.3.136.0/22 +103.3.140.0/22 +103.3.148.0/22 +103.3.152.0/22 +103.3.156.0/22 +103.4.56.0/22 +103.4.168.0/22 +103.4.184.0/22 +103.5.36.0/22 +103.5.52.0/22 +103.5.56.0/22 +103.5.252.0/22 +103.6.76.0/22 +103.6.220.0/22 +103.7.4.0/22 +103.7.28.0/22 +103.7.212.0/22 +103.7.216.0/22 +103.7.220.0/22 +103.8.4.0/22 +103.8.8.0/22 +103.8.32.0/22 +103.8.52.0/22 +103.8.108.0/22 +103.8.156.0/22 +103.8.200.0/22 +103.8.204.0/22 +103.8.220.0/22 +103.9.152.0/22 +103.9.248.0/22 +103.9.252.0/22 +103.10.0.0/22 +103.10.16.0/22 +103.10.84.0/22 +103.10.111.0/24 +103.10.140.0/22 +103.11.180.0/22 +103.12.32.0/22 +103.12.68.0/22 +103.12.136.0/22 +103.12.184.0/22 +103.12.232.0/22 +103.13.124.0/22 +103.13.144.0/22 +103.13.196.0/22 +103.13.244.0/22 +103.14.84.0/22 +103.14.112.0/22 +103.14.132.0/22 +103.14.136.0/22 +103.14.156.0/22 +103.14.240.0/22 +103.15.4.0/22 +103.15.8.0/22 +103.15.16.0/22 +103.15.96.0/22 +103.15.200.0/22 +103.16.52.0/22 +103.16.80.0/22 +103.16.84.0/22 +103.16.88.0/22 +103.16.108.0/22 +103.16.124.0/22 +103.17.40.0/22 +103.17.120.0/22 +103.17.160.0/22 +103.17.204.0/22 +103.17.228.0/22 +103.18.192.0/22 +103.18.208.0/22 +103.18.212.0/22 +103.18.224.0/22 +103.19.12.0/22 +103.19.40.0/22 +103.19.44.0/22 +103.19.64.0/22 +103.19.68.0/22 +103.19.72.0/22 +103.19.232.0/22 +103.20.12.0/22 +103.20.32.0/22 +103.20.112.0/22 +103.20.128.0/22 +103.20.160.0/22 +103.20.248.0/22 +103.21.112.0/22 +103.21.116.0/22 +103.21.136.0/22 +103.21.140.0/22 +103.21.176.0/22 +103.21.208.0/22 +103.21.240.0/22 +103.22.0.0/22 +103.22.4.0/22 +103.22.8.0/22 +103.22.12.0/22 +103.22.16.0/22 +103.22.20.0/22 +103.22.24.0/22 +103.22.28.0/22 +103.22.32.0/22 +103.22.36.0/22 +103.22.40.0/22 +103.22.44.0/22 +103.22.48.0/22 +103.22.52.0/22 +103.22.56.0/22 +103.22.60.0/22 +103.22.64.0/22 +103.22.68.0/22 +103.22.72.0/22 +103.22.76.0/22 +103.22.80.0/22 +103.22.84.0/22 +103.22.88.0/22 +103.22.92.0/22 +103.22.100.0/22 +103.22.104.0/22 +103.22.108.0/22 +103.22.112.0/22 +103.22.116.0/22 +103.22.120.0/22 +103.22.124.0/22 +103.22.188.0/22 +103.22.228.0/22 +103.22.252.0/22 +103.23.8.0/22 +103.23.56.0/22 +103.23.160.0/22 +103.23.164.0/22 +103.23.176.0/22 +103.23.228.0/22 +103.24.116.0/22 +103.24.128.0/22 +103.24.144.0/22 +103.24.176.0/22 +103.24.184.0/22 +103.24.220.0/22 +103.24.228.0/22 +103.24.248.0/22 +103.24.252.0/22 +103.25.8.0/23 +103.25.20.0/22 +103.25.24.0/22 +103.25.28.0/22 +103.25.32.0/22 +103.25.36.0/22 +103.25.40.0/22 +103.25.48.0/22 +103.25.64.0/22 +103.25.68.0/22 +103.25.148.0/22 +103.25.156.0/22 +103.25.216.0/22 +103.26.0.0/22 +103.26.64.0/22 +103.26.156.0/22 +103.26.160.0/22 +103.26.228.0/22 +103.26.240.0/22 +103.27.4.0/22 +103.27.12.0/22 +103.27.24.0/22 +103.27.56.0/22 +103.27.96.0/22 +103.27.208.0/22 +103.27.240.0/22 +103.28.4.0/22 +103.28.8.0/22 +103.28.204.0/22 +103.29.16.0/22 +103.29.128.0/22 +103.29.132.0/22 +103.29.136.0/22 +103.30.20.0/22 +103.30.96.0/22 +103.30.148.0/22 +103.30.200.0/22 +103.30.216.0/22 +103.30.228.0/22 +103.30.232.0/22 +103.30.236.0/22 +103.31.0.0/22 +103.31.48.0/22 +103.31.52.0/22 +103.31.56.0/22 +103.31.60.0/22 +103.31.64.0/22 +103.31.68.0/22 +103.31.72.0/22 +103.31.148.0/22 +103.31.160.0/22 +103.31.168.0/22 +103.31.200.0/22 +103.224.40.0/22 +103.224.44.0/22 +103.224.60.0/22 +103.224.80.0/22 +103.240.16.0/22 +103.240.36.0/22 +103.240.72.0/22 +103.240.84.0/22 +103.240.124.0/22 +103.240.156.0/22 +103.240.172.0/22 +103.240.244.0/22 +103.241.12.0/22 +103.241.72.0/22 +103.241.92.0/22 +103.241.96.0/22 +103.241.160.0/22 +103.241.184.0/22 +103.241.188.0/22 +103.241.220.0/22 +103.242.8.0/22 +103.242.64.0/22 +103.242.128.0/22 +103.242.132.0/22 +103.242.160.0/22 +103.242.168.0/22 +103.242.172.0/22 +103.242.176.0/22 +103.242.200.0/22 +103.242.212.0/22 +103.242.220.0/22 +103.242.240.0/22 +103.243.24.0/22 +103.243.136.0/22 +103.243.252.0/22 +103.244.16.0/22 +103.244.56.0/22 +103.244.60.0/22 +103.244.64.0/22 +103.244.68.0/22 +103.244.72.0/22 +103.244.76.0/22 +103.244.80.0/22 +103.244.84.0/22 +103.244.164.0/22 +103.244.232.0/22 +103.244.252.0/22 +103.245.23.0/24 +103.245.52.0/22 +103.245.60.0/22 +103.245.80.0/22 +103.245.124.0/22 +103.245.128.0/22 +103.246.8.0/22 +103.246.12.0/22 +103.246.120.0/22 +103.246.124.0/22 +103.246.132.0/22 +103.246.152.0/22 +103.246.156.0/22 +103.247.168.0/22 +103.247.172.0/22 +103.247.176.0/22 +103.247.200.0/22 +103.247.212.0/22 +103.248.0.0/23 +103.248.64.0/22 +103.248.100.0/22 +103.248.124.0/22 +103.248.152.0/22 +103.248.168.0/22 +103.248.192.0/22 +103.248.212.0/22 +103.248.224.0/22 +103.248.228.0/22 +103.249.12.0/22 +103.249.52.0/22 +103.249.128.0/22 +103.249.136.0/22 +103.249.144.0/22 +103.249.164.0/22 +103.249.168.0/22 +103.249.172.0/22 +103.249.176.0/22 +103.249.188.0/22 +103.249.192.0/22 +103.249.244.0/22 +103.249.252.0/22 +103.250.32.0/22 +103.250.104.0/22 +103.250.124.0/22 +103.250.180.0/22 +103.250.192.0/22 +103.250.216.0/22 +103.250.224.0/22 +103.250.236.0/22 +103.250.248.0/22 +103.250.252.0/22 +103.251.32.0/22 +103.251.84.0/22 +103.251.96.0/22 +103.251.124.0/22 +103.251.128.0/22 +103.251.160.0/22 +103.251.204.0/22 +103.251.236.0/22 +103.251.240.0/22 +103.252.28.0/22 +103.252.36.0/22 +103.252.64.0/22 +103.252.104.0/22 +103.252.172.0/22 +103.252.204.0/22 +103.252.208.0/22 +103.252.232.0/22 +103.252.248.0/22 +103.253.4.0/22 +103.253.60.0/22 +103.253.204.0/22 +103.253.220.0/22 +103.253.224.0/22 +103.253.232.0/22 +103.254.8.0/22 +103.254.20.0/22 +103.254.64.0/22 +103.254.68.0/22 +103.254.72.0/22 +103.254.76.0/22 +103.254.112.0/22 +103.254.148.0/22 +103.254.176.0/22 +103.254.188.0/22 +103.254.196.0/24 +103.254.220.0/22 +103.255.68.0/22 +103.255.88.0/22 +103.255.92.0/22 +103.255.136.0/22 +103.255.140.0/22 +103.255.184.0/22 +103.255.200.0/22 +103.255.208.0/22 +103.255.212.0/22 +103.255.228.0/22 +106.0.0.0/24 +106.0.2.0/23 +106.0.4.0/22 +106.0.8.0/21 +106.0.16.0/20 +106.0.64.0/18 +106.2.0.0/15 +106.4.0.0/14 +106.8.0.0/15 +106.11.0.0/16 +106.12.0.0/14 +106.16.0.0/12 +106.32.0.0/12 +106.48.0.0/15 +106.50.0.0/16 +106.52.0.0/14 +106.56.0.0/13 +106.74.0.0/15 +106.80.0.0/12 +106.108.0.0/14 +106.112.0.0/13 +106.120.0.0/13 +106.224.0.0/12 +110.6.0.0/15 +110.16.0.0/14 +110.40.0.0/14 +110.44.144.0/20 +110.48.0.0/16 +110.51.0.0/16 +110.52.0.0/15 +110.56.0.0/13 +110.64.0.0/15 +110.72.0.0/15 +110.75.0.0/17 +110.75.128.0/19 +110.75.160.0/19 +110.75.192.0/18 +110.76.0.0/19 +110.76.32.0/19 +110.76.156.0/22 +110.76.184.0/22 +110.76.192.0/18 +110.77.0.0/17 +110.80.0.0/13 +110.88.0.0/14 +110.93.32.0/19 +110.94.0.0/15 +110.96.0.0/11 +110.152.0.0/14 +110.156.0.0/15 +110.165.32.0/19 +110.166.0.0/15 +110.172.192.0/18 +110.173.0.0/19 +110.173.32.0/20 +110.173.64.0/19 +110.173.96.0/19 +110.173.192.0/19 +110.176.0.0/13 +110.184.0.0/13 +110.192.0.0/11 +110.228.0.0/14 +110.232.32.0/19 +110.236.0.0/15 +110.240.0.0/12 +111.0.0.0/10 +111.66.0.0/16 +111.67.192.0/20 +111.68.64.0/19 +111.72.0.0/13 +111.85.0.0/16 +111.91.192.0/19 +111.112.0.0/15 +111.114.0.0/15 +111.116.0.0/15 +111.118.200.0/21 +111.119.64.0/18 +111.119.128.0/19 +111.120.0.0/14 +111.124.0.0/16 +111.126.0.0/15 +111.128.0.0/11 +111.160.0.0/13 +111.170.0.0/16 +111.172.0.0/14 +111.176.0.0/13 +111.186.0.0/15 +111.192.0.0/12 +111.208.0.0/14 +111.212.0.0/14 +111.221.128.0/17 +111.222.0.0/16 +111.223.240.0/22 +111.223.248.0/22 +111.224.0.0/14 +111.228.0.0/14 +111.235.96.0/19 +111.235.156.0/22 +111.235.160.0/19 +112.0.0.0/10 +112.64.0.0/15 +112.66.0.0/15 +112.73.0.0/16 +112.74.0.0/15 +112.80.0.0/13 +112.88.0.0/13 +112.96.0.0/15 +112.98.0.0/15 +112.100.0.0/14 +112.109.128.0/17 +112.111.0.0/16 +112.112.0.0/14 +112.116.0.0/15 +112.122.0.0/15 +112.124.0.0/14 +112.128.0.0/14 +112.132.0.0/16 +112.137.48.0/21 +112.192.0.0/14 +112.224.0.0/11 +113.0.0.0/13 +113.8.0.0/15 +113.11.192.0/19 +113.12.0.0/14 +113.16.0.0/15 +113.18.0.0/16 +113.24.0.0/14 +113.31.0.0/16 +113.44.0.0/14 +113.48.0.0/14 +113.52.160.0/19 +113.54.0.0/15 +113.56.0.0/15 +113.58.0.0/16 +113.59.0.0/17 +113.59.224.0/22 +113.62.0.0/15 +113.64.0.0/11 +113.96.0.0/12 +113.112.0.0/13 +113.120.0.0/13 +113.128.0.0/15 +113.130.96.0/20 +113.130.112.0/21 +113.132.0.0/14 +113.136.0.0/13 +113.194.0.0/15 +113.197.100.0/22 +113.200.0.0/15 +113.202.0.0/16 +113.204.0.0/14 +113.208.96.0/19 +113.208.128.0/17 +113.209.0.0/16 +113.212.0.0/18 +113.212.100.0/22 +113.212.184.0/21 +113.213.0.0/17 +113.214.0.0/15 +113.218.0.0/15 +113.220.0.0/14 +113.224.0.0/12 +113.240.0.0/13 +113.248.0.0/14 +114.28.0.0/16 +114.54.0.0/15 +114.60.0.0/14 +114.64.0.0/14 +114.68.0.0/16 +114.79.64.0/18 +114.80.0.0/12 +114.96.0.0/13 +114.104.0.0/14 +114.110.0.0/20 +114.110.64.0/18 +114.111.0.0/19 +114.111.160.0/19 +114.112.0.0/14 +114.116.0.0/15 +114.118.0.0/15 +114.132.0.0/16 +114.135.0.0/16 +114.138.0.0/15 +114.141.64.0/21 +114.141.128.0/18 +114.196.0.0/15 +114.198.248.0/21 +114.208.0.0/14 +114.212.0.0/15 +114.214.0.0/16 +114.215.0.0/16 +114.216.0.0/13 +114.224.0.0/12 +114.240.0.0/12 +115.24.0.0/14 +115.28.0.0/15 +115.32.0.0/14 +115.44.0.0/15 +115.46.0.0/16 +115.47.0.0/16 +115.48.0.0/12 +115.69.64.0/20 +115.84.0.0/18 +115.84.192.0/19 +115.85.192.0/18 +115.100.0.0/14 +115.104.0.0/14 +115.120.0.0/14 +115.124.16.0/20 +115.148.0.0/14 +115.152.0.0/15 +115.154.0.0/15 +115.156.0.0/15 +115.158.0.0/16 +115.159.0.0/16 +115.166.64.0/19 +115.168.0.0/14 +115.172.0.0/14 +115.180.0.0/14 +115.190.0.0/15 +115.192.0.0/11 +115.224.0.0/12 +116.0.8.0/21 +116.0.24.0/21 +116.1.0.0/16 +116.2.0.0/15 +116.4.0.0/14 +116.8.0.0/14 +116.13.0.0/16 +116.16.0.0/12 +116.50.0.0/20 +116.52.0.0/14 +116.56.0.0/15 +116.58.128.0/20 +116.58.208.0/20 +116.60.0.0/14 +116.66.0.0/17 +116.69.0.0/16 +116.70.0.0/17 +116.76.0.0/15 +116.78.0.0/15 +116.85.0.0/16 +116.89.144.0/20 +116.90.80.0/20 +116.90.184.0/21 +116.95.0.0/16 +116.112.0.0/14 +116.116.0.0/15 +116.128.0.0/10 +116.192.0.0/16 +116.193.16.0/20 +116.193.32.0/19 +116.193.176.0/21 +116.194.0.0/15 +116.196.0.0/16 +116.198.0.0/16 +116.199.0.0/17 +116.199.128.0/19 +116.204.0.0/15 +116.207.0.0/16 +116.208.0.0/14 +116.212.160.0/20 +116.213.64.0/18 +116.213.128.0/17 +116.214.32.0/19 +116.214.64.0/20 +116.214.128.0/17 +116.215.0.0/16 +116.216.0.0/14 +116.224.0.0/12 +116.242.0.0/15 +116.244.0.0/15 +116.246.0.0/15 +116.248.0.0/15 +116.251.64.0/18 +116.252.0.0/15 +116.254.128.0/17 +116.255.128.0/17 +117.8.0.0/13 +117.21.0.0/16 +117.22.0.0/15 +117.24.0.0/13 +117.32.0.0/13 +117.40.0.0/14 +117.44.0.0/15 +117.48.0.0/14 +117.53.48.0/20 +117.53.176.0/20 +117.57.0.0/16 +117.58.0.0/17 +117.59.0.0/16 +117.60.0.0/14 +117.64.0.0/13 +117.72.0.0/15 +117.74.64.0/20 +117.74.80.0/20 +117.74.128.0/17 +117.75.0.0/16 +117.76.0.0/14 +117.80.0.0/12 +117.100.0.0/15 +117.103.16.0/20 +117.103.40.0/21 +117.103.72.0/21 +117.103.128.0/20 +117.104.168.0/21 +117.106.0.0/15 +117.112.0.0/13 +117.120.64.0/18 +117.120.128.0/17 +117.121.0.0/17 +117.121.128.0/18 +117.121.192.0/21 +117.122.128.0/17 +117.124.0.0/14 +117.128.0.0/10 +118.24.0.0/15 +118.26.0.0/16 +118.28.0.0/15 +118.30.0.0/16 +118.31.0.0/16 +118.64.0.0/15 +118.66.0.0/16 +118.67.112.0/20 +118.72.0.0/13 +118.80.0.0/15 +118.84.0.0/15 +118.88.32.0/19 +118.88.64.0/18 +118.88.128.0/17 +118.89.0.0/16 +118.91.240.0/20 +118.102.16.0/20 +118.102.32.0/21 +118.112.0.0/13 +118.120.0.0/14 +118.124.0.0/15 +118.126.0.0/16 +118.127.128.0/19 +118.132.0.0/14 +118.144.0.0/14 +118.178.0.0/16 +118.180.0.0/14 +118.184.0.0/16 +118.186.0.0/15 +118.188.0.0/16 +118.190.0.0/15 +118.192.0.0/15 +118.194.0.0/17 +118.194.128.0/17 +118.195.0.0/16 +118.196.0.0/14 +118.202.0.0/15 +118.204.0.0/14 +118.212.0.0/16 +118.213.0.0/16 +118.224.0.0/14 +118.228.0.0/15 +118.230.0.0/16 +118.239.0.0/16 +118.242.0.0/16 +118.244.0.0/14 +118.248.0.0/13 +119.0.0.0/15 +119.2.0.0/19 +119.2.128.0/17 +119.3.0.0/16 +119.4.0.0/14 +119.8.0.0/16 +119.10.0.0/17 +119.15.136.0/21 +119.16.0.0/16 +119.18.192.0/20 +119.18.208.0/21 +119.18.224.0/20 +119.18.240.0/20 +119.19.0.0/16 +119.20.0.0/14 +119.27.64.0/18 +119.27.128.0/19 +119.27.160.0/19 +119.27.192.0/18 +119.28.0.0/15 +119.30.48.0/20 +119.31.192.0/19 +119.32.0.0/14 +119.36.0.0/16 +119.37.0.0/17 +119.37.128.0/18 +119.37.192.0/18 +119.38.0.0/17 +119.38.128.0/18 +119.38.192.0/20 +119.38.208.0/20 +119.38.224.0/19 +119.39.0.0/16 +119.40.0.0/18 +119.40.64.0/20 +119.40.128.0/17 +119.41.0.0/16 +119.42.0.0/19 +119.42.128.0/21 +119.42.136.0/21 +119.42.224.0/19 +119.44.0.0/15 +119.48.0.0/13 +119.57.0.0/16 +119.58.0.0/16 +119.59.128.0/17 +119.60.0.0/16 +119.61.0.0/16 +119.62.0.0/16 +119.63.32.0/19 +119.75.208.0/20 +119.78.0.0/15 +119.80.0.0/16 +119.82.208.0/20 +119.84.0.0/14 +119.88.0.0/14 +119.96.0.0/13 +119.108.0.0/15 +119.112.0.0/13 +119.120.0.0/13 +119.128.0.0/12 +119.144.0.0/14 +119.148.160.0/20 +119.148.176.0/20 +119.151.192.0/18 +119.160.200.0/21 +119.161.128.0/17 +119.162.0.0/15 +119.164.0.0/14 +119.176.0.0/12 +119.232.0.0/15 +119.235.128.0/18 +119.248.0.0/14 +119.252.96.0/21 +119.252.240.0/20 +119.253.0.0/16 +119.254.0.0/15 +120.0.0.0/12 +120.24.0.0/14 +120.30.0.0/16 +120.31.0.0/16 +120.32.0.0/13 +120.40.0.0/14 +120.44.0.0/14 +120.48.0.0/15 +120.52.0.0/14 +120.64.0.0/14 +120.68.0.0/14 +120.72.32.0/19 +120.72.128.0/17 +120.76.0.0/14 +120.80.0.0/13 +120.88.8.0/21 +120.90.0.0/15 +120.92.0.0/16 +120.94.0.0/16 +120.95.0.0/16 +120.128.0.0/14 +120.132.0.0/17 +120.132.128.0/17 +120.133.0.0/16 +120.134.0.0/15 +120.136.128.0/18 +120.137.0.0/17 +120.143.128.0/19 +120.192.0.0/10 +121.0.8.0/21 +121.0.16.0/20 +121.4.0.0/15 +121.8.0.0/13 +121.16.0.0/13 +121.24.0.0/14 +121.28.0.0/15 +121.30.0.0/16 +121.31.0.0/16 +121.32.0.0/14 +121.36.0.0/16 +121.37.0.0/16 +121.38.0.0/15 +121.40.0.0/14 +121.46.0.0/18 +121.46.128.0/17 +121.47.0.0/16 +121.48.0.0/15 +121.50.8.0/21 +121.51.0.0/16 +121.52.160.0/19 +121.52.208.0/20 +121.52.224.0/19 +121.54.176.0/21 +121.55.0.0/18 +121.56.0.0/15 +121.58.0.0/17 +121.58.136.0/21 +121.58.144.0/20 +121.58.160.0/21 +121.59.0.0/16 +121.60.0.0/14 +121.68.0.0/14 +121.76.0.0/15 +121.79.128.0/18 +121.89.0.0/16 +121.100.128.0/17 +121.101.0.0/18 +121.101.208.0/20 +121.192.0.0/16 +121.193.0.0/16 +121.194.0.0/15 +121.196.0.0/14 +121.200.192.0/21 +121.201.0.0/16 +121.204.0.0/14 +121.224.0.0/12 +121.248.0.0/14 +121.255.0.0/16 +122.0.64.0/18 +122.0.128.0/17 +122.4.0.0/14 +122.8.0.0/16 +122.9.0.0/16 +122.10.0.0/17 +122.10.128.0/17 +122.11.0.0/17 +122.12.0.0/16 +122.13.0.0/16 +122.14.0.0/16 +122.48.0.0/16 +122.49.0.0/18 +122.51.0.0/16 +122.64.0.0/11 +122.96.0.0/15 +122.102.0.0/20 +122.102.64.0/20 +122.102.80.0/20 +122.112.0.0/14 +122.119.0.0/16 +122.128.120.0/21 +122.136.0.0/13 +122.144.128.0/17 +122.152.192.0/18 +122.156.0.0/14 +122.188.0.0/14 +122.192.0.0/14 +122.198.0.0/16 +122.200.64.0/18 +122.201.48.0/20 +122.204.0.0/14 +122.224.0.0/12 +122.240.0.0/13 +122.248.24.0/21 +122.248.48.0/20 +122.255.64.0/21 +123.0.128.0/18 +123.4.0.0/14 +123.8.0.0/13 +123.49.128.0/17 +123.50.160.0/19 +123.52.0.0/14 +123.56.0.0/15 +123.58.0.0/16 +123.59.0.0/16 +123.60.0.0/15 +123.62.0.0/16 +123.64.0.0/11 +123.96.0.0/15 +123.98.0.0/17 +123.99.128.0/17 +123.100.0.0/19 +123.101.0.0/16 +123.103.0.0/17 +123.108.128.0/20 +123.108.208.0/20 +123.112.0.0/12 +123.128.0.0/13 +123.136.80.0/20 +123.137.0.0/16 +123.138.0.0/15 +123.144.0.0/14 +123.148.0.0/16 +123.149.0.0/16 +123.150.0.0/15 +123.152.0.0/13 +123.160.0.0/14 +123.164.0.0/14 +123.168.0.0/14 +123.172.0.0/15 +123.174.0.0/15 +123.176.60.0/22 +123.176.80.0/20 +123.177.0.0/16 +123.178.0.0/15 +123.180.0.0/14 +123.184.0.0/14 +123.188.0.0/14 +123.196.0.0/15 +123.199.128.0/17 +123.206.0.0/15 +123.232.0.0/14 +123.242.0.0/17 +123.244.0.0/14 +123.249.0.0/16 +123.253.0.0/16 +124.6.64.0/18 +124.14.0.0/15 +124.16.0.0/15 +124.20.0.0/16 +124.21.0.0/20 +124.21.16.0/20 +124.21.32.0/19 +124.21.64.0/18 +124.21.128.0/17 +124.22.0.0/15 +124.28.192.0/18 +124.29.0.0/17 +124.31.0.0/16 +124.40.112.0/20 +124.40.128.0/18 +124.40.192.0/19 +124.42.0.0/17 +124.42.128.0/17 +124.47.0.0/18 +124.64.0.0/15 +124.66.0.0/17 +124.67.0.0/16 +124.68.0.0/14 +124.72.0.0/16 +124.73.0.0/16 +124.74.0.0/15 +124.76.0.0/14 +124.88.0.0/16 +124.89.0.0/17 +124.89.128.0/17 +124.90.0.0/15 +124.92.0.0/14 +124.108.8.0/21 +124.108.40.0/21 +124.109.96.0/21 +124.112.0.0/15 +124.114.0.0/15 +124.116.0.0/16 +124.117.0.0/16 +124.118.0.0/15 +124.126.0.0/15 +124.128.0.0/13 +124.147.128.0/17 +124.151.0.0/16 +124.152.0.0/16 +124.156.0.0/16 +124.160.0.0/16 +124.161.0.0/16 +124.162.0.0/16 +124.163.0.0/16 +124.164.0.0/14 +124.172.0.0/15 +124.174.0.0/15 +124.192.0.0/15 +124.196.0.0/16 +124.200.0.0/13 +124.220.0.0/14 +124.224.0.0/16 +124.225.0.0/16 +124.226.0.0/15 +124.228.0.0/14 +124.232.0.0/15 +124.234.0.0/15 +124.236.0.0/14 +124.240.0.0/17 +124.240.128.0/18 +124.242.0.0/16 +124.243.192.0/18 +124.248.0.0/17 +124.249.0.0/16 +124.250.0.0/15 +124.254.0.0/18 +125.31.192.0/18 +125.32.0.0/16 +125.33.0.0/16 +125.34.0.0/16 +125.35.0.0/17 +125.35.128.0/17 +125.36.0.0/14 +125.40.0.0/13 +125.58.128.0/17 +125.61.128.0/17 +125.62.0.0/18 +125.64.0.0/13 +125.72.0.0/16 +125.73.0.0/16 +125.74.0.0/15 +125.76.0.0/17 +125.76.128.0/17 +125.77.0.0/16 +125.78.0.0/15 +125.80.0.0/13 +125.88.0.0/13 +125.96.0.0/15 +125.98.0.0/16 +125.104.0.0/13 +125.112.0.0/12 +125.169.0.0/16 +125.171.0.0/16 +125.208.0.0/18 +125.210.0.0/16 +125.211.0.0/16 +125.213.0.0/17 +125.214.96.0/19 +125.215.0.0/18 +125.216.0.0/15 +125.218.0.0/16 +125.219.0.0/16 +125.220.0.0/15 +125.222.0.0/15 +125.254.128.0/18 +125.254.192.0/18 +134.196.0.0/16 +139.9.0.0/16 +139.129.0.0/16 +139.148.0.0/16 +139.155.0.0/16 +139.159.0.0/16 +139.170.0.0/16 +139.176.0.0/16 +139.183.0.0/16 +139.186.0.0/16 +139.189.0.0/16 +139.196.0.0/14 +139.200.0.0/13 +139.208.0.0/13 +139.220.0.0/15 +139.224.0.0/16 +139.226.0.0/15 +140.75.0.0/16 +140.143.0.0/16 +140.205.0.0/16 +140.206.0.0/15 +140.210.0.0/16 +140.224.0.0/16 +140.237.0.0/16 +140.240.0.0/16 +140.243.0.0/16 +140.246.0.0/16 +140.249.0.0/16 +140.250.0.0/16 +140.255.0.0/16 +144.0.0.0/16 +144.7.0.0/16 +144.12.0.0/16 +144.52.0.0/16 +144.123.0.0/16 +144.255.0.0/16 +150.0.0.0/16 +150.115.0.0/16 +150.121.0.0/16 +150.122.0.0/16 +150.138.0.0/15 +150.223.0.0/16 +150.255.0.0/16 +153.0.0.0/16 +153.3.0.0/16 +153.34.0.0/15 +153.36.0.0/15 +153.99.0.0/16 +153.101.0.0/16 +153.118.0.0/15 +157.0.0.0/16 +157.18.0.0/16 +157.61.0.0/16 +157.122.0.0/16 +157.148.0.0/16 +157.156.0.0/16 +157.255.0.0/16 +159.226.0.0/16 +161.207.0.0/16 +162.105.0.0/16 +163.0.0.0/16 +163.125.0.0/16 +163.142.0.0/16 +163.177.0.0/16 +163.179.0.0/16 +163.204.0.0/16 +166.111.0.0/16 +167.139.0.0/16 +167.189.0.0/16 +168.160.0.0/16 +171.8.0.0/13 +171.34.0.0/15 +171.36.0.0/14 +171.40.0.0/13 +171.80.0.0/14 +171.84.0.0/14 +171.88.0.0/13 +171.104.0.0/13 +171.112.0.0/14 +171.116.0.0/14 +171.120.0.0/13 +171.208.0.0/12 +175.0.0.0/12 +175.16.0.0/13 +175.24.0.0/14 +175.30.0.0/15 +175.42.0.0/15 +175.44.0.0/16 +175.46.0.0/15 +175.48.0.0/12 +175.64.0.0/11 +175.102.0.0/16 +175.106.128.0/17 +175.146.0.0/15 +175.148.0.0/14 +175.152.0.0/14 +175.160.0.0/12 +175.178.0.0/16 +175.184.128.0/18 +175.185.0.0/16 +175.186.0.0/15 +175.188.0.0/14 +180.76.0.0/16 +180.77.0.0/16 +180.78.0.0/15 +180.84.0.0/15 +180.86.0.0/16 +180.88.0.0/14 +180.94.56.0/21 +180.94.96.0/20 +180.95.128.0/17 +180.96.0.0/11 +180.129.128.0/17 +180.130.0.0/16 +180.136.0.0/13 +180.148.16.0/21 +180.148.152.0/21 +180.148.216.0/21 +180.148.224.0/19 +180.149.128.0/19 +180.150.160.0/19 +180.152.0.0/13 +180.160.0.0/12 +180.178.192.0/18 +180.184.0.0/14 +180.188.0.0/17 +180.189.148.0/22 +180.200.252.0/22 +180.201.0.0/16 +180.202.0.0/15 +180.208.0.0/15 +180.210.224.0/19 +180.212.0.0/15 +180.222.224.0/19 +180.223.0.0/16 +180.233.0.0/18 +180.233.64.0/19 +180.235.64.0/19 +182.16.192.0/19 +182.18.0.0/17 +182.23.184.0/21 +182.23.200.0/21 +182.32.0.0/12 +182.48.96.0/19 +182.49.0.0/16 +182.50.0.0/20 +182.50.112.0/20 +182.51.0.0/16 +182.54.0.0/17 +182.61.0.0/16 +182.80.0.0/14 +182.84.0.0/14 +182.88.0.0/14 +182.92.0.0/16 +182.96.0.0/12 +182.112.0.0/12 +182.128.0.0/12 +182.144.0.0/13 +182.157.0.0/16 +182.160.64.0/19 +182.174.0.0/15 +182.200.0.0/13 +182.236.128.0/17 +182.238.0.0/16 +182.239.0.0/19 +182.240.0.0/13 +182.254.0.0/16 +183.0.0.0/10 +183.64.0.0/13 +183.78.180.0/22 +183.81.180.0/22 +183.84.0.0/15 +183.91.128.0/22 +183.91.136.0/21 +183.91.144.0/20 +183.92.0.0/14 +183.128.0.0/11 +183.160.0.0/13 +183.168.0.0/15 +183.170.0.0/16 +183.172.0.0/14 +183.182.0.0/19 +183.184.0.0/13 +183.192.0.0/10 +192.124.154.0/24 +192.188.170.0/24 +202.0.100.0/23 +202.0.122.0/23 +202.0.176.0/22 +202.3.128.0/23 +202.4.128.0/19 +202.4.252.0/22 +202.6.6.0/23 +202.6.66.0/23 +202.6.72.0/23 +202.6.87.0/24 +202.6.88.0/23 +202.6.92.0/23 +202.6.103.0/24 +202.6.108.0/24 +202.6.110.0/23 +202.6.114.0/24 +202.6.176.0/20 +202.8.0.0/24 +202.8.2.0/23 +202.8.4.0/23 +202.8.12.0/24 +202.8.24.0/24 +202.8.77.0/24 +202.8.128.0/19 +202.8.192.0/20 +202.9.32.0/24 +202.9.34.0/23 +202.9.48.0/23 +202.9.51.0/24 +202.9.52.0/23 +202.9.54.0/24 +202.9.57.0/24 +202.9.58.0/23 +202.10.64.0/20 +202.12.1.0/24 +202.12.2.0/24 +202.12.17.0/24 +202.12.18.0/24 +202.12.19.0/24 +202.12.72.0/24 +202.12.84.0/23 +202.12.96.0/24 +202.12.98.0/23 +202.12.106.0/24 +202.12.111.0/24 +202.12.116.0/24 +202.14.64.0/23 +202.14.69.0/24 +202.14.73.0/24 +202.14.74.0/23 +202.14.76.0/24 +202.14.78.0/23 +202.14.88.0/24 +202.14.97.0/24 +202.14.104.0/23 +202.14.108.0/23 +202.14.111.0/24 +202.14.114.0/23 +202.14.118.0/23 +202.14.124.0/23 +202.14.127.0/24 +202.14.129.0/24 +202.14.135.0/24 +202.14.136.0/24 +202.14.149.0/24 +202.14.151.0/24 +202.14.157.0/24 +202.14.158.0/23 +202.14.169.0/24 +202.14.170.0/23 +202.14.176.0/24 +202.14.184.0/23 +202.14.208.0/23 +202.14.213.0/24 +202.14.219.0/24 +202.14.220.0/24 +202.14.222.0/23 +202.14.225.0/24 +202.14.226.0/23 +202.14.231.0/24 +202.14.235.0/24 +202.14.236.0/23 +202.14.238.0/24 +202.14.239.0/24 +202.14.246.0/24 +202.14.251.0/24 +202.20.66.0/24 +202.20.79.0/24 +202.20.87.0/24 +202.20.88.0/23 +202.20.90.0/24 +202.20.94.0/23 +202.20.114.0/24 +202.20.117.0/24 +202.20.120.0/24 +202.20.125.0/24 +202.20.127.0/24 +202.21.131.0/24 +202.21.132.0/24 +202.21.141.0/24 +202.21.142.0/24 +202.21.147.0/24 +202.21.148.0/24 +202.21.150.0/23 +202.21.152.0/23 +202.21.154.0/24 +202.21.156.0/24 +202.22.248.0/22 +202.22.252.0/22 +202.27.136.0/23 +202.38.0.0/23 +202.38.2.0/23 +202.38.8.0/21 +202.38.48.0/20 +202.38.64.0/19 +202.38.96.0/19 +202.38.128.0/23 +202.38.130.0/23 +202.38.132.0/23 +202.38.134.0/24 +202.38.135.0/24 +202.38.136.0/23 +202.38.138.0/24 +202.38.140.0/23 +202.38.142.0/23 +202.38.146.0/23 +202.38.149.0/24 +202.38.150.0/23 +202.38.152.0/23 +202.38.154.0/23 +202.38.156.0/24 +202.38.158.0/23 +202.38.160.0/23 +202.38.164.0/22 +202.38.168.0/23 +202.38.170.0/24 +202.38.171.0/24 +202.38.176.0/23 +202.38.184.0/21 +202.38.192.0/18 +202.40.4.0/23 +202.40.7.0/24 +202.40.15.0/24 +202.40.135.0/24 +202.40.136.0/24 +202.40.140.0/24 +202.40.143.0/24 +202.40.144.0/23 +202.40.150.0/24 +202.40.155.0/24 +202.40.156.0/24 +202.40.158.0/23 +202.40.162.0/24 +202.41.8.0/23 +202.41.11.0/24 +202.41.12.0/23 +202.41.128.0/24 +202.41.130.0/23 +202.41.152.0/21 +202.41.192.0/24 +202.41.240.0/20 +202.43.76.0/22 +202.43.144.0/20 +202.44.16.0/20 +202.44.67.0/24 +202.44.74.0/24 +202.44.129.0/24 +202.44.132.0/23 +202.44.146.0/23 +202.45.0.0/23 +202.45.2.0/24 +202.45.15.0/24 +202.45.16.0/20 +202.46.16.0/23 +202.46.18.0/24 +202.46.20.0/23 +202.46.32.0/19 +202.46.128.0/24 +202.46.224.0/20 +202.47.82.0/23 +202.47.126.0/24 +202.47.128.0/24 +202.47.130.0/23 +202.57.240.0/20 +202.58.0.0/24 +202.59.0.0/24 +202.59.212.0/22 +202.59.232.0/23 +202.59.236.0/24 +202.60.48.0/21 +202.60.96.0/21 +202.60.112.0/20 +202.60.132.0/22 +202.60.136.0/21 +202.60.144.0/20 +202.62.112.0/22 +202.62.248.0/22 +202.62.252.0/24 +202.62.255.0/24 +202.63.81.0/24 +202.63.82.0/23 +202.63.84.0/22 +202.63.88.0/21 +202.63.160.0/19 +202.63.248.0/22 +202.65.0.0/21 +202.65.8.0/23 +202.67.0.0/22 +202.69.4.0/22 +202.69.16.0/20 +202.70.0.0/19 +202.70.96.0/20 +202.70.192.0/20 +202.72.40.0/21 +202.72.80.0/20 +202.73.128.0/22 +202.74.8.0/21 +202.74.80.0/20 +202.74.254.0/23 +202.75.208.0/20 +202.75.252.0/22 +202.76.252.0/22 +202.77.80.0/21 +202.77.92.0/22 +202.78.8.0/21 +202.79.224.0/21 +202.79.248.0/22 +202.80.192.0/21 +202.80.200.0/21 +202.81.0.0/22 +202.83.252.0/22 +202.84.4.0/22 +202.84.8.0/21 +202.84.24.0/21 +202.85.208.0/20 +202.86.249.0/24 +202.86.252.0/22 +202.87.80.0/20 +202.89.8.0/21 +202.90.0.0/22 +202.90.112.0/20 +202.90.196.0/24 +202.90.224.0/20 +202.91.0.0/22 +202.91.96.0/20 +202.91.128.0/22 +202.91.176.0/20 +202.91.224.0/19 +202.92.0.0/22 +202.92.8.0/21 +202.92.48.0/20 +202.92.252.0/22 +202.93.0.0/22 +202.93.252.0/22 +202.94.92.0/22 +202.95.0.0/22 +202.95.4.0/22 +202.95.8.0/21 +202.95.16.0/20 +202.95.240.0/21 +202.95.252.0/22 +202.96.0.0/18 +202.96.64.0/21 +202.96.72.0/21 +202.96.80.0/20 +202.96.96.0/21 +202.96.104.0/21 +202.96.112.0/20 +202.96.128.0/21 +202.96.136.0/21 +202.96.144.0/20 +202.96.160.0/21 +202.96.168.0/21 +202.96.176.0/20 +202.96.192.0/21 +202.96.200.0/21 +202.96.208.0/20 +202.96.224.0/21 +202.96.232.0/21 +202.96.240.0/20 +202.97.0.0/21 +202.97.8.0/21 +202.97.16.0/20 +202.97.32.0/19 +202.97.64.0/19 +202.97.96.0/20 +202.97.112.0/20 +202.97.128.0/18 +202.97.192.0/19 +202.97.224.0/21 +202.97.232.0/21 +202.97.240.0/20 +202.98.0.0/21 +202.98.8.0/21 +202.98.16.0/20 +202.98.32.0/21 +202.98.40.0/21 +202.98.48.0/20 +202.98.64.0/19 +202.98.96.0/21 +202.98.104.0/21 +202.98.112.0/20 +202.98.128.0/19 +202.98.160.0/21 +202.98.168.0/21 +202.98.176.0/20 +202.98.192.0/21 +202.98.200.0/21 +202.98.208.0/20 +202.98.224.0/21 +202.98.232.0/21 +202.98.240.0/20 +202.99.0.0/18 +202.99.64.0/19 +202.99.96.0/21 +202.99.104.0/21 +202.99.112.0/20 +202.99.128.0/19 +202.99.160.0/21 +202.99.168.0/21 +202.99.176.0/20 +202.99.192.0/21 +202.99.200.0/21 +202.99.208.0/20 +202.99.224.0/21 +202.99.232.0/21 +202.99.240.0/20 +202.100.0.0/21 +202.100.8.0/21 +202.100.16.0/20 +202.100.32.0/19 +202.100.64.0/21 +202.100.72.0/21 +202.100.80.0/20 +202.100.96.0/21 +202.100.104.0/21 +202.100.112.0/20 +202.100.128.0/21 +202.100.136.0/21 +202.100.144.0/20 +202.100.160.0/21 +202.100.168.0/21 +202.100.176.0/20 +202.100.192.0/21 +202.100.200.0/21 +202.100.208.0/20 +202.100.224.0/19 +202.101.0.0/18 +202.101.64.0/19 +202.101.96.0/19 +202.101.128.0/18 +202.101.192.0/19 +202.101.224.0/21 +202.101.232.0/21 +202.101.240.0/20 +202.102.0.0/19 +202.102.32.0/19 +202.102.64.0/18 +202.102.128.0/21 +202.102.136.0/21 +202.102.144.0/20 +202.102.160.0/19 +202.102.192.0/21 +202.102.200.0/21 +202.102.208.0/20 +202.102.224.0/21 +202.102.232.0/21 +202.102.240.0/20 +202.103.0.0/21 +202.103.8.0/21 +202.103.16.0/20 +202.103.32.0/19 +202.103.64.0/19 +202.103.96.0/21 +202.103.104.0/21 +202.103.112.0/20 +202.103.128.0/18 +202.103.192.0/19 +202.103.224.0/21 +202.103.232.0/21 +202.103.240.0/20 +202.104.0.0/15 +202.106.0.0/16 +202.107.0.0/17 +202.107.128.0/17 +202.108.0.0/16 +202.109.0.0/16 +202.110.0.0/18 +202.110.64.0/18 +202.110.128.0/18 +202.110.192.0/18 +202.111.0.0/17 +202.111.128.0/19 +202.111.160.0/19 +202.111.192.0/18 +202.112.0.0/16 +202.113.0.0/20 +202.113.16.0/20 +202.113.32.0/19 +202.113.64.0/18 +202.113.128.0/18 +202.113.192.0/19 +202.113.224.0/20 +202.113.240.0/20 +202.114.0.0/19 +202.114.32.0/19 +202.114.64.0/18 +202.114.128.0/17 +202.115.0.0/19 +202.115.32.0/19 +202.115.64.0/18 +202.115.128.0/17 +202.116.0.0/19 +202.116.32.0/20 +202.116.48.0/20 +202.116.64.0/19 +202.116.96.0/19 +202.116.128.0/17 +202.117.0.0/18 +202.117.64.0/18 +202.117.128.0/17 +202.118.0.0/19 +202.118.32.0/19 +202.118.64.0/18 +202.118.128.0/17 +202.119.0.0/19 +202.119.32.0/19 +202.119.64.0/20 +202.119.80.0/20 +202.119.96.0/19 +202.119.128.0/17 +202.120.0.0/18 +202.120.64.0/18 +202.120.128.0/17 +202.121.0.0/16 +202.122.0.0/21 +202.122.32.0/21 +202.122.64.0/19 +202.122.112.0/21 +202.122.120.0/21 +202.122.128.0/24 +202.122.132.0/24 +202.123.96.0/20 +202.124.16.0/21 +202.124.24.0/22 +202.125.112.0/20 +202.125.176.0/20 +202.127.0.0/23 +202.127.2.0/24 +202.127.3.0/24 +202.127.4.0/24 +202.127.5.0/24 +202.127.6.0/23 +202.127.12.0/22 +202.127.16.0/20 +202.127.40.0/21 +202.127.48.0/20 +202.127.112.0/20 +202.127.128.0/20 +202.127.144.0/20 +202.127.160.0/21 +202.127.192.0/23 +202.127.194.0/23 +202.127.196.0/22 +202.127.200.0/21 +202.127.208.0/24 +202.127.209.0/24 +202.127.212.0/22 +202.127.216.0/21 +202.127.224.0/19 +202.130.0.0/19 +202.130.224.0/19 +202.131.16.0/21 +202.131.48.0/20 +202.131.208.0/20 +202.133.32.0/20 +202.134.58.0/24 +202.134.128.0/20 +202.136.48.0/20 +202.136.208.0/20 +202.136.224.0/20 +202.137.231.0/24 +202.141.160.0/19 +202.142.16.0/20 +202.143.4.0/22 +202.143.16.0/20 +202.143.32.0/20 +202.143.56.0/21 +202.146.160.0/20 +202.146.188.0/22 +202.146.196.0/22 +202.146.200.0/21 +202.147.144.0/20 +202.148.32.0/20 +202.148.64.0/19 +202.148.96.0/19 +202.149.32.0/19 +202.149.160.0/19 +202.149.224.0/19 +202.150.16.0/20 +202.150.32.0/20 +202.150.56.0/22 +202.150.192.0/20 +202.150.224.0/19 +202.151.0.0/22 +202.151.128.0/19 +202.152.176.0/20 +202.153.0.0/22 +202.153.48.0/20 +202.157.192.0/19 +202.158.160.0/19 +202.160.176.0/20 +202.162.67.0/24 +202.162.75.0/24 +202.164.0.0/20 +202.164.96.0/19 +202.165.96.0/20 +202.165.176.0/20 +202.165.208.0/20 +202.165.239.0/24 +202.165.240.0/23 +202.165.243.0/24 +202.165.245.0/24 +202.165.251.0/24 +202.165.252.0/22 +202.166.224.0/19 +202.168.160.0/20 +202.168.176.0/20 +202.170.128.0/19 +202.170.216.0/21 +202.170.224.0/19 +202.171.216.0/21 +202.171.235.0/24 +202.172.0.0/22 +202.173.0.0/22 +202.173.8.0/21 +202.173.224.0/19 +202.174.64.0/20 +202.176.224.0/19 +202.179.240.0/20 +202.180.128.0/19 +202.180.208.0/21 +202.181.112.0/20 +202.182.32.0/20 +202.182.192.0/19 +202.189.0.0/18 +202.189.80.0/20 +202.189.184.0/21 +202.191.0.0/24 +202.191.68.0/22 +202.191.72.0/21 +202.191.80.0/20 +202.192.0.0/13 +202.200.0.0/14 +202.204.0.0/14 +203.0.4.0/22 +203.0.10.0/23 +203.0.18.0/24 +203.0.24.0/24 +203.0.42.0/23 +203.0.45.0/24 +203.0.46.0/23 +203.0.81.0/24 +203.0.82.0/23 +203.0.90.0/23 +203.0.96.0/23 +203.0.104.0/21 +203.0.114.0/23 +203.0.122.0/24 +203.0.128.0/24 +203.0.130.0/23 +203.0.132.0/22 +203.0.137.0/24 +203.0.142.0/24 +203.0.144.0/24 +203.0.146.0/24 +203.0.148.0/24 +203.0.150.0/23 +203.0.152.0/24 +203.0.177.0/24 +203.0.224.0/24 +203.1.4.0/22 +203.1.18.0/24 +203.1.26.0/23 +203.1.65.0/24 +203.1.66.0/23 +203.1.70.0/23 +203.1.76.0/23 +203.1.90.0/24 +203.1.97.0/24 +203.1.98.0/23 +203.1.100.0/22 +203.1.108.0/24 +203.1.253.0/24 +203.1.254.0/24 +203.2.64.0/21 +203.2.73.0/24 +203.2.112.0/21 +203.2.126.0/23 +203.2.140.0/24 +203.2.150.0/24 +203.2.152.0/22 +203.2.156.0/23 +203.2.160.0/21 +203.2.180.0/23 +203.2.196.0/23 +203.2.209.0/24 +203.2.214.0/23 +203.2.226.0/23 +203.2.229.0/24 +203.2.236.0/23 +203.3.68.0/24 +203.3.72.0/23 +203.3.75.0/24 +203.3.80.0/21 +203.3.96.0/22 +203.3.105.0/24 +203.3.112.0/21 +203.3.120.0/24 +203.3.123.0/24 +203.3.135.0/24 +203.3.139.0/24 +203.3.143.0/24 +203.4.132.0/23 +203.4.134.0/24 +203.4.151.0/24 +203.4.152.0/22 +203.4.174.0/23 +203.4.180.0/24 +203.4.186.0/24 +203.4.205.0/24 +203.4.208.0/22 +203.4.227.0/24 +203.4.230.0/23 +203.5.4.0/23 +203.5.7.0/24 +203.5.8.0/23 +203.5.11.0/24 +203.5.21.0/24 +203.5.22.0/24 +203.5.44.0/24 +203.5.46.0/23 +203.5.52.0/22 +203.5.56.0/23 +203.5.60.0/23 +203.5.114.0/23 +203.5.118.0/24 +203.5.120.0/24 +203.5.172.0/24 +203.5.180.0/23 +203.5.182.0/24 +203.5.185.0/24 +203.5.186.0/24 +203.5.188.0/23 +203.5.190.0/24 +203.5.195.0/24 +203.5.214.0/23 +203.5.218.0/23 +203.6.131.0/24 +203.6.136.0/24 +203.6.138.0/23 +203.6.142.0/24 +203.6.150.0/23 +203.6.157.0/24 +203.6.159.0/24 +203.6.224.0/20 +203.6.248.0/23 +203.7.129.0/24 +203.7.138.0/23 +203.7.147.0/24 +203.7.150.0/23 +203.7.158.0/24 +203.7.192.0/23 +203.7.200.0/24 +203.8.0.0/24 +203.8.8.0/24 +203.8.23.0/24 +203.8.24.0/21 +203.8.70.0/24 +203.8.82.0/24 +203.8.86.0/23 +203.8.91.0/24 +203.8.110.0/23 +203.8.115.0/24 +203.8.166.0/23 +203.8.169.0/24 +203.8.173.0/24 +203.8.184.0/24 +203.8.186.0/23 +203.8.190.0/23 +203.8.192.0/24 +203.8.197.0/24 +203.8.198.0/23 +203.8.203.0/24 +203.8.209.0/24 +203.8.210.0/23 +203.8.212.0/22 +203.8.217.0/24 +203.8.220.0/24 +203.9.32.0/24 +203.9.36.0/23 +203.9.57.0/24 +203.9.63.0/24 +203.9.65.0/24 +203.9.70.0/23 +203.9.72.0/24 +203.9.75.0/24 +203.9.76.0/23 +203.9.96.0/22 +203.9.100.0/23 +203.9.108.0/24 +203.9.158.0/24 +203.10.34.0/24 +203.10.56.0/24 +203.10.74.0/23 +203.10.84.0/22 +203.10.88.0/24 +203.10.95.0/24 +203.10.125.0/24 +203.11.70.0/24 +203.11.76.0/22 +203.11.82.0/24 +203.11.84.0/22 +203.11.100.0/22 +203.11.109.0/24 +203.11.117.0/24 +203.11.122.0/24 +203.11.126.0/24 +203.11.136.0/22 +203.11.141.0/24 +203.11.142.0/23 +203.11.180.0/22 +203.11.208.0/22 +203.12.16.0/24 +203.12.19.0/24 +203.12.24.0/24 +203.12.57.0/24 +203.12.65.0/24 +203.12.66.0/24 +203.12.70.0/23 +203.12.87.0/24 +203.12.88.0/21 +203.12.100.0/23 +203.12.103.0/24 +203.12.114.0/24 +203.12.118.0/24 +203.12.130.0/24 +203.12.137.0/24 +203.12.196.0/22 +203.12.200.0/21 +203.12.211.0/24 +203.12.219.0/24 +203.12.226.0/24 +203.12.240.0/22 +203.13.18.0/24 +203.13.24.0/24 +203.13.44.0/23 +203.13.80.0/21 +203.13.88.0/23 +203.13.92.0/22 +203.13.173.0/24 +203.13.224.0/23 +203.13.227.0/24 +203.13.233.0/24 +203.14.24.0/22 +203.14.33.0/24 +203.14.56.0/24 +203.14.61.0/24 +203.14.62.0/24 +203.14.104.0/24 +203.14.114.0/23 +203.14.118.0/24 +203.14.162.0/24 +203.14.184.0/21 +203.14.192.0/24 +203.14.194.0/23 +203.14.214.0/24 +203.14.231.0/24 +203.14.246.0/24 +203.15.0.0/20 +203.15.20.0/23 +203.15.22.0/24 +203.15.87.0/24 +203.15.88.0/23 +203.15.105.0/24 +203.15.112.0/21 +203.15.130.0/23 +203.15.149.0/24 +203.15.151.0/24 +203.15.156.0/22 +203.15.174.0/24 +203.15.227.0/24 +203.15.232.0/21 +203.15.240.0/23 +203.15.246.0/24 +203.16.10.0/24 +203.16.12.0/23 +203.16.16.0/21 +203.16.27.0/24 +203.16.38.0/24 +203.16.49.0/24 +203.16.50.0/23 +203.16.58.0/24 +203.16.133.0/24 +203.16.161.0/24 +203.16.162.0/24 +203.16.186.0/23 +203.16.228.0/24 +203.16.238.0/24 +203.16.240.0/24 +203.16.245.0/24 +203.17.2.0/24 +203.17.18.0/24 +203.17.28.0/24 +203.17.39.0/24 +203.17.56.0/24 +203.17.74.0/23 +203.17.88.0/23 +203.17.136.0/24 +203.17.164.0/24 +203.17.187.0/24 +203.17.190.0/23 +203.17.231.0/24 +203.17.233.0/24 +203.17.248.0/24 +203.17.255.0/24 +203.18.2.0/23 +203.18.4.0/24 +203.18.7.0/24 +203.18.31.0/24 +203.18.37.0/24 +203.18.48.0/23 +203.18.50.0/24 +203.18.52.0/24 +203.18.72.0/22 +203.18.80.0/23 +203.18.87.0/24 +203.18.100.0/23 +203.18.105.0/24 +203.18.107.0/24 +203.18.110.0/24 +203.18.129.0/24 +203.18.131.0/24 +203.18.132.0/23 +203.18.144.0/24 +203.18.153.0/24 +203.18.199.0/24 +203.18.208.0/24 +203.18.211.0/24 +203.18.215.0/24 +203.19.18.0/24 +203.19.24.0/24 +203.19.30.0/24 +203.19.32.0/21 +203.19.41.0/24 +203.19.44.0/23 +203.19.46.0/24 +203.19.58.0/24 +203.19.60.0/23 +203.19.64.0/24 +203.19.68.0/24 +203.19.72.0/24 +203.19.101.0/24 +203.19.111.0/24 +203.19.131.0/24 +203.19.133.0/24 +203.19.144.0/24 +203.19.149.0/24 +203.19.156.0/24 +203.19.176.0/24 +203.19.178.0/23 +203.19.208.0/24 +203.19.228.0/22 +203.19.233.0/24 +203.19.242.0/24 +203.19.248.0/23 +203.19.255.0/24 +203.20.17.0/24 +203.20.40.0/23 +203.20.48.0/24 +203.20.61.0/24 +203.20.65.0/24 +203.20.84.0/23 +203.20.89.0/24 +203.20.106.0/23 +203.20.115.0/24 +203.20.117.0/24 +203.20.118.0/23 +203.20.122.0/24 +203.20.126.0/23 +203.20.135.0/24 +203.20.136.0/21 +203.20.150.0/24 +203.20.230.0/24 +203.20.232.0/24 +203.20.236.0/24 +203.21.0.0/23 +203.21.2.0/24 +203.21.8.0/24 +203.21.10.0/24 +203.21.18.0/24 +203.21.33.0/24 +203.21.34.0/24 +203.21.41.0/24 +203.21.44.0/24 +203.21.68.0/24 +203.21.82.0/24 +203.21.96.0/22 +203.21.124.0/24 +203.21.136.0/23 +203.21.145.0/24 +203.21.206.0/24 +203.22.24.0/24 +203.22.28.0/23 +203.22.31.0/24 +203.22.68.0/24 +203.22.76.0/24 +203.22.78.0/24 +203.22.84.0/24 +203.22.87.0/24 +203.22.92.0/22 +203.22.99.0/24 +203.22.106.0/24 +203.22.122.0/23 +203.22.131.0/24 +203.22.163.0/24 +203.22.166.0/24 +203.22.170.0/24 +203.22.176.0/21 +203.22.194.0/24 +203.22.242.0/23 +203.22.245.0/24 +203.22.246.0/24 +203.22.252.0/23 +203.23.0.0/24 +203.23.47.0/24 +203.23.61.0/24 +203.23.62.0/23 +203.23.73.0/24 +203.23.85.0/24 +203.23.92.0/22 +203.23.98.0/24 +203.23.107.0/24 +203.23.112.0/24 +203.23.130.0/24 +203.23.140.0/23 +203.23.172.0/24 +203.23.182.0/24 +203.23.186.0/23 +203.23.192.0/24 +203.23.197.0/24 +203.23.198.0/24 +203.23.204.0/22 +203.23.224.0/24 +203.23.226.0/23 +203.23.228.0/22 +203.23.249.0/24 +203.23.251.0/24 +203.24.13.0/24 +203.24.18.0/24 +203.24.27.0/24 +203.24.43.0/24 +203.24.56.0/24 +203.24.58.0/24 +203.24.67.0/24 +203.24.74.0/24 +203.24.79.0/24 +203.24.80.0/23 +203.24.84.0/23 +203.24.86.0/24 +203.24.90.0/24 +203.24.111.0/24 +203.24.112.0/24 +203.24.116.0/24 +203.24.122.0/23 +203.24.145.0/24 +203.24.152.0/23 +203.24.157.0/24 +203.24.161.0/24 +203.24.167.0/24 +203.24.186.0/23 +203.24.199.0/24 +203.24.202.0/24 +203.24.212.0/23 +203.24.217.0/24 +203.24.219.0/24 +203.24.244.0/24 +203.25.19.0/24 +203.25.20.0/23 +203.25.46.0/24 +203.25.48.0/21 +203.25.64.0/23 +203.25.91.0/24 +203.25.99.0/24 +203.25.100.0/24 +203.25.106.0/24 +203.25.131.0/24 +203.25.135.0/24 +203.25.138.0/24 +203.25.147.0/24 +203.25.153.0/24 +203.25.154.0/23 +203.25.164.0/24 +203.25.166.0/24 +203.25.174.0/23 +203.25.180.0/24 +203.25.182.0/24 +203.25.191.0/24 +203.25.199.0/24 +203.25.200.0/24 +203.25.202.0/23 +203.25.208.0/20 +203.25.229.0/24 +203.25.235.0/24 +203.25.236.0/24 +203.25.242.0/24 +203.26.12.0/24 +203.26.34.0/24 +203.26.49.0/24 +203.26.50.0/24 +203.26.55.0/24 +203.26.56.0/23 +203.26.60.0/24 +203.26.65.0/24 +203.26.68.0/24 +203.26.76.0/24 +203.26.80.0/24 +203.26.84.0/24 +203.26.97.0/24 +203.26.102.0/23 +203.26.115.0/24 +203.26.116.0/24 +203.26.129.0/24 +203.26.143.0/24 +203.26.144.0/24 +203.26.148.0/23 +203.26.154.0/24 +203.26.158.0/23 +203.26.170.0/24 +203.26.173.0/24 +203.26.176.0/24 +203.26.185.0/24 +203.26.202.0/23 +203.26.210.0/24 +203.26.214.0/24 +203.26.222.0/24 +203.26.224.0/24 +203.26.228.0/24 +203.26.232.0/24 +203.27.0.0/24 +203.27.10.0/24 +203.27.15.0/24 +203.27.16.0/24 +203.27.20.0/24 +203.27.22.0/23 +203.27.40.0/24 +203.27.45.0/24 +203.27.53.0/24 +203.27.65.0/24 +203.27.66.0/24 +203.27.81.0/24 +203.27.88.0/24 +203.27.102.0/24 +203.27.109.0/24 +203.27.117.0/24 +203.27.121.0/24 +203.27.122.0/23 +203.27.125.0/24 +203.27.200.0/24 +203.27.202.0/24 +203.27.233.0/24 +203.27.241.0/24 +203.27.250.0/24 +203.28.10.0/24 +203.28.12.0/24 +203.28.33.0/24 +203.28.34.0/23 +203.28.43.0/24 +203.28.44.0/24 +203.28.54.0/24 +203.28.56.0/24 +203.28.73.0/24 +203.28.74.0/24 +203.28.76.0/24 +203.28.86.0/24 +203.28.88.0/24 +203.28.112.0/24 +203.28.131.0/24 +203.28.136.0/24 +203.28.140.0/24 +203.28.145.0/24 +203.28.165.0/24 +203.28.169.0/24 +203.28.170.0/24 +203.28.178.0/23 +203.28.185.0/24 +203.28.187.0/24 +203.28.196.0/24 +203.28.226.0/23 +203.28.239.0/24 +203.29.2.0/24 +203.29.8.0/23 +203.29.13.0/24 +203.29.14.0/24 +203.29.28.0/24 +203.29.46.0/24 +203.29.57.0/24 +203.29.61.0/24 +203.29.63.0/24 +203.29.69.0/24 +203.29.73.0/24 +203.29.81.0/24 +203.29.90.0/24 +203.29.95.0/24 +203.29.100.0/24 +203.29.103.0/24 +203.29.112.0/24 +203.29.120.0/22 +203.29.182.0/23 +203.29.187.0/24 +203.29.189.0/24 +203.29.190.0/24 +203.29.205.0/24 +203.29.210.0/24 +203.29.217.0/24 +203.29.227.0/24 +203.29.231.0/24 +203.29.233.0/24 +203.29.234.0/24 +203.29.248.0/24 +203.29.254.0/23 +203.30.16.0/23 +203.30.25.0/24 +203.30.27.0/24 +203.30.29.0/24 +203.30.66.0/24 +203.30.81.0/24 +203.30.87.0/24 +203.30.111.0/24 +203.30.121.0/24 +203.30.123.0/24 +203.30.152.0/24 +203.30.156.0/24 +203.30.162.0/24 +203.30.173.0/24 +203.30.175.0/24 +203.30.187.0/24 +203.30.194.0/24 +203.30.217.0/24 +203.30.220.0/24 +203.30.222.0/24 +203.30.232.0/23 +203.30.235.0/24 +203.30.240.0/23 +203.30.246.0/24 +203.30.250.0/23 +203.31.45.0/24 +203.31.46.0/24 +203.31.49.0/24 +203.31.51.0/24 +203.31.54.0/23 +203.31.69.0/24 +203.31.72.0/24 +203.31.80.0/24 +203.31.85.0/24 +203.31.97.0/24 +203.31.105.0/24 +203.31.106.0/24 +203.31.108.0/23 +203.31.124.0/24 +203.31.162.0/24 +203.31.174.0/24 +203.31.177.0/24 +203.31.181.0/24 +203.31.187.0/24 +203.31.189.0/24 +203.31.204.0/24 +203.31.220.0/24 +203.31.222.0/23 +203.31.225.0/24 +203.31.229.0/24 +203.31.248.0/23 +203.31.253.0/24 +203.32.20.0/24 +203.32.48.0/23 +203.32.56.0/24 +203.32.60.0/24 +203.32.62.0/24 +203.32.68.0/23 +203.32.76.0/24 +203.32.81.0/24 +203.32.84.0/23 +203.32.95.0/24 +203.32.102.0/24 +203.32.105.0/24 +203.32.130.0/24 +203.32.133.0/24 +203.32.140.0/24 +203.32.152.0/24 +203.32.186.0/23 +203.32.192.0/24 +203.32.196.0/24 +203.32.203.0/24 +203.32.204.0/23 +203.32.212.0/24 +203.33.4.0/24 +203.33.7.0/24 +203.33.8.0/21 +203.33.21.0/24 +203.33.26.0/24 +203.33.32.0/24 +203.33.63.0/24 +203.33.64.0/24 +203.33.67.0/24 +203.33.68.0/24 +203.33.73.0/24 +203.33.79.0/24 +203.33.100.0/24 +203.33.122.0/24 +203.33.129.0/24 +203.33.131.0/24 +203.33.145.0/24 +203.33.156.0/24 +203.33.158.0/23 +203.33.174.0/24 +203.33.185.0/24 +203.33.200.0/24 +203.33.202.0/23 +203.33.204.0/24 +203.33.206.0/23 +203.33.214.0/23 +203.33.224.0/23 +203.33.226.0/24 +203.33.233.0/24 +203.33.243.0/24 +203.33.250.0/24 +203.34.4.0/24 +203.34.21.0/24 +203.34.27.0/24 +203.34.39.0/24 +203.34.48.0/23 +203.34.54.0/24 +203.34.56.0/23 +203.34.67.0/24 +203.34.69.0/24 +203.34.76.0/24 +203.34.92.0/24 +203.34.106.0/24 +203.34.113.0/24 +203.34.147.0/24 +203.34.150.0/24 +203.34.152.0/23 +203.34.161.0/24 +203.34.162.0/24 +203.34.187.0/24 +203.34.192.0/21 +203.34.204.0/22 +203.34.232.0/24 +203.34.240.0/24 +203.34.242.0/24 +203.34.245.0/24 +203.34.251.0/24 +203.55.2.0/23 +203.55.4.0/24 +203.55.10.0/24 +203.55.13.0/24 +203.55.22.0/24 +203.55.30.0/24 +203.55.93.0/24 +203.55.101.0/24 +203.55.109.0/24 +203.55.110.0/24 +203.55.116.0/23 +203.55.119.0/24 +203.55.128.0/23 +203.55.146.0/23 +203.55.192.0/24 +203.55.196.0/24 +203.55.218.0/23 +203.55.221.0/24 +203.55.224.0/24 +203.56.1.0/24 +203.56.4.0/24 +203.56.12.0/24 +203.56.24.0/24 +203.56.38.0/24 +203.56.40.0/24 +203.56.46.0/24 +203.56.48.0/21 +203.56.68.0/23 +203.56.82.0/23 +203.56.84.0/23 +203.56.95.0/24 +203.56.110.0/24 +203.56.121.0/24 +203.56.161.0/24 +203.56.169.0/24 +203.56.172.0/23 +203.56.175.0/24 +203.56.183.0/24 +203.56.185.0/24 +203.56.187.0/24 +203.56.192.0/24 +203.56.198.0/24 +203.56.201.0/24 +203.56.208.0/23 +203.56.210.0/24 +203.56.214.0/24 +203.56.216.0/24 +203.56.227.0/24 +203.56.228.0/24 +203.56.232.0/24 +203.56.240.0/24 +203.56.252.0/24 +203.56.254.0/24 +203.57.5.0/24 +203.57.6.0/24 +203.57.12.0/23 +203.57.28.0/24 +203.57.39.0/24 +203.57.46.0/24 +203.57.58.0/24 +203.57.61.0/24 +203.57.66.0/24 +203.57.69.0/24 +203.57.70.0/23 +203.57.73.0/24 +203.57.90.0/24 +203.57.101.0/24 +203.57.109.0/24 +203.57.123.0/24 +203.57.157.0/24 +203.57.200.0/24 +203.57.202.0/24 +203.57.206.0/24 +203.57.222.0/24 +203.57.224.0/20 +203.57.246.0/23 +203.57.249.0/24 +203.57.253.0/24 +203.57.254.0/23 +203.62.2.0/24 +203.62.131.0/24 +203.62.139.0/24 +203.62.161.0/24 +203.62.197.0/24 +203.62.228.0/22 +203.62.234.0/24 +203.62.246.0/24 +203.76.160.0/22 +203.76.168.0/22 +203.77.180.0/22 +203.78.48.0/20 +203.79.0.0/20 +203.79.32.0/20 +203.80.4.0/23 +203.80.32.0/20 +203.80.57.0/24 +203.80.132.0/22 +203.80.136.0/21 +203.80.144.0/20 +203.81.0.0/21 +203.81.16.0/20 +203.82.0.0/23 +203.82.16.0/21 +203.83.0.0/22 +203.83.56.0/21 +203.83.224.0/20 +203.86.0.0/19 +203.86.32.0/19 +203.86.64.0/20 +203.86.80.0/20 +203.86.96.0/19 +203.86.254.0/23 +203.88.32.0/19 +203.88.192.0/19 +203.89.0.0/22 +203.89.8.0/21 +203.89.136.0/22 +203.90.0.0/22 +203.90.8.0/22 +203.90.128.0/19 +203.90.160.0/19 +203.90.192.0/19 +203.91.32.0/19 +203.91.96.0/20 +203.91.120.0/21 +203.92.0.0/22 +203.92.160.0/19 +203.93.0.0/22 +203.93.4.0/22 +203.93.8.0/24 +203.93.9.0/24 +203.93.10.0/23 +203.93.12.0/22 +203.93.16.0/20 +203.93.32.0/19 +203.93.64.0/18 +203.93.128.0/21 +203.93.136.0/22 +203.93.140.0/24 +203.93.141.0/24 +203.93.142.0/23 +203.93.144.0/20 +203.93.160.0/19 +203.93.192.0/18 +203.94.0.0/22 +203.94.4.0/22 +203.94.8.0/21 +203.94.16.0/20 +203.95.0.0/21 +203.95.96.0/20 +203.95.112.0/20 +203.95.128.0/18 +203.95.224.0/19 +203.99.8.0/21 +203.99.16.0/20 +203.99.80.0/20 +203.100.32.0/20 +203.100.48.0/21 +203.100.63.0/24 +203.100.80.0/20 +203.100.96.0/19 +203.100.192.0/20 +203.104.32.0/20 +203.105.96.0/19 +203.105.128.0/19 +203.107.0.0/17 +203.110.160.0/19 +203.110.208.0/20 +203.110.232.0/23 +203.110.234.0/24 +203.114.244.0/22 +203.118.192.0/19 +203.118.241.0/24 +203.118.248.0/22 +203.119.24.0/21 +203.119.32.0/22 +203.119.80.0/22 +203.119.85.0/24 +203.119.113.0/24 +203.119.114.0/23 +203.119.116.0/22 +203.119.120.0/21 +203.119.128.0/17 +203.128.32.0/19 +203.128.96.0/19 +203.128.224.0/21 +203.129.8.0/21 +203.130.32.0/19 +203.132.32.0/19 +203.134.240.0/21 +203.135.96.0/20 +203.135.112.0/20 +203.135.160.0/20 +203.142.224.0/19 +203.144.96.0/19 +203.145.0.0/19 +203.148.0.0/18 +203.148.64.0/20 +203.148.80.0/22 +203.148.86.0/23 +203.149.92.0/22 +203.152.64.0/19 +203.152.128.0/19 +203.153.0.0/22 +203.156.192.0/18 +203.158.16.0/21 +203.160.104.0/21 +203.160.129.0/24 +203.160.192.0/19 +203.161.0.0/22 +203.161.180.0/24 +203.161.192.0/19 +203.166.160.0/19 +203.168.0.0/19 +203.170.58.0/23 +203.171.0.0/22 +203.171.224.0/20 +203.174.4.0/24 +203.174.7.0/24 +203.174.96.0/19 +203.175.128.0/19 +203.175.192.0/18 +203.176.0.0/18 +203.176.64.0/19 +203.176.168.0/21 +203.184.80.0/20 +203.187.160.0/19 +203.189.0.0/23 +203.189.6.0/23 +203.189.112.0/22 +203.189.192.0/19 +203.190.96.0/20 +203.190.249.0/24 +203.191.0.0/23 +203.191.16.0/20 +203.191.64.0/18 +203.191.144.0/21 +203.191.152.0/21 +203.192.0.0/19 +203.193.224.0/19 +203.194.120.0/21 +203.195.64.0/19 +203.195.112.0/21 +203.195.128.0/17 +203.196.0.0/21 +203.196.8.0/21 +203.202.236.0/22 +203.205.64.0/19 +203.205.128.0/17 +203.207.64.0/18 +203.207.128.0/17 +203.208.0.0/20 +203.208.16.0/22 +203.208.32.0/19 +203.209.224.0/19 +203.212.0.0/20 +203.212.80.0/20 +203.215.232.0/21 +203.222.192.0/20 +203.223.0.0/20 +203.223.16.0/21 +210.2.0.0/20 +210.2.16.0/20 +210.5.0.0/19 +210.5.56.0/21 +210.5.128.0/20 +210.5.144.0/20 +210.12.0.0/18 +210.12.64.0/18 +210.12.128.0/18 +210.12.192.0/18 +210.13.0.0/18 +210.13.64.0/18 +210.13.128.0/17 +210.14.64.0/19 +210.14.112.0/20 +210.14.128.0/19 +210.14.160.0/19 +210.14.192.0/19 +210.14.224.0/19 +210.15.0.0/19 +210.15.32.0/19 +210.15.64.0/19 +210.15.96.0/19 +210.15.128.0/18 +210.16.128.0/18 +210.21.0.0/17 +210.21.128.0/17 +210.22.0.0/16 +210.23.32.0/19 +210.25.0.0/16 +210.26.0.0/15 +210.28.0.0/14 +210.32.0.0/14 +210.36.0.0/14 +210.40.0.0/13 +210.48.136.0/21 +210.51.0.0/16 +210.52.0.0/18 +210.52.64.0/18 +210.52.128.0/17 +210.53.0.0/17 +210.53.128.0/17 +210.56.192.0/19 +210.72.0.0/17 +210.72.128.0/19 +210.72.160.0/19 +210.72.192.0/18 +210.73.0.0/19 +210.73.32.0/19 +210.73.64.0/18 +210.73.128.0/17 +210.74.0.0/19 +210.74.32.0/19 +210.74.64.0/19 +210.74.96.0/19 +210.74.128.0/19 +210.74.160.0/19 +210.74.192.0/18 +210.75.0.0/16 +210.76.0.0/19 +210.76.32.0/19 +210.76.64.0/18 +210.76.128.0/17 +210.77.0.0/16 +210.78.0.0/19 +210.78.32.0/19 +210.78.64.0/18 +210.78.128.0/19 +210.78.160.0/19 +210.78.192.0/18 +210.79.64.0/18 +210.79.224.0/19 +210.82.0.0/15 +210.87.128.0/20 +210.87.144.0/20 +210.87.160.0/19 +210.185.192.0/18 +210.192.96.0/19 +211.64.0.0/14 +211.68.0.0/15 +211.70.0.0/15 +211.80.0.0/16 +211.81.0.0/16 +211.82.0.0/16 +211.83.0.0/16 +211.84.0.0/15 +211.86.0.0/15 +211.88.0.0/16 +211.89.0.0/16 +211.90.0.0/15 +211.92.0.0/15 +211.94.0.0/15 +211.96.0.0/15 +211.98.0.0/16 +211.99.0.0/18 +211.99.64.0/19 +211.99.96.0/19 +211.99.128.0/17 +211.100.0.0/16 +211.101.0.0/18 +211.101.64.0/18 +211.101.128.0/17 +211.102.0.0/16 +211.103.0.0/17 +211.103.128.0/17 +211.136.0.0/14 +211.140.0.0/15 +211.142.0.0/17 +211.142.128.0/17 +211.143.0.0/16 +211.144.0.0/15 +211.146.0.0/16 +211.147.0.0/16 +211.148.0.0/14 +211.152.0.0/15 +211.154.0.0/16 +211.155.0.0/18 +211.155.64.0/19 +211.155.96.0/19 +211.155.128.0/17 +211.156.0.0/14 +211.160.0.0/14 +211.164.0.0/14 +218.0.0.0/16 +218.1.0.0/16 +218.2.0.0/15 +218.4.0.0/15 +218.6.0.0/16 +218.7.0.0/16 +218.8.0.0/15 +218.10.0.0/16 +218.11.0.0/16 +218.12.0.0/16 +218.13.0.0/16 +218.14.0.0/15 +218.16.0.0/14 +218.20.0.0/16 +218.21.0.0/17 +218.21.128.0/17 +218.22.0.0/15 +218.24.0.0/15 +218.26.0.0/16 +218.27.0.0/16 +218.28.0.0/15 +218.30.0.0/15 +218.56.0.0/14 +218.60.0.0/15 +218.62.0.0/17 +218.62.128.0/17 +218.63.0.0/16 +218.64.0.0/15 +218.66.0.0/16 +218.67.0.0/17 +218.67.128.0/17 +218.68.0.0/15 +218.70.0.0/15 +218.72.0.0/14 +218.76.0.0/15 +218.78.0.0/15 +218.80.0.0/14 +218.84.0.0/14 +218.88.0.0/13 +218.96.0.0/15 +218.98.0.0/17 +218.98.128.0/18 +218.98.192.0/19 +218.98.224.0/19 +218.99.0.0/16 +218.100.88.0/21 +218.100.96.0/19 +218.100.128.0/17 +218.104.0.0/17 +218.104.128.0/19 +218.104.160.0/19 +218.104.192.0/21 +218.104.200.0/21 +218.104.208.0/20 +218.104.224.0/19 +218.105.0.0/16 +218.106.0.0/15 +218.108.0.0/16 +218.109.0.0/16 +218.185.192.0/19 +218.185.240.0/21 +218.192.0.0/16 +218.193.0.0/16 +218.194.0.0/16 +218.195.0.0/16 +218.196.0.0/14 +218.200.0.0/14 +218.204.0.0/15 +218.206.0.0/15 +218.240.0.0/14 +218.244.0.0/15 +218.246.0.0/15 +218.249.0.0/16 +219.72.0.0/16 +219.82.0.0/16 +219.83.128.0/17 +219.128.0.0/12 +219.144.0.0/14 +219.148.0.0/16 +219.149.0.0/17 +219.149.128.0/18 +219.149.192.0/18 +219.150.0.0/19 +219.150.32.0/19 +219.150.64.0/19 +219.150.96.0/20 +219.150.112.0/20 +219.150.128.0/17 +219.151.0.0/19 +219.151.32.0/19 +219.151.64.0/18 +219.151.128.0/17 +219.152.0.0/15 +219.154.0.0/15 +219.156.0.0/15 +219.158.0.0/17 +219.158.128.0/17 +219.159.0.0/18 +219.159.64.0/18 +219.159.128.0/17 +219.216.0.0/15 +219.218.0.0/15 +219.220.0.0/16 +219.221.0.0/16 +219.222.0.0/15 +219.224.0.0/15 +219.226.0.0/16 +219.227.0.0/16 +219.228.0.0/15 +219.230.0.0/15 +219.232.0.0/14 +219.236.0.0/15 +219.238.0.0/15 +219.242.0.0/15 +219.244.0.0/14 +220.101.192.0/18 +220.112.0.0/14 +220.152.128.0/17 +220.154.0.0/15 +220.160.0.0/11 +220.192.0.0/15 +220.194.0.0/15 +220.196.0.0/14 +220.200.0.0/13 +220.231.0.0/18 +220.231.128.0/17 +220.232.64.0/18 +220.234.0.0/16 +220.242.0.0/15 +220.247.136.0/21 +220.248.0.0/14 +220.252.0.0/16 +221.0.0.0/15 +221.2.0.0/16 +221.3.0.0/17 +221.3.128.0/17 +221.4.0.0/16 +221.5.0.0/17 +221.5.128.0/17 +221.6.0.0/16 +221.7.0.0/19 +221.7.32.0/19 +221.7.64.0/19 +221.7.96.0/19 +221.7.128.0/17 +221.8.0.0/15 +221.10.0.0/16 +221.11.0.0/17 +221.11.128.0/18 +221.11.192.0/19 +221.11.224.0/19 +221.12.0.0/17 +221.12.128.0/18 +221.13.0.0/18 +221.13.64.0/19 +221.13.96.0/19 +221.13.128.0/17 +221.14.0.0/15 +221.122.0.0/15 +221.128.128.0/17 +221.129.0.0/16 +221.130.0.0/15 +221.133.224.0/19 +221.136.0.0/16 +221.137.0.0/16 +221.172.0.0/14 +221.176.0.0/13 +221.192.0.0/15 +221.194.0.0/16 +221.195.0.0/16 +221.196.0.0/15 +221.198.0.0/16 +221.199.0.0/19 +221.199.32.0/20 +221.199.48.0/20 +221.199.64.0/18 +221.199.128.0/18 +221.199.192.0/20 +221.199.224.0/19 +221.200.0.0/14 +221.204.0.0/15 +221.206.0.0/16 +221.207.0.0/18 +221.207.64.0/18 +221.207.128.0/17 +221.208.0.0/14 +221.212.0.0/16 +221.213.0.0/16 +221.214.0.0/15 +221.216.0.0/13 +221.224.0.0/13 +221.232.0.0/14 +221.236.0.0/15 +221.238.0.0/16 +221.239.0.0/17 +221.239.128.0/17 +222.16.0.0/15 +222.18.0.0/15 +222.20.0.0/15 +222.22.0.0/16 +222.23.0.0/16 +222.24.0.0/15 +222.26.0.0/15 +222.28.0.0/14 +222.32.0.0/11 +222.64.0.0/13 +222.72.0.0/15 +222.74.0.0/16 +222.75.0.0/16 +222.76.0.0/14 +222.80.0.0/15 +222.82.0.0/16 +222.83.0.0/17 +222.83.128.0/17 +222.84.0.0/16 +222.85.0.0/17 +222.85.128.0/17 +222.86.0.0/15 +222.88.0.0/15 +222.90.0.0/15 +222.92.0.0/14 +222.125.0.0/16 +222.126.128.0/17 +222.128.0.0/14 +222.132.0.0/14 +222.136.0.0/13 +222.160.0.0/15 +222.162.0.0/16 +222.163.0.0/19 +222.163.32.0/19 +222.163.64.0/18 +222.163.128.0/17 +222.168.0.0/15 +222.170.0.0/15 +222.172.0.0/17 +222.172.128.0/17 +222.173.0.0/16 +222.174.0.0/15 +222.176.0.0/13 +222.184.0.0/13 +222.192.0.0/14 +222.196.0.0/15 +222.198.0.0/16 +222.199.0.0/16 +222.200.0.0/14 +222.204.0.0/15 +222.206.0.0/15 +222.208.0.0/13 +222.216.0.0/15 +222.218.0.0/16 +222.219.0.0/16 +222.220.0.0/15 +222.222.0.0/15 +222.240.0.0/13 +222.248.0.0/16 +222.249.0.0/17 +222.249.128.0/19 +222.249.160.0/20 +222.249.176.0/20 +222.249.192.0/18 +223.0.0.0/15 +223.2.0.0/15 +223.4.0.0/14 +223.8.0.0/13 +223.20.0.0/15 +223.27.184.0/22 +223.64.0.0/11 +223.96.0.0/12 +223.112.0.0/14 +223.116.0.0/15 +223.120.0.0/13 +223.128.0.0/15 +223.144.0.0/12 +223.160.0.0/14 +223.166.0.0/15 +223.192.0.0/15 +223.198.0.0/15 +223.201.0.0/16 +223.202.0.0/15 +223.208.0.0/14 +223.212.0.0/15 +223.214.0.0/15 +223.220.0.0/15 +223.223.176.0/20 +223.223.192.0/20 +223.240.0.0/13 +223.248.0.0/14 +223.252.128.0/17 +223.254.0.0/16 +223.255.0.0/17 +223.255.236.0/22 +223.255.252.0/23 diff --git a/lib/shadowsocks.rb b/lib/shadowsocks.rb index 41019bb..2955e75 100644 --- a/lib/shadowsocks.rb +++ b/lib/shadowsocks.rb @@ -8,6 +8,7 @@ module Shadowsocks autoload :Table, 'shadowsocks/table' autoload :Tunnel, 'shadowsocks/tunnel' autoload :Listener, 'shadowsocks/listener' + autoload :IPDetector, 'shadowsocks/ip_detector' module Parser autoload :Base, 'shadowsocks/parser/base' diff --git a/lib/shadowsocks/cli.rb b/lib/shadowsocks/cli.rb index e2ddb73..730f4a7 100644 --- a/lib/shadowsocks/cli.rb +++ b/lib/shadowsocks/cli.rb @@ -10,8 +10,9 @@ class Cli attr_accessor :side, :args, :config def initialize(options) - @side = options[:side] - @config = options[:config] + @side = options[:side] + @config = options[:config] + @ip_detector = Shadowsocks::IPDetector.new if @config.chnroutes @method_options = { method: config.method, @@ -58,7 +59,7 @@ def initialize_connection connection connection.crypto = Shadowsocks::Crypto.new @method_options connection.pending_connect_timeout = @config.timeout connection.comm_inactivity_timeout = @config.timeout + connection.ip_detector = @ip_detector if @config.chnroutes end - end end diff --git a/lib/shadowsocks/config.rb b/lib/shadowsocks/config.rb index d4c640a..5b66d5f 100644 --- a/lib/shadowsocks/config.rb +++ b/lib/shadowsocks/config.rb @@ -2,7 +2,7 @@ module Shadowsocks class Config - attr_reader :args, :server, :server_port, :local_port, :password, :timeout, :method, :config_path + attr_reader :args, :server, :server_port, :local_port, :password, :timeout, :method, :config_path, :chnroutes def initialize(_args) @args = _args || [] @@ -23,12 +23,13 @@ def read_config @local_port = json["local_port"].to_i if @local_port.nil? @timeout = json["timeout"].to_i if @timeout.nil? @method = json["method"] if @method.nil? + @chnroutes = json["chnroutes"] if @chnroutes.nil? end private def parse_args - opt_parser = OptionParser.new do |opts| + opt_parser = OptionParser.new do |opts| opts.banner = "Usage: ss-server [options]" opts.separator "" @@ -41,6 +42,7 @@ def parse_args opts.on("-l", "--local_port PORT", Integer, "Local client port") { |c| @local_port = c } opts.on("-m", "--method METHOD", "Encryption method") { |c| @method = c } opts.on("-t", "--timeout NUMBER", Integer, "connection timeout") { |c| @timeout = c } + opts.on("-d", "--detect", "chnroutes feature") { |c| @chnroutes = c } opts.on_tail("-v", "--version", "Show shadowsocks gem version") { puts Shadowsocks::VERSION; exit } opts.on_tail("-h", "--help", "Show this message") { puts opts; exit } diff --git a/lib/shadowsocks/ip_detector.rb b/lib/shadowsocks/ip_detector.rb new file mode 100644 index 0000000..dd33507 --- /dev/null +++ b/lib/shadowsocks/ip_detector.rb @@ -0,0 +1,30 @@ +require 'ipaddr' +require 'socket' + +module Shadowsocks + class IPDetector + GFW_LIST_PATH = './data/gfwlist.txt' + + def initialize + @internals = {} + @nums = [] + lines = File.readlines(GFW_LIST_PATH) + lines.each do |line| + num = IPAddr.new(line).to_i + @nums << num + @internals[num.to_s] = line + end + @nums.sort! + end + + def behind_gfw?(domain) + ip = IPSocket::getaddress(domain) + + ip_num = IPAddr.new(ip).to_i + + i = @nums.bsearch { |x| x > ip_num } + index = @nums.index(i) - 1 + IPAddr.new(@internals[@nums[index].to_s]).include? ip + end + end +end diff --git a/lib/shadowsocks/listener.rb b/lib/shadowsocks/listener.rb index 87652ce..a6863b0 100644 --- a/lib/shadowsocks/listener.rb +++ b/lib/shadowsocks/listener.rb @@ -1,7 +1,7 @@ module Shadowsocks class Listener < ::Shadowsocks::Connection attr_accessor :stage, :remote_addr, :remote_port, :addr_to_send, :cached_pieces, - :header_length, :connector, :config + :header_length, :connector, :config, :ip_detector def receive_data data data_handler data diff --git a/lib/shadowsocks/local.rb b/lib/shadowsocks/local.rb index e21a8e0..4ed8eca 100644 --- a/lib/shadowsocks/local.rb +++ b/lib/shadowsocks/local.rb @@ -18,7 +18,24 @@ def receive_data data end end + class DirectConnector < ::Shadowsocks::Tunnel + def post_init + p "connecting #{server.remote_addr[3..-1]} directly" + server.cached_pieces.each { |piece| send_data piece } + server.cached_pieces = [] + + server.stage = 5 + end + + def receive_data data + server.send_data data + outbound_scheduler + end + end + class LocalListener < ::Shadowsocks::Listener + attr_accessor :behind_gfw + private def data_handler data @@ -31,7 +48,13 @@ def data_handler data when 4 cached_pieces.push data when 5 - connector.send_data(encrypt(data)) and return + to_send = \ + if behind_gfw + data + else + encrypt(data) + end + connector.send_data(to_send) and return end end @@ -47,7 +70,16 @@ def fireup_tunnel(data) send_data "\x05\x00\x00\x01\x00\x00\x00\x00" + [config.server_port].pack('s>') @stage = 4 - @connector = EventMachine.connect config.server, config.server_port, ServerConnector, self, crypto + + if config.chnroutes + @behind_gfw = @ip_detector.behind_gfw?(@remote_addr[3..-1]) + end + + if config.chnroutes == true and behind_gfw + @connector = EventMachine.connect @remote_addr[3..-1], @remote_port, DirectConnector, self, crypto + else + @connector = EventMachine.connect config.server, config.server_port, ServerConnector, self, crypto + end if data.size > header_length cached_pieces.push data[header_length, data.size] diff --git a/lib/shadowsocks/parser/base.rb b/lib/shadowsocks/parser/base.rb index ffbff4a..e7723e7 100644 --- a/lib/shadowsocks/parser/base.rb +++ b/lib/shadowsocks/parser/base.rb @@ -37,7 +37,7 @@ def addr_to_send def remote_addr case mode when :domain - data[2, addr_len] + data[2, addr_len + 3] when :ip inet_ntoa data[1..4] end @@ -46,7 +46,7 @@ def remote_addr def remote_port case mode when :domain - data[2 + addr_len, 2].unpack('s>')[0] + data[5 + addr_len, 2].unpack('s>')[0] when :ip data[5, 2].unpack('s>')[0] end diff --git a/shadowsocks.gemspec b/shadowsocks.gemspec index 9848a20..a2265a9 100644 --- a/shadowsocks.gemspec +++ b/shadowsocks.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.add_dependency "json", "~> 1.8.0" s.add_dependency "ffi", "~> 1.9.0" - s.add_development_dependency "rake-compiler", "~> 0.9.1" - s.add_development_dependency "mocha", "~> 0.14.0" + s.add_development_dependency "rake-compiler", "~> 0.9.2" + s.add_development_dependency "mocha", "~> 1.0.0" s.add_development_dependency "rake" end diff --git a/tasks/chnroutes.rake b/tasks/chnroutes.rake new file mode 100644 index 0000000..c96849b --- /dev/null +++ b/tasks/chnroutes.rake @@ -0,0 +1,61 @@ +require 'ipaddr' +require 'ipaddress' +require 'benchmark' + +task :fetch_chnroutes do + url = 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' + unless File.exists?('./delegated-apnic-latest') + `wget -v #{url}` + end + + lines = File.readlines './delegated-apnic-latest' + file = File.open("./data/gfwlist.txt", "w") + lines.each do |line| + unit_items = line.split('|') + if unit_items.length >= 5 and unit_items[2] == 'ipv4' and unit_items[1] == "CN" + starting_ip = unit_items[3] + num_ip = unit_items[4].to_i + + file.puts "#{starting_ip}/#{32 - (Math.log(num_ip, 2).ceil).to_i}" + end + end +end + +task :test_ip do + ip = '162.243.140.72' + lines = File.readlines("./data/gfwlist.txt") + internals = [] + lines.each do |line| + internals << IPAddr.new(line) + end + + Benchmark.bm do |x| + x.report { 50.times { internals.any? { |i| i.include?(ip) } } } + end +end + +task :test_new_ip do + ip = '122.97.254.169' + lines = File.readlines("./data/gfwlist.txt") + internals = {} + nums = [] + lines.each do |line| + num = IPAddr.new(line).to_i + nums << num + internals[num.to_s] = line + end + nums.sort! + + Benchmark.bm do |x| + x.report do + 1000.times do + ip_num = IPAddr.new(ip).to_i + + i = nums.bsearch { |x| x > ip_num } + index = nums.index(i) - 1 + IPAddr.new(internals[nums[index].to_s]).include? ip + end + end + end + +end From 372b0a8dc88d4a790b2e5e2d6ed0390d67bb0070 Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 24 Jan 2014 01:21:57 +0800 Subject: [PATCH 35/48] bump version 0.7 --- README.md | 6 ++++-- lib/shadowsocks/version.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c487e3f..21a56b1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ shadowsocks-ruby [![Code Climate](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/badges/9dd6c11b6a17c3a55631/gpa.png)](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/feed) -Current version: 0.6 +Current version: 0.7 shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks). @@ -27,7 +27,8 @@ Create a file named `config.json`, with the following content. "local_port":1080, "password":"barfoo!", "timeout":60, - "method":"aes-128-cfb" + "method":"aes-128-cfb", + "chnroute":true } Explanation of the fields: @@ -38,6 +39,7 @@ Explanation of the fields: password a password used to encrypt transfer timeout in seconds method encryption method, "bf-cfb", "aes-256-cfb", "des-cfb", "rc4", etc. Default is "aes-128-cfb" + chnroute speed up China ip `cd` into the directory of `config.json`. Run `ss-server` on your server. To run it in the background, run `nohup ss-server -c ./config.json > log &`. diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb index ee99875..81de160 100644 --- a/lib/shadowsocks/version.rb +++ b/lib/shadowsocks/version.rb @@ -1,3 +1,3 @@ module Shadowsocks - VERSION = '0.6' + VERSION = '0.7' end From cadcae373a4c2e03b75439258323bae82e4d3a99 Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 24 Jan 2014 01:25:03 +0800 Subject: [PATCH 36/48] fix config.json --- config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index ed71280..7457dcc 100644 --- a/config.json +++ b/config.json @@ -1,8 +1,8 @@ { - "server":"162.243.140.72", + "server":"127.0.0.1", "server_port":8388, "local_port":1080, - "password":"be_tough", + "password":"barfoo!", "timeout":60, "method":"aes-128-cfb", "chnroutes":true From 1fbec6b7b2c705ac11921dda81acbd84bdd8a1a1 Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 24 Jan 2014 01:25:56 +0800 Subject: [PATCH 37/48] bump 0.8 --- lib/shadowsocks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb index 81de160..2b28eb4 100644 --- a/lib/shadowsocks/version.rb +++ b/lib/shadowsocks/version.rb @@ -1,3 +1,3 @@ module Shadowsocks - VERSION = '0.7' + VERSION = '0.8' end From 53a6b254f9e62aeb9f844130407882c7f580baab Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 24 Jan 2014 01:36:08 +0800 Subject: [PATCH 38/48] fix path --- lib/shadowsocks/ip_detector.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shadowsocks/ip_detector.rb b/lib/shadowsocks/ip_detector.rb index dd33507..6703276 100644 --- a/lib/shadowsocks/ip_detector.rb +++ b/lib/shadowsocks/ip_detector.rb @@ -3,7 +3,7 @@ module Shadowsocks class IPDetector - GFW_LIST_PATH = './data/gfwlist.txt' + GFW_LIST_PATH = File.expand_path('../../../data/gfwlist.txt', __FILE__) def initialize @internals = {} From f77cec641e9b93aac452c3fca509b09040c21dab Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 24 Jan 2014 01:36:33 +0800 Subject: [PATCH 39/48] bump version 0.9 --- lib/shadowsocks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb index 2b28eb4..12409ab 100644 --- a/lib/shadowsocks/version.rb +++ b/lib/shadowsocks/version.rb @@ -1,3 +1,3 @@ module Shadowsocks - VERSION = '0.8' + VERSION = '0.9' end From 516b3e12ab0bc05e3bd511b90223968adc0313e5 Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 24 Jan 2014 01:58:23 +0800 Subject: [PATCH 40/48] fix server side --- lib/shadowsocks/parser/base.rb | 14 ++------------ lib/shadowsocks/parser/local.rb | 18 ++++++++++++++++++ lib/shadowsocks/parser/server.rb | 19 +++++++++++++++++++ lib/shadowsocks/server.rb | 2 +- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/lib/shadowsocks/parser/base.rb b/lib/shadowsocks/parser/base.rb index e7723e7..f35c022 100644 --- a/lib/shadowsocks/parser/base.rb +++ b/lib/shadowsocks/parser/base.rb @@ -35,21 +35,11 @@ def addr_to_send end def remote_addr - case mode - when :domain - data[2, addr_len + 3] - when :ip - inet_ntoa data[1..4] - end + raise 'Called abstract method: remote_addr' end def remote_port - case mode - when :domain - data[5 + addr_len, 2].unpack('s>')[0] - when :ip - data[5, 2].unpack('s>')[0] - end + raise 'Called abstract method: remote_port' end def header_length diff --git a/lib/shadowsocks/parser/local.rb b/lib/shadowsocks/parser/local.rb index 2964979..387cb94 100644 --- a/lib/shadowsocks/parser/local.rb +++ b/lib/shadowsocks/parser/local.rb @@ -10,6 +10,24 @@ def addr_len data[4].unpack('c')[0] end end + + def remote_addr + case mode + when :domain + data[2, addr_len + 3] + when :ip + inet_ntoa data[1..4] + end + end + + def remote_port + case mode + when :domain + data[5 + addr_len, 2].unpack('s>')[0] + when :ip + data[5, 2].unpack('s>')[0] + end + end end end end diff --git a/lib/shadowsocks/parser/server.rb b/lib/shadowsocks/parser/server.rb index 4c5fe17..4c72c8b 100644 --- a/lib/shadowsocks/parser/server.rb +++ b/lib/shadowsocks/parser/server.rb @@ -10,6 +10,25 @@ def addr_len data[1].unpack('c')[0] end end + + def remote_addr + case mode + when :domain + data[2, addr_len] + when :ip + inet_ntoa data[1..4] + end + end + + def remote_port + case mode + when :domain + data[2 + addr_len, 2].unpack('s>')[0] + when :ip + data[5, 2].unpack('s>')[0] + end + end + end end end diff --git a/lib/shadowsocks/server.rb b/lib/shadowsocks/server.rb index fa49780..ed08af0 100644 --- a/lib/shadowsocks/server.rb +++ b/lib/shadowsocks/server.rb @@ -2,7 +2,7 @@ module Shadowsocks module Server class RequestConnector < ::Shadowsocks::Tunnel def post_init - p "connecting #{server.remote_addr} via #{server.config.server}" + p "connecting #{server.remote_addr}:#{server.remote_port} via #{server.config.server}" server.cached_pieces.each { |piece| send_data piece } server.cached_pieces = nil From 5462e068f836f7c77f54f29aeaf8107bbd63cb2d Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 24 Jan 2014 01:58:57 +0800 Subject: [PATCH 41/48] bump version 0.10 --- lib/shadowsocks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb index 12409ab..b749c15 100644 --- a/lib/shadowsocks/version.rb +++ b/lib/shadowsocks/version.rb @@ -1,3 +1,3 @@ module Shadowsocks - VERSION = '0.9' + VERSION = '0.10' end From ec9587a8d50d2bf0141e2fe7dd40e1af9fe4c84e Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 24 Jan 2014 10:19:58 +0800 Subject: [PATCH 42/48] update readme(version No. and command example) --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 21a56b1..401469c 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ shadowsocks-ruby ================ -[![Code Climate](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/badges/9dd6c11b6a17c3a55631/gpa.png)](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/feed) - -Current version: 0.7 +Current version: 0.10 shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks). @@ -59,7 +57,7 @@ Command line args You can use args to override settings from `config.json`. - ss-local -s server_name -p server_port -l local_port -k password + ss-local -s server_name -p server_port -l local_port -k password -m aes-128-cfb -d true ss-server -p server_port -k password ss-server -c /etc/shadowsocks/config.json From 86264ab73c0eff4843868ac1b01ceff344d7e35d Mon Sep 17 00:00:00 2001 From: Sen Date: Mon, 3 Feb 2014 15:56:52 +0800 Subject: [PATCH 43/48] dns cache for ip ditector --- lib/shadowsocks/ip_detector.rb | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/shadowsocks/ip_detector.rb b/lib/shadowsocks/ip_detector.rb index 6703276..a18c5d5 100644 --- a/lib/shadowsocks/ip_detector.rb +++ b/lib/shadowsocks/ip_detector.rb @@ -1,5 +1,6 @@ require 'ipaddr' require 'socket' +require 'digest/md5' module Shadowsocks class IPDetector @@ -8,6 +9,7 @@ class IPDetector def initialize @internals = {} @nums = [] + @dns_cache = {} lines = File.readlines(GFW_LIST_PATH) lines.each do |line| num = IPAddr.new(line).to_i @@ -18,13 +20,29 @@ def initialize end def behind_gfw?(domain) - ip = IPSocket::getaddress(domain) + key = Digest::MD5.hexdigest domain - ip_num = IPAddr.new(ip).to_i + if @dns_cache[key] + @dns_cache[key] + else + begin + ip = IPSocket::getaddress(domain) - i = @nums.bsearch { |x| x > ip_num } - index = @nums.index(i) - 1 - IPAddr.new(@internals[@nums[index].to_s]).include? ip + ip_num = IPAddr.new(ip).to_i + + i = @nums.bsearch { |x| x > ip_num } + index = @nums.index(i) - 1 + r = IPAddr.new(@internals[@nums[index].to_s]).include? ip + if @dns_cache.size > 10 + @dns_cache.delete @dns_cache.first[0] + end + + @dns_cache[key] = r + r + rescue Exception + false + end + end end end end From c16c320d8fea5f9e93e151b1057a82450f56fa70 Mon Sep 17 00:00:00 2001 From: Sen Date: Mon, 3 Feb 2014 15:57:20 +0800 Subject: [PATCH 44/48] try to use EM.defer to speed up local side --- lib/shadowsocks/local.rb | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/shadowsocks/local.rb b/lib/shadowsocks/local.rb index 4ed8eca..083b93b 100644 --- a/lib/shadowsocks/local.rb +++ b/lib/shadowsocks/local.rb @@ -71,19 +71,29 @@ def fireup_tunnel(data) @stage = 4 - if config.chnroutes - @behind_gfw = @ip_detector.behind_gfw?(@remote_addr[3..-1]) - end + op = proc { + if config.chnroutes + @behind_gfw = @ip_detector.behind_gfw?(@remote_addr[3..-1]) + else + false + end + } - if config.chnroutes == true and behind_gfw - @connector = EventMachine.connect @remote_addr[3..-1], @remote_port, DirectConnector, self, crypto - else - @connector = EventMachine.connect config.server, config.server_port, ServerConnector, self, crypto - end + callback = proc { |result| + if config.chnroutes and result + @connector = EventMachine.connect @remote_addr[3..-1], @remote_port, \ + DirectConnector, self, crypto + else + @connector = EventMachine.connect config.server, config.server_port, \ + ServerConnector, self, crypto + end - if data.size > header_length - cached_pieces.push data[header_length, data.size] - end + if data.size > header_length + cached_pieces.push data[header_length, data.size] + end + } + + EM.defer op, callback rescue Exception => e warn e connection_cleanup From 217409398b81e574f84b896c11f6e4157fbc0936 Mon Sep 17 00:00:00 2001 From: Sen Date: Thu, 13 Feb 2014 09:49:43 +0800 Subject: [PATCH 45/48] make local side faster --- lib/shadowsocks/ip_detector.rb | 2 +- lib/shadowsocks/local.rb | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/shadowsocks/ip_detector.rb b/lib/shadowsocks/ip_detector.rb index a18c5d5..cee04f8 100644 --- a/lib/shadowsocks/ip_detector.rb +++ b/lib/shadowsocks/ip_detector.rb @@ -33,7 +33,7 @@ def behind_gfw?(domain) i = @nums.bsearch { |x| x > ip_num } index = @nums.index(i) - 1 r = IPAddr.new(@internals[@nums[index].to_s]).include? ip - if @dns_cache.size > 10 + if @dns_cache.size > 512 @dns_cache.delete @dns_cache.first[0] end diff --git a/lib/shadowsocks/local.rb b/lib/shadowsocks/local.rb index 083b93b..0fdfbb7 100644 --- a/lib/shadowsocks/local.rb +++ b/lib/shadowsocks/local.rb @@ -80,11 +80,14 @@ def fireup_tunnel(data) } callback = proc { |result| - if config.chnroutes and result - @connector = EventMachine.connect @remote_addr[3..-1], @remote_port, \ + begin + if !(config.chnroutes and result) + raise 'will use remote server' + end + @connector = EM.connect @remote_addr[3..-1], @remote_port, \ DirectConnector, self, crypto - else - @connector = EventMachine.connect config.server, config.server_port, \ + rescue Exception + @connector = EM.connect config.server, config.server_port, \ ServerConnector, self, crypto end From 524c765edd64b3ea9f2285bbf8ab05760734aa12 Mon Sep 17 00:00:00 2001 From: Sen Date: Thu, 13 Feb 2014 15:16:45 +0800 Subject: [PATCH 46/48] bump version 0.11 --- README.md | 2 +- lib/shadowsocks/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 401469c..a50c55b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ shadowsocks-ruby ================ -Current version: 0.10 +Current version: 0.11 shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks). diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb index b749c15..d7e25d3 100644 --- a/lib/shadowsocks/version.rb +++ b/lib/shadowsocks/version.rb @@ -1,3 +1,3 @@ module Shadowsocks - VERSION = '0.10' + VERSION = '0.11' end From 0e3b21659a57e48a115089a5eaef4e14cee7e752 Mon Sep 17 00:00:00 2001 From: Sen Date: Wed, 2 Jul 2014 15:00:28 +0800 Subject: [PATCH 47/48] try to fix iv length is too short bug --- lib/shadowsocks/server.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/shadowsocks/server.rb b/lib/shadowsocks/server.rb index ed08af0..0eaed11 100644 --- a/lib/shadowsocks/server.rb +++ b/lib/shadowsocks/server.rb @@ -20,7 +20,13 @@ class ServerListener < ::Shadowsocks::Listener private def data_handler data - data = decrypt data + begin + data = decrypt data + rescue Exception => e + warn e + connection_cleanup + end + case stage when 0 fireup_tunnel data From 1f04aa411d12cf4d1c805b757b3593930793dedd Mon Sep 17 00:00:00 2001 From: Sen Date: Mon, 28 Jul 2014 11:10:59 +0800 Subject: [PATCH 48/48] Bump version 0.12 --- lib/shadowsocks/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shadowsocks/version.rb b/lib/shadowsocks/version.rb index d7e25d3..231d0d8 100644 --- a/lib/shadowsocks/version.rb +++ b/lib/shadowsocks/version.rb @@ -1,3 +1,3 @@ module Shadowsocks - VERSION = '0.11' + VERSION = '0.12' end