Skip to content

Instantly share code, notes, and snippets.

View r0yfire's full-sized avatar

Roy Firestein r0yfire

View GitHub Profile
@r0yfire
r0yfire / LoginRequiredMiddleware.py
Created May 6, 2014 17:47
Django Login Required Middleware
from re import compile
from django.conf import settings
from django.http import HttpResponseRedirect
from django.utils.http import is_safe_url
EXEMPT_URLS = [compile(settings.LOGIN_URL.lstrip('/'))]
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
EXEMPT_URLS += [compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
class LoginRequiredMiddleware:
@r0yfire
r0yfire / sendgrid_email_backend.py
Last active August 29, 2015 14:01
Simple SendGrid email backend for Django that uses authentication tokens
from django.conf import settings
from django.core.mail.backends.base import BaseEmailBackend
from django.core.mail.message import sanitize_address
import sendgrid
class SendgridBackend(BaseEmailBackend):
def __init__(self, user=None, token=None, **kwargs):
super(SendgridBackend, self).__init__()
@r0yfire
r0yfire / patch_docx.py
Last active August 29, 2015 14:08
Patch docx file with a tracking URL | www.docping.me
#!/usr/bin/env python
"""
Patch docx file with a tracking URL
Author: Roy Firestein (roy[at]firestein[dot]net)
Date: October 28, 2014
Based on code from https://docping.me
@r0yfire
r0yfire / email_frequency.py
Last active August 29, 2015 14:09
Search your emails for a keyword or string and generate CSV file with frequency by month.
import imaplib
import email
from datetime import datetime
###
### Enter your IMAP server address here
###
mail = imaplib.IMAP4_SSL('mail.example.com')
###
### Enter your email and password here
@r0yfire
r0yfire / fastflux_scraper.sh
Created March 26, 2015 13:12
Scrape FastFlux Domain IP's
#!/bin/bash
cd "$(dirname "$0")"
while test $# -gt 0; do
case "$1" in
-h|--help)
echo " "
echo "domain watcher"
echo " "
@r0yfire
r0yfire / qpdecode.py
Created April 15, 2015 17:18
Decode quoted-printable text in a file
#!/usr/bin/python
"""
Decode quoted-printable text in a file
"""
import sys
import quopri
from BeautifulSoup import BeautifulSoup as bs
print '\t\tHTML Extract0r 2014\n'
@r0yfire
r0yfire / ebextensions_apache_logentries.yaml
Last active August 29, 2015 14:23
Configure AWS Elastic Beanstalk syslog to send Apache logs to logentries.com
# Name: logentries.config
# Description: configure rsyslogd to include logfiles from apache
#
# Steps:
# 1. Save this file as .ebextensions/logentries.config
# 2. Replace 'TOKEN' below (line 37)
# 3. Deploy per normal scripts or aws.push.
#
files:
"/etc/rsyslog.d/apache.conf" :
@r0yfire
r0yfire / cymonlib.py
Last active August 29, 2015 14:23
Example for creating a Cymon API library in python
from copy import copy
import json
import logging
import requests
class Cymon(object):
def __init__(self, auth_token, endpoint='https://cymon.io/api/nexus/v1'):
self.endpoint = endpoint
@r0yfire
r0yfire / nessus_exclude.py
Last active August 29, 2015 14:24
Remove IP/hostnames from Nessus report findings
"""
Remove Nessus findings by hostname or IP address from .nessus files
Example usage:
python nessus_exclude.py –d nessus_files/ -r 10.1.1.1,10.2.2.2,hostname.internal
"""
import os
import xml.dom.minidom
from optparse import OptionParser
@r0yfire
r0yfire / cymon_apache.py
Last active November 5, 2015 19:20
Analyze Apache logs and lookup IP addresses in Cymon for analysis and CIRT
#!/usr/bin/env python
'''
Analyze Apache log file to identify malicious request sources
'''
from os import path
import sys
import urllib
import json
def apache2_logrow(s):