librex 0.0.40 → 0.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  A non-official re-packaging of the Rex library as a gem for easy of usage of the Metasploit REX framework in a non Metasploit application. I received permission from HDM to create this package.
4
4
 
5
5
  Currently based on:
6
- SVN Revision: 13097
6
+ SVN Revision: 13139
7
7
 
8
8
  # Credits
9
9
  The Metasploit development team <http://www.metasploit.com>
@@ -96,7 +96,7 @@ class Dir < Rex::Post::Dir
96
96
 
97
97
  files <<
98
98
  {
99
- 'FileName' => file_name.value,
99
+ 'FileName' => file_name.value,
100
100
  'FilePath' => fpath[idx].value,
101
101
  'StatBuf' => st,
102
102
  }
@@ -189,7 +189,7 @@ class Dir < Rex::Post::Dir
189
189
  ##
190
190
 
191
191
  #
192
- # Downloads the contents of a remote directory a
192
+ # Downloads the contents of a remote directory a
193
193
  # local directory, optionally in a recursive fashion.
194
194
  #
195
195
  def Dir.download(dst, src, recursive = false, force = true, &stat)
@@ -205,7 +205,7 @@ class Dir < Rex::Post::Dir
205
205
 
206
206
  if (src_stat.file?)
207
207
  stat.call('downloading', src_item, dst_item) if (stat)
208
- begin
208
+ begin
209
209
  client.fs.file.download(dst_item, src_item)
210
210
  stat.call('downloaded', src_item, dst_item) if (stat)
211
211
  rescue ::Rex::Post::Meterpreter::RequestError => e
@@ -234,7 +234,7 @@ class Dir < Rex::Post::Dir
234
234
  end
235
235
 
236
236
  #
237
- # Uploads the contents of a local directory to a remote
237
+ # Uploads the contents of a local directory to a remote
238
238
  # directory, optionally in a recursive fashion.
239
239
  #
240
240
  def Dir.upload(dst, src, recursive = false, &stat)
@@ -272,7 +272,7 @@ class Dir < Rex::Post::Dir
272
272
  #
273
273
  # The path of the directory that was opened.
274
274
  #
275
- attr_reader :path
275
+ attr_reader :path
276
276
  protected
277
277
  attr_accessor :client # :nodoc:
278
278
  attr_writer :path # :nodoc:
@@ -23,8 +23,11 @@ module Fs
23
23
  ###
24
24
  class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
25
25
 
26
- SEPARATOR = "\\"
27
- Separator = "\\"
26
+ #
27
+ # This should be replaced with a platform-specific value.
28
+ #
29
+ SEPARATOR = "\\"
30
+ Separator = "\\"
28
31
 
29
32
  include Rex::Post::File
30
33
 
@@ -68,12 +71,13 @@ Separator = "\\"
68
71
  #
69
72
  def File.basename(*a)
70
73
  path = a[0]
71
- sep = "\\" + File::SEPARATOR
72
74
 
73
- # I suck at regex.
74
- path =~ /(.*)#{sep}(.*)$/
75
+ # Allow both kinds of dir serparators since lots and lots of code
76
+ # assumes one or the other so this ends up getting called with strings
77
+ # like: "C:\\foo/bar"
78
+ path =~ %r#.*[/\\](.*)$#
75
79
 
76
- Rex::FileUtils.clean_path($2 || path)
80
+ Rex::FileUtils.clean_path($1 || path)
77
81
  end
78
82
 
79
83
  #
@@ -208,16 +212,16 @@ Separator = "\\"
208
212
  # Download one or more files from the remote computer to the local
209
213
  # directory supplied in destination.
210
214
  #
