Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

author.rb 5.7KB

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