Skip to main content

Advanced Python Code Protection System with AES-256-GCM encryption and AST obfuscation

Project description

PyObfuscator - Advanced Python Code Protection System

Python Version Platform License

A comprehensive Python code obfuscation and encryption system designed for Linux environments. Provides military-grade protection against reverse engineering, code analysis, and unauthorized access through multiple layers of security.

๐Ÿ›ก๏ธ Security Features

  • AES-256-GCM Encryption - Military-grade encryption for maximum security
  • AST-Based Obfuscation - Advanced Abstract Syntax Tree manipulation
  • Anti-Tampering Protection - Runtime integrity checks and modification detection
  • Anti-Debugging - Detects and prevents debugging attempts
  • Variable & Function Renaming - Systematic identifier obfuscation
  • String Obfuscation - Advanced string encoding and hiding
  • Dead Code Injection - Confuses static analysis tools
  • Bytecode Protection - Low-level bytecode manipulation

๐Ÿš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/MohamedQM/PyObfuscator.git
cd PyObfuscator

# Install dependencies (simple method)
python3 install.py

# Or install manually
pip3 install cryptography psutil

Basic Usage

# Obfuscate a Python file
python3 main.py your_script.py

# Maximum security protection
python3 main.py your_script.py --max-security

# Create importable library
python3 main.py your_script.py --library

Programmatic Usage

from pyobfuscator import obfuscate_code, obfuscate_file

# Obfuscate code directly
code = """
def hello():
    print("Hello World!")
hello()
"""
protected_code = obfuscate_code(code, max_security=True)

# Obfuscate a file
success = obfuscate_file("input.py", "output.py")

๐Ÿ“ Project Structure

PyObfuscator/
โ”œโ”€โ”€ pyobfuscator/           # Core library
โ”‚   โ”œโ”€โ”€ __init__.py        # Main API interface
โ”‚   โ”œโ”€โ”€ core.py           # Core obfuscation engine
โ”‚   โ”œโ”€โ”€ obfuscator.py     # AST manipulation
โ”‚   โ”œโ”€โ”€ encryption.py     # AES-256-GCM encryption
โ”‚   โ”œโ”€โ”€ anti_tamper.py    # Anti-tampering protection
โ”‚   โ””โ”€โ”€ utils.py          # Utility functions
โ”œโ”€โ”€ examples/              # Usage examples
โ”‚   โ”œโ”€โ”€ sample_code.py    # Sample code for testing
โ”‚   โ””โ”€โ”€ usage_example.py  # Integration examples
โ”œโ”€โ”€ main.py               # CLI interface
โ”œโ”€โ”€ install.py            # Simple installer
โ”œโ”€โ”€ test_basic.py         # Basic functionality tests
โ””โ”€โ”€ README.md             # This file

๐Ÿ”’ Protection Levels

Basic Protection

  • Variable and function renaming
  • String encoding and obfuscation
  • Basic dead code injection
  • Simple control flow changes

Advanced Protection

  • AES-256-GCM encryption with PBKDF2
  • Advanced AST transformations
  • Metadata removal
  • Enhanced anti-debugging

Maximum Security

  • All protection features enabled
  • Real-time tampering detection
  • Environment analysis
  • Process monitoring
  • Bytecode encryption

๐Ÿงช Testing

# Run basic functionality tests
python3 test_basic.py

# Test with sample code
python3 main.py examples/sample_code.py
python3 examples/sample_code_obfuscated.py

๐Ÿ’ป System Requirements

  • OS: Linux (Ubuntu 18.04+ recommended)
  • Python: 3.7+ (tested on 3.8-3.11)
  • RAM: 512MB minimum
  • Dependencies: cryptography, psutil

๐Ÿ“– CLI Options

python3 main.py [INPUT_FILE] [OPTIONS]

Options:
  -o, --output FILE        Output file path
  --max-security          Enable maximum protection
  --custom-key KEY        Use custom encryption key
  --library              Create importable library
  --no-anti-debug        Disable anti-debugging
  --preserve-names       Keep original function names

๐Ÿ”ง Advanced Configuration

Custom Encryption Key

from pyobfuscator.encryption import AdvancedEncryption

encryptor = AdvancedEncryption()
key = encryptor.generate_key("your_custom_password")
obfuscated = obfuscate_code(source, encryption_key=key)

Selective Protection

from pyobfuscator.core import PyObfuscatorCore

obfuscator = PyObfuscatorCore()
obfuscator.config.rename_variables = True
obfuscator.config.encrypt_strings = True
obfuscator.config.add_fake_code = False
result = obfuscator.obfuscate(source_code)

โš ๏ธ Important Notes

  1. Linux Only: This tool is optimized for Linux environments
  2. Backup Your Code: Always keep original source code backups
  3. Test Thoroughly: Test obfuscated code before deployment
  4. GitHub Safe: No sensitive data included - safe for public repositories

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”— Links


Developed with โค๏ธ for the Python security community

Last Updated: August 2024

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyobfuscator_gmaq-1.0.2.tar.gz (31.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyobfuscator_gmaq-1.0.2-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file pyobfuscator_gmaq-1.0.2.tar.gz.

File metadata

  • Download URL: pyobfuscator_gmaq-1.0.2.tar.gz
  • Upload date:
  • Size: 31.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for pyobfuscator_gmaq-1.0.2.tar.gz
Algorithm Hash digest
SHA256 5e93e752c14867a460364d9bbb641c49fb53d1dc754201219bcd3f0faa7c1181
MD5 218ed8c6a95b3c0511109f27b8f1cda9
BLAKE2b-256 baf5a944ecb0e623e15f1c793d96be50d5dc73cb2eeb8954f883358ead45f4ea

See more details on using hashes here.

File details

Details for the file pyobfuscator_gmaq-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyobfuscator_gmaq-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6464e5c2947647e07189a16cb2fe45a548658d9a58047aff3ba5396db977f602
MD5 8e02d659c6b7a796b84bd6dcbd02da39
BLAKE2b-256 5f703d78d7be24535b350e23d9b00500b9d5003ce8b6a41f2f30971841c2dcda

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page