Skip to content

ThiagoMaria-SecurityIT/python-bytecode-security-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Bytecode Security Demo

Python Version License Security Platform Sponsor

Warning

This project works with Python 3.8 - see here how to setup 3.8 environment
Python 3.9+ are not supported due to decompilation tool compatibility limitations.

Overview

Educational demonstration proving that Python bytecode (.pyc files) compilation does NOT provide real security for source code protection.

Python Bytecode Security Demo GUI

Image above: The Tkinter GUI after decompiling the example bytecode included with this repository

Setting Up Python 3.8 Environment

# Install Python 3.8 if not already available
# Then create a virtual environment:
py -3.8 -m venv venv

# Activate the virtual environment:
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

The Security Myth Exposed

Part 1: The Dangerous Misconception

Many developers believe that compiling Python to .pyc files protects their source code. The common advice "Just compile to bytecode to hide your code" creates a false sense of security that can put intellectual property at risk.

Part 2: The Proof - Watch It Fail

This demonstration shows why bytecode doesn't work for protection. With one simple command or a few clicks in our GUI, anyone can recover your original source code from .pyc files. The process takes seconds and requires no special skills.

Part 3: The Hard Truth

No hacking skills needed. No vulnerabilities exploited. This uses standard Python tools and represents expected behavior - not a security flaw. Bytecode was never designed to provide protection. If you can compile it, anyone can decompile it.

How Easy Is Decompilation?

# With one command, recover original source code:
pip install uncompyle6
uncompyle6 your_script.pyc

Result: Exact original source code recovered in under 30 seconds!

Important

Security through obscurity is NOT security!
Stop trusting bytecode with your code security. The protection is an illusion, and your intellectual property deserves better.

Bytecode Protection Reality Check

Myth Reality
".pyc files hide my code" ❌ Source code easily recovered
"Bytecode is encrypted" ❌ No encryption used
"Provides real security" ❌ Only basic obfuscation
"Hard to reverse engineer" ❌ Trivial to decompile

Quick Start

1. Installation

git clone https://github.com/ThiagoMaria-SecurityIT/python-bytecode-security-demo
cd python-bytecode-security-demo

# Create Python 3.8 virtual environment (see compatibility note above)
# Then install dependencies
pip install -r requirements.txt

2. Run the Demo

# Run the application directly from the src folder
python src/bytecode_tool.py

3. Try It Yourself

  1. Compile: Use the GUI to compile examples/sample_script.py to .pyc
  2. Decompile: Take the generated .pyc file and decompile it back to source
  3. Compare: See how the decompiled code matches the original exactly!

Project Structure

python-bytecode-security-demo/
├── src/                    # Source code
│   ├── bytecode_tool.py   # Main GUI application
│   ├── compiler.py        # .py → .pyc compilation
│   └── decompiler.py      # .pyc → .py decompilation
├── examples/              # Sample scripts to test
├── requirements.txt
└── README.md

Real Security Solutions

If you actually need to protect Python code, consider:

Solution Protection Level Dynamic Features
Cython High Limited - most dynamic features do not work
Nuitka High Some dynamic features will work
Server-side Maximum All

Learning Objectives

  • Understand why bytecode doesn't provide security
  • See decompilation in action with our visual demo
  • Learn real code protection alternatives
  • Avoid common security pitfalls in Python

Important Notes

When bytecode IS appropriate:

  • Slightly faster startup times
  • Hiding code from completely non-technical users
  • When real security doesn't matter

When to NEVER use bytecode for "protection":

  • Protecting intellectual property
  • Security-sensitive algorithms
  • License keys or DRM systems
  • Any code with actual business value

Contributing

Contributions welcome! Feel free to:

  • Add more examples and demo scripts
  • Improve the GUI interface
  • Add additional decompilation methods
  • Create educational content and documentation

AI Transparency

This project was developed with assistance from DeepSeek AI. The AI helped with:

  • Code structure and organization
  • GUI implementation using Tkinter
  • Documentation and educational content
  • Debugging and troubleshooting

The core security concepts and educational value represent original work.

License

MIT License - feel free to use this for education and security testing.


About Me & Contact

Thiago Maria - From Brazil to the World 🌎
Senior Information Security Professional | Security Risk & Compliance Specialist | AI Security Researcher | Software Developer | Post-Quantum Cryptography Enthusiast

My passion for programming and my professional background in security analysis led me to create this GitHub account to share my knowledge of security information, cybersecurity, Python, and AI development practices. My work primarily focuses on prioritizing security in organizations while ensuring usability and productivity.

Let's Connect:

👇🏽 Click on the badges below:

LinkedIn
Hugging Face

Ways to Contribute:

Want to see more upgrades? Help me keep it updated!
👇🏽 Click on the badge below:

Sponsor

About

Educational demo showing why Python bytecode (.pyc files) is NOT secure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages