Class: Rex::Post::Meterpreter::Ui::Console::CommandDispatcher::Stdapi::Fs

Inherits:
Object
  • Object
show all
Includes:
Extensions::Stdapi, Rex::Post::Meterpreter::Ui::Console::CommandDispatcher
Defined in:
lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb

Overview

The file system portion of the standard API extension.

Constant Summary collapse

Klass =
Console::CommandDispatcher::Stdapi::Fs
@@download_opts =

Options for the download command.

Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner" ],
"-c" => [ false, "Resume getting a partially-downloaded file" ],
"-a" => [ false, "Enable adaptive download buffer size" ],
"-b" => [ true,  "Set the initial block size for the download" ],
"-l" => [ true,  "Set the limit of retries (0 unlimits)" ],
"-r" => [ false, "Download recursively" ],
"-t" => [ false, "Timestamp downloaded files" ])
@@upload_opts =

Options for the upload command.

Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner" ],
"-r" => [ false, "Upload recursively" ])
@@ls_opts =

Options for the ls command

Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner" ],
"-S" => [ true,  "Search string on filename (as regular expression)" ],
"-t" => [ false, "Sort by time" ],
"-s" => [ false, "Sort by size" ],
"-r" => [ false, "Reverse sort order" ],
"-x" => [ false, "Show short file names" ],
"-l" => [ false, "List in long format (default)" ],
"-R" => [ false, "Recursively list subdirectories encountered" ])
@@lls_opts =

Options for the lls command

Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner" ],
"-S" => [ true,  "Search string on filename (as regular expression)" ],
"-t" => [ false, "Sort by time" ],
"-s" => [ false, "Sort by size" ],
"-r" => [ false, "Reverse sort order" ])

Constants included from Extensions::Stdapi

