12

Webgoat靶场调试环境配置

 2 years ago
source link: https://yanghaoi.github.io/2021/10/05/webgoat-ba-chang-diao-shi-huan-jing-pei-zhi/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

0x01 简介

选择IDEA作为源码调试工具,Webgoat作为漏洞分析的靶场。将项目源码下载到本地,使用IDEA调试模式编译运行Webgoat。

0x02 IEAD汉化配置

在安装好IDEA后,可使用插件进行汉化,提高后续的调试效率。在File-Setting-Plugins中搜索Chinese插件安装:

bWxUQuoqHgkiZvT.png

加载插件进行使用:

VNtxHrbmJDn6a8z.png

安装完成后重启软件,界面汉化成功:

0646248cf3c557b3aa777447f81b6e79.png

0x03 WebGoat配置

配置源码WebGoat-develop,用IDEA2021.2来导入项目(2021.2选择文件夹打开,然后手动配置;2019.3.2中可以选择导入项目自动配置。),mavn会自动下载依赖启动:

gQJ9ojfDzOa21R5.png

mavn仓库默认在海外,配置文件默认位置在C:\Users\<用户名>\.m2wrapper\dists\中,在setting.xml中配置国内阿里云加速仓库地址:

  <mirrors>
    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
    <mirror>
        <id>repo2</id>
        <name>repo2 maven</name>
        <url>http://repo2.maven.org/maven2</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
tYbVoEzBQlZa1Mx.png

这个过程中可能会遇到包已经在仓库中存在但是mvn依赖报红,可以尝试关闭项目后,重新导入项目。最终效果:

22820cf4926c6e38c429dea528bea41d.png

0x04 JDK和热重载配置

WebGoat需要使用JDK15来运行,在菜单”文件”-“项目结构”-“JDK”中配置版本为JDK15:

VnZADElt6gWNhCu.png

然后在左上角🔨图标配置菜单里选择编辑项目配置,添加一个Spring Boot配置,名称为StartWebGoat,主类org.owasp.webgoat.StartWebGoat,这一步可能输入了主类会报错,提示找不到main函数,要等idea扫描一下类,然后就自己好了:

rdx4onaIChsplJR.png

同样配置webwolf(用来验证一些请求的服务,如SSRF之类的),下面记得设置下更新操作,用来在代码中增加语句后热重载:

zRCi1L4muDyWs2c.png

点击调试按钮,访问本地8080,程序已经运行起来了:

OQBXF76ckWJCLVH.png

然后在src/main/java/org/owasp/webgoat/users/UserService.java中用户名检查断点,浏览器中登录,可以看到成功命中:

Pmfyjs37RA9eVqO.png

再试试热重载,加入一条打印语句,然后重载类:

TSQNfmFGkIe5u2q.png

已经输出了调试语句:

8vltejyMwENUs7f.png

0x04 Burp抓包配置

Webgoat为了安全只会在本地127.0.0.1开启靶场服务,使用burp抓包的时,在Google中没法对127.0.0.1抓包。可以使用Firefox设置本地代理,在地址栏输入about:config,然后搜索network.proxy.allow_hijacking_localhost,设置为True:

O8nuI1YxJLkUfTd.png

然后就可以在Burp中拦截数据包了:

4c0c8ade47a5d71de049e8d2809b9263.png

0x05 源码打包

有时候可能有对源码进行修改后重新打包为JAR进行部署的需求,但是对源码进行 mvn clean install时会出现各种报错,如:
1.JDK版本错误

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
16d129fd3ef443f5556a8b8bcc63c015.png

这是由于没有用正确的JDK版本构建出现的错误,可在cmd中设置正确的jdk位置,如set JAVA_HOME=D:\Program Files\JAVA\jdk-15,然后再执行mvn clean install

2.UTF-8 序列的字节 1 无效

Failures:
[ERROR]   ContentTypeAssignmentTest.workingAttack:74 JSON path "$.feedback"
Expected: is "Congratulations. You have successfully completed the assignment."
     but: was "You are posting XML but there is no XXE attack performed"
02a48a708e953e3675dc688b230d5c35.png

在测试模式中这个问题一直出现,也有相关的issues,关注后续的官方解决方案。因为这里是测试模式中的问题,所以可以在构建时跳过测试来绕过该问题:

stylus
// 跳过单元测试,但是会继续编译
mvn clean install -DskipTests 
//不执行测试用例,也不编译测试用例类
mvn clean install -Dmaven.test.skip=true 
ee4ebf598bee1525edaffc1273417897.png

在IEDA中点击下图标即可跳过测试和联网更新(更新包非常慢,所以可以设置为脱机模式):

d5db49ddfda04586989617a833313e1f.png

编译完成后的JAR包生成在目录webgoat-server/target中,使用 "D:\Program Files\JAVA\jdk-15\bin\java" -Dfile.encoding=UTF-8 -jar webgoat-server-8.2.1-SNAPSHOT.jar 启动:

0f0ac216140ba8acc8f29ced22909f31.png

0x06 参考链接

https://github.com/WebGoat/WebGoat
https://owasp.org/www-project-webgoat/
https://blog.csdn.net/Decline1/article/details/111591085


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK