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/lib/msf/base/serializer/readable_text.rb
Views: 11784
# -*- coding: binary -*-123module Msf4module Serializer56# This class formats information in a plain-text format that7# is meant to be displayed on a console or some other non-GUI8# medium.9class ReadableText1011#Default number of characters to wrap at.12DefaultColumnWrap = 7013#Default number of characters to indent.14DefaultIndent = 21516# Returns a formatted string that contains information about17# the supplied module instance.18#19# @param mod [Msf::Module] the module to dump information for.20# @param indent [String] the indentation to use.21# @return [String] formatted text output of the dump.22def self.dump_module(mod, indent = " ")23case mod.type24when Msf::MODULE_PAYLOAD25return dump_payload_module(mod, indent)26when Msf::MODULE_NOP27return dump_basic_module(mod, indent)28when Msf::MODULE_ENCODER29return dump_basic_module(mod, indent)30when Msf::MODULE_EXPLOIT31return dump_exploit_module(mod, indent)32when Msf::MODULE_AUX33return dump_auxiliary_module(mod, indent)34when Msf::MODULE_POST35return dump_post_module(mod, indent)36when Msf::MODULE_EVASION37return dump_evasion_module(mod, indent)38else39return dump_generic_module(mod, indent)40end41end4243# Dumps an exploit's targets.44#45# @param mod [Msf::Exploit] the exploit module to dump targets46# for.47# @param indent [String] the indentation to use (only the length48# matters).49# @param h [String] the string to display as the table heading.50# @return [String] the string form of the table.51def self.dump_exploit_targets(mod, indent = '', h = nil)52tbl = Rex::Text::Table.new(53'Indent' => indent.length,54'Header' => h,55'Columns' =>56[57'IsTarget',58'Id',59'Name',60],61'SortIndex' => 1,62'ColProps' => {63'IsTarget' => {64'Stylers' => [Msf::Ui::Console::TablePrint::RowIndicatorStyler.new],65'ColumnStylers' => [Msf::Ui::Console::TablePrint::OmitColumnHeader.new],66'Width' => 267}68}69)7071mod.targets.each_with_index do |target, idx|72is_target = mod.target == target7374tbl << [is_target, idx.to_s, target.name || 'All' ]75end7677tbl.to_s + "\n"78end7980def self.dump_evasion_targets(mod, indent = '', h = nil)81tbl = Rex::Text::Table.new(82'Indent' => indent.length,83'Header' => h,84'Columns' =>85[86'IsTarget',87'Id',88'Name',89],90'SortIndex' => 1,91'ColProps' => {92'IsTarget' => {93'Stylers' => [Msf::Ui::Console::TablePrint::RowIndicatorStyler.new],94'ColumnStylers' => [Msf::Ui::Console::TablePrint::OmitColumnHeader.new],95'Width' => 296}97}98)99100mod.targets.each_with_index do |target, idx|101is_target = mod.target == target102103tbl << [is_target, idx.to_s, target.name || 'All' ]104end105106tbl.to_s + "\n"107end108109# Dumps the exploit's selected target110#111# @param mod [Msf::Exploit] the exploit module.112# @param indent [String] the indentation to use (only the length113# matters)114# @param h [String] the string to display as the table heading.115# @return [String] the string form of the table.116def self.dump_exploit_target(mod, indent = '', h = nil)117tbl = Rex::Text::Table.new(118'Indent' => indent.length,119'Header' => h,120'Columns' =>121[122'Id',123'Name',124])125126tbl << [ mod.target_index, mod.target.name || 'All' ]127128tbl.to_s + "\n"129end130131# Dumps the evasion module's selected target132#133# @param mod [Msf::Evasion] The evasion module.134# @param indent [String] The indentation to use (only the length matters)135# @param h [String] The string to display as the table heading.136# @return [String] The strong form of the table.137def self.dump_evasion_target(mod, indent = '', h = nil)138tbl = Rex::Text::Table.new(139'Indent' => indent.length,140'Header' => h,141'Columns' =>142[143'Id',144'Name',145])146147tbl << [ mod.target_index, mod.target.name || 'All' ]148149tbl.to_s + "\n"150end151152# Dumps a module's actions153#154# @param mod [Msf::Module] the module.155# @param indent [String] the indentation to use (only the length156# matters)157# @param h [String] the string to display as the table heading.158# @return [String] the string form of the table.159def self.dump_module_actions(mod, indent = '', h = nil)160tbl = Rex::Text::Table.new(161'Indent' => indent.length,162'Header' => h,163'Columns' =>164[165'ActionEnabled',166'Name',167'Description'168],169'SortIndex' => 1,170'ColProps' => {171'ActionEnabled' => {172'Stylers' => [Msf::Ui::Console::TablePrint::RowIndicatorStyler.new],173'ColumnStylers' => [Msf::Ui::Console::TablePrint::OmitColumnHeader.new],174'Width' => 2175}176}177)178179mod.actions.each_with_index { |target, idx|180action_enabled = mod.action == target181182tbl << [ action_enabled, target.name || 'All' , target.description || '' ]183}184185tbl.to_s + "\n"186end187188# Dumps the module's selected action189#190# @param mod [Msf::Module] the module.191# @param indent [String] the indentation to use (only the length192# matters)193# @param h [String] the string to display as the table heading.194# @return [String] the string form of the table.195def self.dump_module_action(mod, indent = '', h = nil)196tbl = Rex::Text::Table.new(197'Indent' => indent.length,198'Header' => h,199'Columns' =>200[201'Name',202'Description',203])204205tbl << [ mod.action.name || 'All', mod.action.description || '' ]206207tbl.to_s + "\n"208end209210# Dumps the table of payloads that are compatible with the supplied211# exploit.212#213# @param exploit [Msf::Exploit] the exploit module.214# @param indent [String] the indentation to use (only the length215# matters)216# @param h [String] the string to display as the table heading.217# @return [String] the string form of the table.218def self.dump_compatible_payloads(exploit, indent = '', h = nil)219tbl = Rex::Text::Table.new(220'Indent' => indent.length,221'Header' => h,222'Columns' =>223[224'Name',225'Description',226])227228exploit.compatible_payloads.each { |entry|229tbl << [ entry[0], entry[1].new.description ]230}231232tbl.to_s + "\n"233end234235def self.dump_traits(mod, indent=' ')236output = ''237238unless mod.side_effects.empty?239output << "Module side effects:\n"240mod.side_effects.each { |side_effect|241output << indent + side_effect + "\n"242}243output << "\n"244end245246unless mod.stability.empty?247output << "Module stability:\n"248mod.stability.each { |stability|249output << indent + stability + "\n"250}251output << "\n"252end253254unless mod.reliability.empty?255output << "Module reliability:\n"256mod.reliability.each { |reliability|257output << indent + reliability + "\n"258}259output << "\n"260end261262output263end264265# Dumps information about an exploit module.266#267# @param mod [Msf::Exploit] the exploit module.268# @param indent [String] the indentation to use.269# @return [String] the string form of the information.270def self.dump_exploit_module(mod, indent = '')271output = "\n"272output << " Name: #{mod.name}\n"273output << " Module: #{mod.fullname}\n"274output << " Platform: #{mod.platform_to_s}\n"275output << " Arch: #{mod.arch_to_s}\n"276output << " Privileged: " + (mod.privileged? ? "Yes" : "No") + "\n"277output << " License: #{mod.license}\n"278output << " Rank: #{mod.rank_to_s.capitalize}\n"279output << " Disclosed: #{mod.disclosure_date}\n" if mod.disclosure_date280output << "\n"281282# Authors283output << "Provided by:\n"284mod.each_author { |author|285output << indent + author.to_s + "\n"286}287output << "\n"288289output << dump_traits(mod)290291# Targets292output << "Available targets:\n"293output << dump_exploit_targets(mod, indent)294295# Check296output << "Check supported:\n"297output << "#{indent}#{mod.has_check? ? 'Yes' : 'No'}\n\n"298299# Options300if (mod.options.has_options?)301output << "Basic options:\n"302output << dump_options(mod, indent)303output << "\n"304end305306# Payload information307if (mod.payload_info.length)308output << "Payload information:\n"309if (mod.payload_space)310output << indent + "Space: " + mod.payload_space.to_s + "\n"311end312if (mod.payload_badchars)313output << indent + "Avoid: " + mod.payload_badchars.length.to_s + " characters\n"314end315output << "\n"316end317318# Description319output << dump_description(mod, indent)320321# References322output << dump_references(mod, indent)323324# Notes325output << dump_notes(mod, indent)326327return output328329end330331# Dumps information about an auxiliary module.332#333# @param mod [Msf::Auxiliary] the auxiliary module.334# @param indent [String] the indentation to use.335# @return [String] the string form of the information.336def self.dump_auxiliary_module(mod, indent = '')337output = "\n"338output << " Name: #{mod.name}\n"339output << " Module: #{mod.fullname}\n"340output << " License: #{mod.license}\n"341output << " Rank: #{mod.rank_to_s.capitalize}\n"342output << " Disclosed: #{mod.disclosure_date}\n" if mod.disclosure_date343output << "\n"344345# Authors346output << "Provided by:\n"347mod.each_author { |author|348output << indent + author.to_s + "\n"349}350output << "\n"351352output << dump_traits(mod)353354# Actions355if mod.actions.any?356output << "Available actions:\n"357output << dump_module_actions(mod)358end359360# Check361has_check = mod.has_check?362output << "Check supported:\n"363output << "#{indent}#{has_check ? 'Yes' : 'No'}\n\n"364365# Options366if (mod.options.has_options?)367output << "Basic options:\n"368output << dump_options(mod, indent)369output << "\n"370end371372# Description373output << dump_description(mod, indent)374375# References376output << dump_references(mod, indent)377378# Notes379output << dump_notes(mod, indent)380381return output382end383384# Dumps information about a post module.385#386# @param mod [Msf::Post] the post module.387# @param indent [String] the indentation to use.388# @return [String] the string form of the information.389def self.dump_post_module(mod, indent = '')390output = "\n"391output << " Name: #{mod.name}\n"392output << " Module: #{mod.fullname}\n"393output << " Platform: #{mod.platform_to_s}\n"394output << " Arch: #{mod.arch_to_s}\n"395output << " Rank: #{mod.rank_to_s.capitalize}\n"396output << " Disclosed: #{mod.disclosure_date}\n" if mod.disclosure_date397output << "\n"398399# Authors400output << "Provided by:\n"401mod.each_author.each do |author|402output << indent + author.to_s + "\n"403end404output << "\n"405406output << dump_traits(mod)407408# Compatible session types409if mod.session_types410output << "Compatible session types:\n"411mod.session_types.sort.each do |type|412output << indent + type.capitalize + "\n"413end414output << "\n"415end416417# Actions418if mod.actions.any?419output << "Available actions:\n"420output << dump_module_actions(mod)421end422423# Options424if (mod.options.has_options?)425output << "Basic options:\n"426output << dump_options(mod, indent)427output << "\n"428end429430# Description431output << dump_description(mod, indent)432433# References434output << dump_references(mod, indent)435436# Notes437output << dump_notes(mod, indent)438439return output440end441442# Dumps information about an evasion module.443#444# @param mod [Msf::Evasion] The evasion module instance.445# @param indent [String] The indentation to use.446# @return [String] The string form of the information447def self.dump_evasion_module(mod, indent = '')448output = "\n"449output << " Name: #{mod.name}\n"450output << " Module: #{mod.fullname}\n"451output << " Platform: #{mod.platform_to_s}\n"452output << " Arch: #{mod.arch_to_s}\n"453output << " Privileged: " + (mod.privileged? ? "Yes" : "No") + "\n"454output << " License: #{mod.license}\n"455output << " Rank: #{mod.rank_to_s.capitalize}\n"456output << " Disclosed: #{mod.disclosure_date}\n" if mod.disclosure_date457output << "\n"458459# Authors460output << "Provided by:\n"461mod.each_author { |author|462output << indent + author.to_s + "\n"463}464output << "\n"465466# Check467output << "Check supported:\n"468output << "#{indent}#{mod.has_check? ? 'Yes' : 'No'}\n\n"469470# Options471if (mod.options.has_options?)472output << "Basic options:\n"473output << dump_options(mod, indent)474output << "\n"475end476477# Description478output << dump_description(mod, indent)479480# References481output << dump_references(mod, indent)482483return output484end485486# Dumps information about a payload module.487#488# @param mod [Msf::Payload] the payload module.489# @param indent [String] the indentation to use.490# @return [String] the string form of the information.491def self.dump_payload_module(mod, indent = '')492# General493output = "\n"494output << " Name: #{mod.name}\n"495output << " Module: #{mod.fullname}\n"496output << " Platform: #{mod.platform_to_s}\n"497output << " Arch: #{mod.arch_to_s}\n"498output << "Needs Admin: " + (mod.privileged? ? "Yes" : "No") + "\n"499output << " Total size: #{mod.size}\n"500output << " Rank: #{mod.rank_to_s.capitalize}\n"501output << "\n"502503# Authors504output << "Provided by:\n"505mod.each_author { |author|506output << indent + author.to_s + "\n"507}508output << "\n"509510# Options511if (mod.options.has_options?)512output << "Basic options:\n"513output << dump_options(mod)514output << "\n"515end516517# Description518output << dump_description(mod, indent)519output << "\n"520521return output522end523524# Dumps information about a module, just the basics.525#526# @param mod [Msf::Module] the module.527# @param indent [String] the indentation to use.528# @return [String] the string form of the information.529def self.dump_basic_module(mod, indent = '')530# General531output = "\n"532output << " Name: #{mod.name}\n"533output << " Module: #{mod.fullname}\n"534output << " Platform: #{mod.platform_to_s}\n"535output << " Arch: #{mod.arch_to_s}\n"536output << " Rank: #{mod.rank_to_s.capitalize}\n"537output << "\n"538539# Authors540output << "Provided by:\n"541mod.each_author { |author|542output << indent + author.to_s + "\n"543}544output << "\n"545546output << dump_traits(mod)547548# Description549output << dump_description(mod, indent)550551output << dump_references(mod, indent)552553output << "\n"554555return output556557end558559#No current use560def self.dump_generic_module(mod, indent = '')561end562563# Dumps the list of options associated with the564# supplied module.565#566# @param mod [Msf::Module] the module.567# @param indent [String] the indentation to use.568# @param missing [Boolean] dump only empty required options.569# @return [String] the string form of the information.570def self.dump_options(mod, indent = '', missing = false, advanced: false, evasion: false)571filtered_options = mod.options.select { |_name, opt| opt.advanced? == advanced && opt.evasion? == evasion }572573option_groups = mod.options.groups.values.select { |group| group.option_names.any? { |name| filtered_options.keys.include?(name) } }574options_by_group = option_groups.map do |group|575[group, group.option_names.map { |name| filtered_options[name] }.compact]576end.to_h577grouped_option_names = option_groups.flat_map(&:option_names)578remaining_options = filtered_options.reject { |_name, option| grouped_option_names.include?(option.name) }579options_grouped_by_conditions = remaining_options.values.group_by(&:conditions)580581option_tables = []582583options_grouped_by_conditions.sort.each do |conditions, options|584tbl = options_table(missing, mod, options, indent)585586next if tbl.rows.empty?587588if conditions.any?589option_tables << "#{indent}When #{Msf::OptCondition.format_conditions(mod, options.first)}:\n\n#{tbl}"590else591option_tables << tbl.to_s592end593end594595options_by_group.each do |group, options|596tbl = options_table(missing, mod, options, indent)597option_tables << "#{indent}#{group.description}:\n\n#{tbl}"598end599600result = option_tables.join("\n\n")601result602end603604# Creates the table for the given module options605#606# @param missing [Boolean] dump only empty required options.607# @param mod [Msf::Module] the module.608# @param options [Array<Msf::OptBase>] The options to be added to the table609# @param indent [String] the indentation to use.610#611# @return [String] the string form of the table.612def self.options_table(missing, mod, options, indent)613tbl = Rex::Text::Table.new(614'Indent' => indent.length,615'Columns' =>616[617'Name',618'Current Setting',619'Required',620'Description'621]622)623options.sort_by(&:name).each do |opt|624name = opt.name625if mod.datastore.is_a?(Msf::DataStoreWithFallbacks)626val = mod.datastore[name]627else628val = mod.datastore[name].nil? ? opt.default : mod.datastore[name]629end630next if (missing && opt.valid?(val))631632desc = opt.desc.dup633634# Hint at RPORT proto by regexing mixins635if name == 'RPORT' && opt.kind_of?(Msf::OptPort)636mod.class.included_modules.each do |m|637case m.name638when /tcp/i, /HttpClient$/639desc << ' (TCP)'640break641when /udp/i642desc << ' (UDP)'643break644end645end646end647648tbl << [name, opt.display_value(val), opt.required? ? "yes" : "no", desc]649end650tbl651end652653# Dumps the advanced options associated with the supplied module.654#655# @param mod [Msf::Module] the module.656# @param indent [String] the indentation to use.657# @return [String] the string form of the information.658def self.dump_advanced_options(mod, indent = '')659return dump_options(mod, indent, advanced: true)660end661662# Dumps the evasion options associated with the supplied module.663#664# @param mod [Msf::Module] the module.665# @param indent [String] the indentation to use.666# @return [String] the string form of the information.667def self.dump_evasion_options(mod, indent = '')668return dump_options(mod, indent, evasion: true)669end670671# Dumps the references associated with the supplied module.672#673# @param mod [Msf::Module] the module.674# @param indent [String] the indentation to use.675# @return [String] the string form of the information.676def self.dump_references(mod, indent = '')677output = ''678679if (mod.respond_to?(:references) && mod.references && mod.references.length > 0)680output << "References:\n"681682mod.references.each do |ref|683case ref.ctx_id684when 'LOGO', 'SOUNDTRACK'685output << indent + ref.to_s + "\n"686Rex::Compat.open_browser(ref.ctx_val) if Rex::Compat.getenv('FUEL_THE_HYPE_MACHINE')687else688output << indent + ref.to_s + "\n"689end690end691692output << "\n"693end694695output696end697698# Dumps the notes associated with the supplied module.699#700# @param mod [Msf::Module] the module.701# @param indent [String] the indentation to use.702# @return [String] the string form of the information.703def self.dump_notes(mod, indent = '')704output = ''705706mod.notes.each do |name, val|707next unless val.present?708709case name710when 'AKA'711output << "Also known as:\n"712val.each { |aka| output << "#{indent}#{aka}\n" }713when 'NOCVE'714output << "CVE not available for the following reason:\n" \715"#{indent}#{val}\n"716when 'RelatedModules'717output << "Related modules:\n"718val.each { |related| output << "#{indent}#{related}\n" }719when 'Stability', 'SideEffects', 'Reliability'720# Handled by dump_traits721next722else723output << "#{name}:\n"724725case val726when Array727val.each { |v| output << "#{indent}#{v}\n" }728when Hash729val.each { |k, v| output << "#{indent}#{k}: #{v}\n" }730else731# Display the raw note732output << "#{indent}#{val}\n"733end734end735736output << "\n"737end738739output740end741742# Dumps the contents of a datastore.743#744# @param name [String] displayed as the table header.745# @param ds [Msf::DataStore] the DataStore to dump.746# @param indent [Integer] the indentation size.747# @param col [Integer] the column width.748# @return [String] the formatted DataStore contents.749def self.dump_datastore(name, ds, indent = DefaultIndent, col = DefaultColumnWrap)750tbl = Rex::Text::Table.new(751'Indent' => indent,752'Header' => name,753'Columns' =>754[755'Name',756'Value'757])758759ds.keys.sort.each { |k|760tbl << [ k, (ds[k] != nil) ? ds[k].to_s : '' ]761}762763return ds.length > 0 ? tbl.to_s : "#{tbl.header_to_s}No entries in data store.\n"764end765766# Dumps the list of sessions.767#768# @param framework [Msf::Framework] the framework to dump.769# @param opts [Hash] the options to dump with.770# @option opts :verbose [Boolean] gives more information if set to771# true.772# @option opts :indent [Integer] set the indentation amount.773# @return [String] the formatted list of sessions.774def self.dump_sessions(framework, opts={})775output = ""776verbose = opts[:verbose] || false777sessions = opts[:sessions] || framework.sessions778show_active = opts[:show_active] || false779show_inactive = opts[:show_inactive] || false780# if show_active and show_inactive are false the caller didn't781# specify either flag; default to displaying active sessions782show_active = true if !(show_active || show_inactive)783show_extended = opts[:show_extended] || false784indent = opts[:indent] || DefaultIndent785786return dump_sessions_verbose(framework, opts) if verbose787788if show_active789columns = []790columns << 'Id'791columns << 'Name'792columns << 'Type'793columns << 'Checkin?' if show_extended794columns << 'Enc?' if show_extended795columns << 'Local URI' if show_extended796columns << 'Information'797columns << 'Connection'798799tbl = Rex::Text::Table.new(800'Header' => "Active sessions",801'Columns' => columns,802'Indent' => indent)803804sessions.each do |session_id, session|805row = create_msf_session_row(session, show_extended)806tbl << row807end808809output << (tbl.rows.count > 0 ? tbl.to_s : "#{tbl.header_to_s}No active sessions.\n")810end811812if show_inactive813output << "\n" if show_active814815columns = []816columns << 'Closed'817columns << 'Opened'818columns << 'Reason Closed'819columns << 'Type'820columns << 'Address'821822tbl = Rex::Text::Table.new(823'Header' => "Inactive sessions",824'Columns' => columns,825'Indent' => indent,826'SortIndex' => 1)827828if framework.db.active829framework.db.sessions.each do |session|830unless session.closed_at.nil?831row = create_mdm_session_row(session, show_extended)832tbl << row833end834end835end836837output << (tbl.rows.count > 0 ? tbl.to_s : "#{tbl.header_to_s}No inactive sessions.\n")838end839840# return formatted listing of sessions841output842end843844# Creates a table row that represents the specified session.845#846# @param session [Msf::Session] session used to create a table row.847# @param show_extended [Boolean] Indicates if extended information will be included in the row.848# @return [Array] table row of session data.849def self.create_msf_session_row(session, show_extended)850row = []851row << session.sid.to_s852row << session.sname.to_s853row << session.type.to_s854if session.respond_to?(:session_type)855row[-1] << " #{session.session_type}"856elsif session.respond_to?(:platform)857row[-1] << " #{session.platform}"858end859860if show_extended861if session.respond_to?(:last_checkin) && session.last_checkin862row << "#{(Time.now.to_i - session.last_checkin.to_i)}s ago"863else864row << '?'865end866867if session.respond_to?(:tlv_enc_key) && session.tlv_enc_key && session.tlv_enc_key[:key]868row << 'Y'869else870row << 'N'871end872873if session.exploit_datastore && session.exploit_datastore.has_key?('LURI') && !session.exploit_datastore['LURI'].empty?874row << "(#{session.exploit_datastore['LURI']})"875else876row << '?'877end878end879880sinfo = session.info.to_s881sinfo = sinfo.gsub(/[\r\n\t]+/, ' ')882# Arbitrarily cut info at 80 columns883if sinfo.length > 80884sinfo = "#{sinfo[0,77]}..."885end886row << sinfo887888row << "#{session.tunnel_to_s} (#{session.session_host})"889890# return complete row891row892end893894# Creates a table row that represents the specified session.895#896# @param session [Mdm::Session] session used to create a table row.897# @param show_extended [Boolean] Indicates if extended information will be included in the row.898# @return [Array] table row of session data.899def self.create_mdm_session_row(session, show_extended)900row = []901row << session.closed_at.to_s902row << session.opened_at.to_s903row << session.close_reason904row << session.stype905if session.respond_to?(:platform) && !session.platform.nil?906row[-1] << " #{session.platform}"907end908row << (!session.host.nil? ? session.host.address : nil)909910# return complete row911row912end913914# Dumps the list of active sessions in verbose mode915#916# @param framework [Msf::Framework] the framework to dump.917# @param opts [Hash] the options to dump with.918# @return [String] the formatted list of sessions.919def self.dump_sessions_verbose(framework, opts={})920out = "Active sessions\n" +921"===============\n\n"922923if framework.sessions.length == 0924out << "No active sessions.\n"925return out926end927928sessions = opts[:sessions] || framework.sessions929930sessions.each do |session_id, session|931sess_info = session.info.to_s932sess_id = session.sid.to_s933sess_name = session.sname.to_s934sess_tunnel = session.tunnel_to_s + " (#{session.session_host})"935sess_via = session.via_exploit.to_s936sess_type = session.type.to_s937sess_uuid = session.payload_uuid.to_s938sess_luri = session.exploit_datastore['LURI'] || "" if session.exploit_datastore939sess_enc = 'No'940if session.respond_to?(:tlv_enc_key) && session.tlv_enc_key && session.tlv_enc_key[:key]941sess_enc = "Yes (AES-#{session.tlv_enc_key[:key].length * 8}-CBC)"942end943944sess_checkin = "<none>"945sess_registration = "No"946947if session.respond_to?(:platform) && session.platform948sess_type << " #{session.platform}"949end950951if session.respond_to?(:last_checkin) && session.last_checkin952sess_checkin = "#{(Time.now.to_i - session.last_checkin.to_i)}s ago @ #{session.last_checkin.to_s}"953end954955if !session.payload_uuid.nil? && session.payload_uuid.registered956sess_registration = "Yes"957if session.payload_uuid.name958sess_registration << " - Name=\"#{session.payload_uuid.name}\""959end960end961962out << " Session ID: #{sess_id}\n"963out << " Name: #{sess_name}\n"964out << " Type: #{sess_type}\n"965out << " Info: #{sess_info}\n"966out << " Tunnel: #{sess_tunnel}\n"967out << " Via: #{sess_via}\n"968out << " Encrypted: #{sess_enc}\n"969out << " UUID: #{sess_uuid}\n"970out << " CheckIn: #{sess_checkin}\n"971out << " Registered: #{sess_registration}\n"972unless (sess_luri || '').empty?973out << " LURI: #{sess_luri}\n"974end975976out << "\n"977end978979out << "\n"980return out981end982983# Dumps the list of running jobs.984#985# @param framework [Msf::Framework] the framework.986# @param verbose [Boolean] if true, also prints the payload, LPORT, URIPATH987# and start time, if they exist, for each job.988# @param indent [Integer] the indentation amount.989# @param col [Integer] the column wrap width.990# @return [String] the formatted list of running jobs.991def self.dump_jobs(framework, verbose = false, indent = DefaultIndent, col = DefaultColumnWrap)992columns = [ 'Id', 'Name', "Payload", "Payload opts"]993994if (verbose)995columns += [ "URIPATH", "Start Time", "Handler opts", "Persist" ]996end997998tbl = Rex::Text::Table.new(999'Indent' => indent,1000'Header' => "Jobs",1001'Columns' => columns1002)10031004# Get the persistent job info.1005if verbose1006begin1007persist_list = JSON.parse(File.read(Msf::Config.persist_file))1008rescue Errno::ENOENT, JSON::ParserError1009persist_list = []1010end1011end10121013# jobs are stored as a hash with the keys being a numeric String job_id.1014framework.jobs.keys.sort_by(&:to_i).each do |job_id|1015# Job context is stored as an Array with the 0th element being1016# the running module. If that module is an exploit, ctx will also1017# contain its payload.1018exploit_mod, _payload_mod = framework.jobs[job_id].ctx1019row = []1020row[0] = job_id1021row[1] = framework.jobs[job_id].name10221023pinst = exploit_mod.respond_to?(:payload_instance) ? exploit_mod.payload_instance : nil1024payload_uri = ''10251026if pinst.nil?1027row[2] = ""1028row[3] = ""1029else1030row[2] = pinst.refname1031row[3] = ""1032if pinst.respond_to?(:payload_uri)1033payload_uri = pinst.payload_uri.strip1034row[3] << payload_uri1035end1036if pinst.respond_to?(:luri)1037row[3] << pinst.luri1038end1039if pinst.respond_to?(:comm_string)1040via = pinst.comm_string1041if via1042row[3] << " #{via}"1043end1044end1045end10461047if verbose1048uripath = exploit_mod.get_resource if exploit_mod.respond_to?(:get_resource)1049uripath ||= exploit_mod.datastore['URIPATH']1050row[4] = uripath1051row[5] = framework.jobs[job_id].start_time1052row[6] = ''1053row[7] = 'false'10541055if pinst.respond_to?(:listener_uri)1056listener_uri = pinst.listener_uri.strip1057row[6] = listener_uri unless listener_uri == payload_uri1058end10591060persist_list.each do |e|1061handler_ctx = framework.jobs[job_id.to_s].ctx[1]1062if handler_ctx && handler_ctx.respond_to?(:datastore)1063row[7] = 'true' if e['mod_options']['Options'] == handler_ctx.datastore.to_h1064end1065end10661067end1068tbl << row1069end10701071return framework.jobs.keys.length > 0 ? tbl.to_s : "#{tbl.header_to_s}No active jobs.\n"1072end10731074# Dumps the module description1075#1076# @param mod [Msf::Module] the module.1077# @param indent [String] the indentation string1078# @return [String] the string description1079def self.dump_description(mod, indent)1080description = mod.description10811082output = "Description:\n"1083output << word_wrap_description(description, indent)1084output << "\n\n"1085end10861087# @param str [String] the string to wrap.1088# @param indent [String] the indentation string1089# @return [String] the wrapped string.1090def self.word_wrap_description(str, indent = '')1091return '' if str.blank?10921093str_lines = str.strip.lines(chomp: true)1094# Calculate the preceding whitespace length of each line1095smallest_preceding_whitespace = nil1096str_lines[1..].to_a.each do |line|1097preceding_whitespace = line[/^\s+/]1098if preceding_whitespace && (smallest_preceding_whitespace.nil? || preceding_whitespace.length < smallest_preceding_whitespace)1099smallest_preceding_whitespace = preceding_whitespace.length1100end1101end11021103# Normalize any existing left-most whitespace on each line; Ignoring the first line which won't have any preceding whitespace1104result = str_lines.map.with_index do |line, index|1105next if line.blank?11061107"#{indent}#{index == 0 || smallest_preceding_whitespace.nil? ? line : line[smallest_preceding_whitespace..]}"1108end.join("\n")11091110result1111end1112end11131114end end111511161117