Added sinks for RmiBasedExporter and HessianExporter

This commit is contained in:
Artem Smotrakov
2021-06-23 09:53:47 +02:00
parent fa215bcda5
commit 14e724bce6
10 changed files with 80 additions and 21 deletions

View File

@@ -5,5 +5,7 @@ import java
*/ */
predicate isRemoteInvocationSerializingExporter(RefType type) { predicate isRemoteInvocationSerializingExporter(RefType type) {
type.getASupertype*() type.getASupertype*()
.hasQualifiedName("org.springframework.remoting.rmi", "RemoteInvocationSerializingExporter") .hasQualifiedName("org.springframework.remoting.rmi",
["RemoteInvocationSerializingExporter", "RmiBasedExporter"]) or
type.getASupertype*().hasQualifiedName("org.springframework.remoting.caucho", "HessianExporter")
} }

View File

@@ -5,22 +5,20 @@
<overview> <overview>
<p> <p>
The Spring Framework provides an abstract base class <code>RemoteInvocationSerializingExporter</code> The Spring Framework provides several classes for creating remote service exporters.
for creating remote service exporters. Under the hood, the exporters use various deserialization mechanisms
A Spring exporter, which is based on this class, deserializes incoming data using <code>ObjectInputStream</code>. such as <code>ObjectInputStream</code> or Hessian.
Deserializing untrusted data is easily exploitable and in many cases allows an attacker Deserializing untrusted data is easily exploitable and in many cases allows an attacker
to execute arbitrary code. to execute arbitrary code. If a remote attacker can reach endpoints created by the exporters,
</p>
<p>
The Spring Framework also provides <code>HttpInvokerServiceExporter</code>
and <code>SimpleHttpInvokerServiceExporter</code> classes
that extend <code>RemoteInvocationSerializingExporter</code>.
</p>
<p>
These classes export specified beans as HTTP endpoints that deserialize data from an HTTP request
using unsafe <code>ObjectInputStream</code>. If a remote attacker can reach such endpoints,
it results in remote code execution in the worst case. it results in remote code execution in the worst case.
</p> </p>
<p>
Here are examples of unsafe exporters: <code>HttpInvokerServiceExporter</code>,
<code>SimpleHttpInvokerServiceExporter</code>, <code>RmiServiceExporter</code>,
<code>HessianServiceExporter</code>.
</p>
<p> <p>
CVE-2016-1000027 has been assigned to this issue in the Spring Framework. CVE-2016-1000027 has been assigned to this issue in the Spring Framework.
It is regarded as a design limitation, and can be mitigated but not fixed outright. It is regarded as a design limitation, and can be mitigated but not fixed outright.
@@ -29,9 +27,7 @@ It is regarded as a design limitation, and can be mitigated but not fixed outrig
<recommendation> <recommendation>
<p> <p>
Avoid using <code>HttpInvokerServiceExporter</code>, <code>SimpleHttpInvokerServiceExporter</code> Avoid using unsafe service exporters. Instead, use other message formats for API endpoints (for example, JSON),
and any other exporter that is based on <code>RemoteInvocationSerializingExporter</code>.
Instead, use other message formats for API endpoints (for example, JSON),
but make sure that the underlying deserialization mechanism is properly configured but make sure that the underlying deserialization mechanism is properly configured
so that deserialization attacks are not possible. If the vulnerable exporters can not be replaced, so that deserialization attacks are not possible. If the vulnerable exporters can not be replaced,
consider using global deserialization filters introduced in JEP 290. consider using global deserialization filters introduced in JEP 290.

View File

