diff --git a/lib/ronin/exploits/cli/commands/new.rb b/lib/ronin/exploits/cli/commands/new.rb index f44c563e..92b52794 100644 --- a/lib/ronin/exploits/cli/commands/new.rb +++ b/lib/ronin/exploits/cli/commands/new.rb @@ -355,6 +355,8 @@ def initialize(**kwargs) # The path to the new exploit file. # def run(file) + infer_advisory_id(file) + @directory = File.dirname(file) @file_name = File.basename(file,File.extname(file)) @class_name = CommandKit::Inflector.camelize(@file_name) @@ -365,6 +367,21 @@ def run(file) chmod '+x', file end + # + # Automatically detects the CVE or GHSA ID from the file name. + # + # @param [String] file + # The path to the new exploit file. + # + def infer_advisory_id(file) + path = File.expand_path(file) + + if (match = path.match(/CVE-20\d{2}-\d{4,5}|GHSA(?:-[0-9a-z]{4}){3}/)) + # ensure the advisory ID is the first advisory listed + @advisories.unshift(match[0]) + end + end + # # Formats a Hash into Ruby keyword arguments. #