CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/docs/_plugins/metasploit_console_language.rb
Views: 11766
1
require 'rouge'
2
3
# Custom highlighting support for Metasploit's prompt
4
# https://rouge-ruby.github.io/docs/file.LexerDevelopment.html
5
module Rouge
6
# Custom tokens specific to Msf, as the inbuilt lexer tokens can't capture
7
# the detail required for Msf's print_warning/print_good/etc calls.
8
module Tokens
9
def self.token(name, shortname, &b)
10
tok = Token.make_token(name, shortname, &b)
11
const_set(name, tok)
12
end
13
14
# The 'shortname' is the class used when generating the HTML. It is intentionally
15
# short to reduce HTML size.
16
# https://github.com/rouge-ruby/rouge/blob/a4ed658d2778a3e2d3e68873f7221b91149a2ed4/lib/rouge/token.rb#L69
17
SHORTNAME = 'z'
18
19
token :Msf, SHORTNAME do
20
# prompt - msf / msf5 / msf6 / meterpreter
21
token :Prompt, "#{SHORTNAME}p"
22
# [-]
23
token :Error, "#{SHORTNAME}e"
24
# [+]
25
token :Good, "#{SHORTNAME}g"
26
# [*]
27
token :Status, "#{SHORTNAME}s"
28
# [!]
29
token :Warning, "#{SHORTNAME}w"
30
end
31
end
32
33
module Lexers
34
class MetasploitConsoleLanguage < Rouge::RegexLexer
35
title 'msf'
36
tag 'msf'
37
desc 'Metasploit console highlighter'
38
filenames []
39
mimetypes []
40
41
def self.keywords
42
@keywords ||= Set.new %w()
43
end
44
45
state :whitespace do
46
rule %r/\s+/, Text
47
end
48
49
state :root do
50
mixin :whitespace
51
52
# Match msf, msf5, msf6, meterpreter
53
rule %r{^(msf\d?|meterpreter)}, Tokens::Msf::Prompt, :msf_prompt
54
rule %r{^\[-\]}, Tokens::Msf::Error
55
rule %r{^\[\+\]}, Tokens::Msf::Good
56
rule %r{^\[\*\]}, Tokens::Msf::Status
57
rule %r{^\[\!\]}, Tokens::Msf::Warning
58
rule %r{.+}, Text
59
end
60
61
# State for highlighting the prompt such as
62
# msf6 auxiliary(admin/dcerpc/cve_2022_26923_certifried) >
63
state :msf_prompt do
64
mixin :whitespace
65
66
rule %r{exploit|payload|auxiliary|encoder|evasion|post|nop}, Text
67
rule %r{\(}, Punctuation
68
rule %r{\)}, Punctuation
69
rule %r{[\w/]+}, Keyword::Constant
70
rule %r{>}, Punctuation, :pop!
71
end
72
end
73
end
74
end
75
76