censu 0.1.1 → 0.1.2
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 +4 -4
- data/.codeclimate.yml +1 -2
- data/README.md +72 -24
- data/lib/censu.rb +2 -0
- data/lib/censys/document/has_http_response.rb +16 -0
- data/lib/censys/http_response.rb +48 -0
- data/lib/censys/version.rb +1 -1
- data/lib/censys/website.rb +2 -0
- data/spec/view_spec.rb +6 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a65cae212177db3ce66c6b68aae16e212427e21
|
4
|
+
data.tar.gz: 967f33e9e61180fddb1b8b16b35d6454f29c17e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b762c4f2e09e700e130515cbe32edbb7ace961de5031a291100f3d64977933977accd8507e8ca2f1958b7ad31c41c91df05dd103d8e7e1604e95d973c1344ae
|
7
|
+
data.tar.gz: 3b69de965819865490e59189792b74d1ef31480a9e8fba781112f3731bdec2629191cb99f84bb997d95c1ee24fdde13623767120481bd1b4e421d5aacfc71bb7
|
data/.codeclimate.yml
CHANGED
data/README.md
CHANGED
@@ -10,61 +10,109 @@
|
|
10
10
|
|
11
11
|
Ruby API client to the [Censys] internet search engine.
|
12
12
|
|
13
|
-
## Features
|
14
13
|
|
15
14
|
## Examples
|
16
15
|
|
17
16
|
Initialize the API:
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
```ruby
|
19
|
+
require 'censys'
|
20
|
+
api = Censys::API.new(uid, secret)
|
21
|
+
```
|
21
22
|
|
22
23
|
Initialize the API using `$CENSYS_ID` and `$CENSYS_SECRET` environment
|
23
24
|
variables:
|
24
25
|
|
25
|
-
|
26
|
+
```ruby
|
27
|
+
api = Censys::API.new
|
28
|
+
```
|
26
29
|
|
27
30
|
Search for IPv4 addresses:
|
28
31
|
|
29
|
-
|
32
|
+
```ruby
|
33
|
+
response = api.ipv4.search(query: 'dropbox.com')
|
34
|
+
```
|
30
35
|
|
31
36
|
Search for Websites:
|
32
37
|
|
33
|
-
|
38
|
+
```ruby
|
39
|
+
response = api.websites.search(query: 'dropbox.com')
|
40
|
+
```
|
34
41
|
|
35
42
|
Search for Certificates:
|
36
43
|
|
37
|
-
|
44
|
+
```ruby
|
45
|
+
response = api.certificates.search(query: 'dropbox.com')
|
46
|
+
```
|
38
47
|
|
39
48
|
Enumerate through search results:
|
40
49
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
50
|
+
```ruby
|
51
|
+
response.each_page do |page|
|
52
|
+
puts ">>> Page ##{page.metadata.page} / #{page.metadata.pages} ..."
|
53
|
+
page.each do |result|
|
45
54
|
puts result
|
46
|
-
end
|
47
55
|
end
|
56
|
+
end
|
57
|
+
```
|
48
58
|
|
49
|
-
|
59
|
+
View for IPv4 addresses:
|
50
60
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
buckets: 100
|
55
|
-
)
|
61
|
+
```ruby
|
62
|
+
view = api.ipv4["8.8.8.8"]
|
63
|
+
```
|
56
64
|
|
57
|
-
|
58
|
-
|
59
|
-
|
65
|
+
View for Websites:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
view = api.websites["google.com"]
|
69
|
+
```
|
70
|
+
|
71
|
+
View for Certificates:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
view = api.certificates["821a712a29d8e25915f66a9771519746c5aa73a45321fd4ca7ef644e1cadda59"]
|
75
|
+
```
|
76
|
+
|
77
|
+
Generate aggregate reports:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
response = api.websites.report(
|
81
|
+
query: '80.http.get.headers.server: Apache',
|
82
|
+
field: 'location.country_code',
|
83
|
+
buckets: 100
|
84
|
+
)
|
85
|
+
|
86
|
+
response.each do |country,count|
|
87
|
+
puts "#{country}: #{count}"
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
Combine Search and View API.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
api = Censys::API.new
|
95
|
+
response = api.websites.search(query: "hoge")
|
96
|
+
response.each_page do |page|
|
97
|
+
page.each do |result|
|
98
|
+
view = api.websites[result.domain]
|
99
|
+
p view.domain # => e.g. "nrc.nl"
|
100
|
+
p view.autonomous_system.name # => e.g. "NL-INTERMAX"
|
101
|
+
p view.location.country # => e.g. "Netherlands"
|
102
|
+
p view.protocols # => e.g. ["80/http", "0/lookup", "25/smtp", "443/https_www", "443/https", "80/http_www"]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
```
|
60
106
|
|
61
107
|
## Requirements
|
62
108
|
|
63
|
-
* [ruby] >= 2.
|
109
|
+
* [ruby] >= 2.4
|
64
110
|
|
65
111
|
## Install
|
66
112
|
|
67
|
-
|
113
|
+
```bash
|
114
|
+
% gem install censu
|
115
|
+
```
|
68
116
|
|
69
117
|
## License
|
70
118
|
|
@@ -73,4 +121,4 @@ See {file:LICENSE.txt} for details.
|
|
73
121
|
Note:: This gem is forked from [trailofbits/censys-ruby](https://github.com/trailofbits/censys-ruby).
|
74
122
|
|
75
123
|
[ruby]: http://www.ruby-lang.org/
|
76
|
-
[
|
124
|
+
[Censys]: https://censys.io/
|
data/lib/censu.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'censys/http_response'
|
2
|
+
|
3
|
+
module Censys
|
4
|
+
class Document
|
5
|
+
module HasHTTPResponse
|
6
|
+
#
|
7
|
+
# HTTP reponse information.
|
8
|
+
#
|
9
|
+
# @return [HTTPResponse]
|
10
|
+
#
|
11
|
+
def http_response
|
12
|
+
@http_reponse ||= HTTPResponse.new(@attributes.dig("80", "http"))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Censys
|
2
|
+
class HTTPResponse
|
3
|
+
#
|
4
|
+
# Initializes the HTTP Response infromation
|
5
|
+
#
|
6
|
+
# @param [Hash{String => Object}] attributes
|
7
|
+
#
|
8
|
+
def initialize(attributes)
|
9
|
+
@attributes = attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# HTTP body
|
14
|
+
#
|
15
|
+
# @return [String] body
|
16
|
+
#
|
17
|
+
def body
|
18
|
+
@attributes.dig("get", "body")
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# HTTP header
|
23
|
+
#
|
24
|
+
# @return [Hash] header
|
25
|
+
#
|
26
|
+
def header
|
27
|
+
@attributes.dig("get", "headers")
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# HTTP status code
|
32
|
+
#
|
33
|
+
# @return [Integer] status code
|
34
|
+
#
|
35
|
+
def status_code
|
36
|
+
@attributes.dig("get", "status_code")
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# HTTP title
|
41
|
+
#
|
42
|
+
# @return [String] title
|
43
|
+
#
|
44
|
+
def title
|
45
|
+
@attributes.dig("get", "title")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/censys/version.rb
CHANGED
data/lib/censys/website.rb
CHANGED
@@ -2,12 +2,14 @@ require 'censys/document'
|
|
2
2
|
require 'censys/document/has_services'
|
3
3
|
require 'censys/document/has_location'
|
4
4
|
require 'censys/document/has_asn'
|
5
|
+
require 'censys/document/has_http_response'
|
5
6
|
|
6
7
|
module Censys
|
7
8
|
class Website < Document
|
8
9
|
include HasServices
|
9
10
|
include HasLocation
|
10
11
|
include HasASN
|
12
|
+
include HasHTTPResponse
|
11
13
|
|
12
14
|
#
|
13
15
|
# @return [String]
|
data/spec/view_spec.rb
CHANGED
@@ -31,6 +31,12 @@ describe Censys::API do
|
|
31
31
|
expect(view.domain).to eq("google.com")
|
32
32
|
expect(view.to_s).to eq("google.com")
|
33
33
|
expect(view.alexa_rank).to be_a(Integer)
|
34
|
+
|
35
|
+
expect(view.http_response).to be_a(Censys::HTTPResponse)
|
36
|
+
expect(view.http_response.body).to be_a(String)
|
37
|
+
expect(view.http_response.header).to be_a(Hash)
|
38
|
+
expect(view.http_response.status_code).to eq(200)
|
39
|
+
expect(view.http_response.title).to eq("Google")
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: censu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manabu Niseki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -141,15 +141,18 @@ files:
|
|
141
141
|
- README.md
|
142
142
|
- Rakefile
|
143
143
|
- censys.gemspec
|
144
|
+
- lib/censu.rb
|
144
145
|
- lib/censys.rb
|
145
146
|
- lib/censys/api.rb
|
146
147
|
- lib/censys/autonomous_system.rb
|
147
148
|
- lib/censys/certificate.rb
|
148
149
|
- lib/censys/document.rb
|
149
150
|
- lib/censys/document/has_asn.rb
|
151
|
+
- lib/censys/document/has_http_response.rb
|
150
152
|
- lib/censys/document/has_location.rb
|
151
153
|
- lib/censys/document/has_services.rb
|
152
154
|
- lib/censys/exceptions.rb
|
155
|
+
- lib/censys/http_response.rb
|
153
156
|
- lib/censys/ipv4.rb
|
154
157
|
- lib/censys/location.rb
|
155
158
|
- lib/censys/report.rb
|