Skip to content

Instantly share code, notes, and snippets.

@moshekaplan
moshekaplan / test_surf.py
Last active October 19, 2022 18:14
Demo for Python OpenCV SURF
#!/usr/bin/env python
'''
Uses SURF to match two images.
Based on the sample code from opencv:
samples/python2/find_obj.py
USAGE
find_obj.py <image1> <image2>
@moshekaplan
moshekaplan / get_code.py
Created April 5, 2013 11:20
Simple salting to generate x-digit codes.
import hashlib
salt = "This is a super secret salt. Nobody should ever be able to guess this.6rAtas7swe9ach6rAtas7swe9achXrAtas7swe9ach6rAtas7swe9ach6rAtas7swe9ach6rAtas7swe9ach"
def get_code(number, length):
"""Returns the first length bytes of the generated 'code'"""
return hashlib.sha512(str(number) + str(salt)).hexdigest()[:length]
for i in range(10):
print get_code(i, 7)
import sys
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
def get_exif_data(image):
"""Returns a dictionary from the exif data of an PIL Image item. Also converts the GPS Tags"""
exif_data = {}
info = image._getexif()
if info:
@moshekaplan
moshekaplan / cidr_to_ipv4
Last active January 1, 2016 15:59
CIDR to IPv4 converter. Thrown together for corelanc0d3r.
# CIDR to ipv4
# Written by Moshe Kaplan
def to_long(ip):
ip = ip.split('.', 4)
return int(ip[0])*(2**24) + int(ip[1])*(2**16) + int(ip[2])*(2**8) + int(ip[3])
def to_dotted_decimal(long_form):
octets = []
for i in range(4):
octets += [str(long_form % 2**8)]
@moshekaplan
moshekaplan / gist:8320605
Created January 8, 2014 17:21
Check if an IMGUR ID is 'nsfw'
import pyimgur
CLIENT_ID = ""
im = pyimgur.Imgur(CLIENT_ID)
blacklist = ['nsfw']
def is_fishy_imgur(id):
# Takes an Imgur ID and returns True if it is fishy
image = im.get_image(id)
#!/usr/bin/env python
import sys
from scapy.all import *
MAC = "00:0c:29:bf:b0:5a" # MAC Addr of Sockstress Attacker
def findARP(p):
op = p.sprintf("%ARP.op%")
if op == "who-has": # Only respond to ARP Requests
psrc = p.sprintf("%ARP.psrc%")
@moshekaplan
moshekaplan / plink_socks_proxy.bat
Last active March 22, 2024 08:12
plink SOCKS proxy short guide
import traceback
import logging
def get_exception_info(skip=2):
"""Note, this relies on being called from the exception handler. This is very brittle to the depth of the call."""
frames_output = []
for frame in traceback.extract_stack()[:-skip]:
fname, lineno, parent, function = frame
frame_output = """ File "%s", line %d, in %s\n %s""" % (fname, lineno, parent, function)
frames_output.append(frame_output)
#!/usr/bin/env python
"""
Given the result of a multiplication and one of the factors, calculate the
other factor
Arguments:
known_factor = the factor we're given
result = the result of the multiplication modulo some number
size_of_modulo_result = The number of bits in the result
@moshekaplan
moshekaplan / merge_dicts.py
Created August 17, 2014 15:27
Merge Python dictionaries
def merge_dicts(*dicts):
all_items = []
for dictionary in dicts:
all_items += dictionary.items()
return dict(all_items)