ai_root_shield 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4058e912dcc5fae977252eb4ef275a26aed884396fecb5f8b43502d2f4fc677e
4
- data.tar.gz: 4f181c2508ca61cfbc1cb72ddd0da47849db2692b4cf8f49ff3c0880999479b9
3
+ metadata.gz: f0d354e66eecc271bd43c8ac6625c186a3aa38789ac19abbe5eabc0bf4fc1641
4
+ data.tar.gz: f2ce01ca5f411532737549e534db15dd1be0f942c3ef3427e1685a4fe7c964da
5
5
  SHA512:
6
- metadata.gz: 2962bc0900324a1facec5c601fd63348bc13e39f9fb7c43c463c69174f4270f2131f54e5917d663b9d03ad488abce82ef3069de735bddbd96a5dc333b6a38577
7
- data.tar.gz: 1740c00fe8e574f0f44d860c4b269a61b5fc6ed36091481a79ab504d6592f76dbfbddeac75803814216684f6e90fb6c994962227294ed4d96ac6dbbe1df87150
6
+ metadata.gz: 05e5cfacfef14284c46aa5dbc7ae33ae5a1f70a5262c6341de8b22e968feb71c4e2f91385672d3032ea02e47ab1d21d504dfe4c0a3bb2134b9807aaea7647554
7
+ data.tar.gz: 0cc0cd97dab91107681bbbe04951f8c966a23de3e35965e8ed0d50afba5212133c2ef41b569560000c73b2b9ee22b869d22994ed73ca57749e1345c09a36e89d
data/CHANGELOG.md CHANGED
@@ -12,12 +12,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
12
12
  - Real-time threat monitoring capabilities
13
13
  - Custom rule engine for security policies
14
14
 
15
+ ## [0.3.0] - 2024-01-03
16
+
17
+ ### Added
18
+ - 🛡️ **RASP Protection**: Runtime Application Self-Protection with real-time threat blocking
19
+ - 🛡️ **Anti-Debug Mechanisms**: Ptrace, GDB, LLDB detection and blocking
20
+ - 🛡️ **Anti-Tamper Protection**: Code integrity and memory patch detection
21
+ - 🛡️ **Dynamic Memory Protection**: Frida injection hook mitigation
22
+ - 🛡️ **Runtime Integrity Monitor**: Critical function hash validation
23
+ - 🛡️ **Real-Time Event Reporting**: Instant alerts for security violations
24
+ - CLI RASP support with `--enable-rasp` and `--rasp-time` options
25
+ - Comprehensive RASP test suite with 69 passing tests
26
+ - Process monitoring for debugger detection
27
+ - Memory map analysis for injection detection
28
+ - Code integrity hash validation
29
+ - Event callback system for real-time alerts
30
+
31
+ ### Changed
32
+ - Enhanced CLI with RASP protection options
33
+ - Updated main library interface with RASP methods
34
+ - Improved error handling and protection status reporting
35
+
36
+ ### Dependencies
37
+ - Added `fiddle` for low-level system interactions (Ruby standard library)
38
+
15
39
  ## [0.2.0] - 2024-01-02
16
40
 
17
41
  ### Added
18
- - **AI Behavioral Analysis**: ONNX-powered behavioral pattern analysis with anomaly detection
19
- - **ML-Based Emulator Detection**: Advanced machine learning techniques for emulator identification
20
- - **AI Confidence Scoring**: Confidence metrics integrated into risk assessment
42
+ - 🤖 **AI Behavioral Analysis**: ONNX-powered behavioral pattern analysis with anomaly detection
43
+ - 🤖 **ML-Based Emulator Detection**: Advanced machine learning techniques for emulator identification
44
+ - 🤖 **AI Confidence Scoring**: Confidence metrics integrated into risk assessment
21
45
  - File access pattern analysis with entropy calculation
22
46
  - Sensor data consistency validation
23
47
  - Hardware fingerprinting with advanced characteristics
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ai_root_shield (0.2.0)
4
+ ai_root_shield (0.3.0)
5
5
  digest (~> 3.1)
6
6
  json (~> 2.6)
7
7
  numo-narray (~> 0.9)
data/README.md CHANGED
@@ -17,6 +17,11 @@ An AI-powered Ruby library that performs comprehensive on-device compromise dete
17
17
  - **Hooking Framework Detection**: Detects Frida, Xposed, Substrate, and other instrumentation tools
