Links

Python

Useful Python code

Set up virtual environment

Using virtual python environments is helpful when needing to run old python2 or earlier code. It can also keep your main python environment clean if needing to download potentially conflicting python packages.
# Setting up a python2 virtual env called 'etblue-venv' in the /tmp directory
virtualenv /tmp/etblue-venv -p $(which python)
# Connecting to the virtual environment
source /tmp/etblue-venv/bin/activate
# After connecting, your shell will display the name of the venv
┌──(/tmp/etblue-venv)(kali㉿kali)
# Verify python version (depends on version you selected)
└─$ python2.7 -V
Python 2.7.18
# Exit venv (you can go back to it with the 'source' command above)
deactivate
# The venv remains until you delete it
sudo rm -R etblue-venv

View pip modules

pip list
Package Version
---------- -------
pip 20.3.4
setuptools 44.1.1
wheel 0.37.1
xlrd 2.0.1

View installed modules

└─$ python3 -c 'help("modules")'
[SNIP]
Cryptodome cairo ldb retrying
Cython calendar lib2to3 rfc3986
IPy catfish libfuturize rfc3987
IPython catfish_lib libpasteurize rich
[SNIP]

Parsing JSON

  • The JSON file used below is the output of the command:
"ffuf -w /opt/useful/SecLists/Discovery/DNS/namelist.txt -u http://<target IP> -H HOST: FUZZ.<target domain> -o possible-subdomains.json"
1
import json
2
3
json_dump = "./possible-subdomains.json"
4
5
with open(json_dump) as f:
6
data = json.load(f)
7
8
for host in data["results"]:
9
print(host["host"], host["url"]) # print out the host & URL