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/docs/_plugins/metasploit_console_language.rb
Views: 11766
require 'rouge'12# Custom highlighting support for Metasploit's prompt3# https://rouge-ruby.github.io/docs/file.LexerDevelopment.html4module Rouge5# Custom tokens specific to Msf, as the inbuilt lexer tokens can't capture6# the detail required for Msf's print_warning/print_good/etc calls.7module Tokens8def self.token(name, shortname, &b)9tok = Token.make_token(name, shortname, &b)10const_set(name, tok)11end1213# The 'shortname' is the class used when generating the HTML. It is intentionally14# short to reduce HTML size.15# https://github.com/rouge-ruby/rouge/blob/a4ed658d2778a3e2d3e68873f7221b91149a2ed4/lib/rouge/token.rb#L6916SHORTNAME = 'z'1718token :Msf, SHORTNAME do19# prompt - msf / msf5 / msf6 / meterpreter20token :Prompt, "#{SHORTNAME}p"21# [-]22token :Error, "#{SHORTNAME}e"23# [+]24token :Good, "#{SHORTNAME}g"25# [*]26token :Status, "#{SHORTNAME}s"27# [!]28token :Warning, "#{SHORTNAME}w"29end30end3132module Lexers33class MetasploitConsoleLanguage < Rouge::RegexLexer34title 'msf'35tag 'msf'36desc 'Metasploit console highlighter'37filenames []38mimetypes []3940def self.keywords41@keywords ||= Set.new %w()42end4344state :whitespace do45rule %r/\s+/, Text46end4748state :root do49mixin :whitespace5051# Match msf, msf5, msf6, meterpreter52rule %r{^(msf\d?|meterpreter)}, Tokens::Msf::Prompt, :msf_prompt53rule %r{^\[-\]}, Tokens::Msf::Error54rule %r{^\[\+\]}, Tokens::Msf::Good55rule %r{^\[\*\]}, Tokens::Msf::Status56rule %r{^\[\!\]}, Tokens::Msf::Warning57rule %r{.+}, Text58end5960# State for highlighting the prompt such as61# msf6 auxiliary(admin/dcerpc/cve_2022_26923_certifried) >62state :msf_prompt do63mixin :whitespace6465rule %r{exploit|payload|auxiliary|encoder|evasion|post|nop}, Text66rule %r{\(}, Punctuation67rule %r{\)}, Punctuation68rule %r{[\w/]+}, Keyword::Constant69rule %r{>}, Punctuation, :pop!70end71end72end73end747576