Skip to content

Instantly share code, notes, and snippets.

View angrychimp's full-sized avatar

Randall Kahler angrychimp

View GitHub Profile
@angrychimp
angrychimp / random-dist.sh
Last active January 12, 2017 23:18
Using random variables in a subshell
# As an example, how to randomly distribute files to a collection of folders
find source/ -type f -print0 | \
xargs -r0 -P 10 -I{} sh -c "
folders=($(ls targets/))
mv --target-directory=targets/\${folders[\$(expr \$RANDOM % \${#folders[@]})]}/
"
# Dumps all files into the same folder
folders=($(ls targets/))
find source/ -type f -print0 | \
xargs -r0 -P 10 -I{} \
mv --target-directory=targets/${folders[$(expr $RANDOM % ${#folders[@]})]}/
@angrychimp
angrychimp / sftp-setup-ssh-keys.sh
Created January 24, 2017 18:37
Setting up SSH keys for key-auth with ProFTPd (w/ SFTP module)
#!/bin/bash
USERNAME="your username here"
SFTPHOST="your sftp host"
SFTPPORT=22 # or other port, if non-standard
# Create SSH key-pair for SFTP access
# (creates pair with no passphrase)
ssh-keygen -b 2048 -t rsa -C "$SFTPHOST" -N "" -f ~/.ssh/id_rsa.sftp
@angrychimp
angrychimp / update-personal-sg.sh
Last active October 9, 2017 16:33
Script to refresh an AWS VPC security group with your local IP address
#!/bin/bash
SGID=sg-123ad456
PROFILE=aws-profile
# Add current IP to ingress list
myip=$(curl -s https://rand.tools/ip/)
aws --profile $PROFILE ec2 authorize-security-group-ingress --dry-run --group-id $SGID --ip-permissions "[{\"IpProtocol\": \"tcp\", \"FromPort\": 22, \"ToPort\": 22, \"IpRanges\": [{\"CidrIp\": \"$myip/32\"}]}]"
# Remove any old IPs from ingress
### Keybase proof
I hereby claim:
* I am angrychimp on github.
* I am angrychimp (https://keybase.io/angrychimp) on keybase.
* I have a public key ASCBtywTAqDTD8u4ALnVWGevAG93Yj6a2VmCzywZjDO8qgo
To claim this, I am signing this object:
@angrychimp
angrychimp / s3-bucket-scan
Last active September 8, 2017 19:05
Scan S3 buckets for public-read permissions
#!/bin/bash
# requires jq: https://stedolan.github.io/jq/
# requires aws-cli: http://docs.aws.amazon.com/cli/latest/userguide/installing.html
for bucket in `aws s3 ls | awk '{print $NF}'`; do
errors=$(expr $(aws s3api get-bucket-acl --bucket $bucket |
jq '.Grants | .[] | if (.Permission == "READ" and (.Grantee.URI == "http://acs.amazonaws.com/groups/global/AuthenticatedUsers" or .Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers")) then "ERROR" else null end' |
grep ERROR |
wc -l))
@angrychimp
angrychimp / seclists-athena.sh
Last active August 10, 2020 22:11
Create an Athena table from danielmiessler/SecLists
#!/bin/bash
# Assumes that your AWS CLI default profile is set. If not, set the AWS_PROFILE environment variable
SECLISTS_BUCKET=my-seclists-bucket
ATHENA_OUTPUT_BUCKET=my-athena-output-bucket
# Create the bucket (if necessary)
if [[ -n $(aws s3 ls s3://$SECLISTS_BUCKET 2>&1 | grep 'does not exist') ]]; then
aws s3 mb s3://$SECLISTS_BUCKET --region $(aws configure get region)
fi
@angrychimp
angrychimp / s3_threaded_delete.py
Created November 7, 2017 18:07
Python3/boto3 multi-threaded S3 object delete
import boto3
import sys
import json
import logging
from threading import Thread
from queue import Queue
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
@angrychimp
angrychimp / make-pkcs12.sh
Created November 13, 2017 15:13
Alias for how to make a PFX file
alias make-pkcs12='domain=$(pwd | xargs basename); openssl pkcs12 -export -inkey $domain.key -in $domain.crt -certfile $domain.ca.crt -out $domain.pfx'
@angrychimp
angrychimp / create-table.sql
Last active June 6, 2019 15:29
Creating Application ELB Athena tables (updated as of June 2019)
# Create the partitioned table
CREATE EXTERNAL TABLE IF NOT EXISTS {SCHEMA}.{TABLE_NAME} (
type string,
time string,
alb_id string,
alb_name string,
client_ip string,
client_port int,
target_ip string,
request_processing_time double,