Skip to content

Instantly share code, notes, and snippets.

View mmattice's full-sized avatar

Mike Mattice mmattice

View GitHub Profile
@mmattice
mmattice / gist:b2b95c62a3e433e71f0c63ec422b2e4a
Created April 12, 2018 03:15
sha256 hashed ssh key for Cisco
cut -d ' ' -f 2 .ssh/id_rsa.pub | base64 -d | sha256sum | cut -d ' ' -f 1 | sed 's/..\B/&:/g'
def constructpacket(data):
frame = [ 0x60 ]
frame.extend(data)
lrc = 0x00
for x in frame:
lrc = lrc ^ x
frame.append(lrc)
frame.append(0x03)
return frame
@mmattice
mmattice / .gitconfig.aliases
Last active December 13, 2017 20:59
git config aliases
[alias]
pl = log --oneline --decorate --graph
plall = log --oneline --decorate --all --graph
co = checkout
ds = diff --staged
d = diff
dwd = diff --word-diff
dcw = diff --color-words
dswd = diff --staged --word-diff
dscw = diff --staged --color-words
@mmattice
mmattice / namecheap-dns-parse.py
Last active August 9, 2017 15:42
Cheap and easy advanced dns parser for namecheap
from bs4 import BeautifulSoup
html_doc=open('dns.html', 'r').read()
soup = BeautifulSoup(html_doc, 'html.parser')
table = soup.find('table', attrs={'class': 'advanced-dns'})
rows = table.findAll('tr', attrs={'class': '[object Object]'})
for row in rows:
cols = row.findAll('td')
rowtextl = [c.text.strip().replace('\n',' ') for c in cols]
removelist = (u'TTL Automatic', u'Remove Edit')
for r in removelist:
# stolen from glyph
Host *.via.*
ProxyCommand sh -c 'cuttable="$(echo "${0}" | sed -e "s/.via./~/g" )"; to_host="$(echo "${cuttable}" | cut -d "~" -f 1)"; via_host="$(echo "${cuttable}" | cut -d "~" -f 2- | sed -e "s/~/.via./g")"; local_port="${1}"; echo "Connecting to <${to_host}> on port <${local_port}> via <${via_host}>." > /dev/stderr; exec ssh -q "${via_host}" -W "${to_host}:${local_port}";' '%h' '%p'
# IOS 15.4
sed -r 's/(ip ospf authentication-key 7 |ip ospf message-digest-key 1 md5 7 )([0-9A-F]+)/\1*redacted*/;s/(snmp-server community )([^ ]+) (.*)$/\1*redacted* \3/'
# ASA 9.1
sed -i -r 's/( ospf message-digest-key [0-9]+ md5 )([^ ]+)(.*)$/\1*redacted*\3/;s/(snmp-server community )(.*)/\1*redacted*/;s/(ikev1 pre-shared-key )(.*)/\1*redacted*/'
| egrep -o 'Deny ..p.*' | sed -r 's/ by.*$//;s/\([^ ]+\)//g;s!/[0-9]+ ! !' | sort | uniq -c
@mmattice
mmattice / ts-histo.py
Last active September 5, 2016 21:17
Create a 5 minute bucket histogram of input apache-style timestamps
import fileinput
from datetime import datetime
counts = dict()
for i in range(288):
counts[i] = 0
for line in fileinput.input():
dt = datetime.strptime(line.strip(), '%d/%b/%Y:%H:%M:%S')
bucket = (dt.hour*60+dt.minute)/5
#!/usr/bin/python
from binascii import hexlify, unhexlify
frombank = unhexlify('723a860e84da00cc090014c10390b39d7d79861384da00c80e00000000000001ef1d534991a069861384da00c90e00000000000057d981ff69f29ba7')
working = unhexlify('723c303a860e84da00cc090014c10390b39d7d79861384da00c80e00000000000001ef1d534991a069861384da00c90e00000000000057d981ff69f29ba7')
from pyasn1.type import tag, tagmap, univ, namedtype
from pyasn1 import debug
#debug.setLogger(debug.Debug('all'))
# Test on delivery
def register(key):
def decorator(method):
method.response = key
return method
return decorator
@register('$')