Class: Pedant::CheckScriptNotSignedAndUsingTrustedFunction

Inherits:
Check
  • Object
show all
Defined in:
lib/pedant/checks/script_not_signed_and_using_trusted_function.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, run_checks_in_dependency_order, #skip, #warn

Constructor Details

This class inherits a constructor from Pedant::Check

Class Method Details

.requiresObject



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

def self.requires
  super + [:main, :trees, :codes]
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/pedant/checks/script_not_signed_and_using_trusted_function.rb', line 33

def run
  # This check only applies to plugins.
  return skip unless @kb[:main].extname == '.nasl'

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

  tree.all(:Call).each do |node|
    # builtin trusted functions
    next unless [
      "bind_sock_tcp",
      "bind_sock_tcp6",
      "bind_sock_udp",
      "bind_sock_udp6",
      "can_query_report",
      "cfile_open",
      "cfile_stat",
      "db_open",
      "db_open2",
      "db_open_ex",
      "db_query",
      "db_query_foreach",
      "dsa_do_sign",
      "dump_interfaces",
      "file_close",
      "file_fstat",
      "file_is_signed",
      "file_md5",
      "file_mkdir",
      "file_mtime",
      "file_open",
      "file_read",
      "file_rename",
      "file_seek",
      "file_stat",
      "file_write",
      "find_in_path",
      "fork",
      "fread",
      "fwrite",
      "gc",
      "get_preference_file_content",
      "get_preference_file_location",
      "get_tmp_dir",
      "inject_packet",
      "is_user_root",
      "kb_ssh_certificate",
      "kb_ssh_login",
      "kb_ssh_password",
      "kb_ssh_privatekey",
      "kb_ssh_publickey",
      "kb_ssh_realm",
      "kb_ssh_transport",
      "kill",
      "load_db_master_key_cli",
      "mkdir",
      "mkdir_ex",
      "mutex_lock",
      "mutex_unlock",
      "nessus_get_dir",
      "open_sock2",
      "open_sock_ex",
      "pem_to_dsa",
      "pem_to_dsa2",
      "pem_to_pub_rsa",
      "pem_to_rsa",
      "pem_to_rsa2",
      "pread",
      "query_report",
      "readdir",
      "recvfrom",
      "rename",
      "resolv",
      "rmdir",
      "rsa_sign",
      "same_host",
      "schematron_validate",
      "script_get_preference_file_content",
      "script_get_preference_file_location",
      "sendto",
      "set_mem_limits",
      "socket_accept",
      "ssl_accept3",
      "ssl_accept4",
      "syn_scan",
      "tcp_scan",
      "thread_create",
      "udp_scan",
      "unlink",
      "untar_plugins",
      "xmldsig_sign",
      "xmldsig_verify",
      "xmlparse",
      "xsd_validate",
      "xslt_apply_stylesheet",
      "xslt_filter",
      # trusted functions from includes
      # cisco_kb_cmd_func.inc
      "cisco_command_kb_item",
      # macosx_func.inc
      "exec_cmd",
      "exec_cmds",
      "get_users_homes",
      # ssh_func.inc
      "ssh_cmd",
      # ssh1_func.inc
      "ssh_cmd1",
      # functions that can call open_sock2()
      "enable_keepalive",
      "http_is_dead",
      "http_keepalive_enabled",
      "http_open_soc_err",
      "http_open_socket_ka",
      "http_recv_body",
      "http_recv_headers3",
      "http_recv3",
      "http_reopen_socket",
      "http_send_recv_req",
      "http_send_recv3",
      "http_set_error"
    ].include? node.name.ident.name

    if [
      # functions that can call open_sock2()
      "enable_keepalive",
      "http_is_dead",
      "http_keepalive_enabled",
      "http_open_soc_err",
      "http_open_socket_ka",
      "http_recv_body",
      "http_recv_headers3",
      "http_recv3",
      "http_reopen_socket",
      "http_send_recv_req",
      "http_send_recv3",
      "http_set_error"
    ].include? node.name.ident.name
      # check if we use the named argument 'target'
      next unless node.args.any? { |arg|
        arg.respond_to? :name and arg.name.respond_to? :name and arg.name.name == "target" 
      }
      next if codes.index("#TRUSTED") == 0
      report(
        :warn,
        "Plugin is using the function #{node.name.ident.name}() with the 'target' argument, which makes it call open_sock2(), a trusted function, and may need to be signed."
      )
      report(:warn, node.context())
      return fail
    end

    next if codes.index("#TRUSTED") == 0
    report(
      :warn,
      "Plugin is using the trusted function #{node.name.ident.name}() and may need to be signed."
    )
    report(:warn, node.context())
    return fail
  end
  report(:info, "Plugin is not using a trusted function.")
  pass
end