18
18
  - **Application Integrity Checks**: Validates app signatures and detects repackaging/tampering
19
19
  - **Network Security Analysis**: Identifies TLS issues, custom CAs, and MITM tools
20
+ - **🆕 RASP Protection**: Runtime Application Self-Protection with real-time threat blocking
21
+ - **🆕 Anti-Debug Mechanisms**: Ptrace, GDB, LLDB detection and blocking
22
+ - **🆕 Anti-Tamper Protection**: Code integrity and memory patch detection
23
+ - **🆕 Dynamic Memory Protection**: Frida injection hook mitigation
24
+ - **🆕 Runtime Integrity Monitor**: Critical function hash validation
20
25
  - **AI Behavioral Analysis**: ONNX-powered behavioral pattern analysis with anomaly detection
21
26
  - **ML-Based Emulator Detection**: Advanced machine learning techniques for emulator identification
22
27
  - **AI Confidence Scoring**: Confidence metrics integrated into risk assessment
@@ -68,9 +73,9 @@ config = {
68
73
  enable_hooking_detection: true,
69
74
  enable_integrity_checks: true,
70
75
  enable_network_analysis: true,
71
- enable_ai_behavioral_analysis: true, # New in v0.2.0
76
+ enable_ai_behavioral_analysis: true, # v0.2.0
72
77
  risk_threshold: 70,
73
- ai_confidence_threshold: 0.7 # New in v0.2.0
78
+ ai_confidence_threshold: 0.7 # v0.2.0
74
79
  }
75
80
 
76
81
  result = AiRootShield.scan_device_with_config("device_logs/sample.json", config)
@@ -127,6 +132,55 @@ puts "AI Confidence: #{result[:ai_confidence]}"
127
132
  puts "ML Emulator Score: #{result[:ml_emulator_score]}"
128
133
  ```
129
134
 
135
+ ## RASP Protection (New in v0.3.0)
136
+
137
+ Runtime Application Self-Protection provides real-time threat detection and blocking:
138
+
139
+ ### Features
140
+ - **Anti-Debug Protection**: Detects and blocks ptrace, GDB, LLDB, and other debuggers
141
+ - **Anti-Tamper Protection**: Monitors code integrity and detects memory patches
142
+ - **Dynamic Memory Protection**: Prevents Frida injection and hook attempts
143
+ - **Runtime Integrity Monitor**: Validates critical function hashes in real-time
144
+ - **Real-Time Event Reporting**: Instant alerts for security violations
145
+
146
+ ### Usage
147
+
148
+ ```ruby
149
+ # Start RASP protection
150
+ rasp = AiRootShield.start_rasp_protection(
151
+ enable_anti_debug: true,
152
+ enable_anti_tamper: true,
153
+ enable_memory_protection: true,
154
+ enable_integrity_monitor: true,
155
+ enable_real_time_alerts: true,
156
+ protection_interval: 1.0
157
+ )
158
+
159
+ # Register event callback
160
+ rasp.on_rasp_event do |event|
161
+ puts "[RASP] #{event[:type]}: #{event[:message]}"
162
+ # Take action based on threat type
163
+ end
164
+
165
+ # Check protection status
166
+ status = rasp.protection_status
167
+ puts "RASP Active: #{status[:active]}"
168
+ puts "Events Detected: #{status[:events_detected]}"
169
+
170
+ # Stop protection when done
171
+ AiRootShield.stop_rasp_protection
172
+ ```
173
+
174
+ ### CLI RASP Support
175
+
176
+ ```bash
177
+ # Enable RASP protection during scan
178
+ $ ai_root_shield --enable-rasp --rasp-time 10 --verbose device_logs.json
179
+
180
+ # Monitor for 30 seconds with RASP
181
+ $ ai_root_shield --enable-rasp --rasp-time 30 device_logs.json
182
+ ```
183
+
130
184
  ## Risk Scoring
131
185
 
132
186
  The library provides a comprehensive risk score (0-100) based on detected security factors:
@@ -170,7 +224,7 @@ The library expects device logs in JSON format with the following structure:
170
224
  "ABNORMAL_TIMING_PATTERNS"
171
225
  ],
172
226
  "timestamp": 1640995200,
173
- "version": "0.2.0"
227
+ "version": "0.3.0"
174
228
  }
175
229
  ```