Extensions::Stdapi::COMMAND_ID_STDAPI_AUDIO_MIC_LIST, Extensions::Stdapi::COMMAND_ID_STDAPI_AUDIO_MIC_START, Extensions::Stdapi::COMMAND_ID_STDAPI_AUDIO_MIC_STOP, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_CHDIR, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_CHMOD, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_DELETE_DIR, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_DELETE_FILE, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_FILE_COPY, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_FILE_EXPAND_PATH, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_FILE_MOVE, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_GETWD, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_LS, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_MD5, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_MKDIR, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_MOUNT_SHOW, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_SEARCH, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_SEPARATOR, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_SHA1, Extensions::Stdapi::COMMAND_ID_STDAPI_FS_STAT, Extensions::Stdapi::COMMAND_ID_STDAPI_NET_CONFIG_ADD_ROUTE, Extensions::Stdapi::COMMAND_ID_STDAPI_NET_CONFIG_GET_ARP_TABLE, Extensions::Stdapi::COMMAND_ID_STDAPI_NET_CONFIG_GET_INTERFACES, Extensions::Stdapi::COMMAND_ID_STDAPI_NET_CONFIG_GET_NETSTAT, Extensions::Stdapi::COMMAND_ID_STDAPI_NET_CONFIG_GET_PROXY, Extensions::Stdapi::COMMAND_ID_STDAPI_NET_CONFIG_GET_ROUTES, Extensions::Stdapi::COMMAND_ID_STDAPI_NET_CONFIG_REMOVE_ROUTE, Extensions::Stdapi::COMMAND_ID_STDAPI_NET_RESOLVE_HOST, Extensions::Stdapi::COMMAND_ID_STDAPI_NET_RESOLVE_HOSTS, Extensions::Stdapi::COMMAND_ID_STDAPI_NET_SOCKET_TCP_SHUTDOWN, Extensions::Stdapi::COMMAND_ID_STDAPI_NET_TCP_CHANNEL_OPEN, Extensions::Stdapi::COMMAND_ID_STDAPI_RAILGUN_API, Extensions::Stdapi::COMMAND_ID_STDAPI_RAILGUN_API_MULTI, Extensions::Stdapi::COMMAND_ID_STDAPI_RAILGUN_MEMREAD, Extensions::Stdapi::COMMAND_ID_STDAPI_RAILGUN_MEMWRITE, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_CHECK_KEY_EXISTS, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_CLOSE_KEY, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_CREATE_KEY, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_DELETE_KEY, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_DELETE_VALUE, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_ENUM_KEY, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_ENUM_KEY_DIRECT, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_ENUM_VALUE, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_ENUM_VALUE_DIRECT, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_LOAD_KEY, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_OPEN_KEY, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_OPEN_REMOTE_KEY, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_QUERY_CLASS, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_QUERY_VALUE, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_QUERY_VALUE_DIRECT, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_SET_VALUE, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_SET_VALUE_DIRECT, Extensions::Stdapi::COMMAND_ID_STDAPI_REGISTRY_UNLOAD_KEY, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_CONFIG_DRIVER_LIST, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_CONFIG_DROP_TOKEN, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_CONFIG_GETENV, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_CONFIG_GETPRIVS, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_CONFIG_GETSID, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_CONFIG_GETUID, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_CONFIG_LOCALTIME, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_CONFIG_REV2SELF, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_CONFIG_STEAL_TOKEN, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_CONFIG_SYSINFO, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_EVENTLOG_CLEAR, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_EVENTLOG_CLOSE, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_EVENTLOG_NUMRECORDS, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_EVENTLOG_OLDEST, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_EVENTLOG_OPEN, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_EVENTLOG_READ, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_POWER_EXITWINDOWS, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_ATTACH, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_CLOSE, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_EXECUTE, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_GETPID, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_GET_INFO, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_GET_PROCESSES, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_IMAGE_GET_IMAGES, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_IMAGE_GET_PROC_ADDRESS, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_IMAGE_LOAD, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_IMAGE_UNLOAD, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_KILL, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_MEMORY_ALLOCATE, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_MEMORY_FREE, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_MEMORY_LOCK, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_MEMORY_PROTECT, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_MEMORY_QUERY, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_MEMORY_READ, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_MEMORY_UNLOCK, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_MEMORY_WRITE, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_THREAD_CLOSE, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_THREAD_CREATE, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_THREAD_GET_THREADS, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_THREAD_OPEN, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_THREAD_QUERY_REGS, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_THREAD_RESUME, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_THREAD_SET_REGS, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_THREAD_SUSPEND, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_THREAD_TERMINATE, Extensions::Stdapi::COMMAND_ID_STDAPI_SYS_PROCESS_WAIT, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_DESKTOP_ENUM, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_DESKTOP_GET, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_DESKTOP_SCREENSHOT, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_DESKTOP_SET, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_ENABLE_KEYBOARD, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_ENABLE_MOUSE, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_GET_IDLE_TIME, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_GET_KEYS_UTF8, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_SEND_KEYEVENT, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_SEND_KEYS, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_SEND_MOUSE, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_START_KEYSCAN, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_STOP_KEYSCAN, Extensions::Stdapi::COMMAND_ID_STDAPI_UI_UNLOCK_DESKTOP, Extensions::Stdapi::COMMAND_ID_STDAPI_WEBCAM_AUDIO_RECORD, Extensions::Stdapi::COMMAND_ID_STDAPI_WEBCAM_GET_FRAME, Extensions::Stdapi::COMMAND_ID_STDAPI_WEBCAM_LIST, Extensions::Stdapi::COMMAND_ID_STDAPI_WEBCAM_START, Extensions::Stdapi::COMMAND_ID_STDAPI_WEBCAM_STOP, Extensions::Stdapi::DELETE_KEY_FLAG_RECURSIVE, Extensions::Stdapi::EXTENSION_ID_STDAPI, Extensions::Stdapi::PROCESS_EXECUTE_FLAG_CHANNELIZED, Extensions::Stdapi::PROCESS_EXECUTE_FLAG_DESKTOP, Extensions::Stdapi::PROCESS_EXECUTE_FLAG_HIDDEN, Extensions::Stdapi::PROCESS_EXECUTE_FLAG_SESSION, Extensions::Stdapi::PROCESS_EXECUTE_FLAG_SUBSHELL, Extensions::Stdapi::PROCESS_EXECUTE_FLAG_SUSPENDED, Extensions::Stdapi::PROCESS_EXECUTE_FLAG_USE_THREAD_TOKEN, Extensions::Stdapi::TLV_TYPE_ADDR_TYPE, Extensions::Stdapi::TLV_TYPE_ALLOCATION_TYPE, Extensions::Stdapi::TLV_TYPE_ALLOC_BASE_ADDRESS, Extensions::Stdapi::TLV_TYPE_ALLOC_PROTECTION, Extensions::Stdapi::TLV_TYPE_ARCHITECTURE, Extensions::Stdapi::TLV_TYPE_ARP_ENTRY, Extensions::Stdapi::TLV_TYPE_AUDIO_DATA, Extensions::Stdapi::TLV_TYPE_AUDIO_DURATION, Extensions::Stdapi::TLV_TYPE_AUDIO_INTERFACE_ID, Extensions::Stdapi::TLV_TYPE_AUDIO_INTERFACE_NAME, Extensions::Stdapi::TLV_TYPE_BASE_ADDRESS, Extensions::Stdapi::TLV_TYPE_BASE_KEY, Extensions::Stdapi::TLV_TYPE_BUILD_TUPLE, Extensions::Stdapi::TLV_TYPE_COMPUTER_NAME, Extensions::Stdapi::TLV_TYPE_CONNECT_RETRIES, Extensions::Stdapi::TLV_TYPE_CREATION_FLAGS, Extensions::Stdapi::TLV_TYPE_DESKTOP, Extensions::Stdapi::TLV_TYPE_DESKTOP_NAME, Extensions::Stdapi::TLV_TYPE_DESKTOP_SCREENSHOT, Extensions::Stdapi::TLV_TYPE_DESKTOP_SCREENSHOT_PE32DLL_BUFFER, Extensions::Stdapi::TLV_TYPE_DESKTOP_SCREENSHOT_PE64DLL_BUFFER, Extensions::Stdapi::TLV_TYPE_DESKTOP_SCREENSHOT_QUALITY, Extensions::Stdapi::TLV_TYPE_DESKTOP_SESSION, Extensions::Stdapi::TLV_TYPE_DESKTOP_STATION, Extensions::Stdapi::TLV_TYPE_DESKTOP_SWITCH, Extensions::Stdapi::TLV_TYPE_DIRECTORY_PATH, Extensions::Stdapi::TLV_TYPE_DOMAIN, Extensions::Stdapi::TLV_TYPE_DRIVER_BASENAME, Extensions::Stdapi::TLV_TYPE_DRIVER_ENTRY, Extensions::Stdapi::TLV_TYPE_DRIVER_FILENAME, Extensions::Stdapi::TLV_TYPE_ENTRY_PARAMETER, Extensions::Stdapi::TLV_TYPE_ENTRY_POINT, Extensions::Stdapi::TLV_TYPE_ENV_GROUP, Extensions::Stdapi::TLV_TYPE_ENV_VALUE, Extensions::Stdapi::TLV_TYPE_ENV_VARIABLE, Extensions::Stdapi::TLV_TYPE_EVENT_CATEGORY, Extensions::Stdapi::TLV_TYPE_EVENT_DATA, Extensions::Stdapi::TLV_TYPE_EVENT_HANDLE, Extensions::Stdapi::TLV_TYPE_EVENT_ID, Extensions::Stdapi::TLV_TYPE_EVENT_NUMRECORDS, Extensions::Stdapi::TLV_TYPE_EVENT_READFLAGS, Extensions::Stdapi::TLV_TYPE_EVENT_RECORDNUMBER, Extensions::Stdapi::TLV_TYPE_EVENT_RECORDOFFSET, Extensions::Stdapi::TLV_TYPE_EVENT_SOURCENAME, Extensions::Stdapi::TLV_TYPE_EVENT_STRING, Extensions::Stdapi::TLV_TYPE_EVENT_TIMEGENERATED, Extensions::Stdapi::TLV_TYPE_EVENT_TIMEWRITTEN, Extensions::Stdapi::TLV_TYPE_EVENT_TYPE, Extensions::Stdapi::TLV_TYPE_EXIT_CODE, Extensions::Stdapi::TLV_TYPE_FILE_HASH, Extensions::Stdapi::TLV_TYPE_FILE_MODE, Extensions::Stdapi::TLV_TYPE_FILE_MODE_T, Extensions::Stdapi::TLV_TYPE_FILE_NAME, Extensions::Stdapi::TLV_TYPE_FILE_PATH, Extensions::Stdapi::TLV_TYPE_FILE_SHORT_NAME, Extensions::Stdapi::TLV_TYPE_FILE_SIZE, Extensions::Stdapi::TLV_TYPE_GATEWAY, Extensions::Stdapi::TLV_TYPE_GATEWAY_STRING, Extensions::Stdapi::TLV_TYPE_HANDLE, Extensions::Stdapi::TLV_TYPE_HKEY, Extensions::Stdapi::TLV_TYPE_HOST_NAME, Extensions::Stdapi::TLV_TYPE_IDLE_TIME, Extensions::Stdapi::TLV_TYPE_IMAGE_BASE, Extensions::Stdapi::TLV_TYPE_IMAGE_FILE, Extensions::Stdapi::TLV_TYPE_IMAGE_FILE_PATH, Extensions::Stdapi::TLV_TYPE_IMAGE_GROUP, Extensions::Stdapi::TLV_TYPE_IMAGE_NAME, Extensions::Stdapi::TLV_TYPE_INHERIT, Extensions::Stdapi::TLV_TYPE_INTERFACE_FLAGS, Extensions::Stdapi::TLV_TYPE_INTERFACE_INDEX, Extensions::Stdapi::TLV_TYPE_INTERFACE_MTU, Extensions::Stdapi::TLV_TYPE_IP, Extensions::Stdapi::TLV_TYPE_IP6_SCOPE, Extensions::Stdapi::TLV_TYPE_IP_PREFIX, Extensions::Stdapi::TLV_TYPE_KEYEVENT_SEND, Extensions::Stdapi::TLV_TYPE_KEYSCAN_TRACK_ACTIVE_WINDOW, Extensions::Stdapi::TLV_TYPE_KEYS_DUMP, Extensions::Stdapi::TLV_TYPE_KEYS_SEND, Extensions::Stdapi::TLV_TYPE_KEY_NAME, Extensions::Stdapi::TLV_TYPE_LANG_SYSTEM, Extensions::Stdapi::TLV_TYPE_LOCAL_DATETIME, Extensions::Stdapi::TLV_TYPE_LOCAL_HOST, Extensions::Stdapi::TLV_TYPE_LOCAL_HOST_RAW, Extensions::Stdapi::TLV_TYPE_LOCAL_PORT, Extensions::Stdapi::TLV_TYPE_LOGGED_ON_USER_COUNT, Extensions::Stdapi::TLV_TYPE_MAC_ADDRESS, Extensions::Stdapi::TLV_TYPE_MAC_NAME, Extensions::Stdapi::TLV_TYPE_MEMORY_STATE, Extensions::Stdapi::TLV_TYPE_MEMORY_TYPE, Extensions::Stdapi::TLV_TYPE_MOUNT, Extensions::Stdapi::TLV_TYPE_MOUNT_NAME, Extensions::Stdapi::TLV_TYPE_MOUNT_SPACE_FREE, Extensions::Stdapi::TLV_TYPE_MOUNT_SPACE_TOTAL, Extensions::Stdapi::TLV_TYPE_MOUNT_SPACE_USER, Extensions::Stdapi::TLV_TYPE_MOUNT_TYPE, Extensions::Stdapi::TLV_TYPE_MOUNT_UNCPATH, Extensions::Stdapi::TLV_TYPE_MOUSE_ACTION, Extensions::Stdapi::TLV_TYPE_MOUSE_X, Extensions::Stdapi::TLV_TYPE_MOUSE_Y, Extensions::Stdapi::TLV_TYPE_NETMASK, Extensions::Stdapi::TLV_TYPE_NETMASK_STRING, Extensions::Stdapi::TLV_TYPE_NETSTAT_ENTRY, Extensions::Stdapi::TLV_TYPE_NETWORK_INTERFACE, Extensions::Stdapi::TLV_TYPE_NETWORK_ROUTE, Extensions::Stdapi::TLV_TYPE_OS_NAME, Extensions::Stdapi::TLV_TYPE_PARENT_PID, Extensions::Stdapi::TLV_TYPE_PEER_HOST, Extensions::Stdapi::TLV_TYPE_PEER_HOST_RAW, Extensions::Stdapi::TLV_TYPE_PEER_PORT, Extensions::Stdapi::TLV_TYPE_PERMISSION, Extensions::Stdapi::TLV_TYPE_PID, Extensions::Stdapi::TLV_TYPE_PORT, Extensions::Stdapi::TLV_TYPE_POWER_FLAGS, Extensions::Stdapi::TLV_TYPE_POWER_REASON, Extensions::Stdapi::TLV_TYPE_PRIVILEGE, Extensions::Stdapi::TLV_TYPE_PROCEDURE_ADDRESS, Extensions::Stdapi::TLV_TYPE_PROCEDURE_NAME, Extensions::Stdapi::TLV_TYPE_PROCESS_ARCH, Extensions::Stdapi::TLV_TYPE_PROCESS_ARCH_NAME, Extensions::Stdapi::TLV_TYPE_PROCESS_ARGUMENTS, Extensions::Stdapi::TLV_TYPE_PROCESS_FLAGS, Extensions::Stdapi::TLV_TYPE_PROCESS_GROUP, Extensions::Stdapi::TLV_TYPE_PROCESS_HANDLE, Extensions::Stdapi::TLV_TYPE_PROCESS_MEMORY, Extensions::Stdapi::TLV_TYPE_PROCESS_NAME, Extensions::Stdapi::TLV_TYPE_PROCESS_PATH, Extensions::Stdapi::TLV_TYPE_PROCESS_PERMS, Extensions::Stdapi::TLV_TYPE_PROCESS_SESSION, Extensions::Stdapi::TLV_TYPE_PROTECTION, Extensions::Stdapi::TLV_TYPE_PROXY_CFG_AUTOCONFIGURL, Extensions::Stdapi::TLV_TYPE_PROXY_CFG_AUTODETECT, Extensions::Stdapi::TLV_TYPE_PROXY_CFG_PROXY, Extensions::Stdapi::TLV_TYPE_PROXY_CFG_PROXYBYPASS, Extensions::Stdapi::TLV_TYPE_REGISTER, Extensions::Stdapi::TLV_TYPE_REGISTER_NAME, Extensions::Stdapi::TLV_TYPE_REGISTER_SIZE, Extensions::Stdapi::TLV_TYPE_REGISTER_VALUE_32, Extensions::Stdapi::TLV_TYPE_ROOT_KEY, Extensions::Stdapi::TLV_TYPE_ROUTE_METRIC, Extensions::Stdapi::TLV_TYPE_SEARCH_GLOB, Extensions::Stdapi::TLV_TYPE_SEARCH_RECURSE, Extensions::Stdapi::TLV_TYPE_SEARCH_RESULTS, Extensions::Stdapi::TLV_TYPE_SEARCH_ROOT, Extensions::Stdapi::TLV_TYPE_SHUTDOWN_HOW, Extensions::Stdapi::TLV_TYPE_SID, Extensions::Stdapi::TLV_TYPE_STAT_BUF, Extensions::Stdapi::TLV_TYPE_STAT_BUF32, Extensions::Stdapi::TLV_TYPE_SUBNET, Extensions::Stdapi::TLV_TYPE_SUBNET_STRING, Extensions::Stdapi::TLV_TYPE_TARGET_HOST, Extensions::Stdapi::TLV_TYPE_THREAD_HANDLE, Extensions::Stdapi::TLV_TYPE_THREAD_ID, Extensions::Stdapi::TLV_TYPE_THREAD_PERMS, Extensions::Stdapi::TLV_TYPE_USER_NAME, Extensions::Stdapi::TLV_TYPE_VALUE_DATA, Extensions::Stdapi::TLV_TYPE_VALUE_NAME, Extensions::Stdapi::TLV_TYPE_VALUE_TYPE, Extensions::Stdapi::TLV_TYPE_WEBCAM_IMAGE, Extensions::Stdapi::TLV_TYPE_WEBCAM_INTERFACE_ID, Extensions::Stdapi::TLV_TYPE_WEBCAM_NAME, Extensions::Stdapi::TLV_TYPE_WEBCAM_QUALITY

