【发布时间】: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