Class: Pedant::CheckScriptFamilyNotSpecified

Inherits:
Check
  • Object
show all
Defined in:
lib/pedant/checks/script_family_not_specified.rb

Instance Attribute Summary

Attributes inherited from Check

#result

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Check

all, depends, #fail, #fatal, friendly_name, inherited, #initialize, initialize!, list, #pass, provides, ready?, #report, #skip, #warn

Constructor Details

This class inherits a constructor from Pedant::Check

Class Method Details

.requiresObject



29
30
31
# File 'lib/pedant/checks/script_family_not_specified.rb', line 29

def self.requires
  super + [:main, :trees]
end

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# 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",
      "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",
      "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",
      "Junos Local Security Checks",
      "MacOS X Local Security Checks",
      "Mandriva Local Security Checks",
      "Misc.",
      "Mobile Devices",
      "Netware",
      "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