Module: Paraxial

Defined in:
lib/paraxial.rb,
lib/paraxial/cli.rb,
lib/paraxial/engine.rb,
lib/paraxial/checker.rb,
lib/paraxial/helpers.rb,
lib/paraxial/version.rb,
lib/paraxial/free_tier.rb

Defined Under Namespace

Modules: Checker, FreeTier, Helpers Classes: CLI, Configuration, Engine, Error, PHPAttackMiddleware

Constant Summary collapse

VERSION =
'1.4.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



18
19
20
# File 'lib/paraxial.rb', line 18

def configuration
  @configuration
end

Class Method Details

.ban_ip_msg(ip, length, msg) ⇒ Object



134
135
136
137
138
# File 'lib/paraxial.rb', line 134

def self.ban_ip_msg(ip, length, msg)
  return if Paraxial::Helpers.get_api_key.nil?

  Paraxial::Checker.ban_ip_msg(ip, length, msg)
end

.block_cloud_ip(request, routes) ⇒ Object

routes = [‘/login’, ‘/users/:id’]



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/paraxial.rb', line 75

def self.block_cloud_ip(request, routes)
  return if Paraxial::Helpers.get_api_key.nil?

  ip = request.remote_ip
  cloud_provider = get_cloud_provider(ip)

  if cloud_provider
    request.env['paraxial.cloud_ip'] = cloud_provider
  else
    request.env['paraxial.cloud_ip'] = nil
  end

  route_patterns = routes.map do |route|
    Regexp.new("^" + route.gsub(/:\w+/, '\d+') + "$")
  end

  match = route_patterns.any? { |pattern| pattern.match?(request.path) }

  if match and cloud_provider
    request.env['paraxial.deny'] = true
  end
end

.check_exploit_guardObject



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/paraxial.rb', line 167

def self.check_exploit_guard
  if configuration.nil?
    # puts "[Paraxial] Exploit Guard, no configuration exists, will not run"
    return
  end

  case configuration.exploit_guard
  when :monitor
    puts "[Paraxial] Exploit Guard, running in monitor mode"
  when :block
    puts "[Paraxial] Exploit Guard, running in block mode"
  when nil
    puts "[Paraxial] Exploit Guard, not configured, will not run"
  else
    puts "[Paraxial] Exploit Guard, bad configuration value: #{configuration.exploit_guard}, will not run"
  end
end

.cloud_ip?(ip) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
117
118
119
120
121
122
# File 'lib/paraxial.rb', line 114

def self.cloud_ip?(ip)
  return if Paraxial::Helpers.get_api_key.nil?

  if ip.include?('.')
    !!PARAXIAL_IPV4.search_best(ip)
  else
    !!PARAXIAL_IPV6.search_best(ip)
  end
end

.configure {|configuration| ... } ⇒ Object

Yields:



162
163
164
165
# File 'lib/paraxial.rb', line 162

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration) if block_given?
end

.do_not_start?Boolean

Returns:

  • (Boolean)


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/paraxial.rb', line 195

def self.do_not_start?
  defined?(Rails::Command::CredentialsCommand) ||
    defined?(Rails::Command::Db::System::ChangeCommand) ||
    defined?(Rails::Command::DbConsoleCommand) ||
    defined?(Rails::Command::DestroyCommand) ||
    defined?(Rails::Command::DevCommand) ||
    defined?(Rails::Command::EncryptedCommand) ||
    defined?(Rails::Command::GenerateCommand) ||
    defined?(Rails::Command::InitializersCommand) ||
    defined?(Rails::Command::NotesCommand) ||
    defined?(Rails::Command::RoutesCommand) ||
    defined?(Rails::Command::RunnerCommand) ||
    defined?(Rails::Command::SecretsCommand) ||
    defined?(Rails::Command::AboutCommand) ||
    defined?(Rails::Command::DbconsoleCommand)
end

.get_cloud_provider(ip) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/paraxial.rb', line 124

def self.get_cloud_provider(ip)
  return if Paraxial::Helpers.get_api_key.nil?

  if ip.include?('.')
    PARAXIAL_IPV4.search_best(ip)&.data
  else
    PARAXIAL_IPV6.search_best(ip)&.data
  end
end

.get_timestampObject



51
52
53
54
# File 'lib/paraxial.rb', line 51

def self.get_timestamp
  utc_time = Time.now.utc
  utc_time.strftime('%Y-%m-%d %H:%M:%S.%6N') + 'Z'
end

.honeypot_ban(ip, length = :week) ⇒ Object



140
141
142
143
144
# File 'lib/paraxial.rb', line 140

def self.honeypot_ban(ip, length = :week)
  return if Paraxial::Helpers.get_api_key.nil?

  Paraxial::Checker.honeypot_ban(ip, length)
end

.record(request, status) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/paraxial.rb', line 56

def self.record(request, status)
  return if Paraxial::Helpers.get_api_key.nil?

  req_hash =
    {
      ip_address: request.remote_ip,
      http_method: request.request_method,
      path: request.path,
      user_agent: request.user_agent,
      allowed: !request.env['paraxial.deny'],
      status_code: status,
      inserted_at: get_timestamp,
      cloud_ip: request.env['paraxial.cloud_ip'],
      host: request.host
    }
  Paraxial::Checker.req_to_buff(req_hash)
end

.req_allowed?(request) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/paraxial.rb', line 98

def self.req_allowed?(request)
  return if Paraxial::Helpers.get_api_key.nil?

  if Paraxial::Checker.whitelist_ip?(request.remote_ip)
    request.env['paraxial.deny'] = false
    true
  elsif Paraxial::Checker.blacklist_ip?(request.remote_ip)
    request.env['paraxial.deny'] = true
    false
  elsif request.env['paraxial.deny']
    false
  else
    true
  end
end

.trim_dep(input) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/paraxial.rb', line 146

def self.trim_dep(input)
  if input.nil?
    nil
  else
    cleaned_string = input.gsub(/\n/, '')

    # Find the position of the first period
    period_index = cleaned_string.index('.')

    # If there's a period, truncate the string up to that point
    cleaned_string = cleaned_string[0..period_index] if period_index

    cleaned_string
  end
end