Kill rogue shell processes
There is a particular type of attack where an inserted usb stick can act like a keyboard, open a terminal, and start something like this:
while (true); do something_malicious; sleep 3600; done & disown
This process endlessly loops and wakes every hour to
do something malicious. The &
puts it in the
background and the disown
will end its attachment to the current terminal. When the terminal is closed the process will get a parent of 1
.
This process is still detectable and killable at the command line by finding all shell programs with a parent pid of 1 and killing them with -9
.
ps ax -o pid,command,ppid | grep '.*zsh.*\s1$' | awk '{print $1}' | xargs kill -9
This will kill all running rogue zsh processes. There may be reasons why you'd want a process to be detached from its parent terminal, but you could easily decide that this isn't something you want ever and place the above command into a cron job that runs every 2 seconds.
Tweet