urlscan 0.1.1 → 0.2.0
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/.rubocop.yml +7 -0
- data/.travis.yml +5 -4
- data/README.md +23 -18
- data/lib/urlscan.rb +2 -0
- data/lib/urlscan/api.rb +21 -5
- data/lib/urlscan/cli.rb +13 -3
- data/lib/urlscan/exceptions.rb +2 -0
- data/lib/urlscan/version.rb +3 -1
- data/urlscan.gemspec +3 -3
- metadata +7 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 042c7671173ca5f51491179a399986f61c075a4d410851017d43260e37c870f1
|
|
4
|
+
data.tar.gz: 5c090165f7c5d711dddae216934bb35efdf35c26a6864f6f9890841ad69ef7ca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 65782649fe5229b9bed2090a57de4eed5ed85aa257b35b3cde8d3b732275ce3a39fcef2fcdb75fb54d9402682e0528d8e5b6ea7dbb5bb5ee24c93151be3ad64c
|
|
7
|
+
data.tar.gz: 106287f92bbea337c90d2f8af16fe1df6d856b1fb3c827388b051eaf0eae9503e76e8da23fea236bc9634c636137e96e51194fa01273a8e46efc01913b2193de
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
|
@@ -6,54 +6,58 @@
|
|
|
6
6
|
|
|
7
7
|
## Description
|
|
8
8
|
|
|
9
|
-
Ruby API client for [urlscan.io](https://urlscan.io/)
|
|
9
|
+
Ruby API client for [urlscan.io](https://urlscan.io/).
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
|
|
14
|
+
gem install urlscan
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## API usage
|
|
18
18
|
|
|
19
|
-
Initialize the API:
|
|
20
|
-
|
|
21
19
|
```ruby
|
|
22
20
|
require 'urlscan'
|
|
23
|
-
# initialize the API by passing the API key.
|
|
24
|
-
api = UrlScan::API.new(api_key)
|
|
25
|
-
# or initialize the API by using `$URLSCAN_API_KEY` environment variable
|
|
26
|
-
api = UrlScan::API.new
|
|
27
|
-
```
|
|
28
21
|
|
|
29
|
-
|
|
22
|
+
# when given nothing, it tries to load your API key from ENV["SHODAN_API_KEY"]
|
|
23
|
+
api = UrlScan::API.new
|
|
24
|
+
# or you can set it manually
|
|
25
|
+
api = UrlScan::API.new(api_key)
|
|
30
26
|
|
|
31
|
-
|
|
27
|
+
# Submit a URL to scan
|
|
32
28
|
res = api.submit("https://wikipedia.org")
|
|
33
29
|
puts res["result"] # => "https://urlscan.io/result/ac04bc14-4efe-439d-b356-8384843daf75/"
|
|
34
|
-
```
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```ruby
|
|
31
|
+
# Get a scan result
|
|
39
32
|
res = api.result("ac04bc14-4efe-439d-b356-8384843daf75")
|
|
40
33
|
p res # => See the following URL as an example of the response.
|
|
41
34
|
# https://gist.github.com/ninoseki/a974d7e95629813615b380c30e737825#file-result-json
|
|
42
|
-
```
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
# Get a DOM
|
|
37
|
+
res = api.dom("ac04bc14-4efe-439d-b356-8384843daf75")
|
|
38
|
+
p res
|
|
45
39
|
|
|
46
|
-
|
|
40
|
+
# Search
|
|
47
41
|
res = api.search("wikipedia.org")
|
|
48
42
|
p res # => See the following URL as an example of the reponse.
|
|
49
43
|
# https://gist.github.com/ninoseki/a974d7e95629813615b380c30e737825#file-search-json
|
|
50
44
|
```
|
|
51
45
|
|
|
46
|
+
### Supported API endpoints
|
|
47
|
+
|
|
48
|
+
| HTTP Method | URI | API method |
|
|
49
|
+
|-------------|----------------|-------------------------------------------------------------------|
|
|
50
|
+
| POST | /scan | `UrlScan::API#submit(url, is_public = true)` |
|
|
51
|
+
| GET | /result/$uuid/ | `UrlScan::API#result(uuid)` |
|
|
52
|
+
| GET | /dom/$uuid/ | `UrlScan::API#dom(uuid)` |
|
|
53
|
+
| GET | /search | `UrlScan::API#search(q, size = 100, offset = 0, sort = "_score")` |
|
|
54
|
+
|
|
52
55
|
## CLI usage
|
|
53
56
|
|
|
54
57
|
```bash
|
|
55
58
|
$ urlscan
|
|
56
59
|
Commands:
|
|
60
|
+
urlscan dom [UUID] # get the DOM of a scan using the [UUID]
|
|
57
61
|
urlscan help [COMMAND] # Describe available commands or one specific command
|
|
58
62
|
urlscan result [UUID] # get the result of a scan using the [UUID]
|
|
59
63
|
urlscan search [QUERY] # search for scans by [QUERY]
|
|
@@ -61,4 +65,5 @@ Commands:
|
|
|
61
65
|
|
|
62
66
|
Options:
|
|
63
67
|
[--API-KEY=API_KEY]
|
|
68
|
+
|
|
64
69
|
```
|
data/lib/urlscan.rb
CHANGED
data/lib/urlscan/api.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'net/https'
|
|
2
4
|
require 'json'
|
|
3
5
|
|
|
@@ -6,25 +8,34 @@ require 'urlscan/exceptions'
|
|
|
6
8
|
module UrlScan
|
|
7
9
|
class API
|
|
8
10
|
VERSION = 1
|
|
9
|
-
HOST = "urlscan.io"
|
|
10
|
-
URL = "https://#{HOST}/api/v#{VERSION}"
|
|
11
|
+
HOST = "urlscan.io"
|
|
12
|
+
URL = "https://#{HOST}/api/v#{VERSION}"
|
|
11
13
|
|
|
12
14
|
attr_reader :key
|
|
13
15
|
|
|
14
16
|
def initialize(key = ENV["URLSCAN_API_KEY"])
|
|
15
17
|
raise ArgumentError, "`key` argument required" if key.nil?
|
|
18
|
+
|
|
16
19
|
@key = key
|
|
17
20
|
end
|
|
18
21
|
|
|
22
|
+
# @return [Hash]
|
|
19
23
|
def submit(url, is_public = true)
|
|
20
24
|
params = { url: url, public: is_public ? "on" : "off" }
|
|
21
25
|
post("/scan/", params) { |json| json }
|
|
22
26
|
end
|
|
23
27
|
|
|
28
|
+
# @return [Hash]
|
|
24
29
|
def result(uuid)
|
|
25
30
|
get("/result/#{uuid}") { |json| json }
|
|
26
31
|
end
|
|
27
32
|
|
|
33
|
+
# @return [String]
|
|
34
|
+
def dom(uuid)
|
|
35
|
+
get("/dom/#{uuid}/") { |dom| dom }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @return [Hash]
|
|
28
39
|
def search(q, size = 100, offset = 0, sort = "_score")
|
|
29
40
|
params = { q: q, size: size, offset: offset, sort: sort }
|
|
30
41
|
query = URI.encode_www_form(params)
|
|
@@ -39,8 +50,8 @@ module UrlScan
|
|
|
39
50
|
if proxy = ENV["HTTPS_PROXY"]
|
|
40
51
|
uri = URI(proxy)
|
|
41
52
|
{
|
|
42
|
-
proxy_address:
|
|
43
|
-
proxy_port:
|
|
53
|
+
proxy_address: uri.hostname,
|
|
54
|
+
proxy_port: uri.port,
|
|
44
55
|
proxy_from_env: false,
|
|
45
56
|
use_ssl: true
|
|
46
57
|
}
|
|
@@ -54,7 +65,12 @@ module UrlScan
|
|
|
54
65
|
response = http.request(req)
|
|
55
66
|
|
|
56
67
|
case response.code
|
|
57
|
-
when '200'
|
|
68
|
+
when '200'
|
|
69
|
+
if response["Content-Type"].to_s.include? "application/json"
|
|
70
|
+
yield JSON.parse(response.body)
|
|
71
|
+
else
|
|
72
|
+
yield response.body
|
|
73
|
+
end
|
|
58
74
|
when '400' then raise ProcessingError, response.body
|
|
59
75
|
when '401' then raise AuthenticationError, response.body
|
|
60
76
|
when '404' then raise NotFound, response.body
|
data/lib/urlscan/cli.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'json'
|
|
2
4
|
require 'thor'
|
|
3
5
|
|
|
@@ -33,6 +35,14 @@ module UrlScan
|
|
|
33
35
|
end
|
|
34
36
|
end
|
|
35
37
|
|
|
38
|
+
desc "dom [UUID]", "get the DOM of a scan using the [UUID]"
|
|
39
|
+
def dom(uuid)
|
|
40
|
+
with_error_handling do
|
|
41
|
+
res = api.dom(uuid)
|
|
42
|
+
puts res
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
36
46
|
no_commands do
|
|
37
47
|
def api
|
|
38
48
|
options[:API_KEY] ? API.new(options[:API_KEY]) : API.new
|
|
@@ -40,10 +50,10 @@ module UrlScan
|
|
|
40
50
|
|
|
41
51
|
def with_error_handling
|
|
42
52
|
yield
|
|
43
|
-
rescue ArgumentError =>
|
|
53
|
+
rescue ArgumentError => _e
|
|
44
54
|
puts "Warning: please specify your urlscan.io API key via ENV['URLSCAN_API_KEY] or --API-KEY"
|
|
45
|
-
rescue ResponseError =>
|
|
46
|
-
puts "Warning: #{
|
|
55
|
+
rescue ResponseError => _e
|
|
56
|
+
puts "Warning: #{_e}"
|
|
47
57
|
end
|
|
48
58
|
end
|
|
49
59
|
end
|
data/lib/urlscan/exceptions.rb
CHANGED
data/lib/urlscan/version.rb
CHANGED
data/urlscan.gemspec
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
lib = File.expand_path(
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
require "urlscan/version"
|
|
4
4
|
|
|
@@ -19,13 +19,13 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
20
|
spec.require_paths = ["lib"]
|
|
21
21
|
|
|
22
|
-
spec.add_development_dependency "bundler", "~>
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
23
23
|
spec.add_development_dependency "coveralls", "~> 0.8"
|
|
24
24
|
spec.add_development_dependency "dotenv", "~> 2.5"
|
|
25
25
|
spec.add_development_dependency "rake", "~> 12.3"
|
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.8"
|
|
27
27
|
spec.add_development_dependency "vcr", "~> 4.0"
|
|
28
|
-
spec.add_development_dependency "webmock", "~> 3.
|
|
28
|
+
spec.add_development_dependency "webmock", "~> 3.5"
|
|
29
29
|
|
|
30
30
|
spec.add_runtime_dependency "thor", "~> 0.19"
|
|
31
31
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: urlscan
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Manabu Niseki
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-05-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '2.0'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '2.0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: coveralls
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -100,14 +100,14 @@ dependencies:
|
|
|
100
100
|
requirements:
|
|
101
101
|
- - "~>"
|
|
102
102
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: '3.
|
|
103
|
+
version: '3.5'
|
|
104
104
|
type: :development
|
|
105
105
|
prerelease: false
|
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
|
108
108
|
- - "~>"
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: '3.
|
|
110
|
+
version: '3.5'
|
|
111
111
|
- !ruby/object:Gem::Dependency
|
|
112
112
|
name: thor
|
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -165,8 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
165
165
|
- !ruby/object:Gem::Version
|
|
166
166
|
version: '0'
|
|
167
167
|
requirements: []
|
|
168
|
-
|
|
169
|
-
rubygems_version: 2.7.6
|
|
168
|
+
rubygems_version: 3.0.2
|
|
170
169
|
signing_key:
|
|
171
170
|
specification_version: 4
|
|
172
171
|
summary: Ruby API client for urlscan.io
|