Skip to content

Commit 8e7fc89

Browse files
committed
🍺 Java Sec
1 parent 4af8361 commit 8e7fc89

39 files changed

+12959
-266
lines changed

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
1-
# Hello Java Sec
1+
# ☕️ Hello Java Sec ![Stage](https://img.shields.io/badge/Release-DEV-brightgreen.svg)
22
> 学习 Java 漏洞,记录一下代码
33
4-
![](media/16254538162708.jpg)
4+
![](media/16261597400147.jpg)
55

66

7+
- 默认账号:admin/admin
8+
79
## Vulnerability
810
- [ ] SQLi
911
- [x] XSS
1012
- [x] RCE
1113
- [x] SSTI
1214
- [x] SpEL
13-
- [ ] SSRF
15+
- [x] SSRF
1416
- [ ] Directory Traversal
15-
- [ ] Redirect
17+
- [x] Redirect
1618
- [ ] CSRF
1719
- [ ] File Upload
1820
- [ ] XXE
21+
- [x] Actuator
1922
- [ ] Fastjson
2023

2124
## Run
2225
### IDEA
23-
配置环境run即可
26+
配置数据库连接,数据库文件`db.sql`
27+
```
28+
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test
29+
spring.datasource.username=root
30+
spring.datasource.password=1234567
31+
```
2432