Instance Attribute Summary

Attributes included from Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Rex::Post::Meterpreter::Ui::Console::CommandDispatcher

check_hash, #client, #docs_dir, #filter_commands, #initialize, #log_error, #msf_loaded?, set_hash

Methods included from Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #update_prompt

Instance Method Details

#cmd_cat(*args) ⇒ Object

Reads the contents of a file and prints them to the screen.


238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 238

def cmd_cat(*args)
  if (args.length == 0)
    print_line("Usage: cat file")
    return true
  end

  if (client.fs.file.stat(args[0]).directory?)
    print_error("#{args[0]} is a directory")
  else
    fd = client.fs.file.new(args[0], "rb")
    begin
      until fd.eof?
        print(fd.read)
      end
    # EOFError is raised if file is empty, do nothing, just catch
    rescue EOFError
    end
    fd.close
  end

  true
end

#cmd_cat_tabs(str, words) ⇒ Object Also known as: cmd_rm_tabs, cmd_del_tabs, cmd_mv_tabs, cmd_move_tabs, cmd_rename_tabs, cmd_cp_tabs, cmd_chmod_tabs, cmd_edit_tabs

Tab completion for the cat command


264
265
266
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 264

def cmd_cat_tabs(str, words)
  tab_complete_cfilenames(str, words)