211
- def File.download(destination, *src_files, &stat)
215
+ def File.download(dest, *src_files, &stat)
212
216
  src_files.each { |src|
213
- dest = destination
214
-
215
- stat.call('downloading', src, dest) if (stat)
216
-
217
- if (::File.basename(destination) != File.basename(src))
217
+ if (::File.basename(dest) != File.basename(src))
218
+ # The destination when downloading is a local file so use this
219
+ # system's separator
218
220
  dest += ::File::SEPARATOR + File.basename(src)
219
221
  end
220
222
 
223
+ stat.call('downloading', src, dest) if (stat)
224
+
221
225
  download_file(dest, src)
222
226
 
223
227
  stat.call('downloaded', src, dest) if (stat)
@@ -229,7 +233,9 @@ Separator = "\\"
229
233
  #
230
234
  def File.download_file(dest_file, src_file)
231
235
  src_fd = client.fs.file.new(src_file, "rb")
232
- ::FileUtils.mkdir_p(::File.dirname(dest_file))
236
+ dir = ::File.dirname(dest_file)
237
+ ::FileUtils.mkdir_p(dir) if dir and not ::File.directory?(dir)
238
+
233
239
  dst_fd = ::File.new(dest_file, "wb")
234
240
 
235
241
  # Keep transferring until EOF is reached...
@@ -183,7 +183,7 @@ class Console::CommandDispatcher::Stdapi::Fs
183
183
  alias :cmd_del :cmd_rm
184
184
 
185
185
  def cmd_download_help
186
- print_line "Usage: download [options] src1 src2 src3 ... destination"
186
+ print_line "Usage: download [options] src1 src2 src3 ... destination"
187
187
  print_line
188
188
  print_line "Downloads remote files and directories to the local machine."
189
189
  print_line @@download_opts.usage
@@ -206,23 +206,29 @@ class Console::CommandDispatcher::Stdapi::Fs
206
206
 
207
207
  @@download_opts.parse(args) { |opt, idx, val|
208
208
  case opt
209
- when "-r"
210
- recursive = true
211
- when nil
212
- if (last)
213
- src_items << last
214
- end
215
-
216
- last = val
209
+ when "-r"
210
+ recursive = true
211
+ when nil
212
+ src_items << last if (last)
213
+ last = val
217
214
  end
218
215
  }
219
216
 
220
- return true if not last
217
+ # No files given, nothing to do
218
+ if not last
219
+ cmd_download_help
220
+ return true
221
+ end
221
222
 
222
223
  # Source and destination will be the same
223
- src_items << last if src_items.empty?
224
-
225
- dest = last
224
+ if src_items.empty?
225
+ src_items << last
226
+ # Use the basename of the remote filename so we don't end up with
227
+ # a file named c:\\boot.ini in linux
228
+ dest = ::Rex::Post::Meterpreter::Extensions::Stdapi::Fs::File.basename(last)
229
+ else
230
+ dest = last
231
+ end
226
232
 
227
233
  # Go through each source item and download them
228
234
  src_items.each { |src|
@@ -301,7 +307,7 @@ class Console::CommandDispatcher::Stdapi::Fs
301
307
  path = args[0] || client.fs.dir.getwd
302
308
  tbl = Rex::Ui::Text::Table.new(
303
309
  'Header' => "Listing: #{path}",
304
- 'Columns' =>
310
+ 'Columns' =>
305
311
  [
306
312
  'Mode',
307
313
  'Size',
@@ -315,12 +321,12 @@ class Console::CommandDispatcher::Stdapi::Fs
315
321
  # Enumerate each item...
316
322
  client.fs.dir.entries_with_info(path).sort { |a,b| a['FileName'] <=> b['FileName'] }.each { |p|
317
323
 
318
- tbl <<
319
- [
324
+ tbl <<
325
+ [
320
326
  p['StatBuf'] ? p['StatBuf'].prettymode : '',
321
- p['StatBuf'] ? p['StatBuf'].size : '',
322
- p['StatBuf'] ? p['StatBuf'].ftype[0,3] : '',
323
- p['StatBuf'] ? p['StatBuf'].mtime : '',
327
+ p['StatBuf'] ? p['StatBuf'].size : '',
328
+ p['StatBuf'] ? p['StatBuf'].ftype[0,3] : '',
329
+ p['StatBuf'] ? p['StatBuf'].mtime : '',
324
330
  p['FileName'] || 'unknown'
325
331
  ]
326
332
 
@@ -368,7 +374,7 @@ class Console::CommandDispatcher::Stdapi::Fs
368
374
  #
369
375
  def cmd_rmdir(*args)
370
376
  if (args.length == 0 or args.include?("-h"))
371
- print_line("Usage: rmdir dir1 dir2 dir3 ...")
377
+ print_line("Usage: rmdir dir1 dir2 dir3 ...")
372
378
  return true
373
379
  end
374
380
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: librex
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.40
5
+ version: 0.0.41
6
6
  platform: ruby
7
7
  authors:
8
8
  - Metasploit Development Team
@@ -11,11 +11,11 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-07-04 00:00:00 -05:00
14
+ date: 2011-07-09 00:00:00 -05:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
18
- description: Rex provides a variety of classes useful for security testing and exploit development. Based on SVN Revision 13097
18
+ description: Rex provides a variety of classes useful for security testing and exploit development. Based on SVN Revision 13139
19
19
  email:
20
20
  - hdm@metasploit.com
21
21
  - jacob.hammack@hammackj.com