176
230
 
data/exe/ai_root_shield CHANGED
@@ -1,17 +1,25 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "../lib/ai_root_shield"
5
4
  require "optparse"
6
5
  require "json"
6
+ require_relative "../lib/ai_root_shield"
7
7
 
8
- # CLI interface for AI Root Shield
8
+ # Command line interface for AI Root Shield
9
9
  class AiRootShieldCLI
10
10
  def initialize
11
11
  @options = {
12
- config: {},
13
- output_format: "json",
14
- verbose: false
12
+ format: "json",
13
+ verbose: false,
14
+ threshold: 50,
15
+ enable_root_detection: true,
16
+ enable_emulator_detection: true,
17
+ enable_hooking_detection: true,
18
+ enable_integrity_checks: true,
19
+ enable_network_analysis: true,
20
+ enable_ai_behavioral_analysis: true,
21
+ enable_rasp_protection: false,
22
+ rasp_monitoring_time: 5
15
23
  }
16
24
  end
17
25
 
@@ -32,8 +40,35 @@ class AiRootShieldCLI
32
40
  end
33
41
 
34
42
  begin
35
- result = AiRootShield.scan_device_with_config(device_logs_path, @options[:config])
43
+ # Start RASP protection if enabled
44
+ if @options[:enable_rasp_protection]
45
+ puts "Starting RASP protection..." if @options[:verbose]
46
+ rasp = AiRootShield.start_rasp_protection(
47
+ enable_real_time_alerts: @options[:verbose],
48
+ protection_interval: 0.5
49
+ )
50
+
51
+ # Set up RASP event logging if verbose
52
+ if @options[:verbose]
53
+ rasp.on_rasp_event do |event|
54
+ puts "[RASP] #{event[:type]}: #{event[:message]}"
55
+ end
56
+ end
57
+
58
+ # Monitor for specified time
59
+ puts "Monitoring with RASP protection for #{@options[:rasp_monitoring_time]} seconds..." if @options[:verbose]
60
+ sleep(@options[:rasp_monitoring_time])
61
+ end
62
+
63
+ result = AiRootShield.scan_device_with_config(device_logs_path, @options)
64
+
65
+ # Add RASP status to result if enabled
66
+ if @options[:enable_rasp_protection] && AiRootShield.rasp_active?
67
+ result[:rasp_status] = AiRootShield.rasp_protection.protection_status
68
+ end
69
+
36
70
  output_result(result)
71
+
37
72
  rescue AiRootShield::Error => e
38
73
  puts "Error: #{e.message}"
39
74
  exit 1
@@ -41,6 +76,9 @@ class AiRootShieldCLI
41
76
  puts "Unexpected error: #{e.message}"
42
77
  puts e.backtrace if @options[:verbose]
43
78
  exit 1
79
+ ensure
80
+ # Stop RASP protection
81
+ AiRootShield.stop_rasp_protection if @options[:enable_rasp_protection]
44
82
  end
45
83
  end
46
84
 
@@ -54,7 +92,7 @@ class AiRootShieldCLI
54
92
 
55
93
  opts.on("-f", "--format FORMAT", ["json", "text", "summary"],
56
94
  "Output format (json, text, summary)") do |format|
57
- @options[:output_format] = format
95
+ @options[:format] = format
58
96
  end
59
97
 
60
98
  opts.on("-v", "--verbose", "Enable verbose output") do
@@ -63,27 +101,39 @@ class AiRootShieldCLI
63
101
 
64
102
  opts.on("-t", "--threshold SCORE", Integer,
65
103
  "Risk threshold (0-100, default: 50)") do |threshold|
66
- @options[:config][:risk_threshold] = threshold
104
+ @options[:threshold] = threshold
67
105
  end
68
106
 
69
107
  opts.on("--no-root", "Disable root detection") do
70
- @options[:config][:enable_root_detection] = false
108
+ @options[:enable_root_detection] = false
71
109
  end
72
110
 
73
111
  opts.on("--no-emulator", "Disable emulator detection") do
74
- @options[:config][:enable_emulator_detection] = false
112
+ @options[:enable_emulator_detection] = false
75
113
  end
76
114
 
77
115
  opts.on("--no-hooking", "Disable hooking detection") do
