【问题标题】:Crash when trying to run WebGoat with a Java Agent尝试使用 Java 代理运行 WebGoat 时崩溃
【发布时间】:2018-06-07 02:52:03
【问题描述】:

我目前正在学习如何使用 Java 代理启动 Web 应用程序以进行监控。

我选择的 Web 应用程序是 WebGoat,并且按照 WebGoat 的 README 中的说明,使用 java -jar webgoat-server-8.0.0.M17.jar 运行 WebGoat 效果很好。

但是,当我尝试添加我的代理时,我收到以下混乱的错误日志:

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

...

由于跟踪有几页长,我将错误消息缩短了,但主要错误似乎是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}"


我正在按如下方式运行我的代理: 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

我的代理如下:

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

除了一些打印语句外,代理的原始内容已被注释掉,但即使这样,WebGoat 在启动时也会崩溃。

我用 WebGoat 尝试了另一个代理,它运行良好,所以我唯一能想到的就是我的代理有问题,或者它的打包方式有问题。

我用的是Maven,我的MANIFEST.MF如下:

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

运行mvn package后,.jar中打包的MANIFEST如下:

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

在我的 pom.xml 中,我正在执行以下操作以到达清单:

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

如果有人可以为我指出正确的方向来找出 WebGoat 崩溃的原因,或者如果有人可以提供更多关于我目前所做的错误的原因,那将不胜感激。

谢谢。

注意:如果我的 pom.xml 的其余部分是调试所必需的,我很乐意提供它;只是问题已经很长了。

【问题讨论】:

  • 那么是什么让您认为它与 Java 代理有关?错误消息已明确提到它找不到webgoat.user.directory 占位符定义。您是否传递了足够的参数/正确设置了您的应用程序?
  • @AdrianShum 我用另一个 Java 代理测试了完全相同的命令行调用,并且 WebGoat 启动时没有出现问题,所以我倾向于认为问题与我如何将代理附加到WebGoat。
  • 你因为告诉我存在一种叫做“WebGoat”的东西而获得了 +1。
  • @markspace 我将在我的帖子中链接它以获取上下文。 [编辑:完成。 WebGoat README 中有关于如何运行应用程序的说明]
  • 在您刚刚无法使用代理运行的相同环境下,您可以删除代理参数并仅运行普通 Webgoat 吗?我不相信它有效。我怀疑您需要在命令中传递-Dwebgoat.user.directory=blablabla/

标签: java maven spring-boot javaagents


【解决方案1】:

Webgoat(以及大多数基于 Spring 的应用程序)依赖属性文件(通常为 propertiesyaml 格式)来执行占位符查找。

您的失败症状表明 Spring 未能查找用于占位符处理的属性。

鉴于占位符查找在没有您的代理 JAR 的情况下运行良好,并且根据您在评论中提到的信息,问题是由

引起的
  • 您的代理 JAR 提供了 application.properties(与 Webgoat 用于占位符的属性文件有名称冲突)
  • 代理 JAR 将成为类路径的一部分,甚至可能比主 JAR 更早出现
  • 你的空application.properties“遮蔽”了Webgoat主JAR中的那个。这意味着,当 Webgoat 启动时,Spring 选择了您的空 application.properties 进行占位符处理,因此失败了。

【讨论】:

    【解决方案2】:

    解决方案是mvn clean

    之前我有一个application.properties,它是作为 Spring Boot Initializr 的一部分自动添加的。这个文件在我的代理 .jar 中的存在,即使里面什么都没有,似乎是 WebGoat 吓坏了的原因。现在它不再存在,WebGoat 通过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 正常运行

    我要感谢 Adrian Shum 提到 application.properties,因为我不久前将其删除了。 mvn package 在我运行它时实际上并没有重建 .jar,所以我一直在测试的 jar 是仍然包含 application.properties 的那个。

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 2018-02-16
      • 2016-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多