rangescan 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1d88f06375987da13e9983620c34abb676dfe2b12b3e6b6f6f1f8f85468b7e1
4
- data.tar.gz: dde41f60761ce812ee29210468c4c685381a0c7431ff0d1e88be841e88500de6
3
+ metadata.gz: 85943fdeb085b7c2c3066cf997292246d2ec6c2d4fd85447ad31ebc8da586b4a
4
+ data.tar.gz: c4562cf5ea80b8cd2fa744977c42b2dee961e4dfb28ffd7727fa59287a27128d
5
5
  SHA512:
6
- metadata.gz: c33c2d5f53ca8328b5c04df66cb8856dadf13662ee0477576bd56682d4e223083682fec64f3206deb86ce1065a52ab2fd016d93617f5f5b70190b4ebfbd2a202
7
- data.tar.gz: e92a5a7cab860c07d571187cb140260d5ba0510d1ac63077b9c41c8e3608a5b2b11893dfbc6cba75835e2e2e5c34bbd569e883e72b8fc16d875d43d139e6756f
6
+ metadata.gz: 5445af72c8e99671c8760d8b8decbaeb52bef0796e317562efa9b2e32f13be96abdbd74f368fc277796ff930229e2197836ae8dab806b872dcd89140e737254c
7
+ data.tar.gz: 10453c71febba8b2d630997de509befac9b4c1e070a2478df464c4220542ec8616f3e400d413182fcd9c86393ce287a2b970a669e0f8a3a71ed05e31e0783b96
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "protocol/http1/connection"
4
+
5
+ module Protocol
6
+ module HTTP1
7
+ class Connection
8
+ def write_request(authority, method, path, version, headers)
9
+ host = authority
10
+ if headers.include?("host")
11
+ host = headers["host"]
12
+ headers.delete "host"
13
+ end
14
+
15
+ @stream.write("#{method} #{path} #{version}\r\n")
16
+ @stream.write("host: #{host}\r\n")
17
+
18
+ write_headers(headers)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,17 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "http"
4
- require "parallel"
3
+ require "async"
4
+ require "async/barrier"
5
+ require "async/semaphore"
6
+ require "async/http"
7
+ require "etc"
8
+
9
+ require "rangescan/monkey_patch"
5
10
 
6
11
  module RangeScan
7
12
  class Scanner
8
13
  attr_reader :context
9
14
  attr_reader :host
10
15
  attr_reader :port
16
+ attr_reader :processor_count
11
17
  attr_reader :scheme
12
18
  attr_reader :ssl_context
13
19
  attr_reader :timeout
14
20
  attr_reader :user_agent
21
+ attr_reader :verify_ssl
15
22
 
16
23
  def initialize(host: nil, port: nil, scheme: "http", verify_ssl: true, timeout: 5, user_agent: nil)
17
24
  @host = host
@@ -20,8 +27,12 @@ module RangeScan
20
27
  @scheme = scheme
21
28
  @user_agent = user_agent
22
29
 
30
+ @verify_ssl = verify_ssl
31
+
23
32
  @ssl_context = OpenSSL::SSL::SSLContext.new
24
33
  @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE unless verify_ssl
34
+
35
+ @processor_count ||= Etc.nprocessors
25
36
  end
26
37
 
27
38
  def url_for(ipv4)
@@ -31,36 +42,46 @@ module RangeScan
31
42
  end
32
43
 
33
44
  def scan(ipv4s)
34
- Parallel.map(ipv4s) do |ipv4|
35
- get ipv4
36
- end.compact
45
+ results = []
46
+ Async do
47
+ barrier = Async::Barrier.new
48
+ semaphore = Async::Semaphore.new(processor_count, parent: barrier)
49
+
50
+ ipv4s.each do |ipv4|
51
+ semaphore.async do
52
+ url = url_for(ipv4)
53
+
54
+ endpoint = Async::HTTP::Endpoint.parse(url, ssl_context: ssl_context, timeout: timeout)
55
+ client = Async::HTTP::Client.new(endpoint, retries: 0)
56
+ res = client.get(endpoint.path, default_request_headers)
57
+
58
+ headers = res.headers.fields.to_h
59
+ body = res.read || ""
60
+
61
+ results << {
62
+ url: url,
63
+ ipv4: ipv4,
64
+ code: res.status,
65
+ headers: Utils.to_utf8(headers),
66
+ body: Utils.to_utf8(body)
67
+ }
68
+ rescue Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, EOFError, OpenSSL::SSL::SSLError, Async::TimeoutError
69
+ next
70
+ end
71
+ end
72
+ barrier.wait
73
+ end
74
+ results.compact
37
75
  end
38
76
 
39
77
  private
40
78
 
41
- def default_headers
42
- { host: host, user_agent: user_agent }.compact
79
+ def default_request_headers
80
+ @default_request_headers ||= { "host" => host, "user-agent" => user_agent }.compact
43
81
  end
44
82
 
45
83
  def ssl_options
46
84
  scheme == "http" ? {} : { ssl_context: ssl_context }
47
85
  end
48
-
49
- def get(ipv4)
50
- url = url_for(ipv4)
51
-
52
- begin
53
- res = HTTP.timeout(timeout).headers(default_headers).get(url, ssl_options)
54
- {
55
- url: url,
56
- ipv4: ipv4,
57
- code: res.code,
58
- headers: Utils.to_utf8(res.headers),
59
- body: Utils.to_utf8(res.body.to_s)
60
- }
61
- rescue OpenSSL::SSL::SSLError, HTTP::Error, Addressable::URI::InvalidURIError
62
- nil
63
- end
64
- end
65
86
  end
66
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RangeScan
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -32,8 +32,8 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "rspec", "~> 3.9"
33
33
  spec.add_development_dependency "webmock", "~> 3.8"
34
34
 
35
- spec.add_dependency "http", "~> 4.4"
35
+ spec.add_dependency "async", "~> 1.26"
36
+ spec.add_dependency "async-http", "~> 0.52"
36
37
  spec.add_dependency "ipaddress", "~> 0.8"
37
- spec.add_dependency "parallel", "~> 1.19"
38
38
  spec.add_dependency "thor", "~> 1.0"
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rangescan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manabu Niseki
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-20 00:00:00.000000000 Z
11
+ date: 2020-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,47 +95,47 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.8'
97
97
  - !ruby/object:Gem::Dependency
98
- name: http
98
+ name: async
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '4.4'
103
+ version: '1.26'
104
104
  type: :runtime
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: '4.4'
110
+ version: '1.26'
111
111
  - !ruby/object:Gem::Dependency
112
- name: ipaddress
112
+ name: async-http
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.8'
117
+ version: '0.52'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.8'
124
+ version: '0.52'
125
125
  - !ruby/object:Gem::Dependency
126
- name: parallel
126
+ name: ipaddress
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '1.19'
131
+ version: '0.8'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '1.19'
138
+ version: '0.8'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: thor
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -171,6 +171,7 @@ files:
171
171
  - lib/rangescan.rb
172
172
  - lib/rangescan/cli.rb
173
173
  - lib/rangescan/matcher.rb
174
+ - lib/rangescan/monkey_patch.rb
174
175
  - lib/rangescan/range.rb
175
176
  - lib/rangescan/scanner.rb
176
177
  - lib/rangescan/utils.rb
@@ -181,7 +182,7 @@ licenses:
181
182
  - MIT
182
183
  metadata:
183
184
  homepage_uri: https://github.com/ninoseki/rangescan
184
- post_install_message:
185
+ post_install_message:
185
186
  rdoc_options: []
186
187
  require_paths:
187
188
  - lib
@@ -197,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
198
  version: '0'
198
199
  requirements: []
199
200
  rubygems_version: 3.1.2
200
- signing_key:
201
+ signing_key:
201
202
  specification_version: 4
202
203
  summary: Scan websites on a specific IP range
203
204
  test_files: []