Java教程

注入-shell

本文主要是介绍注入-shell,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import java.io.IOException;
import java.lang.ref.SoftReference;
import java.text.Normalizer;
import java.util.Scanner;
import java.util.regex.Pattern;

class Solution {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        String cmd = scanner.next();//next=88.56.21.22;cat /etc/passwd
        if (isIpValidate(cmd)) {
            f(cmd);
        }
    }

    public static void f(String ip) throws IOException {
        String[] cmd = new String[5];
        //RunTime不提供shell编译器,需要加/bin/bash -c才能提供,不然无法解析| >等符号
        cmd[0] = "/bin/bash";
        cmd[1] = "-c";
        cmd[2] = "ping -c 4 ";
        cmd[3] = ip;
        Runtime.getRuntime().exec(cmd);
    }

    private static boolean isIpValidate(String cmd) {
        String normalize = Normalizer.normalize(cmd, Normalizer.Form.NFKC);
        Pattern pattern = Pattern.compile("\\||`|&|;<>");
        boolean isMatched = pattern.matcher(cmd).find();
        return !isMatched;
    }
}
这篇关于注入-shell的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!