2533
### Jar
2634
```
2735
git clone https://github.com/j3ers3/Hello-Java-Sec
2836
mvn clean package -DskipTests
2937
java -jar hello-0.0.1-SNAPSHOT.jar
30-
```
38+
```
39+
40+
41+
## 环境
42+
- Java 1.8
43+
- SpringBoot 4.0
44+
- Bootstrap 4.6.0
45+
- Codemirror 5.62.0
46+
- Fastjson 1.2.24

hello.iml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,13 @@
105105
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-devtools:2.4.1" level="project" />
106106
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.4.1" level="project" />
107107
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.4.1" level="project" />
108+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-actuator:2.4.1" level="project" />
109+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-actuator-autoconfigure:2.4.1" level="project" />
110+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-actuator:2.4.1" level="project" />
111+
<orderEntry type="library" name="Maven: io.micrometer:micrometer-core:1.6.2" level="project" />
112+
<orderEntry type="library" name="Maven: org.hdrhistogram:HdrHistogram:2.1.12" level="project" />
113+
<orderEntry type="library" scope="RUNTIME" name="Maven: org.latencyutils:LatencyUtils:2.0.3" level="project" />
114+
<orderEntry type="library" name="Maven: org.jolokia:jolokia-core:1.4.0" level="project" />
115+
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
108116
</component>
109117
</module>

media/16254538162708.jpg

-723 KB
Binary file not shown.

media/16261597400147.jpg

802 KB
Loading

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@
7979
<optional>true</optional>
8080
</dependency>
8181

82+
<!-- actuator监控 -->
83+
<dependency>
84+
<groupId>org.springframework.boot</groupId>
85+
<artifactId>spring-boot-starter-actuator</artifactId>
86+
</dependency>
87+
88+
<dependency>
89+
<groupId>org.jolokia</groupId>
90+
<artifactId>jolokia-core</artifactId>
91+
<version>1.4.0</version>
92+
</dependency>
93+
94+
8295
</dependencies>
8396

8497
<build>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.best.hello.Dao;
2+
3+
public class User {
4+
private Integer id;
5+
private String user;
6+
private String pass;
7+
8+
public Integer getId() {
9+
return id;
10+
}
11+
12+
public String getUser() {
13+
return user;
14+
}
15+
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.best.hello.config;
2+
3+
import org.springframework.web.servlet.HandlerInterceptor;
4+
5+
import javax.servlet.http.HttpServletRequest;
6+
import javax.servlet.http.HttpServletResponse;
7+
8+
public class LoginHandlerInterceptor implements HandlerInterceptor {
9+
@Override
10+
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
11+
//用户登录成功后,应该有自己的session
12+
Object session = request.getSession().getAttribute("LoginUser");
13+
System.out.println("[*] session用户:" + session);
14+
if (session == null) {
15+
request.setAttribute("msg", "请先登录");
16+
request.getRequestDispatcher("/login").forward(request, response);
17+
return false;
18+
} else {
19+
return true;
20+
}
21+
}
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.best.hello.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
5+
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
6+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7+
8+
/**
9+
* 视图跳转
10+
*/
11+
@Configuration
12+
public class MyMvcConfig implements WebMvcConfigurer {
13+
@Override
14+
public void addViewControllers(ViewControllerRegistry registry) {
15+
registry.addViewController("/").setViewName("index");
16+
registry.addViewController("/index").setViewName("index");
17+
registry.addViewController("/login").setViewName("login");
18+
registry.addViewController("/index/xss").setViewName("xss");
19+
registry.addViewController("/index/rce").setViewName("rce");
20+
registry.addViewController("/index/spel").setViewName("spel");
21+
registry.addViewController("/index/ssti").setViewName("ssti");
22+
registry.addViewController("/index/sqli").setViewName("sqli");
23+
registry.addViewController("/index/ssrf").setViewName("ssrf");
24+
registry.addViewController("/index/ssrf").setViewName("ssrf");
25+
26+
}
27+
28+
/**
29+
* 拦截器,判断是否登录成功
30+
*/
31+
@Override
32+
public void addInterceptors(InterceptorRegistry registry) {
33+
registry.addInterceptor(new LoginHandlerInterceptor())
34+
.addPathPatterns("/**")
35+
.excludePathPatterns("/index", "/", "/user/login", "/login", "/css/**", "/js/**", "/img/**");
36+
}
37+
}

src/main/java/com/best/hello/controller/Index.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@
2424
@Controller
2525
public class Index {
2626

27-
// 如果请求路径为index,则调用index()方法
28-
@RequestMapping("/index")
29-
public String index() {
30-
return "index";
31-
}
32-
33-
@RequestMapping("/login")
34-
public String login() {
35-
return "login";
36-
}
37-
3827
@RequestMapping("/")
3928
public String redirect() {
4029
return "redirect:/index";
@@ -45,33 +34,13 @@ public String redirect() {
4534
public String sysInfo() {
4635
Map<String, String> m = new HashMap<>();
4736

37+
m.put("app", "Hello Java SEC");
38+
m.put("author", "nul1");
4839
m.put("tomcat_version", ServerInfo.getServerInfo());
49-
m.put("app_name", "Java SEC");
5040
m.put("java_version", System.getProperty("java.version"));
5141
m.put("fastjson_version", JSON.VERSION);
5242

5343
return JSON.toJSONString(m);
5444

5545
}
56-
57-
@GetMapping("/index/xss")
58-
public static String xss() {
59-
return "xss";
60-
}
61-
62-
@GetMapping("/index/spel")
63-
public static String spel(){
64-
return "spel";
65-
}
66-
67-
@GetMapping("/index/rce")
68-
public static String rce(){
69-
return "rce";
70-
}
71-
72-
@GetMapping("/index/ssti")
73-
public static String ssti(){
74-
return "ssti";
75-
}
76-
7746
}

src/main/java/com/best/hello/controller/Login.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@
1010
@Controller
1111
public class Login {
1212
@RequestMapping("/user/login")
13-
public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model) {
14-
if ("admin".equals(username) && "123456".equals(password))
13+
public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model, HttpSession session) {
14+
if ("admin".equals(username) && "admin".equals(password)){
15+
session.setAttribute("LoginUser", username);
1516
return "redirect:/index";
16-
else {
17+
} else {
1718
model.addAttribute("msg", "用户名或者密码错误"); //显示错误信息
18-
return "admin789";
19+
return "login";
1920
}
2021
}
22+
23+
// 注销
24+
@RequestMapping("/user/logout")
25+
public String logout(HttpSession session) {
26+
session.invalidate();
27+
return "redirect:/login";
28+
}
2129
}

0 commit comments

Comments
 (0)