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_CONFIG_UPDATE_TOKEN, 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_SEARCH, 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_SET_TERM_SIZE, 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_PTY, 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_SEARCH_MATCH_ADDR, Extensions::Stdapi::TLV_TYPE_MEMORY_SEARCH_MATCH_LEN, Extensions::Stdapi::TLV_TYPE_MEMORY_SEARCH_MATCH_STR, Extensions::Stdapi::TLV_TYPE_MEMORY_SEARCH_NEEDLE, Extensions::Stdapi::TLV_TYPE_MEMORY_SEARCH_RESULTS, Extensions::Stdapi::TLV_TYPE_MEMORY_SEARCH_SECT_LEN, Extensions::Stdapi::TLV_TYPE_MEMORY_SEARCH_START_ADDR, 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_MTIME, Extensions::Stdapi::TLV_TYPE_SEARCH_M_END_DATE, Extensions::Stdapi::TLV_TYPE_SEARCH_M_START_DATE, 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_TERMINAL_COLUMNS, Extensions::Stdapi::TLV_TYPE_TERMINAL_ROWS, 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, #unknown_command

Methods included from Msf::Ui::Console::CommandDispatcher::Session

#cmd_background, #cmd_background_help, #cmd_exit, #cmd_irb, #cmd_irb_help, #cmd_irb_tabs, #cmd_pry, #cmd_pry_help, #cmd_resource, #cmd_resource_help, #cmd_resource_tabs, #cmd_sessions, #cmd_sessions_help

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, included, #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, #unknown_command, #update_prompt

Instance Method Details

#cmd_cat(*args) ⇒ Object

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



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 279

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

  path = args[0]
  path = client.fs.file.expand_path(path) if path =~ path_expand_regex


  if (client.fs.file.stat(path).directory?)
    print_error("#{path} is a directory")
  else
    fd = client.fs.file.new(path, "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_download_tabs, cmd_cp_tabs, cmd_chmod_tabs, cmd_edit_tabs

Tab completion for the cat command



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

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

#cmd_cd(*args) ⇒ Object

Change the working directory.



353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 353

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]))
  else
    client.fs.dir.chdir(args[0])
  end

  return true
end

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

Tab completion for the cd command



370
371
372
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 370

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

#cmd_checksum(*args) ⇒ Object

Retrieve the checksum of a file



419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 419

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|
    filepath = client.fs.file.expand_path(filepath) if filepath =~ path_expand_regex
    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



436
437
438
439
440
441
442
443
444
445
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 436

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



514
515
516
517
518
519
520
521
522
523
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 514

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



494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 494

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.



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
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
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 536

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

  # Expand the destination file path
  dest = ::File.expand_path(dest)

  # Go through each source item and download them
  src_items.each { |src|

    src = client.fs.file.expand_path(src) if src =~ path_expand_regex
    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



525
526
527
528
529
530
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 525

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.



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
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 675

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

  client_path = args[0]
  client_path = client.fs.file.expand_path(client_path) if client_path =~ path_expand_regex

  # Try to download the file, but don't worry if it doesn't exist
  client.fs.file.download_file(temp_path, client_path) 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(client_path, temp_path)
  end

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

#cmd_edit_helpObject



665
666
667
668
669
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 665

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

#cmd_lcat(*args) ⇒ Object

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



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 316

def cmd_lcat(*args)
  if (args.length == 0 || args.include?('-h') || args.include?('--help'))
    print_line("Usage: lcat file")
    return true
  end

  path = args[0]
  path = ::File.expand_path(path) if path =~ path_expand_regex


  if (::File.stat(path).directory?)
    print_error("#{path} is a directory")
  else
    fd = ::File.new(path, "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_lcat_tabs(str, words) ⇒ Object

Tab completion for the lcat command



346
347
348
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 346

def cmd_lcat_tabs(str, words)
  tab_complete_filenames(str, words)
end

#cmd_lcd(*args) ⇒ Object

Change the local working directory.



377
378
379
380
381
382
383
384
385
386
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 377

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



391
392
393
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 391

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

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

List local files



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
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 943

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



865
866
867
868
869
870
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 865

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_lmkdir(*args) ⇒ Object

Create new directory on local machine



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 398

def cmd_lmkdir(*args)
  if (args.length == 0)
    print_line("Usage: lmkdir </path/to/directory>")
    return
  end

  args.each do |path|
    begin
      ::FileUtils.mkdir_p(path)
      print_line("Directory '#{path}' created successfully.")
    rescue ::StandardError => e
      print_error("Error creating #{path} directory: #{e}")
    end
  end

 
end

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

Display the local working directory.



709
710
711
712
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 709

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

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

Lists files



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
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 787

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



717
718
719
720
721
722
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 717

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_mkdir(*args) ⇒ Object

Make one or more directory.



992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 992

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



471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 471

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.



1012
1013
1014
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1012

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).



450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 450

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.



1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1021

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.



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
194
195
196
197
198
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
234
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 158

def cmd_search(*args)

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

  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,  "Recursively search sub directories. (Default: #{recurse})" ],
    "-a" => [ true,  "Find files modified after timestamp (UTC).  Format: YYYY-mm-dd or YYYY-mm-ddTHH:MM:SS"],
    "-b" => [ true,  "Find files modified before timestamp (UTC). Format: YYYY-mm-dd or YYYY-mm-ddTHH:MM:SS"]
  )

  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
        root = client.fs.file.expand_path(root) if root =~ path_expand_regex
      when "-f"
        globs << val
      when "-r"
        recurse = false if val =~ /^(f|n|0)/i
      when "-a"
        modified_start_date = vali_date(val)
        return unless modified_start_date
      when "-b"
        modified_end_date = vali_date(val)
        return unless modified_end_date
    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, -1, modified_start_date, modified_end_date)
  end

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

  header = "Found #{files.length} result#{ files.length > 1 ? 's' : '' }..."
  results_table = Rex::Text::Table.new(
      'WordWrap'   => false,
      'Width'      => 120,
      'Header'     => header,
      'Indent'     => 0,
      'SortIndex'  => 0,
      'Columns'    => ['Path', 'Size (bytes)', 'Modified (UTC)'],
  )

  files.each do | file |
    filestr = ''
    unless file['path'].empty?
      filestr += "#{file['path']}#{client.fs.file.separator}"
    end
    filestr += file['name']
    datestr = ''
    datestr = Time.at(file['mtime']).to_s if file['mtime']
    results_table << [filestr, file['size'], datestr]
  end
  print_line results_table.to_s
