ruby_smb 3.2.7 → 3.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c3642cdede7c8763296f8249419acad490605d06b8dc546411dab0ab25a7250
4
- data.tar.gz: ff2403b3cd0e5b633fcee3db672dee4c4f582d13ac7bfbf3cd1dd7b4c9d2e5f4
3
+ metadata.gz: e4ddd94d3c783b3091a37c946c5069da85350c23294b33ddabcdc0476f828ec4
4
+ data.tar.gz: 990ad64d98bd60dd957c1b8b6fcf1abdbd6e8a52d408e0e6c03d3694354cb4ad
5
5
  SHA512:
6
- metadata.gz: 97bd6b1bdf5b205eb8c21f1d5d980e03a616f7f25dba1219b280a199dbeb72fecc7c9dfe2efd2afa847a3e524f3ea167cc364d79e2be8b72e7e8788cdd5c29b9
7
- data.tar.gz: 61ea09ea2cd46411ead8e4bef0ce4c9eb194d8e741b1a1b1bfdd582a260d89e04edc57bd4e47ae0603a1ae125846062dde03a47ff1b17095b8b605b725461d44
6
+ metadata.gz: bc7b1921009d55e8263ecfe3aa282bd4df35636a5055f5126ffa1866ed8140283bbfa14f341a4d791e30a7f51e0df631676ef211961c9712e457e0939983a6c7
7
+ data.tar.gz: 11982c6c2b2fb653756140c7024ccff301c72ee9b5ac44f85a5071f1d2a27dbdcf31b5936bc3ea646ef7219e3c917b5466ec3e6b26bbba116fc7552169244a4a
checksums.yaml.gz.sig CHANGED
Binary file
@@ -11,7 +11,7 @@ module RubySMB
11
11
  end
12
12
 
13
13
  logger.debug("Received #{SMB1::Commands.name(request.smb_header.command)} request for share: #{share_processor.provider.name}")
14
- share_processor.send(__callee__, request)
14
+ share_processor.share_io(__callee__, request)
15
15
  end
16
16
 
17
17
  alias :do_close_smb1 :proxy_share_io_smb1
@@ -29,7 +29,7 @@ module RubySMB
29
29
  end
30
30
 
31
31
  logger.debug("Received #{SMB2::Commands.name(request.smb2_header.command)} request for share: #{share_processor.provider.name}")
32
- share_processor.send(__callee__, request)
32
+ share_processor.share_io(__callee__, request)
33
33
  end
34
34
 
35
35
  alias :do_close_smb2 :proxy_share_io_smb2
@@ -14,13 +14,13 @@ module RubySMB
14
14
  # @param [String] name The name of this share.
15
15
  # @param [String, Pathname] path The local file system path to share. This path must be an absolute path to an existing
16
16
  # directory.
17
- def initialize(name, path)
17
+ def initialize(name, path, hooks: nil)
18
18
  path = Pathname.new(File.expand_path(path)) if path.is_a?(String)
19
19
  raise ArgumentError.new('path must be a directory') unless path.directory? # it needs to exist
20
20
  raise ArgumentError.new('path must be absolute') unless path.absolute? # it needs to be absolute so it is independent of the cwd
21
21
 
22
22
  @path = path
23
- super(name)
23
+ super(name, hooks: hooks)
24
24
  end
25
25
 
26
26
  attr_accessor :path
@@ -80,6 +80,31 @@ module RubySMB
80
80
  @server_client.server
81
81
  end
82
82
 
83
+ # Forward a share IO method for a particular request. This is a choke point to allow any hooks that were
84
+ # registered with the share provider to be executed before and after the specified method is invoked to
85
+ # process the request and generate the response. This is used for both SMB1 and SMB2 requests.
86
+ #
87
+ # @param [Symbol] method_name The method name to forward the request to
88
+ # @param [RubySMB::GenericPacket] request The request packet to be processed
89
+ # @return [RubySMB::GenericPacket]
90
+ def share_io(method_name, request)
91
+ @provider.hooks.each do |hook|
92
+ next unless hook.request_class == request.class && hook.location == :before
93
+
94
+ request = hook.callback.call(@session, request) || request
95
+ end
96
+
97
+ response = send(method_name, request)
98
+
99
+ @provider.hooks.each do |hook|
100
+ next unless hook.request_class == request.class && hook.location == :after
101
+
102
+ response = hook.callback.call(@session, request, response) || response
103
+ end
104
+
105
+ response
106
+ end
107
+
83
108
  # The underlying share provider that this is a processor for.
84
109
  # @!attribute [r] provider
85
110
  # @return [RubySMB::Server::Share::Provider::Base]