end

#cmd_cd(*args) ⇒ Object

Change the working directory.


271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 271

def cmd_cd(*args)
  if (args.length == 0)
    print_line("Usage: cd directory")
    return true
  end
  if args[0] =~ PATH_EXPAND_REGEX
    client.fs.dir.chdir(client.fs.file.expand_path(args[0].upcase))
  else
    client.fs.dir.chdir(args[0])
  end

  return true
end

#cmd_cd_tabs(str, words) ⇒ Object Also known as: cmd_mkdir_tabs, cmd_rmdir_tabs

Tab completion for the cd command


288
289
290
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 288

def cmd_cd_tabs(str, words)
  tab_complete_cdirectory(str, words)
end

#cmd_checksum(*args) ⇒ Object

Retrieve the checksum of a file


316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 316

def cmd_checksum(*args)
  algorithm = args.shift
  algorithm.downcase! unless algorithm.nil?
  unless args.length > 0 and CHECKSUM_ALGORITHMS.include?(algorithm)
    print_line("Usage: checksum [#{ CHECKSUM_ALGORITHMS.join(' / ') }] file1 file2 file3 ...")
    return true
  end

  args.each do |filepath|
    checksum = client.fs.file.send(algorithm, filepath)
    print_line("#{Rex::Text.to_hex(checksum, '')}  #{filepath}")
  end

  return true
end

#cmd_checksum_tabs(str, words) ⇒ Object


332
333
334
335
336
337
338
339
340
341
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 332

def cmd_checksum_tabs(str, words)
  tabs = []
  return tabs unless words.length == 1

  CHECKSUM_ALGORITHMS.each do |algorithm|
    tabs << algorithm if algorithm.start_with?(str.downcase)
  end

  tabs
end

#cmd_chmod(*args) ⇒ Object

Change the permissions on a remote file


409
410
411
412
413
414
415
416
417
418
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 409

def cmd_chmod(*args)
  if (args.length != 2)
    print_line("Usage: chmod permission file")
    return true
  end
  file_path = args[1]
  file_path = client.fs.file.expand_path(file_path) if file_path =~ PATH_EXPAND_REGEX
  client.fs.file.chmod(file_path, args[0].to_i(8))
  return true
end

#cmd_cp(*args) ⇒ Object Also known as: cmd_copy

Move source to destination


389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 389

