PageRenderTime 43ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/msf/core/module/author.rb

https://gitlab.com/leijianbin/metasploit-framework
Ruby | 146 lines | 91 code | 20 blank | 35 comment | 10 complexity | 70df4566b5be4b49563f21be9ed8677c MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, GPL-2.0, LGPL-2.1
  1. # -*- coding: binary -*-
  2. require 'msf/core'
  3. ###
  4. #
  5. # This data type represents an author of a piece of code in either
  6. # the framework, a module, a script, or something entirely unrelated.
  7. #
  8. ###
  9. class Msf::Module::Author
  10. # A hash of known author names
  11. Known =
  12. {
  13. 'amaloteaux' => 'alex_maloteaux' + 0x40.chr + 'metasploit.com',
  14. 'anonymous' => 'anonymous-contributor' + 0x40.chr + 'metasploit.com',
  15. 'bannedit' => 'bannedit' + 0x40.chr + 'metasploit.com',
  16. 'Carlos Perez' => 'carlos_perez' + 0x40.chr + 'darkoperator.com',
  17. 'cazz' => 'bmc' + 0x40.chr + 'shmoo.com',
  18. 'CG' => 'cg' + 0x40.chr + 'carnal0wnage.com',
  19. 'ddz' => 'ddz' + 0x40.chr + 'theta44.org',
  20. 'egypt' => 'egypt' + 0x40.chr + 'metasploit.com',
  21. 'et' => 'et' + 0x40.chr + 'metasploit.com',
  22. 'hdm' => 'hdm' + 0x40.chr + 'metasploit.com',
  23. 'I)ruid' => 'druid' + 0x40.chr + 'caughq.org',
  24. 'jcran' => 'jcran' + 0x40.chr + 'metasploit.com',
  25. 'jduck' => 'jduck' + 0x40.chr + 'metasploit.com',
  26. 'joev' => 'joev' + 0x40.chr + 'metasploit.com',
  27. 'juan vazquez' => 'juan.vazquez' + 0x40.chr + 'metasploit.com',
  28. 'kf' => 'kf_list' + 0x40.chr + 'digitalmunition.com',
  29. 'kris katterjohn' => 'katterjohn' + 0x40.chr + 'gmail.com',
  30. 'MC' => 'mc' + 0x40.chr + 'metasploit.com',
  31. 'msmith' => 'msmith' + 0x40.chr + 'metasploit.com',
  32. 'mubix' => 'mubix' + 0x40.chr + 'hak5.org',
  33. 'natron' => 'natron' + 0x40.chr + 'metasploit.com',
  34. 'optyx' => 'optyx' + 0x40.chr + 'no$email.com',
  35. 'patrick' => 'patrick' + 0x40.chr + 'osisecurity.com.au',
  36. 'pusscat' => 'pusscat' + 0x40.chr + 'metasploit.com',
  37. 'Ramon de C Valle' => 'rcvalle' + 0x40.chr + 'metasploit.com',
  38. 'sf' => 'stephen_fewer' + 0x40.chr + 'harmonysecurity.com',
  39. 'sinn3r' => 'sinn3r' + 0x40.chr + 'metasploit.com',
  40. 'skape' => 'mmiller' + 0x40.chr + 'hick.org',
  41. 'skylined' => 'skylined' + 0x40.chr + 'edup.tudelft.nl',
  42. 'spoonm' => 'spoonm' + 0x40.chr + 'no$email.com',
  43. 'stinko' => 'vinnie' + 0x40.chr + 'metasploit.com',
  44. 'theLightCosine' => 'theLightCosine' + 0x40.chr + 'metasploit.com',
  45. 'todb' => 'todb' + 0x40.chr + 'metasploit.com',
  46. 'vlad902' => 'vlad902' + 0x40.chr + 'gmail.com'
  47. }
  48. #
  49. # Class method that translates a string to an instance of the Author class,
  50. # if it's of the right format, and returns the Author class instance
  51. #
  52. def self.from_s(str)
  53. instance = self.new
  54. # If the serialization fails...
  55. if (instance.from_s(str) == false)
  56. return nil
  57. end
  58. return instance
  59. end
  60. #
  61. # Transforms the supplied source into an array of authors
  62. #
  63. def self.transform(src)
  64. Rex::Transformer.transform(src, Array, [ self ], 'Author')
  65. end
  66. def initialize(name = nil, email = nil)
  67. self.name = name
  68. self.email = email || Known[name]
  69. end
  70. #
  71. # Compares authors
  72. #
  73. def ==(tgt)
  74. return (tgt.to_s == to_s)
  75. end
  76. #
  77. # Serialize the author object to a string in form:
  78. #
  79. # name <email>
  80. #
  81. def to_s
  82. str = "#{name}"
  83. if (email and not email.empty?)
  84. str += " <#{email}>"
  85. end
  86. return str
  87. end
  88. #
  89. # Translate the author from the supplied string which may
  90. # have either just a name or also an email address
  91. #
  92. def from_s(str)
  93. # Supported formats:
  94. # known_name
  95. # user [at/@] host [dot/.] tld
  96. # Name <user [at/@] host [dot/.] tld>
  97. if ((m = str.match(/^\s*([^<]+)<([^>]+)>\s*$/)))
  98. self.name = m[1].sub(/<.*/, '')
  99. self.email = m[2].sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.')
  100. else
  101. if (Known[str])
  102. self.email = Known[str]
  103. self.name = str
  104. else
  105. self.email = str.sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.').gsub(/^<|>$/, '')
  106. m = self.email.match(/([^@]+)@/)
  107. self.name = m ? m[1] : nil
  108. if !(self.email and self.email.index('@'))
  109. self.name = self.email
  110. self.email = ''
  111. end
  112. end
  113. end
  114. self.name.strip! if self.name
  115. return true
  116. end
  117. #
  118. # Sets the name of the author and updates the email if it's a known author.
  119. #
  120. def name=(name)
  121. self.email = Known[name] if (Known[name])
  122. @name = name
  123. end
  124. attr_accessor :email
  125. attr_reader :name
  126. end