end

#cmd_show_mount(*args) ⇒ Object

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



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 240

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.



1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1049

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 = client.fs.file.basename(last)
  else
    dest = last
  end

  dest = client.fs.file.expand_path(dest) if dest =~ path_expand_regex

  # Go through each source item and upload them
  src_items.each { |src|
    src = ::File.expand_path(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



1038
1039
1040
1041
1042
1043
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1038

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



1114
1115
1116
1117
1118
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1114

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

  tab_complete_filenames(str, words)
end

#commandsObject

List of supported commands.



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
129
130
131
132
133
134
135
136
137
138
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 80

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',
    'lcat'       => 'Read the contents of a local file to the screen',
    'lcd'        => 'Change local working directory',
    'lmkdir'     => 'Create new directory on local machine',
    '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],
    'lcat'       => [],
    'lcd'        => [],
    'lmkdir'     => [],
    '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



875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 875

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



724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 724

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}".force_encoding('UTF-8'),
    '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.force_encoding('UTF-8')
      ]
    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.



143
144
145
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 143

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



925
926
927
928
929
930
931
932
933
934
935
936
937
938
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 925

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.



1132
1133
1134
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1132

def tab_complete_cdirectory(str, words)
  tab_complete_path(str, words, true)
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.



1125
1126
1127
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1125

def tab_complete_cfilenames(str, words)
  tab_complete_path(str, words, false)
end

#tab_complete_path(str, words, dir_only) ⇒ Object



1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1136

def tab_complete_path(str, words, dir_only)
  if client.platform == 'windows'
      ::Readline.completion_case_fold = true
  end
  if client.commands.include?(COMMAND_ID_STDAPI_FS_LS)
    expanded = str
    expanded = client.fs.file.expand_path(expanded) if expanded =~ path_expand_regex
    results = client.fs.dir.match(expanded, dir_only) rescue []
    results = unexpand_path_for_suggestions(str, expanded, results)
    if results.length == 1 && results[0] != str && results[0].end_with?(client.fs.file.separator)
      # If Readline receives a single value from this function, it will assume we're done with the tab
      # completing, and add an extra space at the end.
      # This is annoying if we're recursively tab-traversing our way through subdirectories -
      # we may want to continue traversing, but MSF will add a space, requiring us to back up to continue
      # tab-completing our way through successive subdirectories.
      ::Readline.completion_append_character = nil
    end
    results
  else
    []
  end
end

#unexpand_path_for_suggestions(original_path, expanded_path, suggestions) ⇒ Object

After a path expansion followed by a tab completion suggestion set, unexpand the path back so that Readline is happy



1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 1163

def unexpand_path_for_suggestions(original_path, expanded_path, suggestions)
  if original_path == expanded_path
    suggestions
  else
    result = []
    suggestions.each do |suggestion|
      addition = suggestion[expanded_path.length..-1]
      result.append("#{original_path}#{addition}")
    end
    result
  end
end

#vali_date(str) ⇒ Object



147
148
149
150
151
152
153
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb', line 147

def vali_date(str)
  result = DateTime.parse(str)
  return result.to_time.to_i
rescue
  print_error("Bad date/time specification (#{str}). Use this format: \"YYYY-mm-dd\" or \"YYYY-mm-ddTHH:MM:SS\", e.g \"1970-01-01\"")
  nil
end