Crash lors de la tentative d'exécution de WebGoat avec un agent Java


J'apprends actuellement à démarrer une application Web avec un agent java pour la surveillance.

L'application Web que j'ai choisie était WebGoat, et l'exécution de WebGoat avec java -jar webgoat-server-8.0.0.M17.jar comme indiqué dans le README de WebGoat fonctionne parfaitement bien.

Cependant, lorsque j'essaie d'ajouter mon agent, j'ai le désordre d'un journal d'erreurs:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v1.5.12.RELEASE)

2018-06-06 22:36:08.528  INFO 3741 --- [           main] org.owasp.webgoat.StartWebGoat           : Starting StartWebGoat v8.0.0.M17 on MacBook-Pro.local with PID 3741 (/Users/andrewfan/Desktop/Lang Agent Dev Proj help info/webgoat-server-8.0.0.M17.jar started by andrewfan in /Users/andrewfan/Desktop/Lang Agent Dev Proj help info)
2018-06-06 22:36:08.531  INFO 3741 --- [           main] org.owasp.webgoat.StartWebGoat           : No active profile set, falling back to default profiles: default
2018-06-06 22:36:08.844  INFO 3741 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1376c05c: startup date [Wed Jun 06 22:36:08 EDT 2018]; root of context hierarchy
2018-06-06 22:36:11.354  INFO 3741 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$8e12590a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-06-06 22:36:11.442  WARN 3741 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'webgoat.user.directory' in value "${webgoat.user.directory}"
2018-06-06 22:36:11.455  INFO 3741 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-06-06 22:36:11.464 ERROR 3741 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'webgoat.user.directory' in value "${webgoat.user.directory}"
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372) ~[spring-beans-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268) ~[spring-beans-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
    at 

...

J'ai raccourci les messages d'erreur car la trace fait quelques pages, mais l'erreur principale semble être org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'webgoat.user.directory' in value "${webgoat.user.directory}"


Je je cours mon agent comme suit: java -javaagent:/Users/path/to/jar/Spn-LangAgent-0.0.jar -jar webgoat-server-8.0.0.M17.jar --server.port=8080 --server.address=localhost

Mon agent est le suivant:

package com.spnlangagent.langagent;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.lang.reflect.Field;
import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;

import com.google.monitoring.runtime.instrumentation.AllocationRecorder;

public class LangAgent {

    public static void premain(String agentArgs, Instrumentation inst) throws Exception {
        System.out.println("LangAgent: premain now running");
        setupInstrumentation(agentArgs, inst);
        startRuntime(agentArgs);
    }

    private static void setupInstrumentation(String agentArgs, Instrumentation inst) throws Exception {
        System.out.println("setupInstrumentation: now running with agentArgs: " + agentArgs);
    }

    private static void startRuntime(String agentArgs) throws Exception {
        System.out.println("startRuntime: now running with agentArgs: " + agentArgs);
    }
}

Le contenu original de l'agent a été commenté à l'exception de quelques instructions d'impression, et pourtant, même avec cela, WebGoat plante au démarrage.

J'ai essayé un autre agent avec WebGoat et cela a bien fonctionné, donc la seule chose à laquelle je peux penser est que quelque chose ne va pas avec mon agent ou la façon dont il est empaqueté.

J'utilise Maven, et mon MANIFESTE.MF est comme suit:

Manifest-Version: 1.0
Premain-Class: com.spnlangagent.langagent.LangAgent
Can-Redefine-Classes: true
Can-Retransform-Classes: true

Après avoir exécuté mvn package, le MANIFESTE emballé dans le .jar est comme suit:

Manifest-Version: 1.0
Premain-Class: com.spnlangagent.langagent.LangAgent
Built-By: andrewfan
Can-Redefine-Classes: true
Can-Retransform-Classes: true
Created-By: Apache Maven 3.5.3
Build-Jdk: 1.8.0_172

Dans mon pompon.xml, je fais ce qui suit pour atteindre le manifeste:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <archive>
                    <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>

Si quelqu'un pouvait me diriger dans la bonne direction pour comprendre pourquoi WebGoat se bloque, ou si quelqu'un pouvait fournir plus d'informations sur pourquoi ce que je fais actuellement est mauvais, ce serait grandement apprécié.

Merci.

Note: Si le reste de mon pom.xml est nécessaire pour le débogage, je le fournirai volontiers; c'est juste que la question est déjà très longue telle quelle.

Author: Andrew Fan, 2018-06-07

2 answers

Webgoat (et aussi dans la plupart des applications basées sur Spring) s'appuie sur le fichier de propriétés (au format properties ou yaml généralement) pour effectuer une recherche d'espace réservé.

Le symptôme de votre échec indique que Spring n'a pas réussi à rechercher les propriétés pour le traitement des espaces réservés.

Étant donné que la recherche d'espace réservé fonctionne bien sans présence de votre pot d'agent, et avec les informations que vous avez mentionnées dans le commentaire, le problème est causé par

  • Votre agent JAR a fourni l'application.propriété (qui a une collision de nom avec le fichier de propriétés utilisé par Webgoat pour l'espace réservé)
  • Agent JAR fera partie de classpath, et apparaîtra probablement même plus tôt que le JAR principal
  • votre application.properties vide "ombragé" celui dans le pot principal Webgoat. Ce qui signifie que, lorsque Webgoat démarre, Spring a récupéré votre application.properties vide pour son traitement d'espace réservé, donc échoué.
 0
Author: Adrian Shum, 2018-06-07 03:58:23

La solution était mvn clean

Plus tôt, j'ai eu un application.properties qui a été automatiquement ajouté dans le cadre du Spring Boot Initializr. La présence de ce fichier dans mon agent .jar, même avec rien à l'intérieur, semble avoir été la raison pour laquelle WebGoat flippé. Maintenant qu'il n'est plus présent, WebGoat fonctionne normalement via java -javaagent:/Users/path/to/jar/Spn-LangAgent-0.0.jar -jar webgoat-server-8.0.0.M17.jar --server.port=8080 --server.address=localhost

Je voudrais remercier Adrian Shum d'avoir mentionné application.properties, puisque je l'avais retiré il y a quelque temps. mvn package n'a pas réellement reconstruit le .jar quand je l'ai couru, donc le pot J'avais testé sur celui qui contenait toujours application.properties.

 0
Author: Andrew Fan, 2018-06-07 03:30:05