Class: Msf::Plugin::ThreadTest::ConsoleCommandDispatcher

Inherits:
Object
  • Object
show all
Includes:
Ui::Console::CommandDispatcher
Defined in:
plugins/thread.rb

Overview

This class implements a sample console command dispatcher.

Instance Attribute Summary

Attributes included from Ui::Console::CommandDispatcher

#driver

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

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Ui::Console::CommandDispatcher

#active_module, #active_module=, #active_session, #active_session=, #build_range_array, #docs_dir, #framework, #initialize, #log_error, #remove_lines

Methods included from Rex::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_list_thread(*args) ⇒ Object


70
71
72
73
74
75
# File 'plugins/thread.rb', line 70

def cmd_list_thread(*args)
  Thread.list.each do |t|
    print_line(sprintf("Thread: 0x%.8x (%s/%d) (%s)", t.object_id, t.status, t.priority, t.tsource))
    print_line("")
  end
end

#cmd_start_thread(*args) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'plugins/thread.rb', line 44

def cmd_start_thread(*args)
  if (@mythread)
    print_line("Test thread is already running")
    return
  end

  @mythread = ::Thread.new {
    while(true)
      print_line("--- test thread ---")
      select(nil, nil, nil, 5)
    end
  }
  print_line("Test thread created")
end

#cmd_stop_thread(*args) ⇒ Object


59
60
61
62
63
64
65
66
67
68
# File 'plugins/thread.rb', line 59

def cmd_stop_thread(*args)
  if (! @mythread)
    print_line("No test thread is running")
    return
  end

  @mythread.kill
  @mythread = nil
  print_line("Test thread stopped")
end

#commandsObject

Returns the hash of commands supported by this dispatcher.


36
37
38
39
40
41
42
# File 'plugins/thread.rb', line 36

def commands
  {
    "start_thread" => "Start a background thread that writes to the console",
    "stop_thread" => "Stop a background thread",
    "list_thread" => "List running threads"
  }
end

#nameObject

The dispatcher's name.


29
30
31
# File 'plugins/thread.rb', line 29

def name
  "ThreadTest"
end