提交 71b34101 编写于 作者: K Kohsuke Kawaguchi

Reworked the fix.

Most of the changes are now in remoting.
上级 8622080c
......@@ -23,6 +23,8 @@
*/
package hudson.cli;
import hudson.remoting.ClassFilter;
import hudson.remoting.ObjectInputStreamEx;
import hudson.remoting.SocketChannelStream;
import org.apache.commons.codec.binary.Base64;
......@@ -107,7 +109,8 @@ public class Connection {
* Receives an object sent by {@link #writeObject(Object)}
*/
public <T> T readObject() throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(in);
ObjectInputStream ois = new ObjectInputStreamEx(in,
ClassFilter.DEFAULT.decorate(getClass().getClassLoader()));
return (T)ois.readObject();
}
......
package jenkins.security;
/**
* Prevents problematic classes from getting de-serialized.
*
* @author Kohsuke Kawaguchi
*/
public class RemotingFilterClassLoader extends ClassLoader {
private final ClassLoader actual;
public RemotingFilterClassLoader(ClassLoader actual) {
// intentionally not passing 'actual' as the parent classloader to the super type
// to prevent accidental bypassing of a filter.
this.actual = actual;
}
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
if (isBlacklisted(name)) throw new ClassNotFoundException(name);
Class<?> c = actual.loadClass(name);
if (isBlacklisted(c)) throw new ClassNotFoundException(name);
return c;
}
protected boolean isBlacklisted(String name) {
// these are coming from libraries, so protecting it by name is better as
// some plugins might be bundling them and choosing to mask ones from core.
if (name.startsWith("org.codehaus.groovy.runtime."))
return true; // ConvertedClosure is named in exploit
if (name.startsWith("org.apache.commons.collections.functors."))
return true; // InvokerTransformer, InstantiateFactory, InstantiateTransformer are particularly scary
// this package can appear in ordinary xalan.jar or com.sun.org.apache.xalan
// the target is trax.TemplatesImpl
if (name.contains("org.apache.xalan"))
return true;
return false;
}
protected boolean isBlacklisted(Class c) {
/* Switched to blacklisting by name.
import org.apache.commons.collections.Transformer;
import org.codehaus.groovy.runtime.ConversionHandler;
import javax.xml.transform.Templates;
if (Transformer.class.isAssignableFrom(c))
return true;
if (ConversionHandler.class.isAssignableFrom(c))
return true;
if (Templates.class.isAssignableFrom(c))
return true;
*/
return false;
}
}
/*
Publicized attack payload:
ObjectInputStream.readObject()
PriorityQueue.readObject()
Comparator.compare() (Proxy)
ConvertedClosure.invoke()
MethodClosure.call()
...
Method.invoke()
Runtime.exec()
ObjectInputStream.readObject()
AnnotationInvocationHandler.readObject()
Map(Proxy).entrySet()
AnnotationInvocationHandler.invoke()
LazyMap.get()
ChainedTransformer.transform()
ConstantTransformer.transform()
InvokerTransformer.transform()
Method.invoke()
Class.getMethod()
InvokerTransformer.transform()
Method.invoke()
Runtime.getRuntime()
InvokerTransformer.transform()
Method.invoke()
Runtime.exec()
ObjectInputStream.readObject()
PriorityQueue.readObject()
...
TransformingComparator.compare()
InvokerTransformer.transform()
Method.invoke()
Runtime.exec()
ObjectInputStream.readObject()
SerializableTypeWrapper.MethodInvokeTypeProvider.readObject()
SerializableTypeWrapper.TypeProvider(Proxy).getType()
AnnotationInvocationHandler.invoke()
HashMap.get()
ReflectionUtils.findMethod()
SerializableTypeWrapper.TypeProvider(Proxy).getType()
AnnotationInvocationHandler.invoke()
HashMap.get()
ReflectionUtils.invokeMethod()
Method.invoke()
Templates(Proxy).newTransformer()
AutowireUtils.ObjectFactoryDelegatingInvocationHandler.invoke()
ObjectFactory(Proxy).getObject()
AnnotationInvocationHandler.invoke()
HashMap.get()
Method.invoke()
TemplatesImpl.newTransformer()
TemplatesImpl.getTransletInstance()
TemplatesImpl.defineTransletClasses()
TemplatesImpl.TransletClassLoader.defineClass()
Pwner*(Javassist-generated).<static init>
Runtime.exec()
*/
......@@ -174,7 +174,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>remoting</artifactId>
<version>2.47</version>
<version>2.53-SNAPSHOT</version>
</dependency>
<dependency>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册