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/json.rb
Views: 11784
# -*- coding: binary -*-1# rubocop:disable Metrics/AbcSize2# rubocop:disable Metrics/ClassLength3# rubocop:disable Metrics/CyclomaticComplexity4module Msf5module Serializer6#7# This class formats information in a json format that8# is meant to be displayed on a console or some other non-GUI9# medium.10class Json11#12# Returns a formatted string that contains information about13# the supplied module instance.14#15# @param mod [Msf::Module] the module to dump information for.16# @param _indent [String] the indentation to use.17# @return [String] formatted text output of the dump.18def self.dump_module(mod, _indent = "")19case mod.type20when Msf::MODULE_PAYLOAD21return dump_payload_module(mod)22when Msf::MODULE_NOP23return dump_basic_module(mod)24when Msf::MODULE_ENCODER25return dump_basic_module(mod)26when Msf::MODULE_EXPLOIT27return dump_exploit_module(mod)28when Msf::MODULE_AUX29return dump_auxiliary_module(mod)30when Msf::MODULE_POST31return dump_post_module(mod)32else33return dump_basic_module(mod)34end35end3637# Dumps an exploit's targets.38#39# @param mod [Msf::Exploit] the exploit module to dump targets40# for.41# @return [Array] the exploit targets42def self.dump_exploit_targets(mod)43list = []4445mod.targets.each { |target| list.push(target.name || 'All') }4647list48end4950# Dumps a module's actions51#52# @param mod [Msf::Module] the module.53# @return [Array] the module actions54def self.dump_module_actions(mod)55list = []5657mod.actions.each do |target|58list.push('name' => (target.name || 'All'),59'description' => (target.description || ''))60end6162list63end6465# Dumps the module's selected action66#67# @param mod [Msf::Module] the module.68# @return [Array] the module options69def self.dump_module_action(mod)70list = []7172list.push('name' => (mod.action.name || 'All'),73'description' => (mod.action.description || ''))7475list76end7778# Dumps information common to all modules79def self.dump_common_module_info(mod)80{81'name' => mod.name,82'fullname' => mod.fullname,83'authors' => dump_authors(mod),84'rank' => mod.rank_to_s.capitalize,85'description' => Rex::Text.compress(mod.description),86'options' => dump_options(mod)87}88end8990# Dumps information about an exploit module.91#92# @param mod [Msf::Exploit] the exploit module.93# @return [String] the json string form of the information.94def self.dump_exploit_module(mod)95# Return a json dump of exploit module data96{97'platform' => mod.platform_to_s,98'privileged' => (mod.privileged? ? "Yes" : "No"),99'license' => mod.license,100'disclosure_date' => (mod.disclosure_date if mod.disclosure_date),101'payload' => {102'space' => (mod.payload_space.to_s if mod.payload_space),103'badchars' => (mod.payload_badchars.length.to_s if mod.payload_badchars)104},105'references' => dump_references(mod)106}.merge(dump_common_module_info(mod)).to_json107end108109# Dumps information about an auxiliary module.110#111# @param mod [Msf::Auxiliary] the auxiliary module.112# @return [String] the string form of the information.113def self.dump_auxiliary_module(mod)114# Return a json dump of auxiliary module data115{116'license' => mod.license,117'disclosure_date' => (mod.disclosure_date if mod.disclosure_date),118'actions' => dump_module_actions(mod),119'references' => dump_references(mod)120}.merge(dump_common_module_info(mod)).to_json121end122123# Dumps information about a post module.124#125# @param mod [Msf::Post] the post module.126# @return [String] the string form of the information.127def self.dump_post_module(mod)128# Return a json dump of post module data129{130'platform' => mod.platform_to_s,131'arch' => mod.arch_to_s,132'disclosure_date' => (mod.disclosure_date if mod.disclosure_date),133'actions' => dump_module_actions(mod),134'references' => dump_references(mod)135}.merge(dump_common_module_info(mod)).to_json136end137138# Dumps information about a payload module.139#140# @param mod [Msf::Payload] the payload module.141# @return [String] the string form of the information.142def self.dump_payload_module(mod)143# Return a json dump of post module data144{145'platform' => mod.platform_to_s,146'arch' => mod.arch_to_s,147'privileged' => (mod.privileged? ? "true" : "false"),148'size' => mod.size149}.merge(dump_common_module_info(mod)).to_json150end151152# Returns an array of all authors153#154# @param mod [Msf::Module]155# @return [Array] an array of all authors156def self.dump_authors(mod)157# Authors158authors = []159mod.each_author { |author| authors.push(author.to_s) }160authors161end162163# Dumps information about a module, just the basics.164#165# @param mod [Msf::Module] the module.166# @return [String] the string form of the information.167def self.dump_basic_module(mod)168{169'platform' => mod.platform_to_s,170'arch' => mod.arch_to_s,171'references' => dump_references(mod)172}.merge(dump_common_module_info(mod)).to_json173end174175# Dumps the list of options associated with the176# supplied module.177#178# @param mod [Msf::Module] the module.179# @return [Array] the array of the information.180def self.dump_options(mod)181list = []182mod.options.sorted.each do |entry|183name, opt = entry184val = mod.datastore[name] || opt.default185186next if opt.advanced? || opt.evasion?187188list.push('name' => name,189'display_value' => opt.display_value(val),190'required' => opt.required? ? 'true' : 'false',191'description' => opt.desc.strip)192end193194list195end196197# Dumps the references associated with the supplied module.198#199# @param mod [Msf::Module] the module.200# @return [Array] the array of the information.201def self.dump_references(mod)202if (mod.respond_to? :references) && mod.references && (mod.references.length > 0)203refs = []204mod.references.each { |ref| refs.push(ref.to_s) }205end206207refs208end209end210end211end212213214