// 动态生成Lambda导致RCE
public interface Command {
void execute(String cmd) throws Exception;
}
public static void main(String[] args) {
String userInput = "java.lang.Runtime.getRuntime().exec('calc');";
// 动态生成恶意Lambda
Command cmd = (Command) LambdaMetafactory.metafactory(
null, null, null,
(MethodType)MethodType.methodType(void.class, String.class),
MethodHandles.lookup().findVirtual(Runtime.class, "exec",
MethodType.methodType(Process.class, String.class)),
(MethodType)MethodType.methodType(void.class, String.class)
).getTarget().bindTo(Runtime.getRuntime()).invokeWithArguments(userInput);
cmd.execute(""); // 触发命令执行
}