Skip to content

Instantly share code, notes, and snippets.

@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 / 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"
@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 / 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 / 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 / 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):
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 / aircrack_coverity.sh
Created August 5, 2019 00:56
Aircrack Coverity build
#!/bin/sh
PROJECT_DIR="/home/moshe/Desktop/aircrack-ng"
COV_BUILD="/home/moshe/Downloads/cov-analysis-linux64-7.6.0/bin/cov-build"
PROJECT_NAME="aircrack-ng"
BUILD_DIR="/home/moshe/Desktop/aircrack-ng_cov/cov-int"
TAR_DIR="/home/moshe/Desktop/aircrack-ng_cov/"
BUILD_CMD="make sqlite=true experimental=true pcre=true -j 4"
# Prepare to build commands