Skip to content

KingLinux24/python-exercises

Repository files navigation

Python Security Fundamentals: Scalars & Internals

This repository contains Python scripts that explore the low-level behaviors of Python's scalar types (integers, strings, bytes) and memory management. These concepts are foundational for exploit development, malware analysis, and high-performance security tooling.

📂 Repository Contents

1. Byte Manipulation & Obfuscation

  • endianness.py
    • Concept: Converts integers to Little Endian byte sequences.
    • Security Context: Essential for packing memory addresses when crafting buffer overflow payloads for x86/x64 architectures.
  • mutablexor.py
    • Concept: Uses mutable bytearray types to perform in-place XOR encryption.
    • Security Context: Demonstrates how malware obfuscates payloads in memory to evade signature-based detection (AV/IDS) without generating new object overhead.

2. Performance & Optimization

  • String_Builder_Benchmark.py
    • Concept: Benchmarks string concatenation (+=) versus list joining ("".join).
    • Key Finding: Shows why join() is critical for performance when parsing massive log files or generating large wordlists, avoiding the $O(n^2)$ memory copying cost.

3. Pythonic Coding & Internals

  • Truthiness_Audit.py
    • Concept: Implements custom __bool__ dunder methods in classes.
    • Security Context: Allows for cleaner, "Pythonic" guard clauses in tools (e.g., if port_open: instead of checking status strings manually).
  • intro.py
    • Concept: Basic demonstrations of Python's numeric precision and text vs. bytes separation.

🚀 Usage

You can run each script individually to observe the behavior:

python3 mutablexor.py
python3 String_Builder_Benchmark.py

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages