sockit 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sockit/v5/authentication.rb +53 -42
- data/lib/sockit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f119ae1ef934eccc52447bc1a6858ba528fd246
|
4
|
+
data.tar.gz: 32c92a29a247a47ae15951c0e136fe6aebe2b320
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1631707e3357000ff835b13b5ad788a1c94b7c1d7b8b178cfd8410c2d92c8e5899522f968c30cc83afdf28d04edb3f22160b9215fb721a16ddb41f4429dab86a
|
7
|
+
data.tar.gz: 26422b90f818c9cb59b07d7101fefc0238198e51e3343c24cfde5e5338774d826cabfc916f3c2d08be89435106f7ea9cc56201d4f7a4e60e2f9d69272497c5db
|
@@ -2,7 +2,7 @@ module Sockit
|
|
2
2
|
module V5
|
3
3
|
module Authentication
|
4
4
|
|
5
|
-
def
|
5
|
+
def build_v5_authentication_request(socket)
|
6
6
|
log(:yellow, "Authenticating with SOCKS server #{config.host}:#{config.port}")
|
7
7
|
|
8
8
|
# The authentication methods supported are numbered as follows:
|
@@ -33,10 +33,12 @@ module Sockit
|
|
33
33
|
dump(:write, data)
|
34
34
|
socket.write(data)
|
35
35
|
end
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
# The server's choice is communicated:
|
39
|
+
# field 1: SOCKS version, 1 byte (0x05 for this version)
|
40
|
+
# field 2: chosen authentication method, 1 byte, or 0xFF if no acceptable methods were offered
|
41
|
+
def process_v5_authentication_response(socket)
|
40
42
|
log(:yellow, "Waiting for SOCKS authentication reply")
|
41
43
|
auth_reply = socket.recv(2).unpack("C*")
|
42
44
|
dump(:read, auth_reply)
|
@@ -53,51 +55,60 @@ module Sockit
|
|
53
55
|
log(:green, build_v5_authentication_method_message(server_auth_method))
|
54
56
|
end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
+
server_auth_method
|
59
|
+
end
|
60
|
+
|
61
|
+
def perform_v5_password_authentication_request(socket)
|
62
|
+
# For username/password authentication the client's authentication request is
|
63
|
+
# field 1: version number, 1 byte (must be 0x01)
|
64
|
+
# field 2: username length, 1 byte
|
65
|
+
# field 3: username
|
66
|
+
# field 4: password length, 1 byte
|
67
|
+
# field 5: password
|
68
|
+
data = Array.new
|
69
|
+
data << [0x01].pack("C*")
|
70
|
+
data << [config.username.length.to_i].pack("C*")
|
71
|
+
data << config.username
|
72
|
+
data << [config.password.length.to_i].pack("C*")
|
73
|
+
data << config.password
|
74
|
+
data = data.flatten.join
|
75
|
+
|
76
|
+
log(:yellow, "Sending username and password")
|
77
|
+
dump(:write, data)
|
78
|
+
socket.write(data)
|
79
|
+
|
80
|
+
# Server response for username/password authentication:
|
81
|
+
# field 1: version, 1 byte
|
82
|
+
# field 2: status code, 1 byte.
|
83
|
+
# 0x00 = success
|
84
|
+
# any other value = failure, connection must be closed
|
85
|
+
log(:yellow, "Waiting for SOCKS authentication reply")
|
86
|
+
auth_reply = socket.recv(2).unpack("C*")
|
87
|
+
dump(:read, auth_reply)
|
88
|
+
version = auth_reply[0]
|
89
|
+
status_code = auth_reply[1]
|
90
|
+
|
91
|
+
if status_code == 0x00
|
92
|
+
log(:green, build_v5_authentication_status_message(status_code))
|
93
|
+
else
|
94
|
+
raise SockitError, build_v5_authentication_status_message(status_code)
|
95
|
+
end
|
96
|
+
|
97
|
+
log(:green, "Authenticated to SOCKS server #{config.host}:#{config.port}")
|
98
|
+
end
|
99
|
+
|
100
|
+
def perform_v5_authenticate(socket)
|
101
|
+
build_v5_authentication_request(socket)
|
102
|
+
|
103
|
+
case process_v5_authentication_response(socket)
|
58
104
|
when 0x00 then
|
59
105
|
# No authentication
|
60
106
|
when 0x01 then
|
61
107
|
# GSSAPI
|
62
108
|
raise SockitError, "Authentication method GSSAPI not implemented"
|
63
109
|
when 0x02 then
|
64
|
-
|
65
|
-
# field 1: version number, 1 byte (must be 0x01)
|
66
|
-
# field 2: username length, 1 byte
|
67
|
-
# field 3: username
|
68
|
-
# field 4: password length, 1 byte
|
69
|
-
# field 5: password
|
70
|
-
data = Array.new
|
71
|
-
data << [0x01].pack("C*")
|
72
|
-
data << [config.username.length.to_i].pack("C*")
|
73
|
-
data << config.username
|
74
|
-
data << [config.password.length.to_i].pack("C*")
|
75
|
-
data << config.password
|
76
|
-
data = data.flatten.join
|
77
|
-
|
78
|
-
log(:yellow, "Sending username and password")
|
79
|
-
dump(:write, data)
|
80
|
-
socket.write(data)
|
81
|
-
|
82
|
-
# Server response for username/password authentication:
|
83
|
-
# field 1: version, 1 byte
|
84
|
-
# field 2: status code, 1 byte.
|
85
|
-
# 0x00 = success
|
86
|
-
# any other value = failure, connection must be closed
|
87
|
-
log(:yellow, "Waiting for SOCKS authentication reply")
|
88
|
-
auth_reply = socket.recv(2).unpack("C*")
|
89
|
-
dump(:read, auth_reply)
|
90
|
-
version = auth_reply[0]
|
91
|
-
status_code = auth_reply[1]
|
92
|
-
|
93
|
-
if status_code == 0x00
|
94
|
-
log(:green, build_v5_authentication_status_message(status_code))
|
95
|
-
else
|
96
|
-
raise SockitError, build_v5_authentication_status_message(status_code)
|
97
|
-
end
|
110
|
+
perform_v5_password_authentication_request(socket)
|
98
111
|
end
|
99
|
-
|
100
|
-
log(:green, "Authenticated to SOCKS server #{config.host}:#{config.port}")
|
101
112
|
end
|
102
113
|
|
103
114
|
end
|
data/lib/sockit/version.rb
CHANGED