class Pedant::CheckScriptFamilyNotSpecified

Public Class Methods

requires() click to toggle source
Calls superclass method Pedant::Check::requires
# File lib/pedant/checks/script_family_not_specified.rb, line 29
def self.requires
  super + [:main, :trees]
end

Public Instance Methods

run() click to toggle source
# File lib/pedant/checks/script_family_not_specified.rb, line 33
def run
  # This check only applies to plugins.
  return skip unless @kb[:main].extname == '.nasl'

  args = []

  tree = @kb[:trees][@kb[:main]]

  tree.all(:Call).each do |node|
    next unless node.name.ident.name == 'script_family'
    next unless node.name.indexes == []
    next if node.args.empty?
    next unless node.args.first.expr.is_a? Nasl::String

    # Pull out argument
    arg = node.args.first.expr

    # Ensure that the script family is valid.
    unless [
      "AIX Local Security Checks",
      "Amazon Linux Local Security Checks",
      "Backdoors",
      "Brute force attacks",
      "CentOS Local Security Checks",
      "CGI abuses",
      "CGI abuses : XSS",
      "CISCO",
      "Databases",
      "Debian Local Security Checks",
      "Default Unix Accounts",
      "Denial of Service",
      "DNS",
      "F5 Networks Local Security Checks",
      "Fedora Local Security Checks",
      #"Finger abuses", # removed december 2011
      "Firewalls",
      "FreeBSD Local Security Checks",
      "FTP",
      "Gain a shell remotely",
      "General",
      "Gentoo Local Security Checks",
      "HP-UX Local Security Checks",
      "Huawei Local Security Checks",
      "Junos Local Security Checks",
      "MacOS X Local Security Checks",
      "Mandriva Local Security Checks",
      "Misc.",
      "Mobile Devices",
      "Netware",
      "Oracle Linux Local Security Checks",
      "OracleVM Local Security Checks",
      "Palo Alto Local Security Checks",
      "Peer-To-Peer File Sharing",
      "Policy Compliance",
      "Port scanners",
      "Red Hat Local Security Checks",
      "RPC",
      "SCADA",
      "Scientific Linux Local Security Checks",
      "Service detection",
      "Settings",
      "Slackware Local Security Checks",
      "SMTP problems",
      "SNMP",
      "Solaris Local Security Checks",
      "SuSE Local Security Checks",
      "Ubuntu Local Security Checks",
      "VMware ESX Local Security Checks",
      "Web Servers",
      "Windows",
      "Windows : Microsoft Bulletins",
      "Windows : User management"
    ].include? arg.text

      report(:info, "Plugin belongs to unknown family #{arg.text}:\n#{arg.context(node)}")
      return fail
    end

    args << [arg, node]
  end

  case args.length
  when 0
    report(:error, "Plugin does not specify a script_family.")
    fail
  when 1
    arg = args.first[0]
    call = args.first[1]
    report(:info, "Plugin belongs to script family #{arg.text}:\n#{arg.context(call)}")
    pass
  else
    report(:error, "Plugin specifies multiple script families.")
    args.each { |arg, call| report(:error, arg.context(call)) }
    fail
  end
end