Skip to content

Instantly share code, notes, and snippets.

View kousu's full-sized avatar

Nick Guenther kousu

  • Asymmetric Research
  • Canada
View GitHub Profile
@kousu
kousu / mkcert
Created February 21, 2016 06:52
openssl sucks
#!/bin/sh
#
# generates a self-signed CA and certificates signed by that CA.
# If you install the CA into your certificate stores (in Firefox: Prefs->Advanced->Certs->Import, in Gnome: open the .crt in and whose .crt,.key pair can be used
# worked out with http://www.akadia.com/services/ssh_test_certificate.html and trial and error
# (as usual, with OpenSSL)
# Usage:
# ./mkcert # and follow the prompts, to make a CA
# ./mkcert my.domain.name
#!/bin/sh
# this wraps an arbitrary program in dmenu
# usage: dmenu_do "<dmenu arguments>" -- "<command>"
# dmenu will run with no options, and if the user gives input, <command> will be run with input as trailing arguments
# #
# Example: dmenu_do "-p \"Web Search:\"" -- "sr duckduckgo -j"
# becomes sr duckduckgo -j `dmenu -p "Web Search:"`, except it only runs if dmenu succeeds
#
# This is not a perfect wrapper:
# ideally the API would be: dmenu_do [dmenu args] -- command [args]
@kousu
kousu / diproxy.py
Last active February 15, 2017 22:32
#!/usr/bin/env python
# DI's new licensing restriction setup is basically completely forgeable
# the only thing they actually enforce is referer checking
#
# This program sits and does the necessary referer hacking, so that you can still listen to DI.fm on standard internet radio players
#
# TODO:
# - [x] get a full list of DI channels (maybe dynamically even, at boot?)
# - [ ] pretty-up the menu; jinja2?
# - [ ] print bandwidth reports as listeners join and leave
@kousu
kousu / bsd_thread_syscall_hang.py
Created February 12, 2017 15:15
Unkillable read()s when threads are involved
#!/usr/bin/env python
"""
Unkillable read()s when threads are involved bug:
Set up:
1) run `nc -l 7654 -k` in another terminal
2) run this
3) press control-c
Results:
@kousu
kousu / README.md
Last active February 26, 2017 01:50
Extract SMTP credentials by running a fake server

I forgot my email password.

This is a hacked version of smtpd.py which extracts AUTH PLAIN passwords. You can use to it extract passwords from your email clients if you've forgotten them and would rather not try to figure out where they are stored locally: instead, run this and change the host and port your client uses for an SMTP server.

Example run:

[kousu@host ~/src]$ ./smtpd.py -n -d 0.0.0.0:8025
PureProxy started at Sat Feb 25 20:27:17 2017
	Local addr: ('0.0.0.0', 8025)
@kousu
kousu / Guide.md
Last active March 2, 2017 06:28
Debugging mailservers by self-MITM

Debugging mail is hard. It's even harder when there's SSL in the way. But we can use unix elbow grease to get around this!

Run socat as a proxy, offloading the SSL processing to openssl in a subshell:

$ socat -v TCP-LISTEN:5877 EXEC:'openssl s_client -connect mail.your.server\:587 -starttls smtp'

Test this is working by, in parallel session

@kousu
kousu / README.md
Last active March 3, 2017 21:03
Pare down font files for web use

Sometimes** (**I'm thinking of the web, here, really) you only need a subset of glyphs in a font. A full font file can be pretty bandwidth-heavy.

cut_font will snip a font down to only the characters given on the command line. It will use the same output format as input format. It doesn't handle glyph variations (like italics or bold versions of a font) nor let you choose the output file; sorry about that; patches welcome.

Example

$ ./cut_font Symbola.ttf ≄ a b C D \`
@kousu
kousu / journal
Last active August 19, 2017 19:26
Handy personal journal script
#!/bin/sh
# journal
#
# Usage: journal [date]
#
# Spawn your plain-text $EDITOR open to your diary.
# Journal files are arranged in a simple tree hiearchy by date under ~/Journal/.
# If date is given, it is a date string as understood by GNU date;
# you can say for example,
# journal yesterday
#!/bin/sh
# extract Google's published list of outbound-going smtp servers, for purposes of whitelisting them
# from https://support.google.com/a/answer/60764?hl=en
# the results come back in CIDR notation, so be sure to handle that
# subtlety: i="" on the first iteration, because there is (currently) no _netblocks1, there's just _netblocks
(for i in "" `jot 3 1 3`; do
dig TXT _netblocks$i.google.com @8.8.8.8 +short;
done) |
awk -F ":" -v RS=" " '/^ip4:/ { print $2 }'
@kousu
kousu / .procmailrc
Created December 17, 2017 19:43
procmail snippet for auto-binning / auto-filtering mailing lists
# mailing lists
#
# This automatically sorts mail from mailing lists into folders named after the list
# misc@openbsd.org will go into your IMAP Lists/misc folder
# fanciness@lists.riseup.net will go into Lists/fanciness
# (if you need more specific rules, you can tweak or add a rule for your specific lists *ahead* of this rule)
#
# Now, procmail doesn't(?) have capturing groups, closest it has a capturing \/,
# which grabs everything from itself *to the end* of the line* of the match
# (thanks https://serverfault.com/questions/660159/procmail-recipe-with-capturing-group/660571);