Installing and running Jupyter Notebook / JupyterLab inside a virtual environment for interactive security data analysis and PoC exploration.
Jupyter provides an interactive, cell-based environment ideal for exploratory work: parsing logs, triaging captured traffic, prototyping an exploit chain, or charting scan results. Code runs cell-by-cell with output (including tables and plots) shown inline, so you iterate fast without re-running a whole script. For security work, install Jupyter into a per-project [[Managing-Virtual-Environments|venv]] and register that venv as a kernel so notebooks use your pinned tooling.
# Install into an activated venv
python3 -m venv .venv && source .venv/bin/activate
pip install jupyterlab
# Launch
jupyter lab # full IDE-like interface
# or
jupyter notebook # classic single-notebook UIKey ideas:
- Kernel — the interpreter a notebook runs against. Register your venv as a named kernel so the notebook uses it rather than the global Python.
- Cells — code or Markdown blocks executed independently; state persists in the kernel between cells.
- JupyterLab vs Notebook — Lab is the modern multi-panel UI; classic Notebook is lighter.
# Register the active venv as a Jupyter kernel
pip install ipykernel
python -m ipykernel install --user --name acme-engagement \
--display-name "Python (acme)"
# List and remove kernels
jupyter kernelspec list
jupyter kernelspec uninstall acme-engagementWarning
jupyter lab starts a local web server. Do not bind it to 0.0.0.0 on an untrusted network — a Jupyter server with a leaked token grants remote code execution. Keep it on localhost and use SSH port-forwarding to reach a remote instance.
# In a notebook cell: parse an auth log and count failed SSH logins
import re
from collections import Counter
with open("/var/log/auth.log") as fh:
ips = re.findall(r"Failed password.*from (\d+\.\d+\.\d+\.\d+)", fh.read())
Counter(ips).most_common(5)[('192.168.1.50', 214),
('10.0.0.9', 88),
('172.16.4.2', 31)]
- Triaging large log or PCAP-derived datasets interactively, keeping intermediate results in memory across cells.
- Prototyping an exploit or crypto attack step-by-step, inspecting each transformation before committing it to a script.
- Producing a shareable, reproducible analysis notebook as a client deliverable, with narrative Markdown alongside the code.
- Always install Jupyter into a project venv and register it as a named kernel; never
sudo pip install jupyter. - Reach remote notebooks via
ssh -L 8888:localhost:8888 user@host, never by exposing the port. - Clear sensitive output (tokens, dumped hashes) before saving/sharing a notebook — output is stored in the
.ipynb. - Graduate stable notebook code into a proper module once it works (see [[Project-Structure-Best-Practices]]).
- Running the notebook against the global kernel, so pinned venv packages are missing or wrong versions.
- Binding the server to all interfaces or disabling token auth for convenience — a critical RCE exposure.
- Relying on hidden cell-execution order; re-run "Restart & Run All" to confirm the notebook is reproducible.
Goal: run a venv-backed notebook and analyze data interactively.
- Create and activate a venv, then
pip install jupyterlab pandas. - Register the kernel:
python -m ipykernel install --user --name lab-kernel. jupyter lab, create a notebook, and select thelab-kernel.- In cells, load a CSV of scan results with pandas and compute the count of open ports per host.
- Project Jupyter — Installing
- ipykernel — Kernels for different environments
- Jupyter — Security in notebook documents
- [[Selecting-an-IDE]]
- [[Managing-Virtual-Environments]]
- [[Project-Structure-Best-Practices]]
- [[Python-Environment-Setup/Readme|Python Environment Setup]] — module index
- [[Readme|Python for Security Professionals]] — course home