Skip to content

Instantly share code, notes, and snippets.

@moshekaplan
moshekaplan / pdf_decrypt.py
Created November 16, 2016 17:54
PyPDF2 attempt at decryption
PyPDF2 attempt at decryption
Modifications to file: pdf.py
References:
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
https://github.com/qpdf/qpdf/blob/master/libqpdf/QPDF_encryption.cc#L400
http://security.stackexchange.com/questions/95781/what-security-scheme-is-used-by-pdf-password-encryption-and-why-is-it-so-weak
def decode_permissions(self, permissions_code):
@moshekaplan
moshekaplan / lcs.py
Created December 16, 2012 04:47
Sample code for recursively calculating the longest-common subsequence.
def lcs(str1, str2):
# If either string is empty, stop
if len(str1) == 0 or len(str2) == 0:
return ""
# First property
if str1[-1] == str2[-1]:
return lcs(str1[:-1], str2[:-1]) + str1[-1]
# Second proprerty
@moshekaplan
moshekaplan / selenium_cookies_to_mechanize.py
Created August 29, 2014 14:18
Selenium cookies to Mechanize
import mechanize
import cookielib
import selenium.webdriver
# Create a selenium instance for browsing web pages
driver = selenium.webdriver.Firefox()
# ... Perform some actions
# Grab the cookie
@moshekaplan
moshekaplan / python_md5.py
Created November 27, 2012 17:51
MD5 length-extension, as described in Thai Duong's Flickr API attack. Based on http://www.huyng.com/posts/dont-hash-your-secrets-heres-why-in-python/
"""
MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.
License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
Algorithm" in all material mentioning or referencing this software
or this function.
@moshekaplan
moshekaplan / msg.py
Last active November 15, 2016 14:28
Extract features from MSG files. Based on https://github.com/mattgwwalker/msg-extractor/blob/master/ExtractMsg.py Raw
#!/usr/bin/env python
# -*- coding: latin-1 -*-
"""
ExtractMsg:
Extracts emails and attachments saved in Microsoft Outlook's .msg files
https://github.com/mattgwwalker/msg-extractor
"""
__author__ = "Matthew Walker"
#!/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)]
@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 / 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)