78
- @options[:config][:enable_hooking_detection] = false
116
+ @options[:enable_hooking_detection] = false
79
117
  end
80
118
 
81
119
  opts.on("--no-integrity", "Disable integrity checks") do
82
- @options[:config][:enable_integrity_checks] = false
120
+ @options[:enable_integrity_checks] = false
83
121
  end
84
122
 
85
123
  opts.on("--no-network", "Disable network analysis") do
86
- @options[:config][:enable_network_analysis] = false
124
+ @options[:enable_network_analysis] = false
125
+ end
126
+
127
+ opts.on("--no-ai", "Disable AI behavioral analysis") do
128
+ @options[:enable_ai_behavioral_analysis] = false
129
+ end
130
+
131
+ opts.on("--enable-rasp", "Enable RASP protection during scan") do
132
+ @options[:enable_rasp_protection] = true
133
+ end
134
+
135
+ opts.on("--rasp-time SECONDS", Integer, "RASP monitoring time in seconds (default: 5)") do |time|
136
+ @options[:rasp_monitoring_time] = time
87
137
  end
88
138
 
89
139
  opts.on("-h", "--help", "Show this help message") do
@@ -0,0 +1,359 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "fiddle"
5
+
6
+ module AiRootShield
7
+ # Runtime Application Self-Protection (RASP) system
8
+ # Provides real-time protection against debugging, tampering, and injection attacks
9
+ class RaspProtection
10
+ # RASP event types for real-time reporting
11
+ RASP_EVENTS = {
12
+ debug_attempt: "DEBUG_ATTEMPT_DETECTED",
13
+ tamper_detected: "CODE_TAMPER_DETECTED",
14
+ injection_blocked: "INJECTION_ATTEMPT_BLOCKED",
15
+ integrity_violation: "INTEGRITY_VIOLATION_DETECTED",
16
+ memory_patch: "MEMORY_PATCH_DETECTED"
17
+ }.freeze
18
+
19
+ def initialize(config = {})
20
+ @config = {
21
+ enable_anti_debug: true,
22
+ enable_anti_tamper: true,
23
+ enable_memory_protection: true,
24
+ enable_integrity_monitor: true,
25
+ enable_real_time_alerts: true,
26
+ alert_callback: nil,
27
+ critical_functions: [],
28
+ protection_interval: 1.0
29
+ }.merge(config)
30
+
31
+ @event_callbacks = []
32
+ @protection_active = false
33
+ @integrity_hashes = {}
34
+ @original_memory_maps = {}
35
+ @protection_thread = nil
36
+ @last_check_time = Time.now
37
+
38
+ initialize_protection if @config[:enable_real_time_alerts]
39
+ end
40
+
41
+ # Start RASP protection monitoring
42
+ def start_protection
43
+ return if @protection_active
44
+
45
+ @protection_active = true
46
+
47
+ # Initialize anti-debug protection
48
+ setup_anti_debug_protection if @config[:enable_anti_debug]
49
+
50
+ # Initialize anti-tamper protection
51
+ setup_anti_tamper_protection if @config[:enable_anti_tamper]
52
+
53
+ # Initialize memory protection
54
+ setup_memory_protection if @config[:enable_memory_protection]
55
+
56
+ # Initialize integrity monitoring
57
+ setup_integrity_monitoring if @config[:enable_integrity_monitor]
58
+
59
+ # Start real-time monitoring thread
60
+ start_monitoring_thread
61
+
62
+ report_rasp_event(:protection_started, "RASP protection activated")
63
+ end
64
+
65
+ # Stop RASP protection monitoring
66
+ def stop_protection
67
+ @protection_active = false
68
+ @protection_thread&.kill
69
+ @protection_thread = nil
70
+
71
+ report_rasp_event(:protection_stopped, "RASP protection deactivated")
72
+ end
73
+
74
+ # Register callback for RASP events
75
+ def on_rasp_event(&block)
76
+ @event_callbacks << block if block_given?
77
+ end
78
+
79
+ # Check current protection status
80
+ def protection_status
81
+ {
82
+ active: @protection_active,
83
+ anti_debug_enabled: @config[:enable_anti_debug],
84
+ anti_tamper_enabled: @config[:enable_anti_tamper],
85
+ memory_protection_enabled: @config[:enable_memory_protection],
86
+ integrity_monitor_enabled: @config[:enable_integrity_monitor],
87
+ events_detected: @events_detected || 0,
88
+ last_check: @last_check_time
89
+ }
90
+ end
91
+
92
+ private
93
+
94
+ def initialize_protection
95
+ @events_detected = 0
96
+ @last_check_time = Time.now
97
+ end
98
+
99
+ # Anti-Debug Protection Implementation
100
+ def setup_anti_debug_protection
101
+ # Check for ptrace attachment
102
+ check_ptrace_protection
103
+
104
+ # Check for debugger processes
105
+ check_debugger_processes
106
+
107
+ # Check for debug environment variables
108
+ check_debug_environment
109
+ end
110
+
111
+ def check_ptrace_protection
112
+ # Attempt to detect ptrace attachment
113
+ if ptrace_detected?
114
+ report_rasp_event(:debug_attempt, "Ptrace debugger attachment detected")
115
+ take_protection_action(:debug_attempt)
116
+ end
117
+ end
118
+
119
+ def ptrace_detected?
120
+ # Check /proc/self/status for TracerPid on Linux
121
+ return false unless File.exist?("/proc/self/status")
122
+
123
+ status_content = File.read("/proc/self/status")
124
+ tracer_line = status_content.lines.find { |line| line.start_with?("TracerPid:") }
125
+
126
+ if tracer_line
127
+ tracer_pid = tracer_line.split(":")[1].strip.to_i
128
+ return tracer_pid != 0
129
+ end
130
+
131
+ false
132
+ rescue
133
+ false
134
+ end
135
+
136
+ def check_debugger_processes
137
+ debugger_processes = ["gdb", "lldb", "strace", "ltrace", "frida-server", "frida"]
138
+
139
+ debugger_processes.each do |debugger|
140
+ if process_running?(debugger)
141
+ report_rasp_event(:debug_attempt, "Debugger process detected: #{debugger}")
142
+ take_protection_action(:debug_attempt)
143
+ end
144
+ end
145
+ end
146
+
147
+ def process_running?(process_name)
148
+ `pgrep #{process_name}`.strip.length > 0
149
+ rescue
150
+ false
151
+ end
152
+
153
+ def check_debug_environment
154
+ debug_vars = ["DEBUG", "LLDB_DEBUGSERVER_PATH", "DYLD_INSERT_LIBRARIES"]
155
+
156
+ debug_vars.each do |var|
157
+ if ENV[var]
158
+ report_rasp_event(:debug_attempt, "Debug environment variable detected: #{var}")
159
+ take_protection_action(:debug_attempt)
160
+ end
161
+ end
162
+ end
163
+
164
+ # Anti-Tamper Protection Implementation
165
+ def setup_anti_tamper_protection
166
+ # Calculate initial code integrity hashes
167
+ calculate_code_integrity_hashes
168
+
169
+ # Monitor for code modifications
170
+ monitor_code_integrity
171
+ end
172
+
173
+ def calculate_code_integrity_hashes
174
+ # Hash critical Ruby files and libraries
175
+ critical_files = [
176
+ __FILE__,
177
+ File.join(__dir__, "detector.rb"),
178
+ File.join(__dir__, "ai_behavioral_analyzer.rb")
179
+ ]
180
+
181
+ critical_files.each do |file|
182
+ next unless File.exist?(file)
183
+
184
+ content = File.read(file)
185
+ @integrity_hashes[file] = Digest::SHA256.hexdigest(content)
186
+ end
187
+ end
188
+
189
+ def monitor_code_integrity
190
+ @integrity_hashes.each do |file, original_hash|
191
+ next unless File.exist?(file)
192
+
193
+ current_content = File.read(file)
194
+ current_hash = Digest::SHA256.hexdigest(current_content)
195
+
196
+ if current_hash != original_hash
197
+ report_rasp_event(:tamper_detected, "Code integrity violation: #{file}")
198
+ take_protection_action(:tamper_detected)
199
+ end
200
+ end
201
+ rescue
202
+ # File access errors might indicate tampering
203
+ report_rasp_event(:tamper_detected, "File access anomaly detected")
204
+ end
205
+
206
+ # Memory Protection Implementation
207
+ def setup_memory_protection
208
+ # Monitor for Frida injection signatures
209
+ check_frida_injection
210
+
211
+ # Monitor memory patches
212
+ monitor_memory_patches
213
+ end
214
+
215
+ def check_frida_injection
216
+ frida_indicators = [
217
+ "frida",
218
+ "gum-js-loop",
219
+ "gmain",
220
+ "glib-",
221
+ "FridaGadget"
222
+ ]
223
+
224
+ # Check loaded libraries for Frida signatures
225
+ if maps_content = read_proc_maps
226
+ frida_indicators.each do |indicator|
227
+ if maps_content.include?(indicator)
228
+ report_rasp_event(:injection_blocked, "Frida injection detected: #{indicator}")
229
+ take_protection_action(:injection_blocked)
230
+ end
231
+ end
232
+ end
233
+ end
234
+
235
+ def read_proc_maps
236
+ File.read("/proc/self/maps") if File.exist?("/proc/self/maps")
237
+ rescue
238
+ nil
239
+ end
240
+
241
+ def monitor_memory_patches
242
+ # Check for suspicious memory modifications
243
+ if maps_content = read_proc_maps
244
+ # Look for executable memory regions that shouldn't be there
245
+ suspicious_regions = maps_content.lines.select do |line|
246
+ line.include?("rwxp") && !line.include?("[stack]") && !line.include?("[heap]")
247
+ end
248
+
249
+ unless suspicious_regions.empty?
250
+ report_rasp_event(:memory_patch, "Suspicious executable memory regions detected")
251
+ take_protection_action(:memory_patch)
252
+ end
253
+ end
254
+ end
255
+
256
+ # Runtime Integrity Monitor Implementation
257
+ def setup_integrity_monitoring
258
+ # Monitor critical function integrity
259
+ monitor_critical_functions
260
+ end
261
+
262
+ def monitor_critical_functions
263
+ @config[:critical_functions].each do |function_info|
264
+ validate_function_integrity(function_info)
265
+ end
266
+ end
267
+
268
+ def validate_function_integrity(function_info)
269
+ # Validate function hash if provided
270
+ if function_info[:hash] && function_info[:method]
271
+ current_hash = calculate_method_hash(function_info[:method])
272
+
273
+ if current_hash != function_info[:hash]
274
+ report_rasp_event(:integrity_violation,
275
+ "Critical function integrity violation: #{function_info[:method]}")
276
+ take_protection_action(:integrity_violation)
277
+ end
278
+ end
279
+ end
280
+
281
+ def calculate_method_hash(method_obj)
282
+ # Calculate hash of method source if available
283
+ if method_obj.respond_to?(:source)
284
+ Digest::SHA256.hexdigest(method_obj.source)
285
+ else
286
+ # Fallback to method object hash
287
+ Digest::SHA256.hexdigest(method_obj.to_s)
288
+ end
289
+ rescue
290
+ nil
291
+ end
292
+
293
+ # Real-time Monitoring Thread
294
+ def start_monitoring_thread
295
+ @protection_thread = Thread.new do
296
+ while @protection_active
297
+ perform_protection_checks
298
+ sleep(@config[:protection_interval])
299
+ end
300
+ end
301
+ end
302
+
303
+ def perform_protection_checks
304
+ @last_check_time = Time.now
305
+
306
+ # Perform all protection checks
307
+ check_ptrace_protection if @config[:enable_anti_debug]
308
+ check_debugger_processes if @config[:enable_anti_debug]
309
+ monitor_code_integrity if @config[:enable_anti_tamper]
310
+ check_frida_injection if @config[:enable_memory_protection]
311
+ monitor_memory_patches if @config[:enable_memory_protection]
312
+ monitor_critical_functions if @config[:enable_integrity_monitor]
313
+ end
314
+
315
+ # Event Reporting System
316
+ def report_rasp_event(event_type, message, details = {})
317
+ return unless @config[:enable_real_time_alerts]
318
+
319
+ @events_detected = (@events_detected || 0) + 1
320
+
321
+ event_data = {
322
+ type: RASP_EVENTS[event_type] || event_type.to_s.upcase,
323
+ message: message,
324
+ timestamp: Time.now.to_f,
325
+ details: details,
326
+ protection_status: protection_status
327
+ }
328
+
329
+ # Call registered callbacks
330
+ @event_callbacks.each do |callback|
331
+ callback.call(event_data) rescue nil
332
+ end
333
+
334
+ # Call configured alert callback
335
+ @config[:alert_callback]&.call(event_data) rescue nil
336
+
337
+ # Log to stderr for immediate visibility
338
+ warn "[RASP] #{event_data[:type]}: #{message}" if @config[:enable_real_time_alerts]
339
+ end
340
+
341
+ # Protection Actions
342
+ def take_protection_action(threat_type)
343
+ case threat_type
344
+ when :debug_attempt
345
+ # Could implement process termination, obfuscation, etc.
346
+ report_rasp_event(:protection_action, "Anti-debug countermeasure activated")
347
+ when :tamper_detected
348
+ # Could implement integrity restoration, alerts, etc.
349
+ report_rasp_event(:protection_action, "Anti-tamper countermeasure activated")
350
+ when :injection_blocked
351
+ # Could implement injection blocking, process isolation, etc.
352
+ report_rasp_event(:protection_action, "Injection blocking countermeasure activated")
353
+ when :integrity_violation
354
+ # Could implement function restoration, alerts, etc.
355
+ report_rasp_event(:protection_action, "Integrity protection countermeasure activated")
356
+ end
357
+ end
358
+ end
359
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AiRootShield
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -8,17 +8,21 @@ require_relative "ai_root_shield/analyzers/hooking_detector"
8
8
  require_relative "ai_root_shield/analyzers/integrity_checker"
