rsocks5patch 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +1 -1
- data/lib/rsocks5patch/socks5.rb +65 -0
- data/lib/rsocks5patch/version.rb +1 -1
- data/lib/rsocks5patch.rb +33 -56
- data/rsocks5patch.gemspec +39 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ddd720bb293c195220d0b51f5121a4cd3724e1fd44757c94687b1fd23ca22a1
|
4
|
+
data.tar.gz: c7ca15c0bc42ae88169ffaaef90968b381052e8b6ac29df4a912bd20c4dcd385
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 372a39f79aecfac4223182b669010a5dc1d3c35e176ee449f2a9e0fe5614f7d691e8a45ac7c972ba870131c7518d96a5a0dfaeed7019e533440039f54b2331bb
|
7
|
+
data.tar.gz: cce52e1e236dc8bd6c38b28259bd7fb501138821165b46f6c72edbeeb048dd6d5abbc39440864c0d9e44a7926d2aff03dfd538de66132d35e02af4b63849cf35
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rsocks5patch (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
diff-lcs (1.5.1)
|
11
|
+
json (2.7.2)
|
12
|
+
language_server-protocol (3.17.0.3)
|
13
|
+
parallel (1.24.0)
|
14
|
+
parser (3.3.1.0)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
racc
|
17
|
+
racc (1.8.0)
|
18
|
+
rainbow (3.1.1)
|
19
|
+
rake (13.2.1)
|
20
|
+
regexp_parser (2.9.2)
|
21
|
+
rexml (3.2.8)
|
22
|
+
strscan (>= 3.0.9)
|
23
|
+
rspec (3.13.0)
|
24
|
+
rspec-core (~> 3.13.0)
|
25
|
+
rspec-expectations (~> 3.13.0)
|
26
|
+
rspec-mocks (~> 3.13.0)
|
27
|
+
rspec-core (3.13.0)
|
28
|
+
rspec-support (~> 3.13.0)
|
29
|
+
rspec-expectations (3.13.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.13.0)
|
32
|
+
rspec-mocks (3.13.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.13.0)
|
35
|
+
rspec-support (3.13.1)
|
36
|
+
rubocop (1.64.0)
|
37
|
+
json (~> 2.3)
|
38
|
+
language_server-protocol (>= 3.17.0)
|
39
|
+
parallel (~> 1.10)
|
40
|
+
parser (>= 3.3.0.2)
|
41
|
+
rainbow (>= 2.2.2, < 4.0)
|
42
|
+
regexp_parser (>= 1.8, < 3.0)
|
43
|
+
rexml (>= 3.2.5, < 4.0)
|
44
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
45
|
+
ruby-progressbar (~> 1.7)
|
46
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
47
|
+
rubocop-ast (1.31.3)
|
48
|
+
parser (>= 3.3.1.0)
|
49
|
+
ruby-progressbar (1.13.0)
|
50
|
+
strscan (3.1.0)
|
51
|
+
unicode-display_width (2.5.0)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
x86_64-linux
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
rake (~> 13.0)
|
58
|
+
rsocks5patch!
|
59
|
+
rspec (~> 3.0)
|
60
|
+
rubocop (~> 1.21)
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
2.3.18
|
data/LICENSE.txt
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Rsocks5patch
|
2
|
+
module Socks5
|
3
|
+
def self.mustread(socket, num)
|
4
|
+
data = ""
|
5
|
+
loop do
|
6
|
+
tmp = socket.read(num - data.length)
|
7
|
+
return null if tmp.nil?
|
8
|
+
|
9
|
+
data += tmp
|
10
|
+
return data if data.length == num
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.init_socks5(socket, host, port)
|
15
|
+
socket.write([0x5, 0x1, 0x0].pack("CCC"))
|
16
|
+
ver, auth = mustread(socket, 2).unpack("CC")
|
17
|
+
|
18
|
+
raise StandardError, "Unexpected version #{ver}." if ver != 0x5
|
19
|
+
raise StandardError, "No available auth method." if auth == 0xff
|
20
|
+
|
21
|
+
# Version, CMD=1, RSV=0, ADDRTYPE=3, LEN, HOST, PORT
|
22
|
+
socket.write([0x5, 0x01, 0x00, 0x3, host.length, host, port].pack("CCCCCa*n"))
|
23
|
+
|
24
|
+
ver, status, _resv, addrtype = mustread(socket, 4).unpack("CCCC")
|
25
|
+
raise StandardError, "Unexpected version #{ver}." if ver != 0x5
|
26
|
+
|
27
|
+
case status
|
28
|
+
when 0x00
|
29
|
+
""
|
30
|
+
when 0x01
|
31
|
+
raise StandardError, "general failure"
|
32
|
+
when 0x02
|
33
|
+
raise StandardError, "connection not allowed by ruleset"
|
34
|
+
when 0x03
|
35
|
+
raise StandardError, "network unreachable"
|
36
|
+
when 0x04
|
37
|
+
raise StandardError, "host unreachable"
|
38
|
+
when 0x05
|
39
|
+
raise StandardError, "connection refused by destination host"
|
40
|
+
when 0x06
|
41
|
+
raise StandardError, "TTL expired"
|
42
|
+
when 0x07
|
43
|
+
raise StandardError, "command not supported / protocol error"
|
44
|
+
when 0x08
|
45
|
+
raise StandardError, "address type not supported"
|
46
|
+
else
|
47
|
+
raise StandardError, "unexpected error status #{status}"
|
48
|
+
end
|
49
|
+
|
50
|
+
case addrtype
|
51
|
+
when 0x1
|
52
|
+
_ipv4addr = mustread(socket, 4)
|
53
|
+
when 0x3
|
54
|
+
_len = mustread(socket, 1)
|
55
|
+
_host = mustread(socket, len)
|
56
|
+
when 0x4
|
57
|
+
_ipv6addr = mustread(socket, 16)
|
58
|
+
else
|
59
|
+
raise StandardError, "No available auth method." if auth == 0xff
|
60
|
+
end
|
61
|
+
_port = mustread(socket, 2)
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/rsocks5patch/version.rb
CHANGED
data/lib/rsocks5patch.rb
CHANGED
@@ -7,6 +7,7 @@ require "uri"
|
|
7
7
|
require "socket"
|
8
8
|
|
9
9
|
require_relative "rsocks5patch/version"
|
10
|
+
require_relative "rsocks5patch/socks5"
|
10
11
|
|
11
12
|
# When this module is evaluated it will patch the Ruby Socket class.
|
12
13
|
module Rsocks5patch
|
@@ -21,17 +22,6 @@ module Rsocks5patch
|
|
21
22
|
attr_accessor :socks_host, :socks_port
|
22
23
|
end
|
23
24
|
|
24
|
-
def self.mustread(socket, num)
|
25
|
-
data = ""
|
26
|
-
loop do
|
27
|
-
tmp = socket.read(num - data.length)
|
28
|
-
return null if tmp.nil?
|
29
|
-
|
30
|
-
data += tmp
|
31
|
-
return data if data.length == num
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
25
|
def self.tcp(
|
36
26
|
host,
|
37
27
|
port,
|
@@ -52,55 +42,42 @@ module Rsocks5patch
|
|
52
42
|
|
53
43
|
socket = orig_func(socks_host, socks_port, local_host, local_port, connect_timeout: nil, resolv_timeout: nil)
|
54
44
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
raise StandardError, "connection refused by destination host"
|
80
|
-
when 0x06
|
81
|
-
raise StandardError, "TTL expired"
|
82
|
-
when 0x07
|
83
|
-
raise StandardError, "command not supported / protocol error"
|
84
|
-
when 0x08
|
85
|
-
raise StandardError, "address type not supported"
|
86
|
-
else
|
87
|
-
raise StandardError, "unexpected error status #{status}"
|
88
|
-
end
|
45
|
+
Rsocks5patch::Socks5.init_socks5(socket, host, port)
|
46
|
+
|
47
|
+
socket
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
TCPSocket.class_eval do
|
52
|
+
class << self
|
53
|
+
alias_method :orig_func, :open
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.open(
|
58
|
+
conn_addr,
|
59
|
+
conn_port,
|
60
|
+
local_host=nil,
|
61
|
+
local_port=nil,
|
62
|
+
connect_timeout: nil,
|
63
|
+
resolv_timeout: nil,
|
64
|
+
socks_host: nil,
|
65
|
+
socks_port: nil
|
66
|
+
)
|
67
|
+
socks_host ||= Socket.socks_host
|
68
|
+
socks_port ||= Socket.socks_port
|
89
69
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
when 0x3
|
94
|
-
_len = mustread(socket, 1)
|
95
|
-
_host = mustread(socket, len)
|
96
|
-
when 0x4
|
97
|
-
_ipv6addr = mustread(socket, 16)
|
98
|
-
else
|
99
|
-
raise StandardError, "No available auth method." if auth == 0xff
|
70
|
+
unless socks_host
|
71
|
+
return orig_func(conn_addr, conn_port, local_host, local_port, connect_timeout: connect_timeout,
|
72
|
+
resolv_timeout: resolv_timeout)
|
100
73
|
end
|
101
|
-
|
74
|
+
|
75
|
+
socket = orig_func(socks_host, socks_port, local_host, local_port, connect_timeout: nil, resolv_timeout: nil)
|
76
|
+
|
77
|
+
Rsocks5patch::Socks5.init_socks5(socket, conn_addr, conn_port)
|
102
78
|
|
103
79
|
socket
|
104
80
|
end
|
105
81
|
end
|
82
|
+
|
106
83
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/rsocks5patch/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rsocks5patch"
|
7
|
+
spec.version = Rsocks5patch::VERSION
|
8
|
+
spec.authors = ["Sam Baskinger"]
|
9
|
+
spec.email = ["basking2@yahoo.com"]
|
10
|
+
|
11
|
+
spec.summary = "Patch SOCKS5 capabilities into Ruby's Socket class."
|
12
|
+
# spec.description = "Patch SOCKS5 capabilities into Ruby's Socket class."
|
13
|
+
spec.homepage = "https://gitlab.com/basking2/rsocks5patch"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://gitlab.com/basking2/rsocks5patch"
|
21
|
+
spec.metadata["changelog_uri"] = "https://gitlab.com/basking2/rsocks5patch/-/blob/main/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsocks5patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Baskinger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -21,11 +21,14 @@ files:
|
|
21
21
|
- ".rubocop.yml"
|
22
22
|
- CHANGELOG.md
|
23
23
|
- Gemfile
|
24
|
+
- Gemfile.lock
|
24
25
|
- LICENSE.txt
|
25
26
|
- README.md
|
26
27
|
- Rakefile
|
27
28
|
- lib/rsocks5patch.rb
|
29
|
+
- lib/rsocks5patch/socks5.rb
|
28
30
|
- lib/rsocks5patch/version.rb
|
31
|
+
- rsocks5patch.gemspec
|
29
32
|
- sig/rsocks5patch.rbs
|
30
33
|
homepage: https://gitlab.com/basking2/rsocks5patch
|
31
34
|
licenses:
|
@@ -50,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
53
|
- !ruby/object:Gem::Version
|
51
54
|
version: '0'
|
52
55
|
requirements: []
|
53
|
-
rubygems_version: 3.
|
56
|
+
rubygems_version: 3.5.9
|
54
57
|
signing_key:
|
55
58
|
specification_version: 4
|
56
59
|
summary: Patch SOCKS5 capabilities into Ruby's Socket class.
|