@@ -14,9 +14,9 @@ module RubySMB
14
14
  private_constant :HASH_METHODS
15
15
 
16
16
  # @param [String] name The name of this share.
17
- def initialize(name)
17
+ def initialize(name, hooks: nil)
18
18
  @vfs = {}
19
- super(name, add(VirtualPathname.new(self, File::SEPARATOR)))
19
+ super(name, add(VirtualPathname.new(self, File::SEPARATOR)), hooks: hooks)
20
20
  end
21
21
 
22
22
  # Add a dynamic file to the virtual file system. A dynamic file is one whose contents are generated by the
@@ -86,7 +86,7 @@ module RubySMB
86
86
  end
87
87
 
88
88
  def new_processor(server_client, session)
89
- scoped_virtual_disk = self.class.new(@name)
89
+ scoped_virtual_disk = self.class.new(@name, hooks: @hooks)
90
90
  @vfs.each_value do |path|
91
91
  path = path.dup
92
92
  path.virtual_disk = scoped_virtual_disk if path.is_a?(VirtualPathname)
@@ -6,9 +6,51 @@ module RubySMB
6
6
  # type and name. It is shared across all client connections and
7
7
  # sessions.
8
8
  class Base
9
+ Hook = Struct.new(:request_class, :location, :callback)
10
+
9
11
  # @param [String] name The name of this share.
10
- def initialize(name)
12
+ def initialize(name, hooks: nil)
11
13
  @name = name
14
+ @hooks = hooks || []
15
+ end
16
+
17
+ # Add a hook to be called when the specified request class is processed. Any hook that was previously
18
+ # installed for the request class and location will be removed. A hook installed with a location of :before
19
+ # will be called with the session and request as the only two arguments. The return value, if provided, will
20
+ # replace the request that is to be processed. A hook installed with a location of :after will be called with
21
+ # the session, request and response as the only three arguments. The return value, if provided, will replace
22
+ # the response that is to be sent to the client.
23
+ #
24
+ # @param [RubySMB::GenericPacket] request_class The request class to register the hook for.
25
+ # @param [Proc] callback The routine to be executed when the request class is being processed.
26
+ # @param [Symbol] location When the callback should be invoked. Must be either :before or :after.
27
+ def add_hook(request_class, callback: nil, location: :before, &block)
28
+ unless %i[ before after ].include?(location)
29
+ raise ArgumentError, 'the location argument must be :before or :after'
30
+ end
31
+
32
+ unless callback.nil? ^ block.nil?
33
+ raise ArgumentError, 'either a callback or a block must be specified'
34
+ end
35
+
36
+ # Remove any hooks that were previously installed, this enforces that only one hook can be present at a time
37
+ # for any particular request class and location combination.
38
+ remove_hook(request_class, location: location)
39
+ @hooks << Hook.new(request_class, location, callback || block)
40
+
41
+ nil
42
+ end
43
+
44
+ # Remove a hook for the specified request class.
45
+ #
46
+ # @param [RubySMB::GenericPacket] request_class The request class to register the hook for.
47
+ # @param [Symbol] location When the callback should be invoked.
48
+ def remove_hook(request_class, location: :before)
49
+ @hooks.filter! do |hook|
50
+ hook.request_class == request_class && hook.location == location
51
+ end
52
+
53
+ nil
12
54
  end
13
55
 
14
56
  # Create a new, session-specific processor instance for this share.
@@ -28,6 +70,11 @@ module RubySMB
28
70
  # @!attribute [r] name
29
71
  # @return [String]
30
72
  attr_accessor :name
73
+
74
+ # The hooks installed for this share.
75
+ # @!attribute [r] hooks
76
+ # @return [Array]
77
+ attr_accessor :hooks
31
78
  end
32
79
  end
33
80
  end
@@ -35,7 +35,7 @@ module RubySMB
35
35
  end
36
36
 
37
37
  uint64 :allocation_size, label: 'Allocation Size'
38
- smb_ext_file_attributes :ext_file_attributes, label: 'Extented File Attributes'
38
+ smb_ext_file_attributes :ext_file_attributes, label: 'Extended File Attributes'
39
39
  share_access :share_access, label: 'Share Access'
40
40
  # The following constants are defined in RubySMB::Dispositions
41
41
  uint32 :create_disposition, label: 'Create Disposition'
@@ -1,3 +1,3 @@
1
1
  module RubySMB
2
- VERSION = '3.2.7'.freeze
2
+ VERSION = '3.2.8'.freeze
3
3
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_smb
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.7
4
+ version: 3.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Metasploit Hackers
metadata.gz.sig CHANGED
Binary file