ai_root_shield 0.1.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 +4 -4
- data/CHANGELOG.md +52 -1
- data/Gemfile.lock +10 -1
- data/LICENSE +1 -1
- data/README.md +138 -29
- data/exe/ai_root_shield +63 -13
- data/lib/ai_root_shield/ai_behavioral_analyzer.rb +512 -0
- data/lib/ai_root_shield/detector.rb +31 -3
- data/lib/ai_root_shield/rasp_protection.rb +359 -0
- data/lib/ai_root_shield/risk_calculator.rb +8 -1
- data/lib/ai_root_shield/version.rb +1 -1
- data/lib/ai_root_shield.rb +35 -2
- data/models/README.md +72 -0
- metadata +32 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0d354e66eecc271bd43c8ac6625c186a3aa38789ac19abbe5eabc0bf4fc1641
|
4
|
+
data.tar.gz: f2ce01ca5f411532737549e534db15dd1be0f942c3ef3427e1685a4fe7c964da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05e5cfacfef14284c46aa5dbc7ae33ae5a1f70a5262c6341de8b22e968feb71c4e2f91385672d3032ea02e47ab1d21d504dfe4c0a3bb2134b9807aaea7647554
|
7
|
+
data.tar.gz: 0cc0cd97dab91107681bbbe04951f8c966a23de3e35965e8ed0d50afba5212133c2ef41b569560000c73b2b9ee22b869d22994ed73ca57749e1345c09a36e89d
|
data/CHANGELOG.md
CHANGED
@@ -8,11 +8,62 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
10
|
### Added
|
11
|
-
- AI behavioral analysis integration (ONNX model support)
|
12
11
|
- Enhanced hooking detection for iOS method swizzling
|
13
12
|
- Real-time threat monitoring capabilities
|
14
13
|
- Custom rule engine for security policies
|
15
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
|
+
|
39
|
+
## [0.2.0] - 2024-01-02
|
40
|
+
|
41
|
+
### Added
|
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
|
45
|
+
- File access pattern analysis with entropy calculation
|
46
|
+
- Sensor data consistency validation
|
47
|
+
- Hardware fingerprinting with advanced characteristics
|
48
|
+
- Process behavior monitoring and analysis
|
49
|
+
- Network pattern analysis for anomaly detection
|
50
|
+
- Timing analysis for attack indicator detection
|
51
|
+
- System call entropy analysis
|
52
|
+
- Memory access pattern monitoring
|
53
|
+
- ONNX runtime integration with fallback to rule-based analysis
|
54
|
+
- AI confidence weighting in overall risk calculation
|
55
|
+
- Comprehensive behavioral analysis test suite
|
56
|
+
|
57
|
+
### Changed
|
58
|
+
- Updated risk calculator to incorporate AI confidence metrics
|
59
|
+
- Enhanced detector to support AI behavioral analysis
|
60
|
+
- Improved CLI with AI-specific configuration options
|
61
|
+
- Updated documentation with AI behavioral analysis features
|
62
|
+
|
63
|
+
### Dependencies
|
64
|
+
- Added `onnxruntime` for AI model inference
|
65
|
+
- Added `numo-narray` for numerical computations
|
66
|
+
|
16
67
|
## [0.1.0] - 2024-09-09
|
17
68
|
|
18
69
|
### Added
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ai_root_shield (0.
|
4
|
+
ai_root_shield (0.3.0)
|
5
5
|
digest (~> 3.1)
|
6
6
|
json (~> 2.6)
|
7
|
+
numo-narray (~> 0.9)
|
8
|
+
onnxruntime (~> 0.7)
|
7
9
|
openssl (~> 3.0)
|
8
10
|
|
9
11
|
GEM
|
@@ -14,10 +16,17 @@ GEM
|
|
14
16
|
diff-lcs (1.6.2)
|
15
17
|
digest (3.2.0)
|
16
18
|
docile (1.4.1)
|
19
|
+
ffi (1.17.2)
|
20
|
+
ffi (1.17.2-arm64-darwin)
|
17
21
|
json (2.13.2)
|
18
22
|
language_server-protocol (3.17.0.5)
|
19
23
|
lint_roller (1.1.0)
|
20
24
|
method_source (1.1.0)
|
25
|
+
numo-narray (0.9.2.1)
|
26
|
+
onnxruntime (0.10.0)
|
27
|
+
ffi
|
28
|
+
onnxruntime (0.10.0-arm64-darwin)
|
29
|
+
ffi
|
21
30
|
openssl (3.3.0)
|
22
31
|
parallel (1.27.0)
|
23
32
|
parser (3.3.9.0)
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -10,17 +10,26 @@
|
|
10
10
|
|
11
11
|
An AI-powered Ruby library that performs comprehensive on-device compromise detection for mobile applications without requiring a backend. Protects against root/jailbreak, emulators, hooking frameworks, and provides behavioral risk analysis.
|
12
12
|
|
13
|
-
##
|
14
|
-
|
15
|
-
- **Root & Jailbreak Detection**:
|
16
|
-
- **Emulator/Simulator Detection**: Identifies
|
17
|
-
- **Hooking
|
18
|
-
- **
|
19
|
-
- **Network Security Analysis**:
|
20
|
-
-
|
21
|
-
-
|
22
|
-
|
23
|
-
|
13
|
+
## Features
|
14
|
+
|
15
|
+
- **Root & Jailbreak Detection**: Comprehensive detection of rooted Android devices and jailbroken iOS devices
|
16
|
+
- **Emulator/Simulator Detection**: Identifies virtual devices, emulators, and simulators
|
17
|
+
- **Hooking Framework Detection**: Detects Frida, Xposed, Substrate, and other instrumentation tools
|
18
|
+
- **Application Integrity Checks**: Validates app signatures and detects repackaging/tampering
|
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
|
25
|
+
- **AI Behavioral Analysis**: ONNX-powered behavioral pattern analysis with anomaly detection
|
26
|
+
- **ML-Based Emulator Detection**: Advanced machine learning techniques for emulator identification
|
27
|
+
- **AI Confidence Scoring**: Confidence metrics integrated into risk assessment
|
28
|
+
- **Risk Scoring System**: Comprehensive risk assessment with weighted factors (0-100 scale)
|
29
|
+
- **CLI Tool**: Command-line interface with multiple output formats
|
30
|
+
- **Privacy-First**: Completely offline, no data collection or external dependencies
|
31
|
+
|
32
|
+
## Installation
|
24
33
|
|
25
34
|
Add this line to your application's Gemfile:
|
26
35
|
|
@@ -40,7 +49,7 @@ Or install it yourself as:
|
|
40
49
|
$ gem install ai_root_shield
|
41
50
|
```
|
42
51
|
|
43
|
-
##
|
52
|
+
## Usage
|
44
53
|
|
45
54
|
### Basic Usage
|
46
55
|
|
@@ -64,7 +73,9 @@ config = {
|
|
64
73
|
enable_hooking_detection: true,
|
65
74
|
enable_integrity_checks: true,
|
66
75
|
enable_network_analysis: true,
|
67
|
-
|
76
|
+
enable_ai_behavioral_analysis: true, # v0.2.0
|
77
|
+
risk_threshold: 70,
|
78
|
+
ai_confidence_threshold: 0.7 # v0.2.0
|
68
79
|
}
|
69
80
|
|
70
81
|
result = AiRootShield.scan_device_with_config("device_logs/sample.json", config)
|
@@ -96,7 +107,81 @@ $ ai_root_shield --no-emulator --no-network device_logs/sample.json
|
|
96
107
|
$ ai_root_shield --help
|
97
108
|
```
|
98
109
|
|
99
|
-
##
|
110
|
+
## AI Behavioral Analysis (New in v0.2.0)
|
111
|
+
|
112
|
+
AI Root Shield now includes advanced behavioral analysis powered by ONNX machine learning models:
|
113
|
+
|
114
|
+
### Features
|
115
|
+
- **File Access Pattern Analysis**: Detects unusual file system access patterns
|
116
|
+
- **Sensor Data Consistency**: Validates sensor data against real device behavior
|
117
|
+
- **Hardware Fingerprinting**: Advanced hardware characteristic analysis
|
118
|
+
- **Process Behavior Analysis**: Monitors process execution patterns
|
119
|
+
- **Network Pattern Analysis**: Analyzes network behavior for anomalies
|
120
|
+
- **Timing Analysis**: Detects timing-based attack indicators
|
121
|
+
- **System Call Entropy**: Analyzes system call distribution patterns
|
122
|
+
- **Memory Access Patterns**: Monitors memory usage behavior
|
123
|
+
|
124
|
+
### ONNX Model Integration
|
125
|
+
|
126
|
+
Place your trained ONNX model at `models/behavioral_model.onnx` for AI-powered analysis. The system falls back to rule-based analysis if no model is available.
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
# AI analysis is automatically enabled
|
130
|
+
result = AiRootShield.scan_device('device_logs.json')
|
131
|
+
puts "AI Confidence: #{result[:ai_confidence]}"
|
132
|
+
puts "ML Emulator Score: #{result[:ml_emulator_score]}"
|
133
|
+
```
|
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
|
+
|
184
|
+
## Risk Scoring
|
100
185
|
|
101
186
|
The library provides a comprehensive risk score (0-100) based on detected security factors:
|
102
187
|
|
@@ -115,7 +200,35 @@ The library provides a comprehensive risk score (0-100) based on detected securi
|
|
115
200
|
| Integrity | `REPACKAGED_APP`, `DEX_TAMPERED` | Medium (10-18) |
|
116
201
|
| Network | `TLS_UNPINNED`, `MITM_PROXY_DETECTED` | Medium (8-18) |
|
117
202
|
|
118
|
-
##
|
203
|
+
## Device Log Format
|
204
|
+
|
205
|
+
The library expects device logs in JSON format with the following structure:
|
206
|
+
|
207
|
+
```json
|
208
|
+
{
|
209
|
+
"risk_score": 85,
|
210
|
+
"factors": [
|
211
|
+
"ROOT_BINARY_DETECTED",
|
212
|
+
"SUPERUSER_APP_INSTALLED",
|
213
|
+
"SELINUX_DISABLED",
|
214
|
+
"EMULATOR_DETECTED",
|
215
|
+
"FRIDA_SERVER_RUNNING",
|
216
|
+
"BEHAVIORAL_ANOMALY_DETECTED",
|
217
|
+
"ML_EMULATOR_CONFIDENCE_HIGH"
|
218
|
+
],
|
219
|
+
"ai_confidence": 0.92,
|
220
|
+
"ml_emulator_score": 0.87,
|
221
|
+
"anomaly_indicators": [
|
222
|
+
"SUSPICIOUS_FILE_ACCESS_PATTERN",
|
223
|
+
"SENSOR_DATA_INCONSISTENCY",
|
224
|
+
"ABNORMAL_TIMING_PATTERNS"
|
225
|
+
],
|
226
|
+
"timestamp": 1640995200,
|
227
|
+
"version": "0.3.0"
|
228
|
+
}
|
229
|
+
```
|
230
|
+
|
231
|
+
### Device Log Input Format
|
119
232
|
|
120
233
|
The library expects device logs in JSON format with the following structure:
|
121
234
|
|
@@ -123,22 +236,18 @@ The library expects device logs in JSON format with the following structure:
|
|
123
236
|
{
|
124
237
|
"platform": "android",
|
125
238
|
"system_info": {
|
126
|
-
"os_version": "
|
127
|
-
"
|
128
|
-
"
|
129
|
-
|
130
|
-
|
239
|
+
"os_version": "11",
|
240
|
+
"api_level": 30,
|
241
|
+
"build_tags": "release-keys"
|
242
|
+
},
|
243
|
+
"hardware_info": {
|
244
|
+
"model": "Pixel 5",
|
245
|
+
"manufacturer": "Google"
|
131
246
|
},
|
132
|
-
"installed_packages": [
|
133
|
-
{
|
134
|
-
"name": "com.example.app",
|
135
|
-
"signature": "release-keys"
|
136
|
-
}
|
137
|
-
],
|
138
247
|
"file_system": {
|
139
|
-
"
|
140
|
-
|
141
|
-
|
248
|
+
"files": [
|
249
|
+
{"path": "/system/bin/su", "permissions": "755", "owner": "root"}
|
250
|
+
]
|
142
251
|
},
|
143
252
|
"running_processes": [
|
144
253
|
{
|
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
|
-
#
|
8
|
+
# Command line interface for AI Root Shield
|
9
9
|
class AiRootShieldCLI
|
10
10
|
def initialize
|
11
11
|
@options = {
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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[:
|
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[:
|
104
|
+
@options[:threshold] = threshold
|
67
105
|
end
|
68
106
|
|
69
107
|
opts.on("--no-root", "Disable root detection") do
|
70
|
-
@options[:
|
108
|
+
@options[:enable_root_detection] = false
|
71
109
|
end
|
72
110
|
|
73
111
|
opts.on("--no-emulator", "Disable emulator detection") do
|
74
|
-
@options[:
|
112
|
+
@options[:enable_emulator_detection] = false
|
75
113
|
end
|
76
114
|
|
77
115
|
opts.on("--no-hooking", "Disable hooking detection") do
|
78
|
-
@options[:
|
116
|
+
@options[:enable_hooking_detection] = false
|
79
117
|
end
|
80
118
|
|
81
119
|
opts.on("--no-integrity", "Disable integrity checks") do
|
82
|
-
@options[:
|
120
|
+
@options[:enable_integrity_checks] = false
|
83
121
|
end
|
84
122
|
|
85
123
|
opts.on("--no-network", "Disable network analysis") do
|
86
|
-
@options[:
|
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
|