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/lib/msf/core/author.rb
Views: 11778
1
# -*- coding: binary -*-
2
3
###
4
#
5
# An author of a piece of code in either the framework, a module, a script,
6
# or something entirely unrelated.
7
#
8
###
9
class Msf::Author
10
11
#
12
# Constants
13
#
14
15
# A hash that maps known author names to email addresses
16
KNOWN = {
17
'amaloteaux' => 'alex_maloteaux' + 0x40.chr + 'metasploit.com',
18
'aushack' => 'patrick' + 0x40.chr + 'osisecurity.com.au',
19
'bannedit' => 'bannedit' + 0x40.chr + 'metasploit.com',
20
'bcoles' => 'bcoles' + 0x40.chr + 'gmail.com',
21
'Carlos Perez' => 'carlos_perez' + 0x40.chr + 'darkoperator.com',
22
'cazz' => 'bmc' + 0x40.chr + 'shmoo.com',
23
'CG' => 'cg' + 0x40.chr + 'carnal0wnage.com',
24
'ddz' => 'ddz' + 0x40.chr + 'theta44.org',
25
'egypt' => 'egypt' + 0x40.chr + 'metasploit.com',
26
'et' => 'et' + 0x40.chr + 'metasploit.com',
27
'Christian Mehlmauer' => 'FireFart' + 0x40.chr + 'gmail.com',
28
'hdm' => 'x' + 0x40.chr + 'hdm.io',
29
'I)ruid' => 'druid' + 0x40.chr + 'caughq.org',
30
'jcran' => 'jcran' + 0x40.chr + 'metasploit.com',
31
'jduck' => 'jduck' + 0x40.chr + 'metasploit.com',
32
'joev' => 'joev' + 0x40.chr + 'metasploit.com',
33
'juan vazquez' => 'juan.vazquez' + 0x40.chr + 'metasploit.com',
34
'kf' => 'kf_list' + 0x40.chr + 'digitalmunition.com',
35
'kris katterjohn' => 'katterjohn' + 0x40.chr + 'gmail.com',
36
'MC' => 'mc' + 0x40.chr + 'metasploit.com',
37
'Ben Campbell' => 'eat_meatballs' + 0x40.chr + 'hotmail.co.uk',
38
'msmith' => 'msmith' + 0x40.chr + 'metasploit.com',
39
'mubix' => 'mubix' + 0x40.chr + 'hak5.org',
40
'natron' => 'natron' + 0x40.chr + 'metasploit.com',
41
'optyx' => 'optyx' + 0x40.chr + 'no$email.com',
42
'pusscat' => 'pusscat' + 0x40.chr + 'metasploit.com',
43
'Ramon de C Valle' => 'rcvalle' + 0x40.chr + 'metasploit.com',
44
'sf' => 'stephen_fewer' + 0x40.chr + 'harmonysecurity.com',
45
'sinn3r' => 'sinn3r' + 0x40.chr + 'metasploit.com',
46
'skape' => 'mmiller' + 0x40.chr + 'hick.org',
47
'skylined' => 'skylined' + 0x40.chr + 'edup.tudelft.nl',
48
'spoonm' => 'spoonm' + 0x40.chr + 'no$email.com',
49
'stinko' => 'vinnie' + 0x40.chr + 'metasploit.com',
50
'theLightCosine' => 'theLightCosine' + 0x40.chr + 'metasploit.com',
51
'todb' => 'todb' + 0x40.chr + 'metasploit.com',
52
'vlad902' => 'vlad902' + 0x40.chr + 'gmail.com',
53
'wvu' => 'wvu' + 0x40.chr + 'metasploit.com',
54
'zeroSteiner' => 'zeroSteiner' + 0x40.chr + 'gmail.com'
55
}
56
57
#
58
# Class Methods
59
#
60
61
# Parses an {Author} instance from the specified string.
62
#
63
# @param str [String] the String to parse an Author instance from
64
# @return [Author] a valid {Author} instance
65
# @return nil if `str` is not the correct format
66
def self.from_s(str)
67
instance = self.new
68
69
# If the serialization fails...
70
if instance.from_s(str) == true
71
instance
72
else
73
nil
74
end
75
end
76
77
# Normalizes a single {Author} reference or an Array of {Author} references
78
# to an Array of {Author} references.
79
#
80
# @param src [Author, Array<Author>] a single {Author} or an Array of {Author} instances
81
# @return [Array<Author>] an Array of {Author} instances
82
def self.transform(src)
83
Rex::Transformer.transform(src, Array, [ self ], 'Author')
84
end
85
86
# Constructs an {Author} from a given `name` and `email`
87
#
88
# @param name [String] the author's name
89
# @param email [String] the author's email
90
def initialize(name = nil, email = nil)
91
self.name = name
92
self.email = email || KNOWN[name]
93
end
94
95
#
96
# Instance Attributes
97
#
98
99
# @!attribute email
100
# An optional email associated with this {Author}.
101
#
102
# @return [String, nil]
103
attr_accessor :email
104
105
# @!attribute name
106
# The name associated with this {Author}.
107
#
108
# @return [String]
109
attr_reader :name
110
111
#
112
# Instance Methods
113
#
114
115
# @return [Boolean] whether the {Author} instances are equal
116
def ==(tgt)
117
tgt.to_s == to_s
118
end
119
120
# Serialize the {Author} instance to a string of the form `name` or `name <[email protected]>`
121
#
122
# @return [String] serialized {Author}
123
def to_s
124
str = "#{name}"
125
if (email and not email.empty?)
126
str += " <#{email}>"
127
end
128
str
129
end
130
131
132
# Parses {Author} details from the supplied string which may
133
# be of the form `name` or `name <[email protected]>`
134
#
135
# @param str [String] the String to parse from
136
# @return [Boolean] the translation succeeded
137
def from_s(str)
138
139
# Supported formats:
140
# known_name
141
# user [at/@] host [dot/.] tld
142
# Name <user [at/@] host [dot/.] tld>
143
144
if str.present?
145
if ((m = str.match(/^\s*([^<]+)<([^>]+)>\s*$/)))
146
self.name = m[1].sub(/<.*/, '')
147
self.email = m[2].sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.')
148
else
149
if (KNOWN[str])
150
self.email = KNOWN[str]
151
self.name = str
152
else
153
self.email = str.sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.').gsub(/^<|>$/, '')
154
m = self.email.match(/([^@]+)@/)
155
self.name = m ? m[1] : nil
156
if !(self.email and self.email.index('@'))
157
self.name = self.email
158
self.email = ''
159
end
160
end
161
end
162
end
163
164
self.name.strip! if self.name.present?
165
166
# The parse succeeds only when a name is found
167
self.name.present?
168
end
169
170
# Sets the name of the author and updates the email if it's a known author.
171
# @param name [String] the name to set
172
def name=(name)
173
if KNOWN.has_key?(name)
174
self.email = KNOWN[name]
175
end
176
@name = name
177
end
178
179
end
180
181