mirror of
https://github.com/Shiva108/ai-llm-red-team-handbook.git
synced 2026-05-14 20:58:09 +02:00
b3d3bac51f
- Extracted all code examples from handbook chapters - Organized into 15 attack categories - Created shared utilities (api_client, validators, logging, constants) - Added workflow orchestration scripts - Implemented install.sh for easy setup - Renamed all scripts to descriptive functional names - Added comprehensive README and documentation - Included pytest test suite and configuration
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Approach 2: Statistical Analysis
|
|
|
|
Source: Chapter_13_Data_Provenance_and_Supply_Chain_Security
|
|
Category: supply_chain
|
|
"""
|
|
|
|
import argparse
|
|
import sys
|
|
|
|
# Analyze model behavior across many inputs
|
|
# Look for anomalous patterns
|
|
# - Specific inputs always produce same unusual output
|
|
# - Performance degradation on certain input types
|
|
# - Unexpected confidence scores
|
|
|
|
def backdoor_detection_test(model, test_dataset):
|
|
results = []
|
|
for input_data in test_dataset:
|
|
output = model(input_data)
|
|
# Statistical analysis
|
|
results.append({
|
|
'input': input_data,
|
|
'output': output,
|
|
'confidence': output.confidence,
|
|
'latency': measure_latency(model, input_data)
|
|
})
|
|
|
|
# Detect anomalies
|
|
anomalies = detect_outliers(results)
|
|
return anomalies
|
|
|
|
|
|
def main():
|
|
"""Command-line interface."""
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
|
|
args = parser.parse_args()
|
|
|
|
# TODO: Add main execution logic
|
|
pass
|
|
|
|
if __name__ == "__main__":
|
|
main() |