Skip to content

Instantly share code, notes, and snippets.

@rjzak
rjzak / bloomFilter.py
Created Dec 25, 2019
A simple bloom filter with standard dependencies. Expects the input to be strings.
View bloomFilter.py
#!/usr/bin/python3
import os
import zlib
import pickle
import numpy as np
import unittest
P_B = 227
P_M = 1000005
@rjzak
rjzak / entropy.py
Created Aug 11, 2019
Quick script for getting entropy values for files
View entropy.py
#!/usr/bin/python
import math, string, sys
def range_bytes (): return range(256)
def range_printable(): return (ord(c) for c in string.printable)
def H(data, iterator=range_bytes):
if not data:
return 0
entropy = 0
View ordinal.py
import math
ordinal = lambda n: "%d%s" % (n,"tsnrhtdd"[(math.floor(n/10)%10!=1)*(n%10<4)*n%10::4])
@rjzak
rjzak / reformat_string.py
Created Jun 14, 2018
Reformat an even-length string, like a MAC address
View reformat_string.py
# Input example: 8249CEB658C71D41D7B734449629AB97
# Output example: 82:49:CE:B6:58:C7:1D:41:D7:B7:34:44:96:29:AB:97
reformat = lambda x: ":".join([x[i:i+2] for i in range(0, len(x), 2)])
@rjzak
rjzak / edgeos_adblock.sh
Created Mar 6, 2017
Pull and reformat lists for blocking domains associated with advertising (since ad networks don't police themselves and allow malvertising) and malware/scams.
View edgeos_adblock.sh
#!/bin/bash
# Modified Pi-hole script to generate a dnsmasq file
# Intended for EdgeOS/EdgeMax from Ubuquiti Networks https://www.ubnt.com/
# original : https://github.com/jacobsalmela/pi-hole/blob/master/gravity-adv.sh
# original : https://gist.github.com/OnlyInAmerica/75e200886e02e7562fa1
# inspiration: https://help.ubnt.com/hc/en-us/articles/205223340-EdgeRouter-Ad-blocking-content-filtering-using-EdgeRouter
# Be sure to put this file in /config/user-data/
# Symlink for cron updates:
# ln -s /config/user-data/edgeos_adblock.sh /etc/cron.weekly/edgeos_adblock
@rjzak
rjzak / execSections.py
Created Jan 26, 2017
Use pefile to see if a section in an EXE (PE32) file is executable or not. Convenient, since a lot of EXE's don't have the standard .text section, or have more than one executable section.
View execSections.py
#!/usr/bin/python
import pefile
import sys
'''
Test the section characteristics to see if the section is executable. Check for flags:
* 0x00000020 = Section contains code
* 0x20000000 = Section is executable
@rjzak
rjzak / gen_password.py
Created Dec 30, 2016
A Python 3 script which uses the system's dictionaries to generate xkcd-inspired passwords. Inspired by: https://xkcd.com/936/
View gen_password.py
#!/usr/bin/python3
import os
import sys
import glob
import codecs
import random
cleanup = lambda x: x.split("/")[0] if "/" in x else x # Some hunspell entries have slashes in the second to last character.
@rjzak
rjzak / plot.py
Created Nov 1, 2016
A quick and simple Python script to graph numpy arrays. Useful for initial analysis and comparing of data.
View plot.py
#!/usr/bin/python
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import sys
# Modeled after: http://matplotlib.org/1.3.0/examples/pylab_examples/legend_demo.html
if len(sys.argv) < 2:
@rjzak
rjzak / Makefile
Created May 4, 2016
Makefile template
View Makefile
CFLAGS+=-std=c99 -DMYDEFINE -g -O0
LDFLAGS+=-lm
DEPS = Makefile
all: myproj
%.o: %.c %.h $(DEPS)
$(CC) -fPIC -c -o $@ $< $(CFLAGS)
myproj: file.o main.o
@rjzak
rjzak / randomKey.py
Created Feb 17, 2016
For when you need some random keys as a string, with optional starting value and optional length
View randomKey.py
import random
def randomKey(start=None, bytes=16):
if start is None:
part = "%02x" % random.randint(0,255)
return randomKey(part, bytes)
elif len(start.split(" ")) == bytes:
return start
else:
part = "%s %02x" % (start, random.randint(0,255))
return randomKey(part, bytes)