def cmd_cp(*args)
  if (args.length < 2)
    print_line("Usage: cp oldfile newfile")
    return true
  end
  old_path = args[0]
  old_path = client.fs.file.expand_path(old_path) if old_path =~ PATH_EXPAND_REGEX
  new_path = args[1]
  new_path = client.fs.file.expand_path(new_path) if new_path =~ PATH_EXPAND_REGEX
  client.fs.file.cp(old_path, new_path)
  return true
end

#cmd_download(*args) ⇒ Object

Downloads a file or directory from the remote machine to the local machine.


431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 431

def cmd_download(*args)
  if (args.empty? or args.include? "-h")
    cmd_download_help
    return true
  end

  recursive = false
  src_items = []
  last      = nil
  dest      = nil
  tries     = false
  tries_no  = 0
  opts      = {}

  @@download_opts.parse(args) { |opt, idx, val|
    case opt
    when "-a"
      opts['adaptive'] = true
    when "-b"
      opts['block_size'] = val.to_i
    when "-r"
      recursive = true
      opts['recursive'] = true
    when "-c"
      opts['continue'] = true
    when "-l"
      tries = true
      tries_no = val.to_i
      opts['tries'] = true
      opts['tries_no'] = tries_no
    when "-t"
      opts['timestamp'] = '_' + Time.now.iso8601
    when nil
      src_items << last if (last)
      last = val
    end
  }

  # No files given, nothing to do
  if not last
    cmd_download_help
    return true
  end

  # Source and destination will be the same
  if src_items.empty?
    src_items << last
    # Use the basename of the remote filename so we don't end up with
    # a file named c:\\boot.ini in linux
    dest = ::Rex::Post::Meterpreter::Extensions::Stdapi::Fs::File.basename(last)
  else
    dest = last
  end

  # Download to a directory, not a pattern
  if client.fs.file.is_glob?(dest)
    dest = ::File.dirname(dest)
  end

  # Go through each source item and download them
  src_items.each { |src|
    glob = nil
    if client.fs.file.is_glob?(src)
      glob = ::File.basename(src)
      src = ::File.dirname(src)
    end

    # Use search if possible for recursive pattern matching. It will work
    # more intuitively since it will not try to match on intermediate
    # directories, only file names.
    if glob && recursive && client.commands.include?(COMMAND_ID_STDAPI_FS_SEARCH)

      files = client.fs.file.search(src, glob, recursive)
      if !files.empty?
        print_line("Downloading #{files.length} file#{files.length > 1 ? 's' : ''}...")

        files.each do |file|
          src_separator = client.fs.file.separator
          src_path = file['path'] + client.fs.file.separator + file['name']
          dest_path = ::File.join(dest, ::Rex::FileUtils::clean_path(file['path'].tr(src_separator, ::File::SEPARATOR)))

          client.fs.file.download(dest_path, src_path, opts) do |step, src, dst|
            print_status("#{step.ljust(11)}: #{src} -> #{dst}")
            client.framework.events.on_session_download(client, src, dest) if msf_loaded?
          end
        end

      else
        print_status("No matching files found for download")
      end

    else
      # Perform direct matching
      tries_cnt = 0
      begin
        stat = client.fs.file.stat(src)
      rescue Rex::TimeoutError
        if (tries && (tries_no == 0 || tries_cnt < tries_no))
          tries_cnt += 1
          print_error("Error opening: #{src} - retry (#{tries_cnt})")
          retry
        else
          print_error("Error opening: #{src} - giving up")
          raise
        end
      end

      if (stat.directory?)
        client.fs.dir.download(dest, src, opts, true, glob) do |step, src, dst|
          print_status("#{step.ljust(11)}: #{src} -> #{dst}")
          client.framework.events.on_session_download(client, src, dest) if msf_loaded?
        end
      elsif (stat.file?)
        client.fs.file.download(dest, src, opts) do |step, src, dst|
          print_status("#{step.ljust(11)}: #{src} -> #{dst}")
          client.framework.events.on_session_download(client, src, dest) if msf_loaded?
        end
      end
    end
  }

  true
end

#cmd_download_helpObject


420
421
422
423
424
425
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 420

def cmd_download_help
  print_line("Usage: download [options] src1 src2 src3 ... destination")
  print_line
  print_line("Downloads remote files and directories to the local machine.")
  print_line(@@download_opts.usage)
end

#cmd_edit(*args) ⇒ Object

Downloads a file to a temporary file, spawns and editor, and then uploads the contents to the remote machine after completion.


565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 565

def cmd_edit(*args)
  if args.empty? || args.include?('-h')
    cmd_edit_help
    return true
  end

  # Get a temporary file path
  meterp_temp = Tempfile.new('meterp')
  meterp_temp.binmode
  temp_path = meterp_temp.path

  # Try to download the file, but don't worry if it doesn't exist
  client.fs.file.download_file(temp_path, args[0]) rescue nil

  # Spawn the editor (default to vi)
  editor = Rex::Compat.getenv('EDITOR') || 'vi'

  # If it succeeds, upload it to the remote side.
  if (system("#{editor} #{temp_path}") == true)
    client.fs.file.upload_file(args[0], temp_path)
  end

  # Get rid of that pesky temporary file
  ::File.delete(temp_path) rescue nil
end

#cmd_edit_helpObject


555
556
557
558
559
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 555

def cmd_edit_help
  print_line('Edit a file on remote machine.')
  print_line("Usage: edit file")
  print_line
end

#cmd_lcd(*args) ⇒ Object

Change the local working directory.


295
296
297
298
299
300
301
302
303
304
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 295

def cmd_lcd(*args)
  if (args.length == 0)
    print_line("Usage: lcd directory")
    return true
  end

  ::Dir.chdir(args[0])

  return true
end

#cmd_lcd_tabs(str, words) ⇒ Object Also known as: cmd_lls_tabs

Tab completion for the lcd command


309
310
311
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 309

def cmd_lcd_tabs(str, words)
  tab_complete_directory(str, words)
end

#cmd_lls(*args) ⇒ Object Also known as: cmd_ldir

List local files


836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 836

