Skip to content

Security: Deepesh70/Unreal-MCP

Security

Security.md

Security & Anti-Reverse Engineering Guide for Python Desktop Software

This document provides a real-world technical explanation of how Python code is hacked/reverse-engineered, why standard packaging fails, and how Nuitka C++ compilation and anti-tampering algorithms protect your intellectual property (IP).


1. How Hackers Reverse-Engineer Standard Python Executables

When developers package Python applications using standard tools like PyInstaller, cx_Freeze, or py2exe, they often believe their code is compiled and secure. This is a misconception.

The PyInstaller Hack Flow (Seconds to Decompile):

┌───────────────────────────┐
│   UnrealMCP_Relay.exe     │  (PyInstaller Executable)
└─────────────┬─────────────┘
              │ 1. Run 'pyinstxtractor.py UnrealMCP_Relay.exe'
              ▼
┌───────────────────────────┐
│ Extracted .pyc Bytecode   │  (Compiled Python Bytecode)
└─────────────┬─────────────┘
              │ 2. Run 'uncompyle6' or 'decompyle++'
              ▼
┌───────────────────────────┐
│  Original .py Source Code │  (100% Readable Python Code!)
└───────────────────────────┘
  1. Extraction: Tools like pyinstxtractor extract the internal .zip archive embedded inside the .exe.
  2. Decompilation: Python bytecode (.pyc) contains variable names, function names, logic flow, and docstrings. Decompilers like uncompyle6 or pycdc reconstruct the exact original Python source code.
  3. Result: Anyone who downloads your PyInstaller .exe can read, copy, or steal your algorithms in less than 30 seconds.

2. The Commercial Solution: Nuitka (Python-to-C++ Compilation)

To prevent decompilation entirely, we use Nuitka.

How Nuitka Works Under the Hood:

┌───────────────────────────┐
│     Python Source Code    │  (server.py)
└─────────────┬─────────────┘
              │ 1. Nuitka parses Python AST into C++ Source Code
              ▼
┌───────────────────────────┐
│     Native C++ Source     │  (server.cpp, module.cpp)
└─────────────┬─────────────┘
              │ 2. MSVC / GCC Compiles C++ to x86_64 Machine Code
              ▼
┌───────────────────────────┐
│  UnrealMCP_Relay.exe      │  (Native Binary - NO Python Bytecode!)
└───────────────────────────┘

Why Nuitka is Immune to Python Decompilers:

  • No Bytecode (.pyc) Exists: The executable does NOT contain Python bytecode. It contains raw x86_64 machine code instructions.
  • Decompiler Rejection: Tools like uncompyle6 fail completely because there is no Python archive to extract.
  • Reverse Engineering Barrier: A hacker would have to use advanced disassemblers like IDA Pro or Ghidra to inspect raw assembly language, making reverse-engineering prohibitively expensive and difficult.

3. Defense-in-Depth Protection Layers

For maximum security in commercial SaaS apps, developers combine multiple security layers:

Layer 1: PyArmor Obfuscation  (Encrypts & mangles AST logic)
           ↓
Layer 2: Nuitka C++ Build     (Translates to machine code)
           ↓
Layer 3: License Key Validation (JWT + Hardware Fingerprinting)
           ↓
Layer 4: Anti-Debugging & Integrity Checks

Layer Details:

A. PyArmor Obfuscation (Code Mangling)

PyArmor encrypts bytecode and obfuscates function logic before compilation. Even if someone inspects memory dumps, variable names and control flow logic are scrambled.

B. Hardware Fingerprinting (Licensing)

To prevent users from sharing your .exe with unauthorized users, the Relay app computes a machine hash:

import hashlib, platform, uuid

def get_machine_fingerprint():
    raw_id = f"{uuid.getnode()}-{platform.processor()}-{platform.machine()}"
    return hashlib.sha256(raw_id.encode()).hexdigest()

The app checks this fingerprint against your backend database to verify an active subscription.

C. Anti-Debugging Checks

The app checks if it is being run inside a debugger (like x64dbg or Ghidra):

import ctypes

def check_debugger():
    if ctypes.windll.kernel32.IsDebuggerPresent():
        print("Debugger detected. Terminating...")
        exit(1)

4. Summary Matrix

Protection Technique Reversibility Difficulty to Hack Best Use Case
PyInstaller Extremely Easy (< 1 min) Trivial Internal testing / Open source
PyArmor Obfuscation Moderate (Requires memory dump) Medium Distributing scripts
Nuitka C++ Compilation Extremely Hard (Requires Ghidra assembly analysis) High Production Commercial SaaS
Nuitka + Hardware License Virtually Impossible for normal users Maximum Enterprise Desktop Software

There aren't any published security advisories