ai_root_shield 0.3.0 → 0.5.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 +4 -4
- data/CHANGELOG.md +25 -0
- data/Gemfile.lock +1 -1
- data/README.md +210 -12
- data/examples/policies/banking_policy.json +79 -0
- data/examples/policies/development_policy.json +64 -0
- data/examples/policies/enterprise_policy.json +89 -0
- data/exe/ai_root_shield +314 -8
- data/lib/ai_root_shield/advanced_proxy_detector.rb +406 -0
- data/lib/ai_root_shield/certificate_pinning_helper.rb +258 -0
- data/lib/ai_root_shield/enterprise_policy_manager.rb +431 -0
- data/lib/ai_root_shield/version.rb +1 -1
- data/lib/ai_root_shield.rb +290 -4
- metadata +15 -5
data/lib/ai_root_shield.rb
CHANGED
@@ -11,12 +11,39 @@ require_relative "ai_root_shield/ai_behavioral_analyzer"
|
|
11
11
|
require_relative "ai_root_shield/rasp_protection"
|
12
12
|
require_relative "ai_root_shield/risk_calculator"
|
13
13
|
require_relative "ai_root_shield/device_log_parser"
|
14
|
+
require_relative "ai_root_shield/certificate_pinning_helper"
|
15
|
+
require_relative "ai_root_shield/advanced_proxy_detector"
|
16
|
+
require_relative "ai_root_shield/enterprise_policy_manager"
|
17
|
+
|
18
|
+
# v0.5.0 Platform-specific security modules
|
19
|
+
require_relative "ai_root_shield/platform/android_security_module"
|
20
|
+
require_relative "ai_root_shield/platform/ios_security_module"
|
21
|
+
require_relative "ai_root_shield/platform/hardware_security_analyzer"
|
22
|
+
require_relative "ai_root_shield/platform/unified_report_generator"
|
23
|
+
|
24
|
+
# v0.5.0 CI/CD and developer tools
|
25
|
+
require_relative "ai_root_shield/ci_cd/security_test_module"
|
26
|
+
|
27
|
+
# v0.5.0 Dashboard and visualization
|
28
|
+
require_relative "ai_root_shield/dashboard/web_dashboard"
|
29
|
+
|
30
|
+
# v0.5.0 Third-party integrations
|
31
|
+
require_relative "ai_root_shield/integrations/siem_connector"
|
14
32
|
|
15
33
|
module AiRootShield
|
16
34
|
class Error < StandardError; end
|
17
35
|
|
18
|
-
# Global
|
36
|
+
# Global instances
|
19
37
|
@rasp_protection = nil
|
38
|
+
@policy_manager = nil
|
39
|
+
@certificate_pinning = nil
|
40
|
+
@proxy_detector = nil
|
41
|
+
@android_module = nil
|
42
|
+
@ios_module = nil
|
43
|
+
@hardware_analyzer = nil
|
44
|
+
@report_generator = nil
|
45
|
+
@ci_cd_module = nil
|
46
|
+
@siem_connector = nil
|
20
47
|
|
21
48
|
# Main entry point for device scanning
|
22
49
|
# @param device_logs_path [String] Path to device logs JSON file
|
@@ -25,13 +52,26 @@ module AiRootShield
|
|
25
52
|
scan_device_with_config(device_logs_path)
|
26
53
|
end
|
27
54
|
|
28
|
-
# Scan device with custom configuration
|
55
|
+
# Scan device with custom configuration and policy validation
|
29
56
|
# @param device_logs_path [String] Path to device logs JSON file
|
30
57
|
# @param config [Hash] Configuration options
|
31
|
-
# @return [Hash] Risk assessment result with score and
|
58
|
+
# @return [Hash] Risk assessment result with score, factors, and compliance
|
32
59
|
def self.scan_device_with_config(device_logs_path, config = {})
|
33
60
|
detector = Detector.new(config)
|
34
|
-
detector.scan(device_logs_path)
|
61
|
+
scan_result = detector.scan(device_logs_path)
|
62
|
+
|
63
|
+
# Add network security analysis if enabled
|
64
|
+
if config[:enable_network_analysis]
|
65
|
+
scan_result = enhance_with_network_analysis(scan_result, config)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Add policy compliance validation if policy manager is configured
|
69
|
+
if @policy_manager
|
70
|
+
compliance_result = @policy_manager.validate_compliance(scan_result)
|
71
|
+
scan_result[:compliance] = compliance_result
|
72
|
+
end
|
73
|
+
|
74
|
+
scan_result
|
35
75
|
end
|
36
76
|
|
37
77
|
# Start RASP protection
|
@@ -49,21 +89,267 @@ module AiRootShield
|
|
49
89
|
@rasp_protection = nil
|
50
90
|
end
|
51
91
|
|
92
|
+
# Configure enterprise policy
|
93
|
+
# @param policy_config [String, Hash] Policy file path or configuration hash
|
94
|
+
# @return [EnterprisePolicyManager] Policy manager instance
|
95
|
+
def self.configure_policy(policy_config)
|
96
|
+
@policy_manager = EnterprisePolicyManager.new(policy_config)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Configure certificate pinning
|
100
|
+
# @param config [Hash] Certificate pinning configuration
|
101
|
+
# @return [CertificatePinningHelper] Certificate pinning helper instance
|
102
|
+
def self.configure_certificate_pinning(config = {})
|
103
|
+
@certificate_pinning = CertificatePinningHelper.new(config)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Configure proxy detection
|
107
|
+
# @param config [Hash] Proxy detection configuration
|
108
|
+
# @return [AdvancedProxyDetector] Proxy detector instance
|
109
|
+
def self.configure_proxy_detection(config = {})
|
110
|
+
@proxy_detector = AdvancedProxyDetector.new(config)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Validate certificate pinning for a URL
|
114
|
+
# @param url [String] URL to validate
|
115
|
+
# @return [Hash] Validation result
|
116
|
+
def self.validate_certificate_pinning(url)
|
117
|
+
return { error: "Certificate pinning not configured" } unless @certificate_pinning
|
118
|
+
|
119
|
+
cert_chain = @certificate_pinning.get_certificate_chain(url)
|
120
|
+
@certificate_pinning.validate_pin(url, cert_chain)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Detect proxy usage for an IP address
|
124
|
+
# @param ip_address [String] IP address to analyze
|
125
|
+
# @param additional_data [Hash] Additional network data
|
126
|
+
# @return [Hash] Proxy detection result
|
127
|
+
def self.detect_proxy(ip_address, additional_data = {})
|
128
|
+
return { error: "Proxy detection not configured" } unless @proxy_detector
|
129
|
+
|
130
|
+
@proxy_detector.detect_proxy(ip_address, additional_data)
|
131
|
+
end
|
132
|
+
|
52
133
|
# Get current RASP protection instance
|
53
134
|
# @return [RaspProtection, nil] Current RASP protection instance
|
54
135
|
def self.rasp_protection
|
55
136
|
@rasp_protection
|
56
137
|
end
|
57
138
|
|
139
|
+
# Get current policy manager instance
|
140
|
+
# @return [EnterprisePolicyManager, nil] Current policy manager instance
|
141
|
+
def self.policy_manager
|
142
|
+
@policy_manager
|
143
|
+
end
|
144
|
+
|
145
|
+
# Get current certificate pinning helper instance
|
146
|
+
# @return [CertificatePinningHelper, nil] Current certificate pinning helper instance
|
147
|
+
def self.certificate_pinning
|
148
|
+
@certificate_pinning
|
149
|
+
end
|
150
|
+
|
151
|
+
# Get current proxy detector instance
|
152
|
+
# @return [AdvancedProxyDetector, nil] Current proxy detector instance
|
153
|
+
def self.proxy_detector
|
154
|
+
@proxy_detector
|
155
|
+
end
|
156
|
+
|
157
|
+
# v0.5.0 Platform-specific security analysis
|
158
|
+
# Analyze Android device security using SafetyNet and Play Integrity APIs
|
159
|
+
# @param device_logs [Hash] Device logs data
|
160
|
+
# @param config [Hash] Configuration options
|
161
|
+
# @return [Hash] Android security analysis results
|
162
|
+
def self.analyze_android_security(device_logs, config = {})
|
163
|
+
@android_module ||= Platform::AndroidSecurityModule.new(config)
|
164
|
+
@android_module.analyze_device_security(device_logs)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Analyze iOS device security with advanced jailbreak detection
|
168
|
+
# @param device_logs [Hash] Device logs data
|
169
|
+
# @return [Hash] iOS security analysis results
|
170
|
+
def self.analyze_ios_security(device_logs)
|
171
|
+
@ios_module ||= Platform::IosSecurityModule.new
|
172
|
+
@ios_module.analyze_device_security(device_logs)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Analyze hardware security features (TEE/SE, biometrics)
|
176
|
+
# @param device_logs [Hash] Device logs data
|
177
|
+
# @param platform [String] Platform type ('android' or 'ios')
|
178
|
+
# @return [Hash] Hardware security analysis results
|
179
|
+
def self.analyze_hardware_security(device_logs, platform)
|
180
|
+
@hardware_analyzer ||= Platform::HardwareSecurityAnalyzer.new
|
181
|
+
@hardware_analyzer.analyze_hardware_security(device_logs, platform)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Generate unified cross-platform security report
|
185
|
+
# @param android_results [Hash] Android analysis results
|
186
|
+
# @param ios_results [Hash] iOS analysis results
|
187
|
+
# @param metadata [Hash] Report metadata
|
188
|
+
# @return [Hash] Unified security report
|
189
|
+
def self.generate_unified_report(android_results: nil, ios_results: nil, metadata: {})
|
190
|
+
@report_generator ||= Platform::UnifiedReportGenerator.new
|
191
|
+
@report_generator.generate_unified_report(
|
192
|
+
android_results: android_results,
|
193
|
+
ios_results: ios_results,
|
194
|
+
metadata: metadata
|
195
|
+
)
|
196
|
+
end
|
197
|
+
|
198
|
+
# Run CI/CD security tests
|
199
|
+
# @param device_logs_path [String] Path to device logs file
|
200
|
+
# @param options [Hash] Test configuration options
|
201
|
+
# @return [Hash] CI/CD test results
|
202
|
+
def self.run_ci_cd_tests(device_logs_path, options = {})
|
203
|
+
@ci_cd_module ||= CiCd::SecurityTestModule.new(options)
|
204
|
+
@ci_cd_module.run_security_tests(device_logs_path, options)
|
205
|
+
end
|
206
|
+
|
207
|
+
# Generate CI/CD configuration for specified platform
|
208
|
+
# @param platform [String] CI/CD platform name
|
209
|
+
# @param options [Hash] Configuration options
|
210
|
+
# @return [String] CI/CD configuration content
|
211
|
+
def self.generate_ci_config(platform, options = {})
|
212
|
+
@ci_cd_module ||= CiCd::SecurityTestModule.new
|
213
|
+
@ci_cd_module.generate_ci_config(platform, options)
|
214
|
+
end
|
215
|
+
|
216
|
+
# Configure SIEM integration
|
217
|
+
# @param platform [Symbol] SIEM platform (:splunk, :elastic, etc.)
|
218
|
+
# @param config [Hash] SIEM configuration
|
219
|
+
# @return [Integrations::SiemConnector] SIEM connector instance
|
220
|
+
def self.configure_siem(platform, config = {})
|
221
|
+
@siem_connector = Integrations::SiemConnector.new(platform, config)
|
222
|
+
end
|
223
|
+
|
224
|
+
# Send security events to SIEM
|
225
|
+
# @param analysis_results [Hash] Security analysis results
|
226
|
+
# @param metadata [Hash] Event metadata
|
227
|
+
# @return [Hash] SIEM response
|
228
|
+
def self.send_to_siem(analysis_results, metadata = {})
|
229
|
+
return { error: "SIEM not configured" } unless @siem_connector
|
230
|
+
|
231
|
+
@siem_connector.send_security_event(analysis_results, metadata)
|
232
|
+
end
|
233
|
+
|
234
|
+
# Start web dashboard
|
235
|
+
# @param port [Integer] Port number
|
236
|
+
def self.start_dashboard(port = 4567)
|
237
|
+
dashboard = AiRootShield::Dashboard::WebDashboard.new
|
238
|
+
dashboard.start(port)
|
239
|
+
end
|
240
|
+
|
241
|
+
# Platform-specific analysis methods for CLI
|
242
|
+
def self.analyze_android_device(device_logs_path, config = {})
|
243
|
+
device_logs = JSON.parse(File.read(device_logs_path))
|
244
|
+
android_module = AiRootShield::Platform::AndroidSecurityModule.new(
|
245
|
+
api_key: config[:safetynet_api_key],
|
246
|
+
package_name: config[:package_name]
|
247
|
+
)
|
248
|
+
android_module.analyze_device_security(device_logs)
|
249
|
+
end
|
250
|
+
|
251
|
+
def self.analyze_ios_device(device_logs_path, config = {})
|
252
|
+
device_logs = JSON.parse(File.read(device_logs_path))
|
253
|
+
ios_module = AiRootShield::Platform::IosSecurityModule.new
|
254
|
+
ios_module.analyze_device_security(device_logs)
|
255
|
+
end
|
256
|
+
|
257
|
+
# CI/CD integration method for CLI
|
258
|
+
def self.run_ci_cd_tests(device_logs_path, config = {})
|
259
|
+
ci_module = AiRootShield::CiCd::SecurityTestModule.new
|
260
|
+
ci_module.run_security_tests(device_logs_path, config)
|
261
|
+
end
|
262
|
+
|
263
|
+
# Generate CI configuration for CLI
|
264
|
+
def self.generate_ci_config(platform)
|
265
|
+
ci_module = AiRootShield::CiCd::SecurityTestModule.new
|
266
|
+
ci_module.generate_ci_config(platform)
|
267
|
+
end
|
268
|
+
|
269
|
+
# Generate unified cross-platform report for CLI
|
270
|
+
def self.generate_unified_report(android_results: nil, ios_results: nil, metadata: {})
|
271
|
+
report_generator = AiRootShield::Platform::UnifiedReportGenerator.new
|
272
|
+
report_generator.generate_unified_report(
|
273
|
+
android_results: android_results,
|
274
|
+
ios_results: ios_results,
|
275
|
+
metadata: metadata
|
276
|
+
)
|
277
|
+
end
|
278
|
+
|
58
279
|
# Check if RASP protection is active
|
59
280
|
# @return [Boolean] True if RASP protection is active
|
60
281
|
def self.rasp_active?
|
61
282
|
@rasp_protection&.protection_status&.dig(:active) || false
|
62
283
|
end
|
63
284
|
|
285
|
+
# Get comprehensive security status
|
286
|
+
# @return [Hash] Security status across all components
|
287
|
+
def self.security_status
|
288
|
+
{
|
289
|
+
version: VERSION,
|
290
|
+
rasp_active: rasp_active?,
|
291
|
+
policy_configured: !@policy_manager.nil?,
|
292
|
+
certificate_pinning_configured: !@certificate_pinning.nil?,
|
293
|
+
proxy_detection_configured: !@proxy_detector.nil?,
|
294
|
+
siem_configured: !@siem_connector.nil?,
|
295
|
+
platform_modules: {
|
296
|
+
android_module: !@android_module.nil?,
|
297
|
+
ios_module: !@ios_module.nil?,
|
298
|
+
hardware_analyzer: !@hardware_analyzer.nil?,
|
299
|
+
report_generator: !@report_generator.nil?
|
300
|
+
},
|
301
|
+
components: {
|
302
|
+
rasp: @rasp_protection&.protection_status,
|
303
|
+
policy: @policy_manager&.policy_statistics,
|
304
|
+
certificate_pinning: @certificate_pinning&.pinning_status,
|
305
|
+
proxy_detection: @proxy_detector&.detection_statistics,
|
306
|
+
siem: @siem_connector ? { platform: @siem_connector.instance_variable_get(:@platform) } : nil
|
307
|
+
}
|
308
|
+
}
|
309
|
+
end
|
310
|
+
|
64
311
|
# Get version information
|
65
312
|
# @return [String] Current version
|
66
313
|
def self.version
|
67
314
|
VERSION
|
68
315
|
end
|
316
|
+
|
317
|
+
private
|
318
|
+
|
319
|
+
# Enhance scan result with network security analysis
|
320
|
+
# @param scan_result [Hash] Original scan result
|
321
|
+
# @param config [Hash] Configuration options
|
322
|
+
# @return [Hash] Enhanced scan result
|
323
|
+
def self.enhance_with_network_analysis(scan_result, config)
|
324
|
+
network_analysis = {}
|
325
|
+
|
326
|
+
# Add proxy detection if configured
|
327
|
+
if @proxy_detector && config[:target_ip]
|
328
|
+
proxy_result = @proxy_detector.detect_proxy(config[:target_ip], config[:network_data] || {})
|
329
|
+
network_analysis[:proxy_detection] = proxy_result
|
330
|
+
|
331
|
+
# Add proxy indicators to risk factors if detected
|
332
|
+
if proxy_result[:proxy_detected]
|
333
|
+
scan_result[:factors] ||= []
|
334
|
+
proxy_result[:proxy_types].each do |type|
|
335
|
+
scan_result[:factors] << "NETWORK_#{type.upcase}_DETECTED"
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
# Add certificate pinning validation if configured
|
341
|
+
if @certificate_pinning && config[:target_url]
|
342
|
+
pinning_result = validate_certificate_pinning(config[:target_url])
|
343
|
+
network_analysis[:certificate_pinning] = pinning_result
|
344
|
+
|
345
|
+
# Add certificate pinning failure to risk factors if invalid
|
346
|
+
unless pinning_result[:valid]
|
347
|
+
scan_result[:factors] ||= []
|
348
|
+
scan_result[:factors] << "CERTIFICATE_PINNING_FAILED"
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
scan_result[:network_analysis] = network_analysis unless network_analysis.empty?
|
353
|
+
scan_result
|
354
|
+
end
|
69
355
|
end
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmet KAHRAMAN
|
@@ -149,9 +149,12 @@ dependencies:
|
|
149
149
|
- - "~>"
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '0.9'
|
152
|
-
description: An AI-powered Ruby library that performs on-device compromise
|
153
|
-
for mobile applications
|
154
|
-
hooking
|
152
|
+
description: An AI-powered Ruby library that performs comprehensive on-device compromise
|
153
|
+
detection for mobile applications. Features include root/jailbreak detection, emulator
|
154
|
+
detection, hooking framework detection, application integrity checks, advanced network
|
155
|
+
security analysis with certificate pinning and proxy detection, enterprise policy
|
156
|
+
management, AI behavioral analysis, and RASP protection - all without requiring
|
157
|
+
a backend.
|
155
158
|
email:
|
156
159
|
- ahmetxhero@gmail.com
|
157
160
|
executables:
|
@@ -168,16 +171,22 @@ files:
|
|
168
171
|
- Rakefile
|
169
172
|
- examples/device_logs/clean_device.json
|
170
173
|
- examples/device_logs/rooted_android.json
|
174
|
+
- examples/policies/banking_policy.json
|
175
|
+
- examples/policies/development_policy.json
|
176
|
+
- examples/policies/enterprise_policy.json
|
171
177
|
- exe/ai_root_shield
|
172
178
|
- lib/ai_root_shield.rb
|
179
|
+
- lib/ai_root_shield/advanced_proxy_detector.rb
|
173
180
|
- lib/ai_root_shield/ai_behavioral_analyzer.rb
|
174
181
|
- lib/ai_root_shield/analyzers/emulator_detector.rb
|
175
182
|
- lib/ai_root_shield/analyzers/hooking_detector.rb
|
176
183
|
- lib/ai_root_shield/analyzers/integrity_checker.rb
|
177
184
|
- lib/ai_root_shield/analyzers/network_analyzer.rb
|
178
185
|
- lib/ai_root_shield/analyzers/root_detector.rb
|
186
|
+
- lib/ai_root_shield/certificate_pinning_helper.rb
|
179
187
|
- lib/ai_root_shield/detector.rb
|
180
188
|
- lib/ai_root_shield/device_log_parser.rb
|
189
|
+
- lib/ai_root_shield/enterprise_policy_manager.rb
|
181
190
|
- lib/ai_root_shield/rasp_protection.rb
|
182
191
|
- lib/ai_root_shield/risk_calculator.rb
|
183
192
|
- lib/ai_root_shield/version.rb
|
@@ -206,5 +215,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
215
|
requirements: []
|
207
216
|
rubygems_version: 3.6.9
|
208
217
|
specification_version: 4
|
209
|
-
summary: AI-powered mobile
|
218
|
+
summary: AI-powered mobile security library with advanced network security and enterprise
|
219
|
+
policy management
|
210
220
|
test_files: []
|