def cmd_lls(*args)
  # Set Defaults
  path = ::Dir.pwd
  sort = 'Name'
  order = :forward
  search_term = nil

  # Parse the args
  @@lls_opts.parse(args) { |opt, idx, val|
    case opt
    # Sort options
    when '-s'
      sort = 'Size'
    when '-t'
      sort = 'Last modified'
    # Output options
    when '-r'
      order = :reverse
    # Search
    when '-S'
      search_term = val
      if search_term.nil?
        print_error("Enter a search term")
        return true
      else
        search_term = /#{search_term}/nmi
      end
    # Help and path
    when "-h"
      cmd_lls_help
      return 0
    when nil
      path = val
    end
  }

  list_local_path(path, sort, order, search_term)
end

#cmd_lls_helpObject


758
759
760
761
762
763
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 758

def cmd_lls_help
  print_line "Usage: lls [options]"
  print_line
  print_line "Lists contents of a local directory or file info"
  print_line @@lls_opts.usage
end

#cmd_lpwd(*args) ⇒ Object Also known as: cmd_getlwd

Display the local working directory.


596
597
598
599
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 596

def cmd_lpwd(*args)
  print_line(::Dir.pwd)
  return true
end

#cmd_ls(*args) ⇒ Object Also known as: cmd_dir

Lists files


674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 674

def cmd_ls(*args)
  # Set defaults
  path = client.fs.dir.getwd
  search_term = nil
  sort = 'Name'
  short = nil
  order = :forward
  recursive = nil

  # Parse the args
  @@ls_opts.parse(args) { |opt, idx, val|
    case opt
    # Sort options
    when '-s'
      sort = 'Size'
    when '-t'
      sort = 'Last modified'
    # Output options
    when '-x'
      short = true
    when '-l'
      short = nil
    when '-r'
      order = :reverse
    when '-R'
      recursive = true
    # Search
    when '-S'
      search_term = val
      if search_term.nil?
        print_error("Enter a search term")
        return true
      else
        search_term = /#{search_term}/nmi
      end
    # Help and path
    when "-h"
      cmd_ls_help
      return 0
    when nil
      path = val
      path = client.fs.file.expand_path(path) if path =~ PATH_EXPAND_REGEX
    end
  }

  columns = [ 'Mode', 'Size', 'Type', 'Last modified', 'Name' ]
  columns.insert(4, 'Short Name') if short

  stat_path = path

  # Check session capabilities
  is_glob = client.fs.file.is_glob?(path)
  if is_glob
    if !client.commands.include?(COMMAND_ID_STDAPI_FS_SEARCH)
      print_line('File globbing not supported with this session')
      return
    end
    stat_path = ::File.dirname(path)
  end

  stat = client.fs.file.stat(stat_path)
  if stat.directory?
    list_path(path, columns, sort, order, short, recursive, 0, search_term)
  else
    print_line("#{stat.prettymode}  #{stat.size}  #{stat.ftype[0,3]}  #{stat.mtime}  #{path}")
  end

  return true
end

#cmd_ls_helpObject Also known as: cmd_dir_help


604
605
606
607
608
609
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 604

def cmd_ls_help
  print_line "Usage: ls [options] [glob/path]"
  print_line
  print_line "Lists contents of directory or file info, searchable"
  print_line @@ls_opts.usage
end

#cmd_ls_tabs(str, words) ⇒ Object Also known as: cmd_dir_tabs

Tab completion for the ls command


747
748
749
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 747

def cmd_ls_tabs(str, words)
  tab_complete_cdirectory(str, words)
end

#cmd_mkdir(*args) ⇒ Object

Make one or more directory.


885
886
887
888
889
890
891
892
893
894
895
896
897
898
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 885

def cmd_mkdir(*args)
  if (args.length == 0)
    print_line("Usage: mkdir dir1 dir2 dir3 ...")
    return true
  end

  args.each { |dir_path|
    dir_path = client.fs.file.expand_path(dir_path) if dir_path =~ PATH_EXPAND_REGEX
    print_line("Creating directory: #{dir_path}")
    client.fs.dir.mkdir(dir_path)
  }

  return true
end

#cmd_mv(*args) ⇒ Object Also known as: cmd_move, cmd_rename

Move source to destination


367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 367

def cmd_mv(*args)
  if (args.length < 2)
    print_line("Usage: mv oldfile newfile")
    return true
  end
  old_path = args[0]
  old_path = client.fs.file.expand_path(old_path) if old_path =~ PATH_EXPAND_REGEX
  new_path = args[1]
  new_path = client.fs.file.expand_path(new_path) if new_path =~ PATH_EXPAND_REGEX
  client.fs.file.mv(old_path, new_path)
  return true
end

#cmd_pwd(*args) ⇒ Object Also known as: cmd_getwd

Display the working directory.


905
906
907
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 905

def cmd_pwd(*args)
  print_line(client.fs.dir.getwd)
end

#cmd_rm(*args) ⇒ Object Also known as: cmd_del

Delete the specified file(s).


346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 346

def cmd_rm(*args)
  if (args.length == 0)
    print_line("Usage: rm file1 [file2...]")
    return true
  end

  args.each do |file_path|
    file_path = client.fs.file.expand_path(file_path) if file_path =~ PATH_EXPAND_REGEX
    client.fs.file.rm(file_path)
  end

  return true
end

#cmd_rmdir(*args) ⇒ Object

Removes one or more directory if it's empty.


914
915
916
917
918
919
920
921
922
923
924
925
926
927
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 914

def cmd_rmdir(*args)
  if (args.length == 0 or args.include?("-h"))
    print_line("Usage: rmdir dir1 dir2 dir3 ...")
    return true
  end

  args.each { |dir_path|
    dir_path = client.fs.file.expand_path(dir_path) if dir_path =~ PATH_EXPAND_REGEX
    print_line("Removing directory: #{dir_path}")
    client.fs.dir.rmdir(dir_path)
  }

  return true
end

#cmd_search(*args) ⇒ Object

Search for files.


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 140

