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.
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
bytearraytypes 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.
- Concept: Uses mutable
-
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.
-
Concept: Benchmarks string concatenation (
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).
- Concept: Implements custom
intro.py- Concept: Basic demonstrations of Python's numeric precision and text vs. bytes separation.
You can run each script individually to observe the behavior:
python3 mutablexor.py
python3 String_Builder_Benchmark.py