Crash quando si tenta di eseguire WebGoat con un agente Java


Attualmente sto imparando come avviare un'applicazione Web con un agente java per il monitoraggio.

L'applicazione Web che ho scelto era WebGoat, e l'esecuzione di WebGoat con java -jar webgoat-server-8.0.0.M17.jar come indicato nel README di WebGoat funziona perfettamente.

Tuttavia, quando provo ad aggiungere il mio agente, ottengo il seguente disordine di un log degli errori:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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 

...

Ho tagliato i messaggi di errore in quanto la traccia è lunga alcune pagine, ma l'errore principale sembra essere 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}"


I sto gestendo il mio agente come segue: 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

Il mio agente è il seguente:

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);
    }
}

I contenuti originali dell'agente sono stati commentati ad eccezione di alcune istruzioni di stampa, eppure anche con questo, WebGoat si blocca all'avvio.

Ho provato un altro agente con WebGoat e ha funzionato bene, quindi l'unica cosa che posso pensare è che qualcosa non va con il mio agente o con il modo in cui viene impacchettato.

Sto usando Maven, e il mio MANIFESTO.MF è come segue:

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

Dopo aver eseguito mvn package, il MANIFEST impacchettato nel .jar è il seguente:

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

Nel mio pom.xml, sto facendo quanto segue per raggiungere il manifest:

         <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>

Se qualcuno potesse indicarmi la giusta direzione per capire perché WebGoat si sta schiantando, o se qualcuno potesse fornire maggiori informazioni sul perché quello che sto facendo è sbagliato, sarebbe molto apprezzato.

Grazie.

Nota: Se il resto del mio pom.xml è necessario per il debug, lo fornirò volentieri; è solo che la domanda è già molto lunga così com'è.

Author: Andrew Fan, 2018-06-07

2 answers

Webgoat (e anche nella maggior parte delle applicazioni basate su Spring) si basa sul file delle proprietà (in formato properties o yaml di solito) per eseguire la ricerca dei segnaposto.

Il sintomo nell'errore indica che Spring non è riuscito a cercare le proprietà per l'elaborazione dei segnaposto.

Dato che la ricerca segnaposto funziona bene senza la presenza del JAR dell'agente e con le informazioni menzionate nel commento, il problema è causato da

  • Il tuo JAR agente ha fornito l'applicazione.proprieta (che ha una collisione del nome con il file delle proprietà utilizzato da Webgoat per segnaposto)
  • Il JAR dell'agente farà parte di classpath e probabilmente apparirà anche prima del JAR principale
  • il tuo application.properties vuoto "ombreggiato" quello nel vaso principale di Webgoat. Il che significa che, all'avvio di Webgoat, Spring ha raccolto il tuo application.properties vuoto per la sua elaborazione segnaposto, quindi non è riuscito.
 0
Author: Adrian Shum, 2018-06-07 03:58:23

La soluzione era mvn clean

In precedenza ho avuto un application.properties che è stato aggiunto automaticamente come parte della primavera Avvio Initializr. La presenza stessa di questo file nel mio agente .jar, anche con niente dentro, sembra essere stato il motivo per cui WebGoat ha dato di matto. Ora che non è più presente, WebGoat funziona normalmente tramite 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

Vorrei ringraziare Adrian Shum per aver menzionato application.properties, dato che l'avevo rimosso un po ' di tempo fa. mvn package non ha effettivamente ricostruito il .jar quando l'ho eseguito, quindi il jar Avevo testato su era quello che conteneva ancora application.properties.

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