Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Function to quickly rotate ASCII characters by 90 places
- # emulates charXor in a lazy way but is infinitely faster
- charRotate() {
- # shellcheck disable=SC2020
- tr ' !"#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~' 'z{|}~ !"#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxy'
- }
- # xor function derived from http://zurlinux.com/?p=712
- charXor() {
- while read -r line; do
- # Start by removing whitespace to reduce character bias
- # pipe to 'od' which converts each character to one octal per line
- for i in $(printf "%s" "${line}" | tr -d " " | od -A n -t o1 -w1 -v); do
- # for each octal, run an xor and then print it
- # shellcheck disable=SC2059
- printf \\"$(printf '%03o' "$(( i ^ 90 ))" )"
- done
- done
- }
- # Redacted stuff
- # Check we have the required binaries
- ErrCount=0
- for Prog in od tr tail head; do
- if ! command -v "${Prog}" >/dev/null 2>&1; then
- printf "%s\n" "[ERROR]: '${Prog}' is required but was not found."
- ErrCount=$(( ErrCount + 1 ))
- fi
- done
- # If any packages are missing, then ErrCount's going
- # to be greater than 0, in which case, exit.
- if [ "${ErrCount}" -gt 0 ]; then
- exit 1
- fi
- # Let's try and find a hashing method, we use this sparingly for now
- for cryptopt in sha256sum sha1sum shasum md5sum digest csum cksum; do
- if command -v "${cryptopt}" > /dev/null 2>&1; then
- crypt="${cryptopt}"
- if [ "${crypt}" = digest ]; then
- crypt="digest -v -a md5"
- fi
- break
- else
- printf "%s\n" "[ERROR]: no hash method is available"
- exit 1
- fi
- done
- # We need some "entropy", so let's first check for an existing entropy file from
- # a previous invocation. If found, we want to rotate its characters
- if [ -f /tmp/entropy ]; then
- charRotate < /tmp/entropy > /tmp/entropy2
- mv /tmp/entropy2 /tmp/entropy
- # Otherwise, let's generate some "entropy" by simply running through this list of commands
- # And trying to remove as much whitespace as possible, then do a fast 'xor'
- # Some of these may fail, so we redirect stderr into the stream anyway. Throw it all at the wall, see what sticks.
- else
- {
- ps aux
- printf "%s" "$$"
- top -n 1
- date '+%H%M%S'
- df -k
- printf "%s" "$$"
- netstat -a
- date '+%H%M%S'
- vmstat -i
- printf "%s" "$$"
- vmstat -s
- date '+%H%M%S'
- iostat
- printf "%s" "$$"
- pstat -afipSsT
- } 2>&1 | tr -d " " | tr -d "\n" | charRotate > /tmp/entropy
- fi
- # Redacted stuff
- # Now we have to churn the entropy file. We remove the leading 32 Bytes
- # of the entropy file, and temporarily store the result
- tail -c +33 /tmp/entropy | tr -d "\n" > /tmp/entropy2
- {
- # Seed some more data into the temporary entropy file, here we hash the PID
- printf "%s" "$$" | charXor | tr -d " " | tr -d "\n" | "${crypt}"
- # Rotate the entropy, get the first 64 chars, xor it to the bottom of the temp file
- printf "%s" "$(fold -b -w 64 /tmp/entropy | head -n 1 | charXor)"
- date '+%H%M%S' | charXor | tr -d " " | tr -d "\n"
- } >> /tmp/entropy2
- # Move the temporary file into place
- mv /tmp/entropy2 /tmp/entropy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement