paraxial 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paraxial/checker.rb +18 -10
- data/lib/paraxial/cli.rb +2 -25
- data/lib/paraxial/helpers.rb +8 -0
- data/lib/paraxial/initializers/marshal_patch.rb +37 -0
- data/lib/paraxial/initializers/startup.rb +9 -6
- data/lib/paraxial/version.rb +1 -1
- data/lib/paraxial.rb +40 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa19e78278421371d0e25cd1e387383676df44a7d09ec936520e6e2e9a4fa70f
|
4
|
+
data.tar.gz: 807b6b4401164502c8b38ea4b6ff861c667b0aee5fcd124d68a5f98c19ed5e38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f99fc3adc1dab0e302e45b26b2a245055b2b03eac517e5640b7f18828de1a78d64362a37811be9221b4f5c560feff727324b171d1c9493609b513de43579780a
|
7
|
+
data.tar.gz: fbe25d2549601ab95b67934deda8dd1e070d7ced5cb0abf570f85b8650acc9700d35c4274f3460a25d434a6f09c67ad80b85927564da3ba78a1b1dfa9b9ed2d0
|
data/lib/paraxial/checker.rb
CHANGED
@@ -4,10 +4,13 @@ module Paraxial
|
|
4
4
|
@allows = { 'v4' => Patricia.new, 'v6' => Patricia.new(:AF_INET6) }
|
5
5
|
@bans = { 'v4' => Patricia.new, 'v6' => Patricia.new(:AF_INET6) }
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
|
8
|
+
if Paraxial::Helpers.get_api_key
|
9
|
+
@thread = Thread.new do
|
10
|
+
loop do
|
11
|
+
get_abr
|
12
|
+
sleep(10)
|
13
|
+
end
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
@@ -15,11 +18,16 @@ module Paraxial
|
|
15
18
|
uri = URI.parse(Paraxial::Helpers.get_paraxial_url + '/api/abr')
|
16
19
|
headers = { 'Content-Type': 'application/json' }
|
17
20
|
|
18
|
-
body = { api_key:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
body = { api_key: Paraxial::Helpers.get_api_key }
|
22
|
+
begin
|
23
|
+
r = Net::HTTP.post(uri, body.to_json, headers)
|
24
|
+
if r.code == '200'
|
25
|
+
put_abr(JSON.parse(r.body))
|
26
|
+
else
|
27
|
+
'ab_failed'
|
28
|
+
end
|
29
|
+
rescue StandardError => e
|
30
|
+
puts '[Paraxial] HTTP connection to backend failed, check configuration'
|
23
31
|
'ab_failed'
|
24
32
|
end
|
25
33
|
end
|
@@ -100,7 +108,7 @@ module Paraxial
|
|
100
108
|
uri = URI.parse(Paraxial::Helpers.get_ban_url)
|
101
109
|
headers = { 'Content-Type': 'application/json' }
|
102
110
|
|
103
|
-
body = { api_key:
|
111
|
+
body = { api_key: Paraxial::Helpers.get_api_key, ip_address: ip }
|
104
112
|
r = Net::HTTP.post(uri, body.to_json, headers)
|
105
113
|
if r.code == '200'
|
106
114
|
:ok
|
data/lib/paraxial/cli.rb
CHANGED
@@ -18,15 +18,8 @@ module Paraxial
|
|
18
18
|
|
19
19
|
def scan
|
20
20
|
puts '[Paraxial] Scan starting...'
|
21
|
-
if check_rubocop_configuration
|
22
|
-
puts '[Paraxial] .rubocop.yml contains the required paraxial configuration.'
|
23
|
-
else
|
24
|
-
puts '[Paraxial] .rubocop.yml does not contain the required paraxial configuration.'
|
25
|
-
puts '[Paraxial] How to configure: TODO_URL'
|
26
|
-
exit
|
27
|
-
end
|
28
21
|
|
29
|
-
if
|
22
|
+
if Paraxial::Helpers.get_api_key.nil?
|
30
23
|
puts '[Paraxial] Environment variable PARAXIAL_API_KEY not found'
|
31
24
|
else
|
32
25
|
github_app = options[:github_app]
|
@@ -36,7 +29,7 @@ module Paraxial
|
|
36
29
|
pr_number = options[:pr_number]
|
37
30
|
|
38
31
|
cops = 'Paraxial,Security/Eval,Security/IoMethods,Security/JSONLoad,Security/MarshalLoad,Security/Open,Security/YAMLLoad'
|
39
|
-
rubocop = `rubocop --only #{cops} --format json`
|
32
|
+
rubocop = `rubocop --require paraxial --only #{cops} --disable-pending-cops --format json`
|
40
33
|
lockfile = File.read('./Gemfile.lock')
|
41
34
|
api_key = ENV['PARAXIAL_API_KEY']
|
42
35
|
uri = URI.parse(Paraxial::Helpers.get_paraxial_url + '/api/ruby_scan')
|
@@ -96,21 +89,5 @@ module Paraxial
|
|
96
89
|
end
|
97
90
|
end
|
98
91
|
|
99
|
-
private
|
100
|
-
|
101
|
-
def check_rubocop_configuration
|
102
|
-
rubocop_file = File.join(Dir.pwd, '.rubocop.yml')
|
103
|
-
|
104
|
-
return false unless File.exist?(rubocop_file)
|
105
|
-
|
106
|
-
config = YAML.load_file(rubocop_file)
|
107
|
-
required_key = 'require'
|
108
|
-
|
109
|
-
if config.is_a?(Hash) && config[required_key].is_a?(Array)
|
110
|
-
config[required_key].include?('paraxial')
|
111
|
-
else
|
112
|
-
false
|
113
|
-
end
|
114
|
-
end
|
115
92
|
end
|
116
93
|
end
|
data/lib/paraxial/helpers.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
unless Rails.env.test? || File.basename($0) == 'rake' || defined?(Rails::Generators)
|
2
|
+
module Marshal
|
3
|
+
class << self
|
4
|
+
alias_method :original_load, :load
|
5
|
+
|
6
|
+
def load(source, proc = nil)
|
7
|
+
exg = Paraxial.configuration.exploit_guard
|
8
|
+
if [:monitor, :block].include?(exg)
|
9
|
+
if source.is_a?(String) && source.match?(/ActionView|Net::BufferedIO|ERB|ActiveSupport/)
|
10
|
+
puts "[Paraxial] Exploit Guard triggered, malicious input to Marshal.load"
|
11
|
+
puts source
|
12
|
+
|
13
|
+
m = {
|
14
|
+
"api_key" => Paraxial::Helpers.get_api_key,
|
15
|
+
"mode" => exg,
|
16
|
+
"message" => "Marshal.load exploit behavior detected: #{Base64.encode64(source)}"
|
17
|
+
}
|
18
|
+
headers = { 'Content-Type': 'application/json' }
|
19
|
+
uri = URI.parse(Paraxial::Helpers.get_exploit_url)
|
20
|
+
Thread.new do
|
21
|
+
Net::HTTP.post(uri, m.to_json, headers)
|
22
|
+
end
|
23
|
+
if exg == :monitor
|
24
|
+
original_load(source, proc)
|
25
|
+
else
|
26
|
+
:block
|
27
|
+
end
|
28
|
+
else
|
29
|
+
original_load(source, proc)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
original_load(source, proc)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -8,16 +8,19 @@ Bundler.setup
|
|
8
8
|
|
9
9
|
unless Rails.env.test? || File.basename($0) == 'rake' || defined?(Rails::Generators)
|
10
10
|
Rails.application.config.to_prepare do
|
11
|
-
puts '[Paraxial]
|
12
|
-
api_key =
|
11
|
+
puts '[Paraxial] Agent starting...'
|
12
|
+
api_key = Paraxial::Helpers.get_api_key
|
13
13
|
|
14
14
|
if api_key.nil?
|
15
|
-
puts '[Paraxial]
|
15
|
+
puts '[Paraxial] PARAXIAL_API_KEY key not set, agent not started'
|
16
16
|
elsif Rails.env.test?
|
17
|
-
puts '[Paraxial]
|
17
|
+
puts '[Paraxial] Test environment detected, agent not started'
|
18
18
|
else
|
19
19
|
begin
|
20
|
-
puts '[Paraxial]
|
20
|
+
puts '[Paraxial] API key detected, agent starting'
|
21
|
+
|
22
|
+
Paraxial.check_exploit_guard
|
23
|
+
|
21
24
|
deps_and_licenses = []
|
22
25
|
Bundler.load.specs.each do |spec|
|
23
26
|
# Print the gem name and license
|
@@ -30,7 +33,7 @@ unless Rails.env.test? || File.basename($0) == 'rake' || defined?(Rails::Generat
|
|
30
33
|
uri = URI.parse(Paraxial::Helpers.get_paraxial_url + '/api/ruby_app_lic')
|
31
34
|
headers = { 'Content-Type': 'application/json' }
|
32
35
|
|
33
|
-
body = { app_lic: deps_and_licenses, api_key
|
36
|
+
body = { app_lic: deps_and_licenses, api_key: api_key, timestamp: Paraxial.get_timestamp }
|
34
37
|
cloud_uri = URI.parse(Paraxial::Helpers.get_paraxial_url + '/api/cloud_ip_list')
|
35
38
|
response = Net::HTTP.get(cloud_uri)
|
36
39
|
|
data/lib/paraxial/version.rb
CHANGED
data/lib/paraxial.rb
CHANGED
@@ -13,6 +13,10 @@ require_relative 'paraxial/version'
|
|
13
13
|
require_relative 'paraxial/cli'
|
14
14
|
|
15
15
|
module Paraxial
|
16
|
+
class << self
|
17
|
+
attr_accessor :configuration
|
18
|
+
end
|
19
|
+
|
16
20
|
class Error < StandardError; end
|
17
21
|
# Your code goes here...
|
18
22
|
|
@@ -40,7 +44,11 @@ module Paraxial
|
|
40
44
|
end
|
41
45
|
|
42
46
|
def self.cloud_ip?(ip)
|
43
|
-
|
47
|
+
if ip.include?('.')
|
48
|
+
!!PARAXIAL_IPV4.search_best(ip)
|
49
|
+
else
|
50
|
+
!!PARAXIAL_IPV6.search_best(ip)
|
51
|
+
end
|
44
52
|
end
|
45
53
|
|
46
54
|
def self.ban_ip(ip)
|
@@ -66,4 +74,35 @@ module Paraxial
|
|
66
74
|
cleaned_string
|
67
75
|
end
|
68
76
|
end
|
77
|
+
|
78
|
+
def self.configure
|
79
|
+
self.configuration ||= Configuration.new
|
80
|
+
yield(configuration) if block_given?
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.check_exploit_guard
|
84
|
+
if configuration.nil?
|
85
|
+
puts "[Paraxial] Exploit Guard, no config exists, will not run"
|
86
|
+
return
|
87
|
+
end
|
88
|
+
|
89
|
+
case configuration.exploit_guard
|
90
|
+
when :monitor
|
91
|
+
puts "[Paraxial] Exploit Guard, running in monitor mode"
|
92
|
+
when :block
|
93
|
+
puts "[Paraxial] Exploit Guard, running in block mode"
|
94
|
+
when nil
|
95
|
+
puts "[Paraxial] Exploit Guard, not configured, will not run"
|
96
|
+
else
|
97
|
+
puts "[Paraxial] Exploit Guard, bad value"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class Configuration
|
102
|
+
attr_accessor :exploit_guard
|
103
|
+
|
104
|
+
def initialize
|
105
|
+
@exploit_guard = nil
|
106
|
+
end
|
107
|
+
end
|
69
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paraxial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Lubas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/paraxial/cli.rb
|
85
85
|
- lib/paraxial/engine.rb
|
86
86
|
- lib/paraxial/helpers.rb
|
87
|
+
- lib/paraxial/initializers/marshal_patch.rb
|
87
88
|
- lib/paraxial/initializers/startup.rb
|
88
89
|
- lib/paraxial/version.rb
|
89
90
|
- lib/rubocop/cop/paraxial/constantize.rb
|