censu 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/.codeclimate.yml +13 -0
- data/.document +3 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.rubocop.yml +166 -0
- data/.travis.yml +12 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +4 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +7 -0
- data/README.md +76 -0
- data/Rakefile +21 -0
- data/censys.gemspec +28 -0
- data/lib/censys.rb +2 -0
- data/lib/censys/api.rb +254 -0
- data/lib/censys/autonomous_system.rb +43 -0
- data/lib/censys/certificate.rb +31 -0
- data/lib/censys/document.rb +48 -0
- data/lib/censys/document/has_asn.rb +16 -0
- data/lib/censys/document/has_location.rb +16 -0
- data/lib/censys/document/has_services.rb +21 -0
- data/lib/censys/exceptions.rb +16 -0
- data/lib/censys/ipv4.rb +26 -0
- data/lib/censys/location.rb +54 -0
- data/lib/censys/report.rb +1 -0
- data/lib/censys/report/metadata.rb +41 -0
- data/lib/censys/report/response.rb +54 -0
- data/lib/censys/search.rb +1 -0
- data/lib/censys/search/certificate.rb +19 -0
- data/lib/censys/search/ipv4.rb +18 -0
- data/lib/censys/search/metadata.rb +33 -0
- data/lib/censys/search/response.rb +124 -0
- data/lib/censys/search/result.rb +49 -0
- data/lib/censys/search/website.rb +18 -0
- data/lib/censys/version.rb +4 -0
- data/lib/censys/website.rb +30 -0
- data/spec/censys_spec.rb +8 -0
- data/spec/fixtures/vcr_cassettes/Censys_API/_report/certificates/should_return_certificate_response.yml +49 -0
- data/spec/fixtures/vcr_cassettes/Censys_API/_report/ipv4/should_return_ipv4_response.yml +52 -0
- data/spec/fixtures/vcr_cassettes/Censys_API/_report/websites/should_return_website_response.yml +49 -0
- data/spec/fixtures/vcr_cassettes/Censys_API/_search/certificates/should_return_Certificate_response.yml +397 -0
- data/spec/fixtures/vcr_cassettes/Censys_API/_search/ipv4/should_return_IPv4_response.yml +606 -0
- data/spec/fixtures/vcr_cassettes/Censys_API/_search/websites/should_return_Website_response.yml +112 -0
- data/spec/fixtures/vcr_cassettes/Censys_API/_view/certificates/should_return_Certificate_response.yml +143 -0
- data/spec/fixtures/vcr_cassettes/Censys_API/_view/ipv4/should_return_IPv4_response.yml +176 -0
- data/spec/fixtures/vcr_cassettes/Censys_API/_view/websites/should_return_Website_response.yml +1020 -0
- data/spec/report_spec.rb +60 -0
- data/spec/search_spec.rb +49 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/view_spec.rb +48 -0
- metadata +219 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
module Censys
|
2
|
+
class AutonomousSystem
|
3
|
+
# @return [String]
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
# @return [String]
|
7
|
+
attr_reader :rir
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
attr_reader :routed_prefix
|
11
|
+
|
12
|
+
# @return [String]
|
13
|
+
attr_reader :country_code
|
14
|
+
|
15
|
+
# @return [Array<Integer>]
|
16
|
+
attr_reader :path
|
17
|
+
|
18
|
+
# @return [String]
|
19
|
+
attr_reader :organization
|
20
|
+
|
21
|
+
# @return [Integer]
|
22
|
+
attr_reader :asn
|
23
|
+
|
24
|
+
# @return [String]
|
25
|
+
attr_reader :description
|
26
|
+
|
27
|
+
#
|
28
|
+
# Initializes the Autonomous System (AS) information.
|
29
|
+
#
|
30
|
+
# @param [Hash{String => Object}] attributes
|
31
|
+
#
|
32
|
+
def initialize(attributes)
|
33
|
+
@name = attributes['name']
|
34
|
+
@rir = attributes['rir']
|
35
|
+
@routed_prefix = attributes['routed_prefix']
|
36
|
+
@country_code = attributes['country_code']
|
37
|
+
@path = attributes['path']
|
38
|
+
@organization = attributes['organization']
|
39
|
+
@asn = attributes['asn']
|
40
|
+
@description = attributes['description']
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Censys
|
4
|
+
class Certificate < Document
|
5
|
+
#
|
6
|
+
# @return [String]
|
7
|
+
#
|
8
|
+
def raw
|
9
|
+
@attributes['raw']
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# @return [Hash]
|
14
|
+
#
|
15
|
+
def parsed
|
16
|
+
@attributes['parsed']
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# @return [Boolean]
|
21
|
+
#
|
22
|
+
def valid_nss
|
23
|
+
@attributes['validation']['nss']['valid']
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Time]
|
27
|
+
def validation_timestamp
|
28
|
+
@validation_timestamp ||= Time.parse(@attributes['validation_timestamp'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Censys
|
2
|
+
class Document
|
3
|
+
#
|
4
|
+
# Initializes the document.
|
5
|
+
#
|
6
|
+
# @param [Hash{String => Object}] attributes
|
7
|
+
#
|
8
|
+
def initialize(attributes)
|
9
|
+
@attributes = attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Dig attributes
|
14
|
+
#
|
15
|
+
# @return [Object]
|
16
|
+
#
|
17
|
+
def dig(*keys)
|
18
|
+
@attributes.dig(*keys)
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Tags.
|
23
|
+
#
|
24
|
+
# @return [Array<String>]
|
25
|
+
#
|
26
|
+
def tags
|
27
|
+
@attributes['tags']
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Time last updated at.
|
32
|
+
#
|
33
|
+
# @return [Time]
|
34
|
+
#
|
35
|
+
def updated_at
|
36
|
+
@updated_at ||= Time.parse(@attributes['updated_at'])
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Additional document metadata.
|
41
|
+
#
|
42
|
+
# @return [Hash{String => Object}]
|
43
|
+
#
|
44
|
+
def metadata
|
45
|
+
@attributes['metadata']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'censys/autonomous_system'
|
2
|
+
|
3
|
+
module Censys
|
4
|
+
class Document
|
5
|
+
module HasASN
|
6
|
+
#
|
7
|
+
# Autonomous System (AS) information.
|
8
|
+
#
|
9
|
+
# @return [AutonomousSystem]
|
10
|
+
#
|
11
|
+
def autonomous_system
|
12
|
+
@autonomous_system ||= AutonomousSystem.new(@attributes['autonomous_system'])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Censys
|
2
|
+
class Document
|
3
|
+
module HasServices
|
4
|
+
#
|
5
|
+
# Open ports.
|
6
|
+
#
|
7
|
+
# @return [Hash{String => Hash}]
|
8
|
+
#
|
9
|
+
def ports
|
10
|
+
@ports ||= Hash[@attributes.select { |key, _| key =~ /\A\d+\z/ }]
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# @return [Array<String>]
|
15
|
+
#
|
16
|
+
def protocols
|
17
|
+
@attributes['protocols']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Censys
|
2
|
+
class ResponseError < RuntimeError
|
3
|
+
end
|
4
|
+
|
5
|
+
class AuthenticationError < ResponseError
|
6
|
+
end
|
7
|
+
|
8
|
+
class NotFound < ResponseError
|
9
|
+
end
|
10
|
+
|
11
|
+
class RateLimited < ResponseError
|
12
|
+
end
|
13
|
+
|
14
|
+
class InternalServerError < ResponseError
|
15
|
+
end
|
16
|
+
end
|
data/lib/censys/ipv4.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'censys/document'
|
2
|
+
require 'censys/document/has_services'
|
3
|
+
require 'censys/document/has_location'
|
4
|
+
require 'censys/document/has_asn'
|
5
|
+
|
6
|
+
require 'time'
|
7
|
+
|
8
|
+
module Censys
|
9
|
+
class IPv4 < Document
|
10
|
+
include HasServices
|
11
|
+
include HasLocation
|
12
|
+
include HasASN
|
13
|
+
|
14
|
+
def ip
|
15
|
+
@attributes['ip']
|
16
|
+
end
|
17
|
+
|
18
|
+
def protocols
|
19
|
+
@protocols ||= Array(@attributes['protocols'])
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
ip
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Censys
|
2
|
+
class Location
|
3
|
+
# @return [String]
|
4
|
+
attr_reader :postal_code
|
5
|
+
|
6
|
+
# @return [String]
|
7
|
+
attr_reader :city
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
attr_reader :province
|
11
|
+
|
12
|
+
# @return [String]
|
13
|
+
attr_reader :country
|
14
|
+
|
15
|
+
# @return [String]
|
16
|
+
attr_reader :continent
|
17
|
+
|
18
|
+
# @return [String]
|
19
|
+
attr_reader :registered_country
|
20
|
+
|
21
|
+
# @return [String]
|
22
|
+
attr_reader :registered_country_code
|
23
|
+
|
24
|
+
# @return [String]
|
25
|
+
attr_reader :timezone
|
26
|
+
|
27
|
+
# @return [Float]
|
28
|
+
attr_reader :latitude
|
29
|
+
|
30
|
+
# @return [Float]
|
31
|
+
attr_reader :longitude
|
32
|
+
|
33
|
+
#
|
34
|
+
# Initializes the location information.
|
35
|
+
#
|
36
|
+
# @param [Hash{String => Object}] attributes
|
37
|
+
#
|
38
|
+
def initialize(attributes)
|
39
|
+
@postal_code = attributes['postal_code']
|
40
|
+
@city = attributes['city']
|
41
|
+
@province = attributes['province']
|
42
|
+
@country = attributes['country']
|
43
|
+
@continent = attributes['continent']
|
44
|
+
|
45
|
+
@registered_country = attributes['registered_country']
|
46
|
+
@registered_country_code = attributes['registered_country_code']
|
47
|
+
|
48
|
+
@timezone = attributes['timezone']
|
49
|
+
|
50
|
+
@latitude = attributes['latitude']
|
51
|
+
@longitude = attributes['longitude']
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'censys/report/response'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Censys
|
2
|
+
module Report
|
3
|
+
class Metadata
|
4
|
+
# @return [Fixnum]
|
5
|
+
attr_reader :count
|
6
|
+
|
7
|
+
# @return [Fixnum]
|
8
|
+
attr_reader :backend_time
|
9
|
+
|
10
|
+
# @return [Fixnum]
|
11
|
+
attr_reader :non_null_count
|
12
|
+
|
13
|
+
# @return [Fixnum]
|
14
|
+
attr_reader :other_result_count
|
15
|
+
|
16
|
+
# @return [Fixnum]
|
17
|
+
attr_reader :buckets
|
18
|
+
|
19
|
+
# @return [Fixnum]
|
20
|
+
attr_reader :error_bound
|
21
|
+
|
22
|
+
# @return [String]
|
23
|
+
attr_reader :query
|
24
|
+
|
25
|
+
#
|
26
|
+
# Initializes the report metadata.
|
27
|
+
#
|
28
|
+
# @param [Hash{String => Object}] attributes
|
29
|
+
#
|
30
|
+
def initialize(attributes)
|
31
|
+
@count = attributes['count']
|
32
|
+
@backend_time = attributes['backend_time']
|
33
|
+
@non_null_count = attributes['nonnull_count']
|
34
|
+
@other_result_count = attributes['other_result_count']
|
35
|
+
@buckets = attributes['buckets']
|
36
|
+
@error_bound = attributes['error_bound']
|
37
|
+
@query = attributes['query']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'censys/report/metadata'
|
2
|
+
|
3
|
+
module Censys
|
4
|
+
module Report
|
5
|
+
class Response
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
# Response status.
|
9
|
+
#
|
10
|
+
# @return [String]
|
11
|
+
attr_reader :status
|
12
|
+
|
13
|
+
# Response results.
|
14
|
+
#
|
15
|
+
# @return [Hash{String => Fixnum}]
|
16
|
+
attr_reader :results
|
17
|
+
|
18
|
+
# Response metadata.
|
19
|
+
#
|
20
|
+
# @return [Metadata]
|
21
|
+
attr_reader :metadata
|
22
|
+
|
23
|
+
def initialize(response)
|
24
|
+
@status = response['status']
|
25
|
+
@results = Hash[response['results'].map { |result|
|
26
|
+
[result['key'], result['doc_count']]
|
27
|
+
}]
|
28
|
+
@metadata = Metadata.new(response['metadata'])
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Determines if the response was OK.
|
33
|
+
#
|
34
|
+
# @return [Boolean]
|
35
|
+
#
|
36
|
+
def ok?
|
37
|
+
@status == 'ok'
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Enumerate through all response results.
|
42
|
+
#
|
43
|
+
# @yield [key, doc_count]
|
44
|
+
#
|
45
|
+
# @yieldparam [String] key
|
46
|
+
#
|
47
|
+
# @yieldparam [Fixnum] doc_count
|
48
|
+
#
|
49
|
+
def each(&block)
|
50
|
+
@results.each(&block)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'censys/search/response'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'censys/search/result'
|
2
|
+
|
3
|
+
module Censys
|
4
|
+
module Search
|
5
|
+
class Certificate < Result
|
6
|
+
def fingerprint_sha256
|
7
|
+
@attributes['parsed.fingerprint_sha256']
|
8
|
+
end
|
9
|
+
|
10
|
+
def subject_dn
|
11
|
+
@attributes['parsed.subject_dn']
|
12
|
+
end
|
13
|
+
|
14
|
+
def issuer_dn
|
15
|
+
@attributes['parsed.issuer_dn']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Censys
|
2
|
+
module Search
|
3
|
+
class Metadata
|
4
|
+
# @return [Integer]
|
5
|
+
attr_reader :count
|
6
|
+
|
7
|
+
# @return [String]
|
8
|
+
attr_reader :query
|
9
|
+
|
10
|
+
# @return [Integer]
|
11
|
+
attr_reader :backend_time
|
12
|
+
|
13
|
+
# @return [Integer]
|
14
|
+
attr_reader :page
|
15
|
+
|
16
|
+
# @return [Integer]
|
17
|
+
attr_reader :pages
|
18
|
+
|
19
|
+
#
|
20
|
+
# Initializes the search metadata.
|
21
|
+
#
|
22
|
+
# @param [Hash{String => Object}] metadata
|
23
|
+
#
|
24
|
+
def initialize(metadata)
|
25
|
+
@count = metadata['count']
|
26
|
+
@query = metadata['query']
|
27
|
+
@backend_time = metadata['backend_time']
|
28
|
+
@page = metadata['page']
|
29
|
+
@pages = metadata['pages']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|