9
9
  require_relative "ai_root_shield/analyzers/network_analyzer"
10
10
  require_relative "ai_root_shield/ai_behavioral_analyzer"
11
+ require_relative "ai_root_shield/rasp_protection"
11
12
  require_relative "ai_root_shield/risk_calculator"
12
13
  require_relative "ai_root_shield/device_log_parser"
13
14
 
14
15
  module AiRootShield
15
16
  class Error < StandardError; end
16
17
 
18
+ # Global RASP protection instance
19
+ @rasp_protection = nil
20
+
17
21
  # Main entry point for device scanning
18
22
  # @param device_logs_path [String] Path to device logs JSON file
19
23
  # @return [Hash] Risk assessment result with score and factors
20
24
  def self.scan_device(device_logs_path)
21
- Detector.new.scan(device_logs_path)
25
+ scan_device_with_config(device_logs_path)
22
26
  end
23
27
 
24
28
  # Scan device with custom configuration
@@ -26,7 +30,35 @@ module AiRootShield
26
30
  # @param config [Hash] Configuration options
27
31
  # @return [Hash] Risk assessment result with score and factors
28
32
  def self.scan_device_with_config(device_logs_path, config = {})
29
- Detector.new(config).scan(device_logs_path)
33
+ detector = Detector.new(config)
34
+ detector.scan(device_logs_path)
35
+ end
36
+
37
+ # Start RASP protection
38
+ # @param config [Hash] RASP configuration options
39
+ # @return [RaspProtection] RASP protection instance
40
+ def self.start_rasp_protection(config = {})
41
+ @rasp_protection = RaspProtection.new(config)
42
+ @rasp_protection.start_protection
43
+ @rasp_protection
44
+ end
45
+
46
+ # Stop RASP protection
47
+ def self.stop_rasp_protection
48
+ @rasp_protection&.stop_protection
49
+ @rasp_protection = nil
50
+ end
51
+
52
+ # Get current RASP protection instance
53
+ # @return [RaspProtection, nil] Current RASP protection instance
54
+ def self.rasp_protection
55
+ @rasp_protection
56
+ end
57
+
58
+ # Check if RASP protection is active
59
+ # @return [Boolean] True if RASP protection is active
60
+ def self.rasp_active?
61
+ @rasp_protection&.protection_status&.dig(:active) || false
30
62
  end
31
63
 
32
64
  # Get version information
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ai_root_shield
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmet KAHRAMAN
@@ -178,6 +178,7 @@ files:
178
178
  - lib/ai_root_shield/analyzers/root_detector.rb
179
179
  - lib/ai_root_shield/detector.rb
180
180
  - lib/ai_root_shield/device_log_parser.rb
181
+ - lib/ai_root_shield/rasp_protection.rb
181
182
  - lib/ai_root_shield/risk_calculator.rb
182
183
  - lib/ai_root_shield/version.rb
183
184
  - models/README.md