Closed zeroSteiner closed 2 years ago
Thanks for updating this @zeroSteiner ! It looks good to me. I tested from multiple Windows and SMB versions. It works as expected. I'll go ahead and land it.
ruby examples/virtual_file_server.rb --no-smbv2 --no-smbv3 --username smbtest --password 123456 --share public
ruby examples/virtual_file_server.rb --no-smbv1 --no-smbv3 --username smbtest --password 123456 --share public
ruby examples/virtual_file_server.rb --no-smbv1 --no-smbv2 --username smbtest --password 123456 --share public
C:\Users\adminuser>type \\192.168.1.33\public\greeting
Hello World!
C:\Users\adminuser>type \\192.168.1.33\public\self\static
#!/usr/bin/ruby
require 'bundler/setup' ... C:\Users\adminuser>type \192.168.1.33\public\self\mapped
require 'bundler/setup' ... C:\Users\adminuser>type \192.168.1.33\public\magic_8_ball Outlook good.
- Testing the `static` type from command line:
ruby examples/virtual_file_server.rb --no-smbv1 --no-smbv2 --username \smbtest --password 123456 --share public --virtual-name test --virtual-type static --virtual-content 'My content'
C:\Users\n00tmeg>type \192.168.1.33\public\test My content
- Testing the `mapped` type from command line:
ruby examples/virtual_file_server.rb --no-smbv1 --no-smbv2 --username \smbtest --password 123456 --share public --virtual-name test --virtual-type mapped --virtual-content /tmp/tmp.txt
C:\Users\n00tmeg>type \192.168.1.33\public\test testtttt
- Testing the `dynamic` type from command line:
ruby examples/virtual_file_server.rb --no-smbv1 --no-smbv2 --username \smbtest --password 123456 --share public --virtual-name test --virtual-type dynamic --virtual-content /tmp/tmp.txt
C:\Users\n00tmeg>type \192.168.1.33\public\test testtttt
As it's name implies the Virtual Disk share provider allows the server to host files with contents that don't exist on disk. Files are divided into three types depending on if they're static, dynamically generated or mapped. Static files are pretty self explanatory. Dynamic files, are generated by a block when the share is opened. The block is passed the server client and session that the open request is associated with. This allows content specific to the session to be easily generated as well as by dynamically sized. Sizing is tricky because clients will often request information about the file including it's size before reading it. Dynamic files can be used in the future to do interesting things like generate payloads or simply display a message that a file was opened. Mapped files expose real entries on the file system. They provide a memory efficient way to host a large file without reading all of its contents into memory.
That vast majority of this works by defining a
VirtualPathname
class that emulates Ruby's builtinPathname
object for which the existing Disk share provider is currently using. It's also necessary to have aVirtualStat
object that describes the fake file which closely emulates Ruby'sStat
object. The current implementation requires that the described object either must not exist or it needs to be either a file or a directory. Nothing fancy like block devices or sockets is currently supported. The disk share also requires that real objects are directories and files anyways so that limitation won't change anything. A couple of files under the existing Disk processor were updated, mostly to ensure that files are opened exactly once per Create request. This fixes some implications with dynamic files.Example
There is a Virtual file server example. It uses a subset of the existing file server example's command line options. It hosts the following 3 files:
greeting
-- this is a plain static file that will display a friendly greetingself
-- this demonstrates a convenient method to expose files that do exist on disk through the virtual file system or another file-like object. This is not a mapped file, it just reads from the object and creates a static file.magic_8_ball
-- this is a simple PoC that will generate a file with a magic 8 ball answer each time the share is opened, it demonstrates the content is dynamically createdDemo
Demo shows file reads for SMB 1-3 and then the dynamic file that changes each time.