deepsecurity 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  ## CHANGELOG (notable new features or fixes)
4
4
 
5
+ ### 0.0.20
6
+
7
+ * `dsc` command refactoring
8
+ * SOAP Interface refactoring
9
+ * Extracted savon TypeMapping functionality/DSL into seperate classes
10
+ * Added `--detail_level` flag for `host_detail` command
11
+ * Added `-time_format` flag to specifiy time format
12
+
13
+ ### 0.0.19
14
+
15
+ * Updated documentation
16
+ * Streamlined search API (e.g. `find(id)` vs. `find_by_id(id)`
17
+ * host_group hint accessor for hosts/host_details
18
+
19
+
5
20
  ### 0.0.18
6
21
 
7
22
  * Added automatic build of Windows Installer
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # group :development do
4
+ # gem 'unroller' ,:git => 'git://github.com/falsetto/unroller.git'
5
+ # end
6
+
7
+
3
8
  # Specify your gem's dependencies in deepsecurity.gemspec
4
9
  gemspec
data/bin/dsc CHANGED
@@ -27,69 +27,12 @@ program_desc 'DeepSecurity command line client'
27
27
 
28
28
  version Dsc::VERSION
29
29
 
30
- desc "Enable client debug output. (One of #{Dsc::Command.valid_debug_levels_string})"
31
- arg_name 'debug'
32
- flag [:d, :debug]
30
+ Dsc::Command.define_global_flags(self)
31
+ Dsc::Command.define_misc_commands(self)
33
32
 
34
- desc 'Deep Security Manager Host'
35
- arg_name 'hostname'
36
- flag [:m, :manager]
33
+ Dsc::HostDetailCommand.define_commands(self)
34
+ Dsc::AntiMalwareEventCommand.define_commands(self)
37
35
 
38
- desc 'Webservice Port'
39
- arg_name 'port'
40
- default_value '4119'
41
- flag [:port]
42
-
43
- desc 'Tenat Name'
44
- arg_name 'tenat'
45
- default_value ''
46
- flag [:t, :tenant]
47
-
48
- desc 'Username'
49
- arg_name 'username'
50
- default_value 'MasterAdmin'
51
- flag [:u, :username]
52
-
53
- desc 'Password'
54
- arg_name 'password'
55
- flag [:p, :password]
56
-
57
- desc 'Output filename'
58
- default_value '--'
59
- flag [:o, :outfile]
60
-
61
- desc 'Show progressbar'
62
- default_value false
63
- switch [:P]
64
-
65
- command_class = Dsc::HostDetailCommand
66
- desc "Access #{command_class.transport_class_string}s"
67
- command command_class.command_symbol do |c|
68
- command_class.define_list_command(c)
69
- command_class.define_schema_command(c)
70
- end
71
-
72
- command_class = Dsc::AntiMalwareEventCommand
73
- desc "Access #{command_class.transport_class_string}s"
74
- command command_class.command_symbol do |c|
75
- command_class.define_list_command(c)
76
- command_class.define_schema_command(c)
77
- end
78
-
79
- desc 'Display API Version'
80
- command :api_version do |c|
81
- c.action do |global_options, options, args|
82
- Dsc::Command.new(global_options).print_api_version(options, args)
83
- end
84
- end
85
-
86
- desc 'Display Manager time'
87
- command :manager_time do |c|
88
-
89
- c.action do |global_options, options, args|
90
- Dsc::Command.new(global_options).print_manager_time(options, args)
91
- end
92
- end
93
36
 
94
37
  pre do |global, command, options, args|
95
38
  # Pre logic here
data/deepsecurity.gemspec CHANGED
@@ -17,14 +17,19 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency "savon"
19
19
  gem.add_dependency "ruby-cache"
20
-
21
20
  gem.add_dependency "gli"
22
21
  gem.add_dependency 'progressbar'
23
22
  gem.add_dependency "json"
24
23
 
24
+ gem.add_development_dependency 'rake'
25
25
  gem.add_development_dependency 'yard'
26
26
  gem.add_development_dependency 'redcarpet'
27
- gem.add_development_dependency 'github-markup'
27
+ # gem.add_development_dependency 'github-markup'
28
+
29
+ # gem.add_development_dependency 'facets' # , '2.8.4'
30
+ # gem.add_development_dependency 'ruby-termios' # you're gonna need this gem too, for some reason
31
+ # gem.add_development_dependency 'unroller'
32
+
28
33
 
29
34
  end
30
35
 
data/dsc.md CHANGED
@@ -61,16 +61,6 @@ The `host_detail list` command dislays a list of host details.
61
61
  SYNOPSIS
62
62
  dsc [global options] host_detail list [command options]
63
63
 
64
- COMMAND OPTIONS
65
- --fields=arg - A comma separated list of fields to display. (Available fields: anti_malware_classic_pattern_version, anti_malware_engine_version, anti_malware_intelli_trap_exception_version, anti_malware_intelli_trap_version,
66
- anti_malware_smart_scan_pattern_version, anti_malware_spyware_pattern_version, cloud_object_image_id, cloud_object_instance_id, cloud_object_internal_unique_id, cloud_object_security_group_ids, cloud_object_type,
67
- component_klasses, component_names, component_types, component_versions, description, display_name, external, external_id, host_group_id, host_group_name, host_interfaces, host_light, host_type, id,
68
- last_anit_malware_scheduled_scan, last_anti_malware_event, last_anti_malware_manual_scan, last_dpi_event, last_firewall_event, last_integrity_monitoring_event, last_ip_used, last_log_inspection_event,
69
- last_web_reputation_event, light, locked, name, overall_anti_malware_status, overall_dpi_status, overall_firewall_status, overall_integrity_monitoring_status, overall_last_recommendation_scan,
70
- overall_last_successful_communication, overall_last_successful_update, overall_last_update_required, overall_log_inspection_status, overall_status, overall_version, overall_web_reputation_status, platform,
71
- security_profile_id, security_profile_name, virtual_name, virtual_uuid) (default:
72
- name,display_name,anti_malware_classic_pattern_version,anti_malware_engine_version,anti_malware_intelli_trap_exception_version,anti_malware_intelli_trap_version,anti_malware_smart_scan_pattern_version,anti_malware_spyware_pattern_version,overall_last_successful_communication,platform,host_type,host_group_id)
73
-
74
64
  If you don't specify an explicit list of fields, the following fields are used by default:
75
65
 
76
66
  * name
@@ -96,12 +86,6 @@ The `anti_malware_event list`command displays a list of AntiMalware events.
96
86
  SYNOPSIS
97
87
  dsc [global options] anti_malware_event list [command options]
98
88
 
99
- COMMAND OPTIONS
100
- --fields=arg - A comma separated list of fields to display. (Available fields: anti_malware_config_id, anti_malware_event_id, end_time, error_code, host, host_id, infected_file_path, infection_source, log_date, malware_name,
101
- malware_type, protocol, quarantine_record_id, scan_action1, scan_action2, scan_result_action1, scan_result_action2, scan_type, spyware_items, start_time, summary_scan_result, tags) (default:
102
- host.name,host.display_name,log_date,start_time,end_time,scan_action1,scan_action2,summary_scan_result,scan_result_action1,scan_result_action2,malware_name,malware_type,infected_file_path,infection_source)
103
- --time_filter=arg - A filter specifying the time interval to query (One of last_hour, last_24_hours, last_7_days, last_day) (default: last_day)
104
-
105
89
  If you don't specify an explicit list of fields, the following fields are used by default:
106
90
 
107
91
  * host.name
@@ -126,13 +110,13 @@ Please note that if you don't specify a time filter all events of the previous d
126
110
 
127
111
  ### FIELDS
128
112
 
129
- The `--fields` option takes a list of comma-separated values of fields to display. You can check available fields usind the `schema` subcommand.
113
+ The `--fields` flag takes a list of comma-separated values of fields to display. You can check available fields usind the `schema` subcommand.
130
114
  You can also get further output by separating method calls with a dot `.`. E.g.: If the field itself is called `host_name` you can also
131
115
  specify `host_name.size` which would call the `size()` method returning the length of the String.
132
116
 
133
117
  ### TIME FILTER
134
118
 
135
- The `--time_filter` option allows you to specify the time to be queried. One of
119
+ The `--time_filter` flag allows you to specify the time to be queried. One of
136
120
 
137
121
  * last_hour
138
122
  * last_24_hours
@@ -142,6 +126,24 @@ The `--time_filter` option allows you to specify the time to be queried. One of
142
126
  Please note the difference between `last_24_hours` and `last_day`. `last_24_hours` returns events from the current time yesterday to now.
143
127
  `last_day` returns events from yesterday 00:00:00UTC to 23:59:59UTC.
144
128
 
129
+ ### DETAIL LEVEL
130
+
131
+ The `--detail_level` flag allows you to specify the ammount of data queried for some commands. Possible options are
132
+
133
+ * low
134
+ * medium
135
+ * high
136
+
137
+ Please note that this is especially interesting if you are querying lots of objects as this reduces the ammount of data
138
+ queried from the database as well as the network traffic.
139
+
140
+ Please also note that if certain fields are empty it might be worth using higher query levels if you need that data.
141
+
142
+ ### TIME FORMAT
143
+
144
+ The `--time_format` allows you to specify a `strftime()` compatible string to use for outputting date/time. Please check
145
+ http://www.ruby-doc.org/core-2.0/Time.html#method-i-strftime for possible parameters.
146
+
145
147
  # TIPS & TRICKS
146
148
 
147
149
  ## DEFINE ROLE/USER FOR SOAP ACCESS
data/lib/deepsecurity.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  # @author Udo Schneider <Udo.Schneider@homeaddress.de>
2
2
 
3
- # require "time"
4
- # require "cache"
5
- # require "active_support/core_ext"
3
+ require "logger"
6
4
 
7
5
  require "json"
8
6
 
@@ -10,12 +8,13 @@ require "savon_helper"
10
8
 
11
9
  require "deepsecurity/version"
12
10
 
13
- require "deepsecurity/ds_object"
14
11
  require "deepsecurity/enums"
15
12
 
16
13
  require "deepsecurity/exceptions/authentication_failed_exception"
17
14
  require "deepsecurity/exceptions/authentication_required_exception"
18
15
 
16
+ require "deepsecurity/soap_interface"
17
+
19
18
  require "deepsecurity/manager"
20
19
  require "deepsecurity/screenscraping"
21
20
 
@@ -43,16 +42,16 @@ require "deepsecurity/transport_objects/private/vulnerability"
43
42
 
44
43
  module DeepSecurity
45
44
 
46
- def self.logger
47
- if @logger.nil?
48
- @logger ||= Logger.new(STDOUT)
49
- @logger.level = Logger::INFO
50
- end
51
- @logger
52
- end
53
-
54
45
  def self.dsm
55
46
  Manager.current
56
47
  end
57
48
 
49
+ LOG_MAPPING = {
50
+ :debug => Logger::DEBUG,
51
+ :info => Logger::INFO,
52
+ :warn => Logger::WARN,
53
+ :error => Logger::ERROR,
54
+ :fatal => Logger::FATAL
55
+ }
56
+
58
57
  end
@@ -1,136 +1,82 @@
1
1
  # @author Udo Schneider <Udo.Schneider@homeaddress.de>
2
2
 
3
- require "savon"
4
- require "cache"
5
- # require "httpi"
6
- require "logger"
7
- # require "yaml"
8
-
9
3
  module DeepSecurity
10
4
 
11
- LOG_MAPPING = {
12
- :debug => Logger::DEBUG,
13
- :info => Logger::INFO,
14
- :warn => Logger::WARN,
15
- :error => Logger::ERROR,
16
- :fatal => Logger::FATAL
17
- }
18
-
19
- # This class represents the DeepSecurity Manager. It's the entry point for all further actions
20
- class Manager <DSObject
5
+ # This class represents the DeepSecurity Manager. It's the entry point for all further actions
6
+ class Manager < SavonHelper::CachingObject
21
7
 
22
- @@current = nil
23
-
24
- def self.current
25
- @@current
26
- end
8
+ # @!group High-Level SOAP Wrapper
27
9
 
28
- def reset
29
- @@current = nil
10
+ # Set connection parameters
11
+ # @param hostname [String] host to connect to
12
+ # @param port [Integer] port to connect to
13
+ # @param log_level [LOG_MAPPING] Log Level
14
+ def self.server(hostname, port=4119, log_level=nil, logger = nil)
15
+ default_logger = Logger.new(STDOUT)
16
+ default_logger.level = LOG_MAPPING[log_level] || Logger::INFO
17
+ self.new(DeepSecurity::SOAPInterface.new(hostname, port, logger || default_logger, log_level))
30
18
  end
31
19
 
32
- # Obtain a new wrapper around the DeepSecurity Manager SOAP API.
33
- def initialize(hostname, port=4119, log_level)
34
- @hostname = hostname
35
- @port = port
36
- super()
37
- @client = Savon.client(:wsdl => "https://#{hostname}:#{port}/webservice/Manager?WSDL",
38
- :convert_request_keys_to => :none, # or one of [:lower_camelcase, :upcase, :none]
39
- :ssl_verify_mode => :none,
40
- :logger => logger,
41
- :log_level => log_level,
42
- :log => (!log_level.nil?))
20
+ # @param interface [DeepSecurity::SOAPInterface] The initialized interface to direct further calls to.
21
+ def initialize(interface)
22
+ @interface = interface
23
+ @interface.manager = self
43
24
  end
44
25
 
45
- # @!group Request Helper
46
-
47
- # Send an authenticated WebUI Request to the Server for URL +url and return the response body
48
- def send_authenticated_http_get(path)
49
- logger.debug { "#{self.class}\##{__method__}(#{path.inspect})" }
50
- url = "https://#{@hostname}:#{@port}#{path}"
51
- request = HTTPI::Request.new(url)
52
- request.auth.ssl.verify_mode = :none
53
- request.headers = {
54
- "Cookie" => "sID=#{@sID}"
55
- }
56
- request.gzip
57
- response = HTTPI.get request
58
- response.body
59
- end
60
26
 
61
- # Send an authenticated WebUI Request to the Server for URL +url and return the response body
62
- def send_authenticated_http_post(path, body)
63
- logger.debug { "#{self.class}\##{__method__}(#{path.inspect})" }
64
- url = "https://#{@hostname}:#{@port}#{path}"
65
- request = HTTPI::Request.new(url)
66
- request.auth.ssl.verify_mode = :none
67
- request.headers = {
68
- "Cookie" => "sID=#{@sID}",
69
- "Content-Type" => "application/x-www-form-urlencoded"
70
- }
71
- request.gzip
72
- request.body = body
73
- response = HTTPI.post request
74
- response.body
27
+ # Authenticates a user within the given tenant, and returns a session ID for use when calling other methods of Manager.
28
+ # When no longer required, the session should be terminated by calling disconnect.
29
+ # @param tenant [String]
30
+ # @param username [String]
31
+ # @param password [String]
32
+ # @return [Manager] The current manager
33
+ def connect(tenant, username, password)
34
+ @sID = (tenant.blank? ? interface.authenticate(username, password) : interface.authenticateTenant(tenant, username, password)).to_s
35
+ self
36
+ rescue Savon::SOAPFault => error
37
+ fault = error.to_hash[:fault]
38
+ message = fault[:faultstring].to_s
39
+ message = fault[:detail][:exception_name].to_s if message.blank?
40
+ raise AuthenticationFailedException.new("(#{message})")
75
41
  end
76
42
 
77
- # @!endgroup
78
-
79
- # @!group Caching
80
-
81
- def cache
82
- @cache ||= Cache.new(nil, nil, 10000, 5*60)
43
+ # Ends an authenticated user session. The Web Service client should end the authentication session in all exit cases.
44
+ # @return [void]
45
+ def disconnect
46
+ interface.endSession() if authenticated?
83
47
  end
84
48
 
85
- # @!endgroup
86
-
87
- public
88
-
89
- # @!group High-Level SOAP Wrapper
90
-
91
49
  # Retrieves the Manager Web Service API version. Not the same as the Manager version.
92
50
  # @return [Integer] The Web Service API version.
93
51
  def api_version
94
- dsm.getApiVersion()
52
+ interface.getApiVersion().to_i
95
53
  end
96
54
 
97
55
  # Retrieve the Manager Web Service API version. Not the same as the Manager version.
98
56
  # @return [Time] Manager time as a language localized object.
99
57
  def manager_time
100
- dsm.getManagerTime()
58
+ Time.parse(interface.getManagerTime())
101
59
  end
102
60
 
103
- # Set connection parameters
104
- # @param [String] hostname host to connect to
105
- # @param [Integer] port port to connect to
106
- # @param [LOG_MAPPING] log_level Log Level
107
- def self.server(hostname, port=4119, log_level=nil)
108
- dsm = self.new(hostname, port, log_level)
109
- dsm.logger.level = LOG_MAPPING[log_level] unless log_level.nil?
110
- @@current = dsm
61
+ # @!endgroup
62
+
63
+ # Check if the session has been authenticated.
64
+ def authenticated?
65
+ !@sID.nil?
111
66
  end
112
67
 
113
- # Authenticates a user within the given tenant, and returns a session ID for use when calling other methods of Manager. When no longer required, the session should be terminated by calling endSession.
114
- # @param [String] tenant
115
- # @param [String] username
116
- # @param [String] password
117
- # @return [Manager] The current manager
118
- def connect(tenant, username, password)
119
- @sID = tenant.blank? ? authenticate(username, password) : authenticate_tenant(tenant, username, password)
120
- dsm
121
- rescue Savon::SOAPFault => error
122
- raise AuthenticationFailedException.new(error.to_hash[:fault][:faultstring].to_s)
68
+ def sID
69
+ raise DeepSecurity::AuthenticationRequiredException unless authenticated?
70
+ @sID
123
71
  end
124
72
 
125
- # Ends an authenticated user session. The Web Service client should end the authentication session in all exit cases.
126
- # @return [void]
127
- def disconnect
128
- dsm.end_session() if authenticated?
129
- dsm.reset
130
- nil
73
+ def interface
74
+ @interface
131
75
  end
132
76
 
133
- # @!endgroup
77
+ end
78
+
79
+ class SOAPInterface
134
80
 
135
81
  # @!group Low-Level SOAP Wrapper
136
82
 
@@ -144,7 +90,7 @@ module DeepSecurity
144
90
  # RETURNS
145
91
  # The Web Service API version.
146
92
  def getApiVersion
147
- send_soap(:get_api_version).to_i
93
+ send_soap(:get_api_version)
148
94
  end
149
95
 
150
96
  # Retrieve the Manager Web Service API version. Not the same as the Manager version.
@@ -157,7 +103,7 @@ module DeepSecurity
157
103
  # RETURNS
158
104
  # Manager time as a language localized object. For example, a Java client would return a Calendar object, and a C# client would return a DataTime object.
159
105
  def getManagerTime
160
- Time.parse(send_soap(:get_manager_time))
106
+ send_soap(:get_manager_time)
161
107
  end
162
108
 
163
109
  # Authenticates a user for and returns a session ID for use when calling other Web Service methods.
@@ -172,7 +118,7 @@ module DeepSecurity
172
118
  # RETURNS
173
119
  # Authenticated user session ID.
174
120
  def authenticate(username, password)
175
- send_soap(:authenticate, {:username => username, :password => password}).to_s
121
+ send_soap(:authenticate, {:username => username, :password => password})
176
122
  end
177
123
 
178
124
  # Authenticates a user within the given tenant, and returns a session ID for use when calling other methods of Manager. When no longer required, the session should be terminated by calling endSession.
@@ -187,8 +133,8 @@ module DeepSecurity
187
133
  #
188
134
  # RETURNS
189
135
  # Authenticated user session ID.
190
- def authenticate_tenant(tenantName, username, password)
191
- send_soap(:authenticate_tenant, {:tenantName => tenantName, :username => username, :password => password}).to_s
136
+ def authenticateTenant(tenantName, username, password)
137
+ send_soap(:authenticate_tenant, {:tenantName => tenantName, :username => username, :password => password})
192
138
  end
193
139
 
194
140
  # Ends an authenticated user session. The Web Service client should end the authentication session in all exit cases.
@@ -199,25 +145,12 @@ module DeepSecurity
199
145
  # PARAMETERS
200
146
  # sID Authentication session identifier ID.
201
147
  # RETURNS
202
- def end_session(sID = dsm.sID)
148
+ def endSession(sID = manager.sID)
203
149
  send_soap(:end_session, :sID => sID)
204
150
  end
205
151
 
206
152
  # @!endgroup
207
153
 
208
- # Check if the session has been authenticated.
209
- def authenticated?
210
- !@sID.nil?
211
- end
212
-
213
- def sID
214
- raise DeepSecurity::AuthenticationRequiredException unless authenticated?
215
- @sID
216
- end
217
-
218
- def client
219
- @client
220
- end
221
-
222
154
  end
155
+
223
156
  end