Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/plugins/thread.rb
Views: 11705
module Msf1class Plugin::ThreadTest < Msf::Plugin2class ConsoleCommandDispatcher3include Msf::Ui::Console::CommandDispatcher45def name6'ThreadTest'7end89def commands10{11'start_thread' => 'Start a background thread that writes to the console',12'stop_thread' => 'Stop a background thread',13'list_thread' => 'List running threads'14}15end1617def cmd_start_thread(*_args)18if @mythread19print_line('Test thread is already running')20return21end2223@mythread = ::Thread.new do24loop do25print_line('--- test thread ---')26select(nil, nil, nil, 5)27end28end29print_line('Test thread created')30end3132def cmd_stop_thread(*_args)33if !@mythread34print_line('No test thread is running')35return36end3738@mythread.kill39@mythread = nil40print_line('Test thread stopped')41end4243def cmd_list_thread(*_args)44Thread.list.each do |t|45print_line(format('Thread: 0x%.8x (%s/%d) (%s)', t.object_id, t.status, t.priority, t.tsource))46print_line('')47end48end49end5051#52# The constructor is called when an instance of the plugin is created. The53# framework instance that the plugin is being associated with is passed in54# the framework parameter. Plugins should call the parent constructor when55# inheriting from Msf::Plugin to ensure that the framework attribute on56# their instance gets set.57#58def initialize(framework, opts)59super6061# If this plugin is being loaded in the context of a console application62# that uses the framework's console user interface driver, register63# console dispatcher commands.64add_console_dispatcher(ConsoleCommandDispatcher)6566# Extend the thread to track the calling source67Thread.class_eval("68attr_accessor :tsource6970alias initialize_old initialize7172def initialize(&block)73self.tsource = caller(1)74initialize_old(&block)75end76", __FILE__, __LINE__ - 9)7778print_status('ThreadTest plugin loaded.')79end8081#82# The cleanup routine for plugins gives them a chance to undo any actions83# they may have done to the framework. For instance, if a console84# dispatcher was added, then it should be removed in the cleanup routine.85#86def cleanup87# If we had previously registered a console dispatcher with the console,88# deregister it now.89remove_console_dispatcher('ThreadTest')90end9192#93# This method returns a short, friendly name for the plugin.94#95def name96'threadtest'97end9899#100# This method returns a brief description of the plugin. It should be no101# more than 60 characters, but there are no hard limits.102#103def desc104'Internal test tool for testing thread usage in Metasploit'105end106107end108end109110111