mirror of
https://github.com/Shiva108/ai-llm-red-team-handbook.git
synced 2026-10-14 03:31:24 +02:00
Add practical scripts directory with 400+ tools
- 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
This commit is contained in:
1 parent
2c69755b97
commit
b3d3bac51f
380 files changed
+3022
-16549
No files matched your search
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Implementation
|
||||
|
||||
Source: Chapter_18_Evasion_Obfuscation_and_Adversarial_Inputs
|
||||
Category: evasion
|
||||
"""
|
||||
|
||||
import base64
|
||||
from urllib.parse import quote, quote_plus
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
class EncodingObfuscator:
|
||||
"""Use various encodings to bypass text filters"""
|
||||
|
||||
def base64_encode(self, text):
|
||||
"""Encode text in base64"""
|
||||
encoded = base64.b64encode(text.encode()).decode()
|
||||
return encoded, f"echo '{encoded}' | base64 -d"
|
||||
|
||||
def base64_url_safe(self, text):
|
||||
"""Base64 URL-safe encoding"""
|
||||
encoded = base64.urlsafe_b64encode(text.encode()).decode()
|
||||
return encoded
|
||||
|
||||
def hex_encode(self, text):
|
||||
"""Encode as hexadecimal"""
|
||||
hex_str = text.encode().hex()
|
||||
return hex_str, f"echo '{hex_str}' | xxd -r -p"
|
||||
|
||||
def url_encode(self, text):
|
||||
"""URL encoding"""
|
||||
return quote(text), quote_plus(text)
|
||||
|
||||
def multiple_layers(self, text, layers=3):
|
||||
"""Apply multiple encoding layers"""
|
||||
result = text
|
||||
encodings = []
|
||||
|
||||
for i in range(layers):
|
||||
result = base64.b64encode(result.encode()).decode()
|
||||
encodings.append(f"Layer {i+1}: {result[:50]}...")
|
||||
|
||||
return result, encodings
|
||||
|
||||
def mixed_encoding(self, text):
|
||||
"""Mix different encodings"""
|
||||
# Base64 first half, hex second half
|
||||
mid = len(text) // 2
|
||||
first_half = base64.b64encode(text[:mid].encode()).decode()
|
||||
second_half = text[mid:].encode().hex()
|
||||
|
||||
return f"{first_half}|{second_half}"
|
||||
|
||||
# Example usage
|
||||
enc = EncodingObfuscator()
|
||||
|
||||
payload = "rm -rf /"
|
||||
print("=== Encoding Examples ===\n")
|
||||
|
||||
b64, b64_cmd = enc.base64_encode(payload)
|
||||
print(f"Original: {payload}")
|
||||
print(f"Base64: {b64}")
|
||||
print(f"Decode: {b64_cmd}\n")
|
||||
|
||||
hex_enc, hex_cmd = enc.hex_encode(payload)
|
||||
print(f"Hex: {hex_enc}")
|
||||
print(f"Decode: {hex_cmd}\n")
|
||||
|
||||
url_enc, url_plus = enc.url_encode(payload)
|
||||
print(f"URL: {url_enc}")
|
||||
print(f"URL Plus: {url_plus}\n")
|
||||
|
||||
multi, layers = enc.multiple_layers(payload, 3)
|
||||
print(f"3x Base64: {multi}")
|
||||
for layer in layers:
|
||||
print(f" {layer}")
|
||||
|
||||
|
||||
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()
|
||||
Reference in new issue
Block a user