Skip to content

Instantly share code, notes, and snippets.

View bwindsor's full-sized avatar

Ben Windsor bwindsor

  • Skyrad
  • England
View GitHub Profile
@bwindsor
bwindsor / time_alphabet.py
Created February 15, 2024 12:08
Function to time you typing the alphabet
def time_alphabet():
print("Time starts when you press a. Time will be printed when you finish by pressing z. If you go wrong, it won't tell you and your time won't stop. Press 0 to quit in this case.")
a1 = msvcrt.getch()
if a1 == b'a':
t0 = time.monotonic()
u = b''
while u != b'bcdefghijklmnopqrstuvwxyz':
c = msvcrt.getch()
u += c
if c == b'0':
@bwindsor
bwindsor / ip_scan.py
Created December 7, 2021 18:15
Ping many IP addresses in parallel to see which respond to a ping. Useful for finding IPs of another device you put on the network.
import threading
import subprocess
def f(x: int) -> None:
try:
output = subprocess.check_output(["ping", "-n", "1", f"192.168.1.{x}"])
if b"unreachable" not in output:
print(f"{x} was successful")
except subprocess.CalledProcessError:
@bwindsor
bwindsor / Dockerfile
Last active March 23, 2021 22:17
Dockerfile for ImageMagick container
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y imagemagick
RUN sed -i -E 's/name="memory" value=".+"/name="memory" value="4GB"/g' /etc/ImageMagick-6/policy.xml && \
sed -i -E 's/name="map" value=".+"/name="map" value="4GB"/g' /etc/ImageMagick-6/policy.xml && \
sed -i -E 's/name="area" value=".+"/name="area" value="4GB"/g' /etc/ImageMagick-6/policy.xml && \
sed -i -E 's/name="disk" value=".+"/name="disk" value="8GiB"/g' /etc/ImageMagick-6/policy.xml && \
sed -i -E 's/name="width" value=".+"/name="width" value="64KP"/g' /etc/ImageMagick-6/policy.xml && \
sed -i -E 's/name="height" value=".+"/name="height" value="64KP"/g' /etc/ImageMagick-6/policy.xml
@bwindsor
bwindsor / CLEAR_CHROME_HSTS_SETTINGS.md
Last active December 3, 2020 09:34
Clear chrome localhost https HSTS settings
  1. Go to chrome://net-internals/#hsts
  2. Under Query HSTS/PKP domain type localhost and click query. If it says not found this is not the solution. If it lists some things, continue.
  3. At the bottom, under Delete domain security policies enter localhost and click delete
  4. Done!
@bwindsor
bwindsor / reproducible_zip.py
Last active February 7, 2020 09:29
Reproducability of Zip file (and Terraform)
#!/usr/bin/env python
"""
This provides reproducible zipping, i.e. the zip file has doesn't change every time you recreate it unless the contents of any file within it have changed
See https://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute since files different because of file permissions
"""
import os
import sys
from subprocess import check_output
from tempfile import TemporaryDirectory
import shutil
@bwindsor
bwindsor / mps_to_mph.py
Created November 26, 2019 09:22
Metres per second to miles per hour in Python
def mps_to_mph(mps: float) -> float:
return mps * 3.6 / 1.609344
@bwindsor
bwindsor / Instructions.md
Last active October 9, 2019 22:26
OpenVPN + ObfsProxy Setup
  1. Start an AWS EC2 Instance from the Ubuntu 16.04 Amazon image. t3a.micro will do. Open ports 22 and 2443. Assign an elastic IP so it can't change.
  2. Download the private key for the EC2 instance whilst creating it
  3. SSH into the server
  4. Update to the latest sudo apt-get update then sudo apt-get upgrade -y
  5. Install PiVPN curl -L https://install.pivpn.io | bash. Make sure to select TCP and not UDP when given the option. Set the port as 1194. The rest can be left as defaults. If the screen does a strange flashy thing try ssh from Cygwin instead.
  6. Install obfsproxy sudo apt-get install obfsproxy
  7. Put the attached systemd file at /lib/systemd/system/obfsproxy.service
  8. Start the service sudo systemctl enable obfsproxy then sudo systemctl start obfsproxy
  9. Add users with pivpn add. Then follow the steps it gives you.
  10. Use scp to download the .ovpn files and put them on relevant devices. You'll need to modify 1443 to 2443 as the port number in these client config files.
@bwindsor
bwindsor / PasswordHashing.md
Created August 6, 2019 10:19
Good story of password hashing methods from stack exchange

This was copied and pasted from here.

Many years ago, it was standard practice to store passwords in plaintext in databases. This was a bad idea because, when the database was compromised, the attacker got all the passwords. To combat this, we started hashing passwords in the database using one-way cryptographic hash algorithms. MD5 became popular, but weaknesses (collisions, partial preimage, etc) discovered in it mean it's no longer recommended. A lot of people moved onto SHA1, which is more secure.

The problem with this approach is that it's possible to construct a huge table of hashes and their corresponding plaintexts. These are called rainbow tables. They work on the concept that it is more efficient to compute a huge list of hashes for all possible passwords (within a certain set) and then store it, so it can be quickly queried later on. So, instead of brute-forcing indi

@bwindsor
bwindsor / MySQLDatabase.py
Created January 2, 2019 13:41
Base class for connecting to a MySQL database from Python
import mysql.connector
from contextlib import closing
import logging
log = logging.getLogger(__name__)
class Database:
"""
Contains code for interfacing with a MySql database
@bwindsor
bwindsor / pivpn-obfsproxy-setup.md
Created September 30, 2018 00:08
Obfuscated VPN setup on EC2
  • Create an EC2 instance with Ubuntu 18.04 (I used t3.nano), and ssh into it
  • sudo apt-get update
  • sudo apt-get upgrade
  • Install PiVPN with curl -L https://install.pivpn.io | bash
  • Follow the on screen instructions. Mostly use defaults but the protocol must be TCP, and I chose 1443 as my port
  • Install obfsproxy with pip install obfsproxy
  • Create a service file /etc/systemd/system/obfsproxy.service with contents
[Unit]
Description=Obfsproxy server