rex-socket 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/rex/socket.rb +18 -0
- data/lib/rex/socket/comm/local.rb +44 -57
- data/lib/rex/socket/tcp.rb +0 -18
- data/lib/rex/socket/version.rb +1 -1
- metadata +2 -2
- metadata.gz.sig +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 902535274c4d182988dbaa9575b42dfb98fa04f4
|
4
|
+
data.tar.gz: b5b5ae8fed2ba779b2bb9a457f904feaf955495d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fed81f4863ea30cda9ef78637e41f4505faf7fb077a112fb667c06add342513ddfc62e0950a3048d6658be66c35dec998910ac6e212e9e5c72333eb3a624b7b
|
7
|
+
data.tar.gz: 6cfd80dd79ddfe0ce788cf08aafc3eb71e866dba3555c7e8323a16efb2497228f69133a541dc6ca7813d93897c0a6010e2e05c64b438fd9682e12c5b5fbb34af
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/rex/socket.rb
CHANGED
@@ -745,6 +745,24 @@ module Socket
|
|
745
745
|
return peer_name
|
746
746
|
end
|
747
747
|
|
748
|
+
#
|
749
|
+
# Returns peer information (host + port) in host:port format.
|
750
|
+
#
|
751
|
+
def peerinfo
|
752
|
+
if (pi = getpeername_as_array)
|
753
|
+
return pi[1] + ':' + pi[2].to_s
|
754
|
+
end
|
755
|
+
end
|
756
|
+
|
757
|
+
#
|
758
|
+
# Returns local information (host + port) in host:port format.
|
759
|
+
#
|
760
|
+
def localinfo
|
761
|
+
if (pi = getlocalname)
|
762
|
+
return pi[1] + ':' + pi[2].to_s
|
763
|
+
end
|
764
|
+
end
|
765
|
+
|
748
766
|
#
|
749
767
|
# Returns a string that indicates the type of the socket, such as 'tcp'.
|
750
768
|
#
|
@@ -52,10 +52,10 @@ class Rex::Socket::Comm::Local
|
|
52
52
|
|
53
53
|
case param.proto
|
54
54
|
when 'tcp'
|
55
|
-
if
|
55
|
+
if param.server?
|
56
56
|
sock = TCPServer.new(param.localport, param.localhost)
|
57
57
|
klass = Rex::Socket::TcpServer
|
58
|
-
if
|
58
|
+
if param.ssl
|
59
59
|
klass = Rex::Socket::SslTcpServer
|
60
60
|
end
|
61
61
|
sock.extend(klass)
|
@@ -63,13 +63,13 @@ class Rex::Socket::Comm::Local
|
|
63
63
|
else
|
64
64
|
sock = TCPSocket.new(param.peerhost, param.peerport)
|
65
65
|
klass = Rex::Socket::Tcp
|
66
|
-
if
|
66
|
+
if param.ssl
|
67
67
|
klass = Rex::Socket::SslTcp
|
68
68
|
end
|
69
69
|
sock.extend(klass)
|
70
70
|
end
|
71
71
|
when 'udp'
|
72
|
-
if
|
72
|
+
if param.server?
|
73
73
|
sock = UDPServer.new(param.localport, param.localhost)
|
74
74
|
klass = Rex::Socket::UdpServer
|
75
75
|
sock.extend(klass)
|
@@ -101,7 +101,7 @@ class Rex::Socket::Comm::Local
|
|
101
101
|
# Configure broadcast support
|
102
102
|
sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_BROADCAST, true)
|
103
103
|
|
104
|
-
if
|
104
|
+
if !param.bare?
|
105
105
|
sock.extend(::Rex::Socket::Ip)
|
106
106
|
sock.initsock(param)
|
107
107
|
end
|
@@ -117,59 +117,41 @@ class Rex::Socket::Comm::Local
|
|
117
117
|
#
|
118
118
|
def self.create_by_type(param, type, proto = 0)
|
119
119
|
|
120
|
-
# Whether to use IPv6 addressing
|
121
|
-
usev6 = false
|
122
|
-
|
123
120
|
# Detect IPv6 addresses and enable IPv6 accordingly
|
124
|
-
if
|
125
|
-
|
126
|
-
# Allow the caller to force IPv6
|
127
|
-
if (param.v6)
|
128
|
-
usev6 = true
|
129
|
-
end
|
130
|
-
|
131
|
-
# Force IPv6 mode for non-connected UDP sockets
|
132
|
-
if (type == ::Socket::SOCK_DGRAM and not param.peerhost)
|
133
|
-
# FreeBSD allows IPv6 socket creation, but throws an error on sendto()
|
134
|
-
# Windows 7 SP1 and newer also fail to sendto with IPv6 udp sockets
|
135
|
-
unless Rex::Compat.is_freebsd or Rex::Compat.is_windows
|
136
|
-
usev6 = true
|
137
|
-
end
|
138
|
-
end
|
121
|
+
if Rex::Socket.support_ipv6?
|
139
122
|
|
140
123
|
local = Rex::Socket.resolv_nbo(param.localhost) if param.localhost
|
141
124
|
peer = Rex::Socket.resolv_nbo(param.peerhost) if param.peerhost
|
142
125
|
|
143
|
-
|
144
|
-
|
145
|
-
|
126
|
+
# Enable IPv6 dual-bind mode for unbound UDP sockets on Linux
|
127
|
+
if type == ::Socket::SOCK_DGRAM && Rex::Compat.is_linux && !local && !peer
|
128
|
+
param.v6 = true
|
146
129
|
|
147
|
-
if
|
148
|
-
|
130
|
+
# Check if either of the addresses is 16 octets long
|
131
|
+
elsif (local && local.length == 16) || (peer && peer.length == 16)
|
132
|
+
param.v6 = true
|
149
133
|
end
|
150
134
|
|
151
|
-
if
|
152
|
-
if
|
153
|
-
if
|
135
|
+
if param.v6
|
136
|
+
if local && local.length == 4
|
137
|
+
if local == "\x00\x00\x00\x00"
|
154
138
|
param.localhost = '::'
|
155
|
-
elsif
|
139
|
+
elsif local == "\x7f\x00\x00\x01"
|
156
140
|
param.localhost = '::1'
|
157
141
|
else
|
158
142
|
param.localhost = '::ffff:' + Rex::Socket.getaddress(param.localhost, true)
|
159
143
|
end
|
160
144
|
end
|
161
145
|
|
162
|
-
if
|
163
|
-
if
|
146
|
+
if peer && peer.length == 4
|
147
|
+
if peer == "\x00\x00\x00\x00"
|
164
148
|
param.peerhost = '::'
|
165
|
-
elsif
|
149
|
+
elsif peer == "\x7f\x00\x00\x01"
|
166
150
|
param.peerhost = '::1'
|
167
151
|
else
|
168
152
|
param.peerhost = '::ffff:' + Rex::Socket.getaddress(param.peerhost, true)
|
169
153
|
end
|
170
154
|
end
|
171
|
-
|
172
|
-
param.v6 = true
|
173
155
|
end
|
174
156
|
else
|
175
157
|
# No IPv6 support
|
@@ -181,16 +163,23 @@ class Rex::Socket::Comm::Local
|
|
181
163
|
|
182
164
|
# Create the socket
|
183
165
|
sock = nil
|
184
|
-
if
|
166
|
+
if param.v6
|
185
167
|
sock = ::Socket.new(::Socket::AF_INET6, type, proto)
|
186
168
|
else
|
187
169
|
sock = ::Socket.new(::Socket::AF_INET, type, proto)
|
188
170
|
end
|
189
171
|
|
190
172
|
# Bind to a given local address and/or port if they are supplied
|
191
|
-
if param.localport
|
173
|
+
if param.localport || param.localhost
|
192
174
|
begin
|
193
|
-
|
175
|
+
|
176
|
+
# SO_REUSEADDR has undesired semantics on Windows, intead allowing
|
177
|
+
# sockets to be stolen without warning from other unprotected
|
178
|
+
# processes.
|
179
|
+
unless Rex::Compat.is_windows
|
180
|
+
sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true)
|
181
|
+
end
|
182
|
+
|
194
183
|
sock.bind(Rex::Socket.to_sockaddr(param.localhost, param.localport))
|
195
184
|
|
196
185
|
rescue ::Errno::EADDRNOTAVAIL,::Errno::EADDRINUSE
|
@@ -200,17 +189,17 @@ class Rex::Socket::Comm::Local
|
|
200
189
|
end
|
201
190
|
|
202
191
|
# Configure broadcast support for all datagram sockets
|
203
|
-
if
|
192
|
+
if type == ::Socket::SOCK_DGRAM
|
204
193
|
sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_BROADCAST, true)
|
205
194
|
end
|
206
195
|
|
207
196
|
# If a server TCP instance is being created...
|
208
|
-
if
|
197
|
+
if param.server?
|
209
198
|
sock.listen(256)
|
210
199
|
|
211
|
-
if
|
200
|
+
if !param.bare?
|
212
201
|
klass = Rex::Socket::TcpServer
|
213
|
-
if
|
202
|
+
if param.ssl
|
214
203
|
klass = Rex::Socket::SslTcpServer
|
215
204
|
end
|
216
205
|
sock.extend(klass)
|
@@ -222,7 +211,7 @@ class Rex::Socket::Comm::Local
|
|
222
211
|
chain = []
|
223
212
|
|
224
213
|
# If we were supplied with host information
|
225
|
-
if
|
214
|
+
if param.peerhost
|
226
215
|
|
227
216
|
# A flag that indicates whether we need to try multiple scopes
|
228
217
|
retry_scopes = false
|
@@ -310,7 +299,7 @@ class Rex::Socket::Comm::Local
|
|
310
299
|
end
|
311
300
|
end
|
312
301
|
|
313
|
-
if
|
302
|
+
if !param.bare?
|
314
303
|
case param.proto
|
315
304
|
when 'tcp'
|
316
305
|
klass = Rex::Socket::Tcp
|
@@ -422,7 +411,7 @@ class Rex::Socket::Comm::Local
|
|
422
411
|
when 'http'
|
423
412
|
setup = "CONNECT #{host}:#{port} HTTP/1.0\r\n\r\n"
|
424
413
|
size = sock.put(setup)
|
425
|
-
if
|
414
|
+
if size != setup.length
|
426
415
|
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to send the entire request to the proxy"), caller
|
427
416
|
end
|
428
417
|
|
@@ -445,7 +434,7 @@ class Rex::Socket::Comm::Local
|
|
445
434
|
when 'socks4'
|
446
435
|
setup = [4,1,port.to_i].pack('CCn') + Socket.gethostbyname(host)[3] + Rex::Text.rand_text_alpha(rand(8)+1) + "\x00"
|
447
436
|
size = sock.put(setup)
|
448
|
-
if
|
437
|
+
if size != setup.length
|
449
438
|
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to send the entire request to the proxy"), caller
|
450
439
|
end
|
451
440
|
|
@@ -455,7 +444,7 @@ class Rex::Socket::Comm::Local
|
|
455
444
|
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to receive a response from the proxy"), caller
|
456
445
|
end
|
457
446
|
|
458
|
-
if
|
447
|
+
if ret.nil? || ret.length < 8
|
459
448
|
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to receive a complete response from the proxy"), caller
|
460
449
|
end
|
461
450
|
if ret[1,1] != "\x5a"
|
@@ -464,18 +453,18 @@ class Rex::Socket::Comm::Local
|
|
464
453
|
when 'socks5'
|
465
454
|
auth_methods = [5,1,0].pack('CCC')
|
466
455
|
size = sock.put(auth_methods)
|
467
|
-
if
|
456
|
+
if size != auth_methods.length
|
468
457
|
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to send the entire request to the proxy"), caller
|
469
458
|
end
|
470
459
|
ret = sock.get_once(2,30)
|
471
|
-
if
|
460
|
+
if ret[1,1] == "\xff"
|
472
461
|
raise Rex::ConnectionProxyError.new(host, port, type, "The proxy requires authentication"), caller
|
473
462
|
end
|
474
463
|
|
475
|
-
if
|
464
|
+
if Rex::Socket.is_ipv4?(host)
|
476
465
|
addr = Rex::Socket.gethostbyname(host)[3]
|
477
466
|
setup = [5,1,0,1].pack('C4') + addr + [port.to_i].pack('n')
|
478
|
-
elsif
|
467
|
+
elsif Rex::Socket.support_ipv6? && Rex::Socket.is_ipv6?(host)
|
479
468
|
# IPv6 stuff all untested
|
480
469
|
addr = Rex::Socket.gethostbyname(host)[3]
|
481
470
|
setup = [5,1,0,4].pack('C4') + addr + [port.to_i].pack('n')
|
@@ -487,7 +476,7 @@ class Rex::Socket::Comm::Local
|
|
487
476
|
end
|
488
477
|
|
489
478
|
size = sock.put(setup)
|
490
|
-
if
|
479
|
+
if size != setup.length
|
491
480
|
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to send the entire request to the proxy"), caller
|
492
481
|
end
|
493
482
|
|
@@ -497,7 +486,7 @@ class Rex::Socket::Comm::Local
|
|
497
486
|
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to receive a response from the proxy"), caller
|
498
487
|
end
|
499
488
|
|
500
|
-
if
|
489
|
+
if response.nil? || response.length < 10
|
501
490
|
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to receive a complete response from the proxy"), caller
|
502
491
|
end
|
503
492
|
if response[1,1] != "\x00"
|
@@ -513,7 +502,6 @@ class Rex::Socket::Comm::Local
|
|
513
502
|
# Registration
|
514
503
|
#
|
515
504
|
##
|
516
|
-
|
517
505
|
def self.register_event_handler(handler) # :nodoc:
|
518
506
|
self.instance.register_event_handler(handler)
|
519
507
|
end
|
@@ -525,5 +513,4 @@ class Rex::Socket::Comm::Local
|
|
525
513
|
def self.each_event_handler(handler) # :nodoc:
|
526
514
|
self.instance.each_event_handler(handler)
|
527
515
|
end
|
528
|
-
|
529
516
|
end
|
data/lib/rex/socket/tcp.rb
CHANGED
@@ -53,24 +53,6 @@ module Rex::Socket::Tcp
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
#
|
57
|
-
# Returns peer information (host + port) in host:port format.
|
58
|
-
#
|
59
|
-
def peerinfo
|
60
|
-
if (pi = getpeername_as_array)
|
61
|
-
return pi[1] + ':' + pi[2].to_s
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
# Returns local information (host + port) in host:port format.
|
67
|
-
#
|
68
|
-
def localinfo
|
69
|
-
if (pi = getlocalname)
|
70
|
-
return pi[1] + ':' + pi[2].to_s
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
56
|
# returns socket type
|
75
57
|
def type?
|
76
58
|
return 'tcp'
|
data/lib/rex/socket/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rex-socket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Maloney
|
@@ -88,7 +88,7 @@ cert_chain:
|
|
88
88
|
G+Hmcg1v810agasPdoydE0RTVZgEOOMoQ07qu7JFXVWZ9ZQpHT7qJATWL/b2csFG
|
89
89
|
8mVuTXnyJOKRJA==
|
90
90
|
-----END CERTIFICATE-----
|
91
|
-
date:
|
91
|
+
date: 2017-01-10 00:00:00.000000000 Z
|
92
92
|
dependencies:
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: bundler
|
metadata.gz.sig
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
�O`�¬ydރ��Z ��2�f�T���!����Ay$l��F�I�ӂ;�2jf=ſ7y�B4��' J�����,���^���xϴ4G�x��ވ�',@�A3x}�jv�b��;��gw��V����O�Mˬ�U
|
2
|
+
%����2�$�ȦL
|
3
|
+
o���FܾU�~@�o���(^����`�q.=��ezV
|