def cmd_search(*args)

  root    = nil
  recurse = true
  globs   = []
  files   = []

  opts = Rex::Parser::Arguments.new(
    "-h" => [ false, "Help Banner" ],
    "-d" => [ true,  "The directory/drive to begin searching from. Leave empty to search all drives. (Default: #{root})" ],
    "-f" => [ true,  "A file pattern glob to search for. (e.g. *secret*.doc?)" ],
    "-r" => [ true,  "Recursivly search sub directories. (Default: #{recurse})" ]
  )

  opts.parse(args) { | opt, idx, val |
    case opt
      when "-h"
        print_line("Usage: search [-d dir] [-r recurse] -f pattern [-f pattern]...")
        print_line("Search for files.")
        print_line(opts.usage)
        return
      when "-d"
        root = val
      when "-f"
        globs << val
      when "-r"
        recurse = false if val =~ /^(f|n|0)/i
    end
  }

  if globs.empty?
    print_error("You must specify a valid file glob to search for, e.g. >search -f *.doc")
    return
  end

  globs.uniq.each do |glob|
    files += client.fs.file.search(root, glob, recurse)
  end

  if files.empty?
    print_line("No files matching your search were found.")
    return
  end

  print_line("Found #{files.length} result#{ files.length > 1 ? 's' : '' }...")
  files.each do | file |
    if file['size'] > 0
      print("    #{file['path']}#{ file['path'].empty? ? '' : client.fs.file.separator }#{file['name']} (#{file['size']} bytes)\n")
    else
      print("    #{file['path']}#{ file['path'].empty? ? '' : client.fs.file.separator }#{file['name']}\n")
    end
  end

end

#cmd_show_mount(*args) ⇒ Object

Show all the mount points/logical drives (currently geared towards the Windows Meterpreter).


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 199

def cmd_show_mount(*args)
  if args.include?('-h')
    print_line('Usage: show_mount')
    return true
  end

  mounts = client.fs.mount.show_mount

  table = Rex::Text::Table.new(
    'Header'    => 'Mounts / Drives',
    'Indent'    => 0,
    'SortIndex' => 0,
    'Columns'   => [
      'Name', 'Type', 'Size (Total)', 'Size (Free)', 'Mapped to'
    ]
  )

  mounts.each do |d|
    ts = ::Filesize.from("#{d[:total_space]} B").pretty.split(' ')
    fs = ::Filesize.from("#{d[:free_space]} B").pretty.split(' ')
    table << [
      d[:name],
      d[:type],
      "#{ts[0].rjust(6)} #{ts[1].ljust(3)}",
      "#{fs[0].rjust(6)} #{fs[1].ljust(3)}",
      d[:unc]
    ]
  end

  print_line
  print_line(table.to_s)
  print_line
  print_line("Total mounts/drives: #{mounts.length}")
  print_line
end

#cmd_upload(*args) ⇒ Object

Uploads a file or directory to the remote machine from the local machine.


942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 942

def cmd_upload(*args)
  if (args.empty? or args.include?("-h"))
    cmd_upload_help
    return true
  end

  recursive = false
  src_items = []
  last      = nil
  dest      = nil

  @@upload_opts.parse(args) { |opt, idx, val|
    case opt
      when "-r"
        recursive = true
      when nil
        if (last)
          src_items << last
        end

        last = val
    end
  }

  return true if not last

  # Source and destination will be the same
  src_items << last if src_items.empty?

  if args.size == 1
    dest = last.split(/(\/|\\)/).last
  else
    dest = last
  end

  # Go through each source item and upload them
  src_items.each { |src|
    stat = ::File.stat(src)

    if (stat.directory?)
      client.fs.dir.upload(dest, src, recursive) { |step, src, dst|
        print_status("#{step.ljust(11)}: #{src} -> #{dst}")
        client.framework.events.on_session_upload(client, src, dest) if msf_loaded?
      }
    elsif (stat.file?)
      if client.fs.file.exist?(dest) && client.fs.file.stat(dest).directory?
        client.fs.file.upload(dest, src) { |step, src, dst|
          print_status("#{step.ljust(11)}: #{src} -> #{dst}")
          client.framework.events.on_session_upload(client, src, dest) if msf_loaded?
        }
      else
        client.fs.file.upload_file(dest, src) { |step, src, dst|
          print_status("#{step.ljust(11)}: #{src} -> #{dst}")
          client.framework.events.on_session_upload(client, src, dest) if msf_loaded?
        }
      end
    end
  }

  return true
end

#cmd_upload_helpObject


931
932
933
934
935
936
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 931

def cmd_upload_help
  print_line("Usage: upload [options] src1 src2 src3 ... destination")
  print_line
  print_line("Uploads local files and directories to the remote machine.")
  print_line(@@upload_opts.usage)
end

#cmd_upload_tabs(str, words) ⇒ Object


1004
1005
1006
1007
1008
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1004

def cmd_upload_tabs(str, words)
  return [] if words.length > 1

  tab_complete_filenames(str, words)
end

#commandsObject

List of supported commands.


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 74

def commands
  all = {
    'cat'        => 'Read the contents of a file to the screen',
    'cd'         => 'Change directory',
    'checksum'   => 'Retrieve the checksum of a file',
    'del'        => 'Delete the specified file',
    'dir'        => 'List files (alias for ls)',
    'download'   => 'Download a file or directory',
    'edit'       => 'Edit a file',
    'getlwd'     => 'Print local working directory',
    'getwd'      => 'Print working directory',
    'lcd'        => 'Change local working directory',
    'lpwd'       => 'Print local working directory',
    'ls'         => 'List files',
    'lls'        => 'List local files',
    'mkdir'      => 'Make directory',
    'pwd'        => 'Print working directory',
    'rm'         => 'Delete the specified file',
    'mv'         => 'Move source to destination',
    'cp'         => 'Copy source to destination',
    'chmod'      => 'Change the permissions of a file',
    'rmdir'      => 'Remove directory',
    'search'     => 'Search for files',
    'upload'     => 'Upload a file or directory',
    'show_mount' => 'List all mount points/logical drives',
  }

  reqs = {
    'cat'        => [],
    'cd'         => [COMMAND_ID_STDAPI_FS_CHDIR],
    'checksum'   => [COMMAND_ID_STDAPI_FS_MD5, COMMAND_ID_STDAPI_FS_SHA1],
    'del'        => [COMMAND_ID_STDAPI_FS_DELETE_FILE],
    'dir'        => [COMMAND_ID_STDAPI_FS_STAT, COMMAND_ID_STDAPI_FS_LS],
    'download'   => [],
    'edit'       => [],
    'getlwd'     => [],
    'getwd'      => [COMMAND_ID_STDAPI_FS_GETWD],
    'lcd'        => [],
    'lpwd'       => [],
    'ls'         => [COMMAND_ID_STDAPI_FS_STAT, COMMAND_ID_STDAPI_FS_LS],
    'lls'        => [],
    'mkdir'      => [COMMAND_ID_STDAPI_FS_MKDIR],
    'pwd'        => [COMMAND_ID_STDAPI_FS_GETWD],
    'rmdir'      => [COMMAND_ID_STDAPI_FS_DELETE_DIR],
    'rm'         => [COMMAND_ID_STDAPI_FS_DELETE_FILE],
    'mv'         => [COMMAND_ID_STDAPI_FS_FILE_MOVE],
    'cp'         => [COMMAND_ID_STDAPI_FS_FILE_COPY],
    'chmod'      => [COMMAND_ID_STDAPI_FS_CHMOD],
    'search'     => [COMMAND_ID_STDAPI_FS_SEARCH],
    'upload'     => [],
    'show_mount' => [COMMAND_ID_STDAPI_FS_MOUNT_SHOW],
  }

  filter_commands(all, reqs)
