Skip to content

Instantly share code, notes, and snippets.

View dwallraff's full-sized avatar

Dave Wallraff dwallraff

View GitHub Profile
@dwallraff
dwallraff / sample_debug.sh
Created September 13, 2016 17:07
Simple way to print debug messages in bash
function debug() {
if [[ $DEBUG ]]
then
echo ">>> $*"
fi
}
# For any debug message
debug "Trying to find config file"
@dwallraff
dwallraff / default_value.sh
Created September 13, 2016 17:08
Bash: check for user provided value or use default value
URL=${URL:-http://localhost:8080}
@dwallraff
dwallraff / hashes.sh
Created September 13, 2016 18:41
Extract hashes
# Extract md5 hashes
egrep -oE '(^|[^a-fA-F0-9])[a-fA-F0-9]{32}(1|$)' *.txt | egrep -o '[a-fA-F0-9]{32}' > md5-hashes.txt
# An alternative could be with sed
sed -rn 's/.*[^a-fA-F0-9]([a-fA-F0-9]{32})[^a-fA-F0-9].*/1/p' *.txt > md5-hashes
# Note: The above regexes can be used for SHA1, SHA256 and other unsalted hashes represented in hex.
# The only thing you have to do is change the '{32}' to the corresponding length for your desired hash-type.
@dwallraff
dwallraff / other_hashes.sh
Created September 13, 2016 18:42
Extract (other) hashes
# Extract valid MySQL-Old hashes
cat *.txt | grep -e "[0-7][0-9a-f]{7}[0-7][0-9a-f]{7}" > mysql-old-hashes.txt
# Extract blowfish hashes
cat *.txt | grep -e "$2a$8$(.){75}" > blowfish-hashes.txt
# Extract Joomla hashes
cat *.txt | egrep -o "([0-9a-zA-Z]{32}):(w{16,32})" > joomla.txt
# Extract VBulletin hashes
@dwallraff
dwallraff / extract.sh
Created September 13, 2016 18:43
Extract various info from files
# Extract e-mails from text files
cat *.txt | grep -E -o "[a-zA-Z0-9.#?$*_-]+@[a-zA-Z0-9.#?$*_-]+.[a-zA-Z0-9.-]+" > e-mails.txt
# Extract HTTP URLs from text files
cat *.txt | grep http | grep -shoP 'http.*?[" >]' > http-urls.txt
# For extracting HTTPS, FTP and other URL format use
cat *.txt | grep -E '(((https|ftp|gopher)|mailto)[.:][^ >" ]*|www.[-a-z0-9.]+)[^ .,; >">):]' > urls.txt
# Note: if grep returns "Binary file (standard input) matches" use the following approaches
@dwallraff
dwallraff / PII.sh
Last active August 14, 2019 21:44
Extract PII from files
# Visa
cat *.txt | grep -E -o "4[0-9]{3}[ -]?[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}" > visa.txt
# MasterCard
cat *.txt | grep -E -o "5[0-9]{3}[ -]?[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}" > mastercard.txt
# American Express
cat *.txt | grep -E -o "3[47][0-9]{13}" > american-express.txt
# Diners Club
@dwallraff
dwallraff / urandom.sh
Last active October 27, 2022 01:02
Generate random passwords with urandom
cat /dev/urandom | tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' | fold -w 32 | head -n 5
# cat /dev/urandom | tr -dc 'a-zA-Z0-9._!@#$%^&*()' | fold -w 8 | head -n 500000 > wordlist.txt
# cat /dev/urandom | tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' | fold -w 12 | head -n 4
# cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
# cat /dev/urandom | base64 | tr -d '[^:alnum:]' | cut -c1-10 | head -2
# cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 4
# cat /dev/urandom| tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?='|fold -w 12| head -n 4| grep -i '[!@#$%^&*()_+{}|:<>?=]'
# < /dev/urandom tr -dc '[:print:]' |fold -w 10| head -n 10
# tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n2
@dwallraff
dwallraff / convert.sh
Created September 13, 2016 18:50
OS file conversions
# Mac to unix
tr '15' '12' < in_file > out_file
# Dos to Unix
dos2unix file.txt
# Unix to Dos
unix2dos file.txt
@dwallraff
dwallraff / sed_one_liners.md
Last active September 26, 2022 20:59
Sed one-lines

File spacing

double space a file
sed G

double space a file which already has blank lines in it.
output file should contain no more than one blank line between lines of text.
sed '/^$/d;G'

@dwallraff
dwallraff / awk_one_liners.md
Created September 13, 2016 19:22
AWK one liners

File spacing

double space a file
awk '1;{print ""}'
awk 'BEGIN{ORS="\n\n"};1'

double space a file which already has blank lines in it. Output file
should contain no more than one blank line between lines of text.
NOTE: On Unix systems, DOS lines which have only CRLF (\r\n) are