一、概述
任意代码执行(Remote Code Execution)是危害最为严重的漏洞之一,挖掘难度也是相对高的,除了常见的文件上传漏洞,还有OS命令注入、表达式注入、模板注入、代码注入和第三方组件漏洞,下面依次讲解审计方法和技巧。
二、分类挖掘技巧
1、OS命令注入
OS命令注入涉及执行系统命令,通过关键字定位执行命令的方法是否参数可控,常用的搜索关键字有:
System|exec|passthru|popen|shell_exec|eval|preg_replace|str_replace|call_user_func|getRuntime().exec|system|execlp|execvp|ShellExecute|wsystem|popen(|getRuntime|ProcessBuilder|execfile|input|Shell|ShellExecuteForExplore(|ShellExecute|execute|.exec|/bin/sh、/bin/bash|cmd
一个典型的OS命令注入案例:
public class RuntimeExec {public static Boolean runtimeExec(String cmd){try {Process proc = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c", cmd});StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
2、表达式注入
主流的Java表达式主要有OGNL、SpEL、MVEL、EL、Fel、jstl_el等。
2.1 SpEL
Spring 表达式语言(简称SpEL):是一个支持运行时查询和操作对象图的强大的表达式语言。在spring中使用parseExpression()方法解析SPEL表达式,使用expression.getValue()方法执行SPEL表达式,如下案例: