Skip to content

Instantly share code, notes, and snippets.

View kkirsche's full-sized avatar

Kevin Kirsche kkirsche

View GitHub Profile
@kkirsche
kkirsche / python_init.py
Created August 17, 2016 02:45
Python kwargs initialization method
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
@kkirsche
kkirsche / python_sysloghandler.py
Created August 22, 2016 19:57
Python based stdout logger and logger using logging.handlers.SysLogHandler
import logging
from logging.handlers import SysLogHandler
import sys
def create_logger(name, verbosity):
"""create_logger uses a name and verbosity level. The name is most commonly
the __name__ variable and verbosity is most often passed to the program
from command line arguments via ConfigParser/configparser. This then sets
the log level to Warning (no verbosity), Information (verbosity 1), or
@kkirsche
kkirsche / nmapxml_to_csv.py
Last active July 25, 2017 18:57
Nmap XML to CSV File
import os
import glob
import csv
from libnmap.parser import NmapParser
dir_path = os.path.dirname(os.path.realpath(__file__))
with open('nmap_results.csv', 'wb') as output_file:
writer = csv.writer(output_file)
@kkirsche
kkirsche / nmapxml_to_elasticsearch.py
Created August 22, 2016 23:42
Nmap XML to Elasticsearch
import os
import glob
from datetime import datetime
from elasticsearch import Elasticsearch
from libnmap.parser import NmapParser
dir_path = os.path.dirname(os.path.realpath(__file__))
es = Elasticsearch()
@kkirsche
kkirsche / package_finder.py
Created September 21, 2016 21:28
Find installed binary and configuration files on CentOS
import logging
import os
import re
import subprocess
import yum
yb = yum.YumBase()
yb.setCacheDir()
dependency_installed = yb.rpmdb.searchNevra(name='yum-utils')
if not dependency_installed:
@kkirsche
kkirsche / recursive_grep.sh
Created October 4, 2016 14:30
Grep for pattern in file(s)
#
sudo grep -rni --exclude-dir={proc,boot,sys} "searchingfor" /
# or use https://docs.python.org/3/library/itertools.html#itertools.permutations
def permutations(string, step = 0):
# if we've gotten to the end, print the permutation
if step == len(string):
print "".join(string)
# everything to the right of step has not been swapped yet
for i in range(step, len(string)):
# copy the string (store as array)
@kkirsche
kkirsche / extract_osx_plists.sh
Created December 15, 2016 19:56
OS X Password Hash Extraction
#!/bin/bash
pat="^[0-9a-zA-Z ]{1,}\.plist"
xml_pat="^<\?xml.*"
if [[ $EUID -ne 0 ]]; then
echo "[-] Not running as root, you probably won't see any results."
fi
for f in /var/db/dslocal/nodes/Default/users/*
@kkirsche
kkirsche / ansible.cfg
Created December 16, 2016 17:54
General Ansible Configuration File
[defaults]
inventory: ./inventories/production/hosts.yml
remote_user: kkirsche
remote_port: 22
forks: 20
pipelining: True
callback_whitelist: json
retry_files_enabled: False
@kkirsche
kkirsche / prompts.sh
Created February 28, 2017 22:20
Shell Prompt Coloring
Red Prompt — Production
STARTCOLOR="\e[0;31m"
ENDCOLOR="\e[0;0m"
PS1="\[$STARTCOLOR\][\u@\h \W]\\$ \[$ENDCOLOR\]"
Yellow Prompt — Staging
STARTCOLOR="\e[0;33m"
ENDCOLOR="\e[0;0m"
PS1="\[$STARTCOLOR\][\u@\h \W]\\$ \[$ENDCOLOR\]"