zaws 0.0.5 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +9 -18
- data/Gemfile +0 -0
- data/Gemfile.lock +26 -35
- data/Gemfile.lock.linux +69 -0
- data/Gemfile.lock.mac +81 -0
- data/Gemfile.lock.windows +77 -0
- data/LICENSE +0 -0
- data/README.md +11 -0
- data/Rakefile +1 -7
- data/archive/cloud_trail/cloud_trail.feature +124 -0
- data/bin/win_zaws.bat +2 -0
- data/lib/zaws.rb +54 -41
- data/lib/zaws/command/ai.rb +34 -0
- data/lib/zaws/command/bucket.rb +35 -0
- data/lib/zaws/command/cloud_trail.rb +43 -0
- data/lib/zaws/command/compute.rb +152 -87
- data/lib/zaws/command/config.rb +42 -0
- data/lib/zaws/command/elasticip.rb +19 -9
- data/lib/zaws/command/hosted_zone.rb +31 -18
- data/lib/zaws/command/iam.rb +37 -0
- data/lib/zaws/command/load_balancer.rb +54 -51
- data/lib/zaws/command/nessus.rb +41 -0
- data/lib/zaws/command/newrelic.rb +30 -0
- data/lib/zaws/command/route_table.rb +135 -122
- data/lib/zaws/command/security_group.rb +95 -82
- data/lib/zaws/command/subnet.rb +58 -46
- data/lib/zaws/command/sumo.rb +34 -0
- data/lib/zaws/command/vpc.rb +53 -0
- data/lib/zaws/external/awscli/awscli.rb +65 -0
- data/lib/zaws/external/awscli/commands.rb +10 -0
- data/lib/zaws/external/awscli/commands/aws.rb +40 -0
- data/lib/zaws/external/awscli/commands/ec2.rb +74 -0
- data/lib/zaws/external/awscli/commands/ec2/allocate_address.rb +42 -0
- data/lib/zaws/external/awscli/commands/ec2/assign_private_ip_addresses.rb +49 -0
- data/lib/zaws/external/awscli/commands/ec2/associate_address.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/associate_route_table.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/authorize_security_group_ingress.rb +70 -0
- data/lib/zaws/external/awscli/commands/ec2/create_route.rb +60 -0
- data/lib/zaws/external/awscli/commands/ec2/create_route_table.rb +40 -0
- data/lib/zaws/external/awscli/commands/ec2/create_security_group.rb +58 -0
- data/lib/zaws/external/awscli/commands/ec2/create_subnet.rb +62 -0
- data/lib/zaws/external/awscli/commands/ec2/create_tags.rb +53 -0
- data/lib/zaws/external/awscli/commands/ec2/create_vpc.rb +21 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_route.rb +54 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_route_table.rb +46 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_security_group.rb +46 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_subnet.rb +46 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_addresses.rb +41 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_images.rb +58 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_instances.rb +56 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_route_tables.rb +44 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_security_groups.rb +50 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_subnets.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_vpc_peering_connections.rb +23 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_vpcs.rb +26 -0
- data/lib/zaws/external/awscli/commands/ec2/disable_vgw_route_propagation.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/disassociate-address.rb +42 -0
- data/lib/zaws/external/awscli/commands/ec2/disassociate_route_table.rb +41 -0
- data/lib/zaws/external/awscli/commands/ec2/enable_vgw_route_propagation.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/filter.rb +115 -0
- data/lib/zaws/external/awscli/commands/ec2/modify_instance_attribute.rb +62 -0
- data/lib/zaws/external/awscli/commands/ec2/network_interfaces.rb +63 -0
- data/lib/zaws/external/awscli/commands/ec2/release_address.rb +42 -0
- data/lib/zaws/external/awscli/commands/ec2/revoke_security_group_ingress.rb +70 -0
- data/lib/zaws/external/awscli/commands/ec2/run_instances.rb +21 -0
- data/lib/zaws/external/awscli/commands/ec2/stop_instances.rb +21 -0
- data/lib/zaws/external/awscli/commands/ec2/terminate_instances.rb +40 -0
- data/lib/zaws/external/awscli/commands/ec2/unassign_private_ip_addresses.rb +49 -0
- data/lib/zaws/external/awscli/commands/elb.rb +19 -0
- data/lib/zaws/external/awscli/commands/elb/create_load_balancer.rb +64 -0
- data/lib/zaws/external/awscli/commands/elb/create_load_balancer_listeners.rb +47 -0
- data/lib/zaws/external/awscli/commands/elb/delete_load_balancer.rb +40 -0
- data/lib/zaws/external/awscli/commands/elb/delete_load_balancer_listeners.rb +49 -0
- data/lib/zaws/external/awscli/commands/elb/deregister_instances_with_load_balancer.rb +49 -0
- data/lib/zaws/external/awscli/commands/elb/describe_load_balancers.rb +30 -0
- data/lib/zaws/external/awscli/commands/elb/register_instances_with_load_balancer.rb +49 -0
- data/lib/zaws/external/awscli/commands/iam.rb +31 -0
- data/lib/zaws/external/awscli/commands/iam/GetPolicy.rb +21 -0
- data/lib/zaws/external/awscli/commands/iam/GetPolicyVersion.rb +21 -0
- data/lib/zaws/external/awscli/commands/iam/GetRolePolicy.rb +21 -0
- data/lib/zaws/external/awscli/commands/route53.rb +19 -0
- data/lib/zaws/external/awscli/commands/route53/list_hosted_zones.rb +30 -0
- data/lib/zaws/external/awscli/commands/route53/list_resource_record_sets.rb +41 -0
- data/lib/zaws/external/awscli/commands/s3/ls.rb +34 -0
- data/lib/zaws/external/awscli/commands/s3/mb.rb +41 -0
- data/lib/zaws/external/awscli/commands/s3/sync.rb +48 -0
- data/lib/zaws/external/awscli/credentials.rb +22 -0
- data/lib/zaws/external/awscli/data.rb +10 -0
- data/lib/zaws/external/awscli/data/ec2.rb +33 -0
- data/lib/zaws/external/awscli/data/ec2/instance.rb +162 -0
- data/lib/zaws/external/awscli/data/ec2/security_group.rb +51 -0
- data/lib/zaws/external/awscli/data/ec2/subnet.rb +59 -0
- data/lib/zaws/external/awscli/data/ec2/vpc.rb +85 -0
- data/lib/zaws/external/awscli/data/iam.rb +34 -0
- data/lib/zaws/external/awscli/data/iam/policy.rb +42 -0
- data/lib/zaws/external/awscli/data/iam/policy_document.rb +52 -0
- data/lib/zaws/external/awscli/data/iam/policy_version.rb +42 -0
- data/lib/zaws/external/awscli/data/iam/role_policy.rb +52 -0
- data/lib/zaws/external/awscli/generators/result/ec2/addresses.rb +70 -0
- data/lib/zaws/external/awscli/generators/result/ec2/allocation_id.rb +39 -0
- data/lib/zaws/external/awscli/generators/result/ec2/association_id.rb +29 -0
- data/lib/zaws/external/awscli/generators/result/ec2/images.rb +46 -0
- data/lib/zaws/external/awscli/generators/result/ec2/instances.rb +57 -0
- data/lib/zaws/external/awscli/generators/result/ec2/ip_permissions.rb +70 -0
- data/lib/zaws/external/awscli/generators/result/ec2/network_interfaces.rb +53 -0
- data/lib/zaws/external/awscli/generators/result/ec2/private_ip_addresses.rb +41 -0
- data/lib/zaws/external/awscli/generators/result/ec2/route_tables.rb +80 -0
- data/lib/zaws/external/awscli/generators/result/ec2/routes.rb +58 -0
- data/lib/zaws/external/awscli/generators/result/ec2/security_groups.rb +73 -0
- data/lib/zaws/external/awscli/generators/result/ec2/subnets.rb +88 -0
- data/lib/zaws/external/awscli/generators/result/ec2/tags.rb +34 -0
- data/lib/zaws/external/awscli/generators/result/ec2/virtual_gateway.rb +32 -0
- data/lib/zaws/external/awscli/generators/result/elb/listeners.rb +65 -0
- data/lib/zaws/external/awscli/generators/result/elb/load_balancers.rb +61 -0
- data/lib/zaws/external/awscli/generators/result/route53/hosted_zones.rb +52 -0
- data/lib/zaws/external/awscli/regions.rb +13 -0
- data/lib/zaws/external/nessusapi/data/agents.rb +36 -0
- data/lib/zaws/external/nessusapi/data/scanners.rb +35 -0
- data/lib/zaws/external/nessusapi/nessusapi.rb +57 -0
- data/lib/zaws/external/nessusapi/reources.rb +10 -0
- data/lib/zaws/external/nessusapi/resources/agents.rb +18 -0
- data/lib/zaws/external/nessusapi/resources/agents/list.rb +20 -0
- data/lib/zaws/external/nessusapi/resources/scanners.rb +18 -0
- data/lib/zaws/external/nessusapi/resources/scanners/list.rb +20 -0
- data/lib/zaws/external/newrelicapi/data/servers.rb +36 -0
- data/lib/zaws/external/newrelicapi/newrelic_client.rb +64 -0
- data/lib/zaws/external/newrelicapi/newrelic_creds.rb +60 -0
- data/lib/zaws/external/newrelicapi/newrelicapi.rb +46 -0
- data/lib/zaws/external/newrelicapi/resources/servers.rb +18 -0
- data/lib/zaws/external/newrelicapi/resources/servers/list.rb +20 -0
- data/lib/zaws/external/sumoapi/data/collectors.rb +35 -0
- data/lib/zaws/external/sumoapi/data/sources.rb +35 -0
- data/lib/zaws/external/sumoapi/resources/collectors.rb +18 -0
- data/lib/zaws/external/sumoapi/resources/collectors/list.rb +20 -0
- data/lib/zaws/external/sumoapi/resources/sources.rb +18 -0
- data/lib/zaws/external/sumoapi/resources/sources/list.rb +20 -0
- data/lib/zaws/external/sumoapi/sumo_client.rb +63 -0
- data/lib/zaws/external/sumoapi/sumo_creds.rb +67 -0
- data/lib/zaws/external/sumoapi/sumoapi.rb +56 -0
- data/lib/zaws/helper/data_lattice.rb +22 -0
- data/lib/zaws/helper/filestore.rb +48 -0
- data/lib/zaws/helper/filter.rb +15 -0
- data/lib/zaws/helper/inifile.rb +632 -0
- data/lib/zaws/helper/nessus_client.rb +143 -0
- data/lib/zaws/helper/nessus_creds.rb +67 -0
- data/lib/zaws/helper/option.rb +14 -15
- data/lib/zaws/helper/output.rb +81 -29
- data/lib/zaws/helper/process_hash.rb +47 -0
- data/lib/zaws/helper/shell.rb +0 -0
- data/lib/zaws/helper/verbose.rb +15 -0
- data/lib/zaws/helper/zfile.rb +8 -8
- data/lib/zaws/services/ai.rb +35 -0
- data/lib/zaws/services/ai/query.rb +135 -0
- data/lib/zaws/services/aws.rb +41 -0
- data/lib/zaws/services/chef.rb +0 -0
- data/lib/zaws/services/cloud_trail.rb +76 -0
- data/lib/zaws/services/config.rb +31 -0
- data/lib/zaws/services/ec2.rb +47 -0
- data/lib/zaws/services/ec2/compute.rb +352 -0
- data/lib/zaws/services/ec2/elasticip.rb +82 -0
- data/lib/zaws/services/ec2/route_table.rb +210 -0
- data/lib/zaws/services/ec2/security_group.rb +186 -0
- data/lib/zaws/services/ec2/subnet.rb +111 -0
- data/lib/zaws/services/ec2/vpc.rb +69 -0
- data/lib/zaws/{elb.rb → services/elb.rb} +3 -2
- data/lib/zaws/services/elb/load_balancer.rb +160 -0
- data/lib/zaws/services/iam.rb +25 -0
- data/lib/zaws/services/iam/policy.rb +25 -0
- data/lib/zaws/services/iam/role.rb +23 -0
- data/lib/zaws/services/nessus.rb +24 -0
- data/lib/zaws/services/nessus/agents.rb +19 -0
- data/lib/zaws/services/nessus/scanners.rb +19 -0
- data/lib/zaws/services/newrelic.rb +21 -0
- data/lib/zaws/services/newrelic/servers.rb +19 -0
- data/lib/zaws/{route53.rb → services/route53.rb} +1 -1
- data/lib/zaws/services/route53/hosted_zone.rb +36 -0
- data/lib/zaws/services/s3.rb +15 -0
- data/lib/zaws/services/s3/bucket.rb +42 -0
- data/lib/zaws/services/sumo.rb +21 -0
- data/lib/zaws/services/sumo/collectors.rb +19 -0
- data/lib/zaws/services/vmware.rb +0 -0
- data/lib/zaws/version.rb +1 -1
- data/shove_all.sh +6 -0
- data/shove_all_mac.sh +6 -0
- data/shove_all_windows.sh +6 -0
- data/spec/spec_helper.rb +0 -0
- data/spec/zaws/command/ec2/compute/assoc_security_group_spec.rb +135 -0
- data/spec/zaws/command/ec2/compute/compute_spec.rb +321 -0
- data/spec/zaws/command/ec2/compute/images_spec.rb +69 -0
- data/spec/zaws/command/ec2/compute/management_spec.rb +364 -0
- data/spec/zaws/command/ec2/compute/network_spec.rb +93 -0
- data/spec/zaws/command/ec2/compute/node_spec.rb +70 -0
- data/spec/zaws/command/ec2/compute/secondary_ip_spec.rb +212 -0
- data/spec/zaws/command/ec2/compute/storage_spec.rb +63 -0
- data/spec/zaws/command/ec2/elasticip_spec.rb +271 -0
- data/spec/zaws/command/ec2/route_table_spec.rb +844 -0
- data/spec/zaws/command/ec2/security_group_spec.rb +710 -0
- data/spec/zaws/command/ec2/subnet_spec.rb +273 -0
- data/spec/zaws/command/ec2/vpc_spec.rb +180 -0
- data/spec/zaws/command/elb/load_balancer_spec.rb +633 -0
- data/spec/zaws/command/iam/policy_spec.rb +101 -0
- data/spec/zaws/command/iam/role_policy_spec.rb +35 -0
- data/spec/zaws/command/route53/hosted_zone_spec.rb +100 -0
- data/spec/zaws/command/s3/bucket_spec.rb +70 -0
- data/spec/zaws/external/awscli/data/ec2/instance_spec.rb +90 -0
- data/spec/zaws/external/awscli/data/iam/policy_document_spec.rb +56 -0
- data/spec/zaws/external/awscli/data/iam/role_policy_spec.rb +54 -0
- data/spec/zaws/external/awscli/get_aws_version_spec.rb +18 -0
- data/spec/zaws/helper/option_spec.rb +54 -0
- data/spec/zaws/helper/output_spec.rb +144 -0
- data/spec/zaws/helper/process_hash_spec.rb +48 -0
- data/spec/zaws/helper/shell_spec.rb +56 -0
- data/spec/zaws/nessus/scanners.json +0 -0
- data/spec/zaws/version_spec.rb +18 -0
- data/zaws.gemspec +1 -3
- metadata +260 -189
- data/feature/compute/assoc_security_group.feature +0 -55
- data/feature/compute/compute.feature +0 -138
- data/feature/compute/secondary_ip.feature +0 -107
- data/feature/compute/view.feature +0 -23
- data/feature/compute/view_images.feature +0 -24
- data/feature/elasticip/elasticip.feature +0 -138
- data/feature/elasticip/view.feature +0 -18
- data/feature/hosted_zone/view.feature +0 -17
- data/feature/hosted_zone/view_record.feature +0 -29
- data/feature/load_balancer/instance_registration.feature +0 -120
- data/feature/load_balancer/listener.feature +0 -86
- data/feature/load_balancer/load_balancer.feature +0 -101
- data/feature/load_balancer/view.feature +0 -18
- data/feature/route_table/assoc_subnet.feature +0 -128
- data/feature/route_table/route_propagation.feature +0 -93
- data/feature/route_table/route_table.feature +0 -91
- data/feature/route_table/route_to_gateway.feature +0 -69
- data/feature/route_table/route_to_instance.feature +0 -115
- data/feature/route_table/view.feature +0 -25
- data/feature/security_group/ingress_cidr.feature +0 -144
- data/feature/security_group/ingress_group.feature +0 -184
- data/feature/security_group/security_group.feature +0 -107
- data/feature/security_group/view.feature +0 -23
- data/feature/subnet/subnet.feature +0 -94
- data/feature/subnet/view.feature +0 -24
- data/feature/support/env.rb +0 -14
- data/feature/version.feature +0 -6
- data/lib/zaws/aws.rb +0 -26
- data/lib/zaws/ec2.rb +0 -40
- data/lib/zaws/ec2/compute.rb +0 -247
- data/lib/zaws/ec2/elasticip.rb +0 -79
- data/lib/zaws/ec2/route_table.rb +0 -207
- data/lib/zaws/ec2/security_group.rb +0 -154
- data/lib/zaws/ec2/subnet.rb +0 -109
- data/lib/zaws/elb/load_balancer.rb +0 -157
- data/lib/zaws/route53/hosted_zone.rb +0 -36
- data/spec/zaws/ec2/compute/add_volume_spec.rb +0 -39
- data/spec/zaws/ec2/compute/block_device_mapping_spec.rb +0 -31
- data/spec/zaws/ec2/compute/instance_id_by_external_id_spec.rb +0 -23
- data/spec/zaws/ec2/compute/instance_ping_spec.rb +0 -34
- data/spec/zaws/ec2/compute/instance_running_spec.rb +0 -47
- data/spec/zaws/ec2/compute/network_interface_json_spec.rb +0 -57
- data/spec/zaws/ec2/compute/nosdcheck_spec.rb +0 -17
- data/spec/zaws/ec2/compute/tag_instance_spec.rb +0 -21
- data/spec/zaws/ec2/security_group/id_by_name_spec.rb +0 -32
- data/spec/zaws/ec2/subnet/available_spec.rb +0 -22
- data/spec/zaws/ec2/subnet/declare_spec.rb +0 -31
- data/spec/zaws/ec2/subnet/exists_spec.rb +0 -33
- data/spec/zaws/ec2/subnet/id_array_by_cidrblock_array_spec.rb +0 -48
- data/spec/zaws/ec2/subnet/id_by_cidrblock_spec.rb +0 -35
- data/spec/zaws/ec2/subnet/id_by_ip_spec.rb +0 -42
- data/spec/zaws/ec2/subnet/view_spec.rb +0 -34
- data/spec/zaws/elb/load_balancer/calculated_listener_spec.rb +0 -18
- data/spec/zaws/helper/option/absent_spec.rb +0 -14
- data/spec/zaws/helper/option/exclusive_spec.rb +0 -14
- data/spec/zaws/helper/option/exists_spec.rb +0 -18
- data/spec/zaws/helper/option/minimum_spec.rb +0 -14
- data/spec/zaws/helper/output/binary_nagios_check_spec.rb +0 -19
- data/spec/zaws/helper/output/colorize_spec.rb +0 -30
- data/spec/zaws/helper/output/opt_exclusive_spec.rb +0 -14
- data/spec/zaws/helper/output/opt_minimum_spec.rb +0 -15
- data/spec/zaws/helper/output/opt_required_spec.rb +0 -12
- data/spec/zaws/helper/shell/cli_spec.rb +0 -33
- data/spec/zaws/helper/shell/if_then_spec.rb +0 -24
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'excon'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module ZAWS
|
5
|
+
module Helper
|
6
|
+
class NessusClient
|
7
|
+
|
8
|
+
autoload :NessusCreds, "zaws/helper/nessus_creds"
|
9
|
+
|
10
|
+
# @param [NessusClient::Creds] creds
|
11
|
+
def initialize(creds)
|
12
|
+
@creds = creds
|
13
|
+
end
|
14
|
+
|
15
|
+
def url
|
16
|
+
@creds.url
|
17
|
+
end
|
18
|
+
|
19
|
+
# Make a GET request expecting a JSON response.
|
20
|
+
def get(path, query = {}, options = {})
|
21
|
+
# Handle nil or empty Array
|
22
|
+
options[:query] = query.to_h if query
|
23
|
+
options[:idempotent] = true
|
24
|
+
json_request('GET', path, options)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Make a POST request expecting a JSON response.
|
28
|
+
def post(path, body, options = {})
|
29
|
+
options[:body] = body
|
30
|
+
json_request('POST', path, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Make a PUT request expecting a JSON response.
|
34
|
+
def put(path, body, options = {})
|
35
|
+
options[:body] = body
|
36
|
+
json_request('PUT', path, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete(path, options = {})
|
40
|
+
options[:idempotent] = true
|
41
|
+
json_request('DELETE', path, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def json_request(method, path, options = {})
|
45
|
+
if options[:body] && !options[:body].instance_of?(String)
|
46
|
+
options[:body] = options[:body].to_json
|
47
|
+
end
|
48
|
+
options[:headers] ||= {}
|
49
|
+
options[:headers]['Content-Type'] = 'application/json'
|
50
|
+
response = request(method, path, options)
|
51
|
+
JSON.parse(response.body) if (response.body.length > 0 && response.headers['content-type'].match(/json/))
|
52
|
+
end
|
53
|
+
|
54
|
+
def request(method, path, options = {})
|
55
|
+
connection = Excon.new(@creds.url)
|
56
|
+
options[:expects] ||= [200]
|
57
|
+
options[:method] = method
|
58
|
+
options[:path] = path
|
59
|
+
options[:headers] ||= {}
|
60
|
+
options[:headers]['X-ApiKeys'] = "accessKey=#{@creds.access_key}; secretKey=#{@creds.secret_key}"
|
61
|
+
connection.request(options)
|
62
|
+
end
|
63
|
+
#
|
64
|
+
# # Export and download a scan result
|
65
|
+
# #
|
66
|
+
# # @scan_id
|
67
|
+
# # @body
|
68
|
+
# # A hash to be used for the initial request payload.
|
69
|
+
# # @return String
|
70
|
+
# # The filepath of the file that was downloaded.
|
71
|
+
# def export_download_scan(scan_id, body = {}, download_directory = '', history_id = nil)
|
72
|
+
# body = {
|
73
|
+
# 'format' => 'pdf',
|
74
|
+
# 'chapters' => ['vuln_hosts_summary'],
|
75
|
+
# }.merge(body)
|
76
|
+
# fail("Invalid format #{body['format']}") unless ['nessus', 'csv', 'db', 'html', 'pdf'].include?(body['format'])
|
77
|
+
# diff = body['chapters'] - %w(vuln_hosts_summary vuln_by_host compliance_exec remediations vuln_by_plugin compliance)
|
78
|
+
# fail("Invalid chapter list #{body['chapters'].inspect}") if diff.length > 0
|
79
|
+
# body['chapters'] = body['chapters'].join(';')
|
80
|
+
# options = {}
|
81
|
+
# options[:query] = {'history_id' => history_id} if history_id
|
82
|
+
# data = post("/scans/#{scan_id}/export", body, options)
|
83
|
+
# file_id = data['file']
|
84
|
+
# fail "Invalid response to export" unless file_id
|
85
|
+
# NessusClient.retry do
|
86
|
+
# data = get("/scans/#{scan_id}/export/#{file_id}/status")
|
87
|
+
# data['status'] == 'ready'
|
88
|
+
# end
|
89
|
+
# # Use request() since we the response is a file, not JSON
|
90
|
+
# response = request('GET', "/scans/#{scan_id}/export/#{file_id}/download")
|
91
|
+
# match = response.headers['content-disposition'].match(/attachment; filename="([^"]+)"/)
|
92
|
+
# fail 'Invalid download response' unless match
|
93
|
+
# target_filename = File.join(download_directory, match[1])
|
94
|
+
# bytes = File.write(target_filename, response.body)
|
95
|
+
# content_length = response.headers['content-length'].to_i
|
96
|
+
# fail "File has wrong number of bytes #{bytes} vs #{content_length} in #{target_filename}" unless bytes == content_length
|
97
|
+
# target_filename
|
98
|
+
# end
|
99
|
+
|
100
|
+
# class TimeoutException < RuntimeError
|
101
|
+
# end
|
102
|
+
#
|
103
|
+
# # Retry a block of code multiple times until it returns true, or until
|
104
|
+
# # time limit ais reached. This always runs the block at least once.
|
105
|
+
# #
|
106
|
+
# # Options:
|
107
|
+
# #
|
108
|
+
# # [:delay] Sleep the given number of seconds between each try.
|
109
|
+
# # The default to sleep 2 seconds.
|
110
|
+
# #
|
111
|
+
# # [:timeout] Don't try for longer than the given number of seconds.
|
112
|
+
# #
|
113
|
+
# # [:message] A message that describes what is being attempted.
|
114
|
+
# #
|
115
|
+
# # [:stdout] An IO object to write messages to. Defaults to $stdout.
|
116
|
+
# #
|
117
|
+
# def self.retry(opts = {}, &blk)
|
118
|
+
# opts = {
|
119
|
+
# delay: 2,
|
120
|
+
# timeout: 30,
|
121
|
+
# stdout: $stdout,
|
122
|
+
# }.merge(opts)
|
123
|
+
#
|
124
|
+
# d = opts[:delay]
|
125
|
+
# io = opts[:stdout]
|
126
|
+
# times = 0
|
127
|
+
# start_time = Time.now.to_f
|
128
|
+
# stop_time = Time.now.to_i + opts[:timeout]
|
129
|
+
# io.puts "Waiting for: #{opts[:message]}" if opts[:message]
|
130
|
+
# begin
|
131
|
+
# sleep(d) if times > 0
|
132
|
+
# times += 1
|
133
|
+
# result = blk.call(times)
|
134
|
+
# if (!result) &&(Time.now.to_f - start_time) >= opts[:timeout]
|
135
|
+
# raise TimeoutException.new("Timeout after #{opts[:timeout]} sec.")
|
136
|
+
# end
|
137
|
+
# io.puts "+ retry: #{stop_time-Time.now.to_i} secs left"
|
138
|
+
# end while (!result)
|
139
|
+
# result
|
140
|
+
# end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module ZAWS
|
4
|
+
module Helper
|
5
|
+
class NessusCreds
|
6
|
+
# Simple container for credentials
|
7
|
+
class Creds
|
8
|
+
|
9
|
+
# @param [String] nessus_url
|
10
|
+
# @param [String] access_key
|
11
|
+
# @param [String] secret_key
|
12
|
+
def initialize(nessus_url, access_key, secret_key)
|
13
|
+
@creds = {}
|
14
|
+
@creds[:url] = nessus_url
|
15
|
+
@creds[:access_key] = access_key
|
16
|
+
@creds[:secret_key] = secret_key
|
17
|
+
end
|
18
|
+
|
19
|
+
def url
|
20
|
+
fetch_creds[:url]
|
21
|
+
end
|
22
|
+
|
23
|
+
def access_key
|
24
|
+
fetch_creds[:access_key]
|
25
|
+
end
|
26
|
+
|
27
|
+
def secret_key
|
28
|
+
fetch_creds[:secret_key]
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def fetch_creds
|
34
|
+
# Nothing to do in the base class
|
35
|
+
@creds
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Subclass that loads creds from a YAML file.
|
40
|
+
class Creds::YamlFile < Creds
|
41
|
+
FILENAME = '.nessus.yml'
|
42
|
+
|
43
|
+
def initialize(home)
|
44
|
+
@creds_file = File.join(home, FILENAME)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def fetch_creds
|
50
|
+
unless @creds
|
51
|
+
fail("Missing file #{@creds_file}") unless File.exist?(@creds_file)
|
52
|
+
file_creds = YAML.load(File.read(@creds_file))
|
53
|
+
file_creds ||= {}
|
54
|
+
['url', 'secretKey', 'accessKey'].each do |key|
|
55
|
+
fail("Missing #{key} value in #{@creds_file}") unless file_creds[key]
|
56
|
+
end
|
57
|
+
@creds = {}
|
58
|
+
@creds[:url] = file_creds['url']
|
59
|
+
@creds[:access_key] = file_creds['accessKey']
|
60
|
+
@creds[:secret_key] = file_creds['secretKey']
|
61
|
+
end
|
62
|
+
@creds
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/zaws/helper/option.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
|
-
|
2
1
|
module ZAWS
|
3
2
|
module Helper
|
4
|
-
|
3
|
+
class Option
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def self.exists?(optarr, opt_hash)
|
6
|
+
optarr.all? { |opt| opt_hash[opt] }
|
7
|
+
end
|
9
8
|
|
10
|
-
def self.absent(optarr,opt_hash)
|
11
|
-
optarr.inject([]) { |missing,opt| opt_hash[opt] ? missing : missing << opt }
|
12
|
-
|
9
|
+
def self.absent(optarr, opt_hash)
|
10
|
+
optarr.inject([]) { |missing, opt| opt_hash[opt] ? missing : missing << opt }
|
11
|
+
end
|
13
12
|
|
14
|
-
def self.exclusive?(optarr,opt_hash)
|
15
|
-
|
16
|
-
|
13
|
+
def self.exclusive?(optarr, opt_hash)
|
14
|
+
(optarr.inject(0) { |total, opt| opt_hash[opt] ? total + 1 : total }) <= 1
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def self.minimum?(min, optarr, opt_hash)
|
18
|
+
(optarr.inject(0) { |total, opt| opt_hash[opt] ? total + 1 : total }) >= min
|
19
|
+
end
|
21
20
|
|
22
|
-
|
21
|
+
end
|
23
22
|
end
|
24
23
|
end
|
data/lib/zaws/helper/output.rb
CHANGED
@@ -1,46 +1,98 @@
|
|
1
|
+
require 'json'
|
1
2
|
|
2
3
|
module AWS_consts
|
3
4
|
# Color codes http://kpumuk.info/ruby-on-rails/colorizing-console-ruby-script-output/
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
COLOR_RED=31
|
6
|
+
COLOR_GREEN=32
|
7
|
+
COLOR_YELLOW=33
|
8
|
+
COLOR_DEFAULT=39
|
9
|
+
COLOR_BLUE=34
|
10
|
+
COLOR_CYAN=36
|
10
11
|
end
|
11
12
|
|
12
13
|
module ZAWS
|
13
14
|
module Helper
|
14
|
-
|
15
|
+
class Output
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def self.out_nagios_ok(output, text)
|
18
|
+
output.puts colorize(text, AWS_consts::COLOR_GREEN) if output
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def self.out_nagios_critical(output, text)
|
22
|
+
output.puts colorize(text, AWS_consts::COLOR_RED) if output
|
23
|
+
end
|
23
24
|
|
24
|
-
def self.
|
25
|
+
def self.out_no_op(output, text)
|
26
|
+
output.puts colorize(text, AWS_consts::COLOR_GREEN) if output
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.out_change(output, text)
|
30
|
+
output.puts colorize(text, AWS_consts::COLOR_YELLOW) if output
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.return_change(text)
|
34
|
+
return colorize(text, AWS_consts::COLOR_YELLOW)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.return_no_op( text)
|
38
|
+
return colorize(text, AWS_consts::COLOR_GREEN)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.colorize(text, color_code)
|
42
|
+
"\e[#{color_code}m#{text}\e[0m"
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.opt_required(output, opt_arr)
|
46
|
+
opt_arr.each { |opt| output.puts(" --#{opt} required!") }
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.opt_exclusive(output, opt_arr)
|
25
50
|
output.puts(" These options cannot be combined:")
|
26
|
-
|
27
|
-
|
51
|
+
opt_arr.each { |opt| output.puts(" --#{opt}") }
|
52
|
+
end
|
28
53
|
|
29
|
-
def self.opt_minimum(output,min,opt_arr)
|
54
|
+
def self.opt_minimum(output, min, opt_arr)
|
30
55
|
output.puts(" At mininum, #{min} of the following is required:")
|
31
|
-
|
32
|
-
|
56
|
+
opt_arr.each { |opt| output.puts(" --#{opt}") }
|
57
|
+
end
|
33
58
|
|
34
|
-
def self.binary_nagios_check(ok_condition,ok_msg,critical_msg,textout=nil)
|
59
|
+
def self.binary_nagios_check(ok_condition, ok_msg, critical_msg, textout=nil)
|
35
60
|
if ok_condition
|
36
|
-
textout
|
37
|
-
|
38
|
-
|
39
|
-
textout
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
61
|
+
out_nagios_ok(textout, ok_msg) if textout
|
62
|
+
return 0
|
63
|
+
else
|
64
|
+
out_nagios_critical(textout, critical_msg) if textout
|
65
|
+
return 2
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.cloudtrail(json_data, format = "csv")
|
70
|
+
parsed = JSON.parse(json_data)
|
71
|
+
records = parsed["Records"]
|
72
|
+
|
73
|
+
str_out = ""
|
74
|
+
if format == "csv"
|
75
|
+
records.each do |record|
|
76
|
+
str_out << "#{record["userIdentity"]["userName"]}, "
|
77
|
+
str_out << "#{record["eventTime"]}, "
|
78
|
+
str_out << "#{record["eventSource"]}, "
|
79
|
+
str_out << "#{record["eventName"]}"
|
80
|
+
|
81
|
+
if record["errorCode"]
|
82
|
+
str_out << ", "
|
83
|
+
str_out << "#{record["errorCode"]}, "
|
84
|
+
str_out << "#{record["errorMessage"]}"
|
85
|
+
end
|
86
|
+
|
87
|
+
str_out << "\n"
|
88
|
+
end
|
89
|
+
elsif format == "raw"
|
90
|
+
str_out=json_data
|
91
|
+
end
|
92
|
+
|
93
|
+
return str_out
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
45
97
|
end
|
46
98
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module ZAWS
|
2
|
+
module Helper
|
3
|
+
class ProcessHash
|
4
|
+
def self.keep(target, list_of_strings)
|
5
|
+
result=''
|
6
|
+
if target.instance_of?(Hash)
|
7
|
+
target.each do |k, v|
|
8
|
+
list_of_strings.each do |x|
|
9
|
+
if k.downcase.include? x.downcase
|
10
|
+
result = {} if result.eql?('')
|
11
|
+
result[k]=v
|
12
|
+
end
|
13
|
+
end
|
14
|
+
if result.eql?('')
|
15
|
+
recurse=self.keep(v, list_of_strings)
|
16
|
+
end
|
17
|
+
if !recurse.nil? and !recurse.eql?('')
|
18
|
+
result = {} if result.eql?('')
|
19
|
+
result[k]=recurse
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
if target.instance_of?(String)
|
24
|
+
list_of_strings.each do |x|
|
25
|
+
if target.downcase.include? x.downcase
|
26
|
+
result=target
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
if target.instance_of?(Array)
|
31
|
+
target.each do |y|
|
32
|
+
iterate=self.keep(y, list_of_strings)
|
33
|
+
if !iterate.nil? and !iterate.eql?('')
|
34
|
+
result = [] if result.eql?('')
|
35
|
+
result << iterate
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
if result.nil?
|
40
|
+
return ''
|
41
|
+
end
|
42
|
+
return result
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
data/lib/zaws/helper/shell.rb
CHANGED
File without changes
|
data/lib/zaws/helper/zfile.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module ZAWS
|
2
2
|
module Helper
|
3
|
-
|
3
|
+
class ZFile
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
# This prepend function not currently unit tested,
|
6
|
+
# see "thor/spec/actions/file_manipulation_spec"
|
7
|
+
# for ideas on how to accomplish this.
|
8
|
+
def prepend(command, description, filepath)
|
9
9
|
new_file=filepath + ".new"
|
10
10
|
File.open(new_file, 'w') do |fo|
|
11
11
|
fo.puts description
|
@@ -14,10 +14,10 @@ module ZAWS
|
|
14
14
|
fo.puts li
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
18
|
-
|
17
|
+
File.rename(new_file, filepath)
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
end
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|