Skip to content

Instantly share code, notes, and snippets.

View kkirsche's full-sized avatar

Kevin Kirsche kkirsche

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / ftp.py
Created August 7, 2016 12:00
Python Port Checker — Detect a port opening
import socket;
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
openPort = False
while openPort == False:
result = sock.connect_ex(('10.10.10.136', 20))
if result == 0:
openPort = True
@kkirsche
kkirsche / ssl_puma.sh
Created July 22, 2016 12:46 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@kkirsche
kkirsche / int_to_rgba.go
Created July 21, 2016 01:07
Integer to RGBA in Golang — Similar to C/C++
package main
import "fmt"
func main() {
red := int(0xFF0000FF)
green := int(0x00FF00FF)
blue := int(0x0000FFFF)
redHex, greenHex, blueHex, alphaHex := calcColor(red)
@kkirsche
kkirsche / fileserver.py
Created July 18, 2016 15:49 — forked from vgel/fileserver.py
A very basic HTTP file server in 13 lines of python. Assumes all requests are GETs, and it vulnerable to directory traversal (Run it in ~ and localhost:8080/../../ will ls root), so don't use it online. Will correctly list files in directories.
import sys, os, socket
s = socket.socket()
s.bind((sys.argv[1], int(sys.argv[2])))
s.listen(5)
try:
while True:
conn, addr = s.accept()
path = os.path.join(os.getcwd(), "./"+conn.recv(4096).split("\n")[0].split(" ")[1])
conn.send((open(path).read() if os.path.isfile(path) else reduce(lambda x,s:x+"\n"+s+("/" if os.path.isdir(s) else ""),sorted(os.listdir(path)),"Directory "+path+" ls")) if os.path.exists(path) else '404: '+path)
conn.close()
@kkirsche
kkirsche / tracer.go
Created May 26, 2016 17:40
Golang URL Tracer
package main
import (
"log"
"net/http"
"time"
)
// TransportWrapper wraps the http.Transport structure to allow us to record the
// URLs which we are redirected through