Skip to content

Instantly share code, notes, and snippets.

View TheTechromancer's full-sized avatar

TheTechromancer

View GitHub Profile
@TheTechromancer
TheTechromancer / prevent_vpn_lockout_ssh.sh
Last active August 23, 2024 04:52
Prevent VPN from locking out SSH
echo <<EOF > /etc/systemd/system/vpn-bypass.service
[Unit]
Description=VPN Bypass for SSH and UDP ports 60000-61000
After=network.target
[Service]
Type=oneshot
# ExecStart=/bin/sh -c 'grep -q "200 vpnbypass" /etc/iproute2/rt_tables || echo "200 vpnbypass" >> /etc/iproute2/rt_tables'
# ExecStart=/bin/sh -c 'ip rule del fwmark 0xca6c lookup 200 priority 100 2>/dev/null || true'
# ExecStart=/bin/sh -c 'ip route add unreachable default metric 4278198272 table 200 2>/dev/null || true'
@TheTechromancer
TheTechromancer / python_attach_howto.md
Last active September 7, 2024 15:34
Attach to a running python process and explore its state - useful for troubleshooting deadlocks, memory leaks, etc.

Attach to PID with GDB

gdb -p <pid>

Interactively inspect the running process

To interactively debug a running python process, you can use gdb to execute pdb:

#!/usr/bin/env python3
import sys
import asyncio
from bbot.scanner import Scanner
try:
file = sys.argv[-1]
except KeyError:
@TheTechromancer
TheTechromancer / clean_dns_records.py
Created October 11, 2022 20:39
A simple python script to filter out unresolved/wildcard DNS records.
#!/usr/bin/env python3
import sys
import string
import random
import dns.resolver
import threading
import tldextract
import concurrent.futures
This file has been truncated, but you can view the full file.
# top subdomain append/prepends
# derived from top 1 million subdomains: https://github.com/bitquark/dnspop
401055 {}
8350 {}2
8035 {}1
4012 {}3
2766 {}4
2585 {}01
2183 {}5
@TheTechromancer
TheTechromancer / kill_detached_mosh_sessions.sh
Created May 12, 2021 16:22
Kill all detached mosh sessions
kill $(last -f /var/run/utmp | egrep -o 'mosh \[[0-9]+\]' | egrep -o '[0-9]+')
@TheTechromancer
TheTechromancer / session_logging.sh
Created February 4, 2021 20:18
Enable complete session logging (input and output) for both normal shells and individual tmux panes
# default tmux config
cat <<EOF > "$HOME/.tmux.conf"
set -g mouse on
set -g history-limit 50000
# List of plugins
set -g @plugin 'tmux-plugins/tmux-logging'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
@TheTechromancer
TheTechromancer / dhcp_option_121.py
Created November 9, 2019 22:16
DHCP Option 121 (Routes) with Python 3 for pfSense, etc.
#!/usr/bin/env python3
from ipaddress import *
routes = [
# destination # router
('10.0.0.0/24', '172.16.0.2'),
('0.0.0.0/0', '172.16.0.1')
]