Enhanced iOS Forensics with Artificial Intelligence
Learn how to integrate iLEAPP AI with your existing forensic workflow
This guide provides detailed instructions for integrating iLEAPP AI with your existing digital forensics workflow. Whether you're looking to enhance the standard iLEAPP tool, integrate with other forensic platforms, or build custom solutions using our API, this guide will help you get started.
Note: This integration guide assumes you have already installed iLEAPP AI and have a basic understanding of digital forensics concepts. If you haven't installed iLEAPP AI yet, please refer to the Getting Started guide first.
iLEAPP AI offers several integration options to suit different needs:
Choose the integration option that best fits your workflow and requirements.
iLEAPP AI seamlessly integrates with the standard iLEAPP tool, enhancing its capabilities with AI-powered analysis. This integration is available for both the GUI and CLI versions of iLEAPP.
The GUI integration adds an "AI Analysis" tab to the standard iLEAPP interface, allowing you to apply AI analysis to extracted artifacts with just a few clicks.
To install the GUI integration:
cd /path/to/ileapp
pip install ileapp-ai
python -m ileapp_ai.setup --gui
This will install the necessary components and update the iLEAPP GUI to include AI capabilities.
To use the AI capabilities in the iLEAPP GUI:
Note: The first time you use the AI features, you'll be prompted to enter your API key for the selected LLM provider.
The CLI integration extends the standard iLEAPP command-line interface with additional options for AI analysis.
To install the CLI integration:
cd /path/to/ileapp
pip install ileapp-ai
python -m ileapp_ai.setup --cli
To use the AI capabilities from the command line:
python ileapp.py -i /path/to/extraction -o /path/to/output --ai-analyze --ai-provider openrouter --ai-key YOUR_API_KEY --ai-depth comprehensive
Available AI-specific command-line options:
--ai-analyze: Enable AI analysis--ai-provider: LLM provider (openrouter, anthropic, openai, local)--ai-key: API key for the selected provider--ai-model: Specific model to use (optional)--ai-depth: Analysis depth (basic, standard, comprehensive)--ai-artifacts: Comma-separated list of artifacts to analyze (default: all)--ai-output: Output format for AI reports (html, pdf, json)You can also store your API key and default settings in a configuration file to avoid entering them each time:
python -m ileapp_ai.config --set-provider openrouter --set-key YOUR_API_KEY --set-depth comprehensive
iLEAPP AI allows you to create custom analyzers for specific artifact types or investigation needs. Custom analyzers extend the base Analyzer class and implement specialized analysis logic.
A custom analyzer typically has the following structure:
from ileapp_ai import Analyzer
class CustomAnalyzer(Analyzer):
"""Custom analyzer for specific artifact type."""
def __init__(self, llm_client, config=None):
super().__init__(llm_client, config)
# Initialize analyzer-specific properties
def analyze(self, data, options=None):
"""Analyze the artifact data."""
# Preprocess data if needed
# Send data to LLM for analysis
# Process and structure the results
# Return analysis results
def generate_report(self, results, output_format="html", output_path=None):
"""Generate a specialized report for this analyzer."""
# Generate a report based on the analysis results
# Return report information
Here's an example of a custom analyzer for iOS location data:
from ileapp_ai import Analyzer
from ileapp_ai.processors import get_processor
class LocationAnalyzer(Analyzer):
"""Analyzer for iOS location data with geofencing capabilities."""
def __init__(self, llm_client, config=None):
super().__init__(llm_client, config)
self.geofences = config.get('geofences', []) if config else []
def analyze(self, data_path, options=None):
# Get the appropriate processor for location data
processor = get_processor("location")
location_data = processor.process(data_path)
# Apply geofencing if configured
if self.geofences:
location_data = self._apply_geofencing(location_data)
# Prepare prompt for the LLM
prompt = """
Analyze this iOS location data to identify:
1. Frequently visited locations
2. Travel patterns and routines
3. Anomalous location activity
4. Timeline of movements
For each insight, provide the supporting evidence from the data.
"""
# Send to LLM for analysis
analysis_result = self.llm_client.analyze_structured_data(
data=location_data,
prompt=prompt,
options=options
)
# Process and structure the results
return self._structure_results(analysis_result, location_data)
def _apply_geofencing(self, location_data):
"""Apply geofencing to the location data."""
# Implementation of geofencing logic
# ...
return filtered_data
def _structure_results(self, analysis_result, raw_data):
"""Structure the analysis results."""
# Implementation of result structuring
# ...
return structured_results
To make your custom analyzer available in iLEAPP AI, you need to register it:
from ileapp_ai.registry import register_analyzer
# Register your custom analyzer
register_analyzer("location", LocationAnalyzer)
Once registered, your custom analyzer can be used like any built-in analyzer:
from ileapp_ai import LLMClient
from your_module import LocationAnalyzer
llm_client = LLMClient(provider="openrouter", api_key="your_api_key")
location_analyzer = LocationAnalyzer(llm_client, config={"geofences": [...]})
results = location_analyzer.analyze("/path/to/location_data")
iLEAPP AI uses Jinja2 templates for report generation. You can create custom report templates to customize the appearance and content of your reports.
Report templates are HTML files with Jinja2 template syntax. Here's a basic example:
<!DOCTYPE html>
<html>
<head>
<title>{{ report.title }}</title>
<style>
/* Your custom CSS styles */
</style>
</head>
<body>
<header>
<h1>{{ report.title }}</h1>
<p>Generated on: {{ report.timestamp }}</p>
<p>Case ID: {{ report.case_id }}</p>
</header>
<section class="summary">
<h2>Executive Summary</h2>
<p>{{ report.summary }}</p>
</section>
<section class="artifacts">
<h2>Analyzed Artifacts</h2>
{% for artifact in report.artifacts %}
<div class="artifact">
<h3>{{ artifact.name }}</h3>
<p>{{ artifact.description }}</p>
<h4>Key Findings</h4>
<ul>
{% for finding in artifact.findings %}
<li>{{ finding }}</li>
{% endfor %}
</ul>
{% if artifact.visualizations %}
<h4>Visualizations</h4>
{% for viz in artifact.visualizations %}
<div class="visualization">
<img src="{{ viz.path }}" alt="{{ viz.description }}">
<p>{{ viz.description }}</p>
</div>
{% endfor %}
{% endif %}
</div>
{% endfor %}
</section>
<section class="timeline">
<h2>Event Timeline</h2>
{% if report.timeline %}
<div class="timeline-container">
{% for event in report.timeline %}
<div class="timeline-event">
<div class="timeline-date">{{ event.timestamp }}</div>
<div class="timeline-content">
<h4>{{ event.title }}</h4>
<p>{{ event.description }}</p>
</div>
</div>
{% endfor %}
</div>
{% else %}
<p>No timeline data available.</p>
{% endif %}
</section>
<footer>
<p>Generated by iLEAPP AI v{{ report.version }}</p>
</footer>
</body>
</html>
To use a custom template for report generation:
from ileapp_ai import Analyzer, LLMClient
from ileapp_ai.reporting import ReportGenerator
llm_client = LLMClient(provider="openrouter", api_key="your_api_key")
analyzer = Analyzer(llm_client)
results = analyzer.analyze_artifact("/path/to/sms.db", "messages")
report_generator = ReportGenerator()
report = report_generator.generate_report(
analysis_results=results,
template="/path/to/your/custom_template.html",
output_format="html",
output_path="/path/to/output/report.html"
)
iLEAPP AI provides a comprehensive API that you can integrate into your own forensic tools or workflows. This section provides examples of common API integration scenarios.
Here's a basic example of using the iLEAPP AI API in a Python script:
from ileapp_ai import Analyzer, LLMClient
from ileapp_ai.analyzers import MessageAnalyzer
from ileapp_ai.visualization import TimelineGenerator
# Initialize the LLM client
llm_client = LLMClient(
provider="openrouter",
api_key="your_api_key",
model="anthropic/claude-3-opus-20240229"
)
# Create an analyzer instance
analyzer = Analyzer(llm_client)
# Analyze iOS messages
message_results = analyzer.analyze_artifact(
artifact_path="/path/to/sms.db",
artifact_type="messages",
analysis_depth="comprehensive"
)
# Generate a timeline of events
timeline_generator = TimelineGenerator()
timeline = timeline_generator.generate_timeline(
events=message_results.events,
output_path="/path/to/output/timeline.html"
)
# Generate a report
report = analyzer.generate_report(
analysis_result=message_results,
output_format="pdf",
output_path="/path/to/output/report.pdf"
)
print(f"Analysis complete. Report saved to: {report.path}")
print(f"Timeline saved to: {timeline.path}")
You can integrate iLEAPP AI with other forensic tools by using their output as input for iLEAPP AI analysis:
import subprocess
from ileapp_ai import Analyzer, LLMClient
# Run another forensic tool to extract data
subprocess.run([
"other_forensic_tool",
"--extract",
"/path/to/ios_backup",
"--output",
"/path/to/extraction"
])
# Initialize iLEAPP AI
llm_client = LLMClient(provider="openrouter", api_key="your_api_key")
analyzer = Analyzer(llm_client)
# Analyze the extracted data
results = analyzer.analyze_case(
case_path="/path/to/extraction",
artifacts=["messages", "app_usage", "browser_history"],
analysis_depth="comprehensive"
)
# Generate a report
report = analyzer.generate_report(results)
print(f"Analysis complete. Report saved to: {report.path}")
Here's an example of integrating iLEAPP AI into a Flask web application:
from flask import Flask, request, render_template, jsonify
from ileapp_ai import Analyzer, LLMClient
import os
app = Flask(__name__)
upload_folder = "/path/to/uploads"
output_folder = "/path/to/outputs"
# Initialize iLEAPP AI
llm_client = LLMClient(provider="openrouter", api_key="your_api_key")
analyzer = Analyzer(llm_client)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/upload', methods=['POST'])
def upload_file():
if 'file' not in request.files:
return jsonify({"error": "No file part"}), 400
file = request.files['file']
if file.filename == '':
return jsonify({"error": "No selected file"}), 400
# Save the uploaded file
file_path = os.path.join(upload_folder, file.filename)
file.save(file_path)
# Get analysis options from the form
artifact_type = request.form.get('artifact_type', 'messages')
analysis_depth = request.form.get('analysis_depth', 'standard')
# Analyze the artifact
try:
results = analyzer.analyze_artifact(
artifact_path=file_path,
artifact_type=artifact_type,
analysis_depth=analysis_depth
)
# Generate a report
report = analyzer.generate_report(
analysis_result=results,
output_format="html",
output_path=os.path.join(output_folder, f"{file.filename}_report.html")
)
return jsonify({
"success": True,
"report_url": f"/reports/{os.path.basename(report.path)}",
"summary": results.summary
})
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route('/reports/')
def get_report(filename):
return send_from_directory(output_folder, filename)
if __name__ == '__main__':
app.run(debug=True)
When integrating iLEAPP AI into your forensic workflow, consider the following security best practices:
ChainOfCustody class to track all actions performed on forensic data.import os
from ileapp_ai import LLMClient
# Get API key from environment variable
api_key = os.environ.get('OPENROUTER_API_KEY')
if not api_key:
raise ValueError("API key not found in environment variables")
# Initialize client with the API key
llm_client = LLMClient(provider="openrouter", api_key=api_key)
from ileapp_ai import Analyzer, LLMClient
from ileapp_ai.security import ChainOfCustody, enable_audit_logging
# Enable audit logging
enable_audit_logging(log_path="/path/to/audit.log")
# Initialize chain of custody
chain_of_custody = ChainOfCustody(
case_id="CASE-2025-001",
investigator="John Doe"
)
# Initialize client and analyzer
llm_client = LLMClient(provider="openrouter", api_key="your_api_key")
analyzer = Analyzer(llm_client)
# Log the analysis action
action_id = chain_of_custody.log_action(
action="Analyzing messages",
artifact="/path/to/sms.db"
)
# Perform the analysis
results = analyzer.analyze_artifact(
artifact_path="/path/to/sms.db",
artifact_type="messages"
)
# Log the completion of the analysis
chain_of_custody.log_action(
action="Analysis completed",
artifact="/path/to/sms.db",
details={"action_id": action_id, "findings": len(results.findings)}
)
This section covers common issues you might encounter when integrating iLEAPP AI and how to resolve them.
If you're having trouble connecting to the LLM provider's API:
If you encounter errors when integrating with iLEAPP:
If the AI analysis results are not meeting your expectations:
If you're experiencing slow performance:
If you continue to experience issues:
Note: This integration guide is for iLEAPP AI version 1.0.0. Future versions may include additional integration options and features.