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
42 lines
975 B
Python
42 lines
975 B
Python
#!/usr/bin/env python3
|
|
"""
|
|
Practical Detection Example
|
|
|
|
Source: Chapter_34_Defense_Evasion_Techniques
|
|
Category: evasion
|
|
"""
|
|
|
|
import re
|
|
|
|
import argparse
|
|
import sys
|
|
|
|
#!/usr/bin/env python3
|
|
"""
|
|
Detection Logic for Splitting/Obfuscation
|
|
"""
|
|
|
|
class ObfuscationDetector:
|
|
"""Detects variable assignment and concatenation."""
|
|
|
|
def analyze(self, text: str) -> bool:
|
|
"""
|
|
Heuristic check for splitting patterns.
|
|
"""
|
|
# Check for multiple short variable assignments
|
|
assignments = len(re.findall(r'\w+\s*=\s*["\']', text))
|
|
|
|
# Check for concatenation operators
|
|
concat = text.count(" + ")
|
|
|
|
# If we see multiple assignments and concats, it's suspicious
|
|
if assignments > 3 and concat > 2:
|
|
return True
|
|
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
detector = ObfuscationDetector()
|
|
evil_prompt = 'a="bad"; b="ness"; print(a+b)'
|
|
print(f"Detected Attack: {detector.analyze(evil_prompt)}")
|