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.1.tar.gz (31.3 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.1-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyobfuscator_gmaq-1.0.1.tar.gz
  • Upload date:
  • Size: 31.3 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.1.tar.gz
Algorithm Hash digest
SHA256 88325c0239842f2055f138a80878d33a6c32c5b06d73ec35bf6b0a2a065196d7
MD5 9460d1b850225c21eb4482845d12ee0c
BLAKE2b-256 c189c0843d4a774b0818419e90d2d5c0c8dc462f93d3d689db958afbd9a67866

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyobfuscator_gmaq-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef78cfc85dd5b1a324bdb5d4067bdfb882de37e27a73d7a17de886673043d80f
MD5 2433247237c5c30c91b9094555994031
BLAKE2b-256 a732b96ea8482af9fa21055bd12d49673bd72c4ba78422fdf695f3d5d3293230

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