Skip to content

Instantly share code, notes, and snippets.

/*
miscellaneous language learnings
*/
package main
import "fmt"
func main() {
fmt.Println("Oh yeah.")
@packetchef
packetchef / sizez.c
Created February 28, 2017 00:39
C code to get maximum size of some variable types; architecture-dependent
#include <stdio.h>
int main (int argc, const char * argv[])
{
/*
Shows max length for some types
*/
int zint;
char zchar;
@packetchef
packetchef / mask_ip_subnet.py
Created July 23, 2015 22:59
For a given subnet and salt, mask each IP
# Rumor has it that in newer releases of Python v3, ipaddr objects are not iterable
import ipaddr
import hashlib
salt = 'NN'
subnet = ipaddr.IPNetwork('192.168.100.0/24')
for ip in subnet:
# Try md5 or sha512
maskedIP = hashlib.md5(str(ip) + salt).hexdigest()
print('{ip:<15} :: {maskedIP}'.format(ip=ip, maskedIP=maskedIP))
@packetchef
packetchef / generate_ssn.py
Created August 6, 2017 19:03
Generate random numbers that look like SSNs. This ignores the SSA's algorithms and is really just random numbers.
#!/usr/bin/env python
from random import randrange
while True:
ssn1 = randrange(1, 999, 1)
ssn2 = randrange(1, 99, 1)
ssn3 = randrange(1, 9999, 1)
print('{0:0>3}-{1:0>2}-{2:0>4}'.format(ssn1, ssn2, ssn3))
@packetchef
packetchef / generate_ssn.ps1
Created August 6, 2017 19:09
Generate random numbers that look like SSNs. This ignores the SSA's algorithms and is really just random numbers.
while($True) {
$ssn1 = $(random -min 1 -max 999).tostring("000")
$ssn2 = $(random -min 1 -max 99).tostring("00")
$ssn3 = $(random -min 1 -max 9999).tostring("0000")
$ssn = $ssn1 + "-" + $ssn2 + "-" + $ssn3
write-output $ssn
}
#!/usr/bin/env python
import boto3
from datetime import date
from time import sleep
session = boto3.Session(profile_name = 'default')
athena = session.client('athena')
database = 'ct'
#!/usr/bin/env python
import boto3
from datetime import date
from time import sleep
session = boto3.Session(profile_name = 'default')
athena = session.client('athena')
database = 'ct'
CREATE EXTERNAL TABLE cloudtrail_logs (
eventversion STRING,
userIdentity STRUCT<
type:STRING,
principalid:STRING,
arn:STRING,
accountid:STRING,
invokedby:STRING,
accesskeyid:STRING,
userName:String,
@packetchef
packetchef / cloudtrail_scanlogs.py
Created August 7, 2017 21:28
For all CloudTrail logs in the current directory, in JSON format, get any logs for specifics AWS services (KMS and Athena in this example)
#!/usr/bin/env python
import sys
import json
import glob
def getlogs(logfile):
with open(logfile, 'rb') as fs:
return json.load(fs)['Records']
def scanlogs(logs):
import json
import requests
url = 'http://api.shoutcloud.io/V1/SHOUT'
input = {'INPUT': 'this is a lowercase string'}
headers = {'content-type': 'application/json'}
payload = json.dumps(input)
r = requests.post(url, data=payload, headers=headers)