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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce7c75f780f9b356d4a15b4fb834bb6f064a8f5a39ead6e629a4f42ff2768010
4
- data.tar.gz: 929b701d0e47c7a12b1654c3426e515b37824f591b7a65b2c9a22630c72bc8cc
3
+ metadata.gz: fa19e78278421371d0e25cd1e387383676df44a7d09ec936520e6e2e9a4fa70f
4
+ data.tar.gz: 807b6b4401164502c8b38ea4b6ff861c667b0aee5fcd124d68a5f98c19ed5e38
5
5
  SHA512:
6
- metadata.gz: b1d9decea112098e9c71cf36d071fe1fbe86028ac23b34d4b9a704771d7a007a42f56abbaea51dc65825067e0ac5d029781b7c344c82a3cd339716908f6d8451
7
- data.tar.gz: 54bff15c7c351b7f3e74eae787d2858f12e4ded57be06cb3f5872147cdccae90819396837fa60e5ddeda6fff758eddeef0868fed4d02748c3873282c6c59306e
6
+ metadata.gz: f99fc3adc1dab0e302e45b26b2a245055b2b03eac517e5640b7f18828de1a78d64362a37811be9221b4f5c560feff727324b171d1c9493609b513de43579780a
7
+ data.tar.gz: fbe25d2549601ab95b67934deda8dd1e070d7ced5cb0abf570f85b8650acc9700d35c4274f3460a25d434a6f09c67ad80b85927564da3ba78a1b1dfa9b9ed2d0
@@ -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
- @thread = Thread.new do
8
- loop do
9
- get_abr
10
- sleep(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: ENV['PARAXIAL_API_KEY'] }
19
- r = Net::HTTP.post(uri, body.to_json, headers)
20
- if r.code == '200'
21
- put_abr(JSON.parse(r.body))
22
- else
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: ENV['PARAXIAL_API_KEY'], ip_address: ip }
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 ENV['PARAXIAL_API_KEY'].nil?
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
@@ -7,5 +7,13 @@ module Paraxial
7
7
  def self.get_ban_url
8
8
  get_paraxial_url + '/api/ban_ip'
9
9
  end
10
+
11
+ def self.get_exploit_url
12
+ get_paraxial_url + '/api/exploit'
13
+ end
14
+
15
+ def self.get_api_key
16
+ @paraxial_api_key ||= ENV['PARAXIAL_API_KEY']
17
+ end
10
18
  end
11
19
  end
@@ -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] Init start'
12
- api_key = ENV['PARAXIAL_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] Init PARAXIAL_API_KEY key not set, agent not started'
15
+ puts '[Paraxial] PARAXIAL_API_KEY key not set, agent not started'
16
16
  elsif Rails.env.test?
17
- puts '[Paraxial] Init Test environment detected, agent not started'
17
+ puts '[Paraxial] Test environment detected, agent not started'
18
18
  else
19
19
  begin
20
- puts '[Paraxial] Init config valid, agent starting'
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:, timestamp: Paraxial.get_timestamp }
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paraxial
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
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
- !!(PARAXIAL_IPV4.search_best(ip) or PARAXIAL_IPV6.search_best(ip))
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.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-22 00:00:00.000000000 Z
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