rsocks5patch 0.1.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +26 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +23 -0
- data/Rakefile +12 -0
- data/lib/rsocks5patch/version.rb +5 -0
- data/lib/rsocks5patch.rb +106 -0
- data/sig/rsocks5patch.rbs +4 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cf1d99bc0cb455cbe4de6e7bf8d89c1ae4050ccdae12c02783d5352dad7c05db
|
4
|
+
data.tar.gz: 45c799e546887483174c50d4bc73b8ad7f9bf89e718bdf039eb73ec05fdaf74f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1125085b0c643e920e2282aaac260b8bfb68e9f9b5dd3c9d865bfd4df5fb5a4a62a606896a95de974c02d5a0386a156511489443e1bc474c447ba1900640ff65
|
7
|
+
data.tar.gz: 632fbd71e14f025ab75ba9667a572c6f5c90864a86246cbf3612d656d13ed06088bf7a224ea183c9dba9edf33232167675ad4fa897caa58e2dad4dd3917e4c56
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Metrics/ParameterLists:
|
16
|
+
Enabled: false
|
17
|
+
Metrics/PerceivedComplexity:
|
18
|
+
Enabled: false
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Enabled: false
|
21
|
+
Metrics/CyclomaticComplexity:
|
22
|
+
Enabled: false
|
23
|
+
Metrics/BlockLength:
|
24
|
+
Enabled: false
|
25
|
+
Metrics/AbcSize:
|
26
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Rsocks5patch
|
2
|
+
|
3
|
+
When including `rsocks5patch` the Ruby `Socket` class function `tcp`
|
4
|
+
will be replaced with one that will first establish a connection
|
5
|
+
through a SOCKS proxy.
|
6
|
+
|
7
|
+
The new `Socket.tcp` function also adds two options, `socks_host`
|
8
|
+
and `socks_port` in situations where the `tcp` function is used directly.
|
9
|
+
|
10
|
+
An example use.
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
|
14
|
+
require "rsocks5patch"
|
15
|
+
Socket.socks_host = "localhost"
|
16
|
+
Socket.socks_port = 9050
|
17
|
+
|
18
|
+
resp = Net::HTTP.get_response(URI("https://gitlab.com/basking2/rsocks5patch/-/tree/main"))
|
19
|
+
```
|
20
|
+
|
21
|
+
## License
|
22
|
+
|
23
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/rsocks5patch.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# vim: set et sw=2:
|
4
|
+
|
5
|
+
require "net/http"
|
6
|
+
require "uri"
|
7
|
+
require "socket"
|
8
|
+
|
9
|
+
require_relative "rsocks5patch/version"
|
10
|
+
|
11
|
+
# When this module is evaluated it will patch the Ruby Socket class.
|
12
|
+
module Rsocks5patch
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
Socket.class_eval do
|
16
|
+
# alias :orig_func :self.tcp
|
17
|
+
#
|
18
|
+
class << self
|
19
|
+
alias_method :orig_func, :tcp
|
20
|
+
|
21
|
+
attr_accessor :socks_host, :socks_port
|
22
|
+
end
|
23
|
+
|
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
|
+
def self.tcp(
|
36
|
+
host,
|
37
|
+
port,
|
38
|
+
local_host = nil,
|
39
|
+
local_port = nil,
|
40
|
+
connect_timeout: nil,
|
41
|
+
resolv_timeout: nil,
|
42
|
+
socks_host: nil,
|
43
|
+
socks_port: nil
|
44
|
+
)
|
45
|
+
socks_host ||= self.socks_host
|
46
|
+
socks_port ||= self.socks_port
|
47
|
+
|
48
|
+
unless socks_host
|
49
|
+
return orig_func(host, port, local_host, local_port, connect_timeout: connect_timeout,
|
50
|
+
resolv_timeout: resolv_timeout)
|
51
|
+
end
|
52
|
+
|
53
|
+
socket = orig_func(socks_host, socks_port, local_host, local_port, connect_timeout: nil, resolv_timeout: nil)
|
54
|
+
|
55
|
+
socket.write([0x5, 0x1, 0x0].pack("CCC"))
|
56
|
+
ver, auth = mustread(socket, 2).unpack("CC")
|
57
|
+
|
58
|
+
raise StandardError, "Unexpected version #{ver}." if ver != 0x5
|
59
|
+
raise StandardError, "No available auth method." if auth == 0xff
|
60
|
+
|
61
|
+
# Version, CMD=1, RSV=0, ADDRTYPE=3, LEN, HOST, PORT
|
62
|
+
socket.write([0x5, 0x01, 0x00, 0x3, host.length, host, port].pack("CCCCCa*n"))
|
63
|
+
|
64
|
+
ver, status, _resv, addrtype = mustread(socket, 4).unpack("CCCC")
|
65
|
+
raise StandardError, "Unexpected version #{ver}." if ver != 0x5
|
66
|
+
|
67
|
+
case status
|
68
|
+
when 0x00
|
69
|
+
""
|
70
|
+
when 0x01
|
71
|
+
raise StandardError, "general failure"
|
72
|
+
when 0x02
|
73
|
+
raise StandardError, "connection not allowed by ruleset"
|
74
|
+
when 0x03
|
75
|
+
raise StandardError, "network unreachable"
|
76
|
+
when 0x04
|
77
|
+
raise StandardError, "host unreachable"
|
78
|
+
when 0x05
|
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
|
89
|
+
|
90
|
+
case addrtype
|
91
|
+
when 0x1
|
92
|
+
_ipv4addr = mustread(socket, 4)
|
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
|
100
|
+
end
|
101
|
+
_port = mustread(socket, 2)
|
102
|
+
|
103
|
+
socket
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsocks5patch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Baskinger
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- basking2@yahoo.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/rsocks5patch.rb
|
28
|
+
- lib/rsocks5patch/version.rb
|
29
|
+
- sig/rsocks5patch.rbs
|
30
|
+
homepage: https://gitlab.com/basking2/rsocks5patch
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata:
|
34
|
+
allowed_push_host: https://rubygems.org
|
35
|
+
homepage_uri: https://gitlab.com/basking2/rsocks5patch
|
36
|
+
source_code_uri: https://gitlab.com/basking2/rsocks5patch
|
37
|
+
changelog_uri: https://gitlab.com/basking2/rsocks5patch/-/blob/main/CHANGELOG.md
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.6.0
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.3.7
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Patch SOCKS5 capabilities into Ruby's Socket class.
|
57
|
+
test_files: []
|