Skip to content

Instantly share code, notes, and snippets.

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)
@moshekaplan
moshekaplan / plink_socks_proxy.bat
Last active March 22, 2024 08:12
plink SOCKS proxy short guide
#!/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 / 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)
@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)]
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 / 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)
@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 / matchTemplate_example.py
Created March 4, 2013 06:57
Python OpenCV example (2.3.1) - matchTemplate
import cv2
from cv2 import cv
method = cv.CV_TM_SQDIFF_NORMED
template_name = "mozicon128.png"
image_name = "test2.jpeg"
# Load
needle = cv2.imread(template_name)
@moshekaplan
moshekaplan / minesweeper_solver.py
Created February 10, 2013 06:40
Code to solve 29c3ctf's minesweeper challenge.
"""
Steps:
1) Save the game before anything happens
2) Solve the game to get the list of mines, as y,x coordinates
3) Reconstruct the savegame
4) XOR the decoded savegame and the reconstructed save game to get the key
5) Build an exploit to steal the entire key.
6) Build an exploit to grab the flag
"""