@@ -2,12 +2,32 @@ import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.caucho.HessianServiceExporter;
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter; import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
import org.springframework.remoting.rmi.RemoteInvocationSerializingExporter; import org.springframework.remoting.rmi.RemoteInvocationSerializingExporter;
import org.springframework.remoting.rmi.RmiServiceExporter;
@Configuration @Configuration
public class SpringExporterUnsafeDeserialization { public class SpringExporterUnsafeDeserialization {
@Bean(name = "/unsafeRmiServiceExporter")
RmiServiceExporter unsafeRmiServiceExporter() {
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setServiceInterface(AccountService.class);
exporter.setService(new AccountServiceImpl());
exporter.setServiceName(AccountService.class.getSimpleName());
exporter.setRegistryPort(1099);
return exporter;
}
@Bean(name = "/unsafeHessianServiceExporter")
HessianServiceExporter unsafeHessianServiceExporter() {
HessianServiceExporter exporter = new HessianServiceExporter();
exporter.setService(new AccountServiceImpl());
exporter.setServiceInterface(AccountService.class);
return exporter;
}
@Bean(name = "/unsafeHttpInvokerServiceExporter") @Bean(name = "/unsafeHttpInvokerServiceExporter")
HttpInvokerServiceExporter unsafeHttpInvokerServiceExporter() { HttpInvokerServiceExporter unsafeHttpInvokerServiceExporter() {
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter(); HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();

View File

@@ -1,4 +1,6 @@
| SpringExporterUnsafeDeserialization.java:12:32:12:63 | unsafeHttpInvokerServiceExporter | Unsafe deserialization in a Spring exporter bean '/unsafeHttpInvokerServiceExporter' | | SpringExporterUnsafeDeserialization.java:14:24:14:47 | unsafeRmiServiceExporter | Unsafe deserialization in a Spring exporter bean '/unsafeRmiServiceExporter' |
| SpringExporterUnsafeDeserialization.java:20:41:20:88 | unsafeCustomeRemoteInvocationSerializingExporter | Unsafe deserialization in a Spring exporter bean '/unsafeCustomeRemoteInvocationSerializingExporter' | | SpringExporterUnsafeDeserialization.java:24:28:24:55 | unsafeHessianServiceExporter | Unsafe deserialization in a Spring exporter bean '/unsafeHessianServiceExporter' |
| SpringExporterUnsafeDeserialization.java:36:32:36:63 | unsafeHttpInvokerServiceExporter | Unsafe deserialization in a Spring exporter bean '/unsafeHttpInvokerServiceExporter' | | SpringExporterUnsafeDeserialization.java:32:32:32:63 | unsafeHttpInvokerServiceExporter | Unsafe deserialization in a Spring exporter bean '/unsafeHttpInvokerServiceExporter' |
| SpringExporterUnsafeDeserialization.java:48:32:48:63 | unsafeHttpInvokerServiceExporter | Unsafe deserialization in a Spring exporter bean '/unsafeHttpInvokerServiceExporter' | | SpringExporterUnsafeDeserialization.java:40:41:40:88 | unsafeCustomeRemoteInvocationSerializingExporter | Unsafe deserialization in a Spring exporter bean '/unsafeCustomeRemoteInvocationSerializingExporter' |
| SpringExporterUnsafeDeserialization.java:56:32:56:63 | unsafeHttpInvokerServiceExporter | Unsafe deserialization in a Spring exporter bean '/unsafeHttpInvokerServiceExporter' |
| SpringExporterUnsafeDeserialization.java:68:32:68:63 | unsafeHttpInvokerServiceExporter | Unsafe deserialization in a Spring exporter bean '/unsafeHttpInvokerServiceExporter' |

View File

@@ -1,2 +1,4 @@
| beans.xml:10:5:13:12 | /unsafeBooking | Unsafe deserialization in a Spring exporter bean '/unsafeBooking' | | beans.xml:10:5:13:12 | /unsafeBooking | Unsafe deserialization in a Spring exporter bean '/unsafeBooking' |
| beans.xml:15:5:18:12 | org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter | Unsafe deserialization in a Spring exporter bean 'org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter' | | beans.xml:15:5:18:12 | org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter | Unsafe deserialization in a Spring exporter bean 'org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter' |
| beans.xml:20:5:24:12 | org.springframework.remoting.rmi.RmiServiceExporter | Unsafe deserialization in a Spring exporter bean 'org.springframework.remoting.rmi.RmiServiceExporter' |
| beans.xml:26:5:29:12 | org.springframework.remoting.caucho.HessianServiceExporter | Unsafe deserialization in a Spring exporter bean 'org.springframework.remoting.caucho.HessianServiceExporter' |

View File

@@ -16,4 +16,15 @@
<property name="service" ref="anotherBookingService"/> <property name="service" ref="anotherBookingService"/>
<property name="serviceInterface" value="com.gypsyengineer.api.CabBookingService"/> <property name="serviceInterface" value="com.gypsyengineer.api.CabBookingService"/>
</bean> </bean>
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="oneMoreBookingService"/>
<property name="serviceInterface" value="com.gypsyengineer.api.CabBookingService"/>
<property name="registryPort" value="1199"/>
</bean>
<bean class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="oneMoreBookingService"/>
<property name="serviceInterface" value="com.gypsyengineer.api.CabBookingService"/>
</bean>
</beans> </beans>

View File

@@ -0,0 +1,8 @@
package org.springframework.remoting.caucho;
public class HessianExporter {
public void setService(Object service) {}
public void setServiceInterface(Class clazz) {}
}

View File

@@ -0,0 +1,3 @@
package org.springframework.remoting.caucho;
public class HessianServiceExporter extends HessianExporter {}

View File

@@ -0,0 +1,12 @@
package org.springframework.remoting.rmi;
public abstract class RmiBasedExporter {
public void setService(Object service) {}
public void setServiceInterface(Class clazz) {}
public void setServiceName(String name) {}
public void setRegistryPort(int port) {}
}

View File

@@ -0,0 +1,3 @@
package org.springframework.remoting.rmi;
public class RmiServiceExporter extends RmiBasedExporter {}