Skip to content

Commit

Permalink
Add upload/download/delete/mkdir/rmdir to smb session
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelch-r7 committed Mar 12, 2024
1 parent d964edd commit 689caf4
Show file tree
Hide file tree
Showing 13 changed files with 427 additions and 90 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ PATH
rex-zip
ruby-macho
ruby-mysql
ruby_smb (~> 3.3.0)
ruby_smb (~> 3.3.3)
rubyntlm
rubyzip
sinatra
Expand Down Expand Up @@ -474,8 +474,8 @@ GEM
ruby-progressbar (1.13.0)
ruby-rc4 (0.1.5)
ruby2_keywords (0.0.5)
ruby_smb (3.3.2)
bindata
ruby_smb (3.3.3)
bindata (= 2.4.15)
openssl-ccm
openssl-cmac
rubyntlm
Expand Down
3 changes: 3 additions & 0 deletions lib/msf/base/sessions/smb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Msf::Sessions::SMB
attr_accessor :console
# @return [RubySMB::Client] The SMB client
attr_accessor :client
# @return [Rex::Proto::SMB::SimpleClient]
attr_accessor :simple_client
attr_accessor :platform, :arch
attr_reader :framework

Expand All @@ -21,6 +23,7 @@ class Msf::Sessions::SMB
# @option opts [RubySMB::Client] :client
def initialize(rstream, opts = {})
@client = opts.fetch(:client)
@simple_client = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client)
self.console = Rex::Post::SMB::Ui::Console.new(self)
super(rstream, opts)
end
Expand Down
15 changes: 15 additions & 0 deletions lib/rex/ntpath.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Rex
module Ntpath

# @param [String] path The path to convert into a valid ntpath format
def self.as_ntpath(path)
Pathname.new(path)
.cleanpath
.each_filename
.drop_while { |file| file == '.' }
.join('\\')
end
end
end
9 changes: 6 additions & 3 deletions lib/rex/post/smb/ui/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def initialize(session)
# The ruby smb client context
self.session = session
self.client = session.client
self.simple_client = session.simple_client

# Queued commands array
self.commands = []
Expand Down Expand Up @@ -125,6 +126,9 @@ def log_error(msg)
# @return [RubySMB::Client]
attr_reader :client # :nodoc:

# @return [Rex::Proto::SMB::SimpleClient]
attr_reader :simple_client

# @return [RubySMB::SMB2::Tree]
attr_accessor :active_share

Expand All @@ -134,7 +138,7 @@ def log_error(msg)
def format_prompt(val)
if active_share
share_name = active_share.share[/[^\\].*$/, 0]
cwd = self.cwd.blank? ? '' : "\\#{self.cwd}"
cwd = self.cwd.blank? ? '' : "\\#{Rex::Ntpath.as_ntpath(self.cwd)}"
prompt = "#{share_name}#{cwd}"
else
prompt = session.address.to_s
Expand All @@ -145,9 +149,8 @@ def format_prompt(val)

protected

attr_writer :session, :client # :nodoc: # :nodoc:
attr_writer :session, :client, :simple_client # :nodoc: # :nodoc:
attr_accessor :commands # :nodoc:

end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/rex/post/smb/ui/console/command_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def client
console.client
end

#
# Returns the smb simple client.
#
# @return [Rex::Proto::SMB::SimpleClient]
def simple_client
shell.simple_client
end

#
# Returns the smb session context.
#
Expand Down
Loading

0 comments on commit 689caf4

Please sign in to comment.