end

#list_local_path(path, sort, order, search_term = nil) ⇒ Object

Get list local path information for lls command


768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 768

def list_local_path(path, sort, order, search_term = nil)
  # Single file as path
  if !::File.directory?(path)
    perms = pretty_perms(path)
    stat = ::File.stat(path)
    print_line("#{perms}  #{stat.size}  #{stat.ftype[0,3]}  #{stat.mtime}  #{path}")
    return
  end

  # Enumerate each item...
  # No need to sort as Table will do it for us
  columns = [ 'Mode', 'Size', 'Type', 'Last modified', 'Name' ]
  tbl = Rex::Text::Table.new(
    'Header'  => "Listing Local: #{path}",
    'SortIndex' => columns.index(sort),
    'SortOrder' => order,
    'Columns' => columns)

  items = 0
  files = ::Dir.entries(path)

  files.each do |file|
    file_path = ::File.join(path, file)

    perms = pretty_perms(file_path)
    stat = ::File.stat(file_path)

    row = [
      perms ? perms                : '',
      stat.size ? stat.size.to_s   : '',
      stat.ftype ? stat.ftype[0,3] : '',
      stat.mtime ? stat.mtime      : '',
      file
    ]
    if file != '.' && file != '..'
      if row.join(' ') =~ /#{search_term}/
        tbl << row
        items += 1
      end
    end
  end
  if items > 0
    print_line(tbl.to_s)
  else
    print_line("No entries exist in #{path}")
  end
end

#list_path(path, columns, sort, order, short, recursive = false, depth = 0, search_term = nil) ⇒ Object


611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 611

def list_path(path, columns, sort, order, short, recursive = false, depth = 0, search_term = nil)

  # avoid infinite recursion
  if depth > 100
    return
  end

  tbl = Rex::Text::Table.new(
    'Header'  => "Listing: #{path}",
    'SortIndex' => columns.index(sort),
    'SortOrder' => order,
    'Columns' => columns,
    'SearchTerm' => search_term)

  items = 0

  # Enumerate each item...
  # No need to sort as Table will do it for us
  client.fs.dir.entries_with_info(path).each do |p|

    ffstat = p['StatBuf']
    fname = p['FileName'] || 'unknown'

    row = [
        ffstat ? ffstat.prettymode : '',
        ffstat ? ffstat.size       : '',
        ffstat ? ffstat.ftype[0,3] : '',
        ffstat ? ffstat.mtime      : '',
        fname
      ]
    row.insert(4, p['FileShortName'] || '') if short

    if fname != '.' && fname != '..'
      if row.join(' ') =~ /#{search_term}/
        tbl << row
        items += 1
      end

      if recursive && ffstat && ffstat.directory?
        if client.fs.file.is_glob?(path)
          child_path = ::File.dirname(path) + ::File::SEPARATOR + fname
          child_path += ::File::SEPARATOR + ::File.basename(path)
        else
          child_path = path + ::File::SEPARATOR + fname
        end
        begin
          list_path(child_path, columns, sort, order, short, recursive, depth + 1, search_term)
        rescue RequestError
        end
      end
    end
  end

  if items > 0
    print_line(tbl.to_s)
  else
    print_line("No entries exist in #{path}")
  end
end

#nameObject

Name for this dispatcher.


133
134
135
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 133

def name
  "Stdapi: File system"
end

#pretty_perms(path) ⇒ Object

Code from prettymode in lib/rex/post/file_stat.rb adapted for local file usage


818
819
820
821
822
823
824
825
826
827
828
829
830
831
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 818

def pretty_perms(path)
  m  = ::File.stat(path).mode
  om = '%04o' % m
  perms = ''

  3.times {
    perms = ((m & 01) == 01 ? 'x' : '-') + perms
    perms = ((m & 02) == 02 ? 'w' : '-') + perms
    perms = ((m & 04) == 04 ? 'r' : '-') + perms
    m >>= 3
  }

  return "#{om}/#{perms}"
end

#tab_complete_cdirectory(str, words) ⇒ Object

Provide a generic tab completion for client directory names.


1026
1027
1028
1029
1030
1031
1032
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1026

def tab_complete_cdirectory(str, words)
  if client.commands.include?(COMMAND_ID_STDAPI_FS_LS)
    return client.fs.dir.match(str, true) rescue nil
  end

  []
end

#tab_complete_cfilenames(str, words) ⇒ Object

Provide a generic tab completion for client file names. This tab complete method would create request to the client, so sometimes it wouldn't execute successfully especailly on bad network.


1015
1016
1017
1018
1019
1020
1021
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1015

def tab_complete_cfilenames(str, words)
  if client.commands.include?(COMMAND_ID_STDAPI_FS_LS)
    return client.fs.dir.match(str) rescue nil
  end

  []
end