4
4
import org .joychou .mapper .UserMapper ;
5
5
import org .joychou .dao .User ;
6
6
import org .springframework .beans .factory .annotation .Autowired ;
7
+ import org .springframework .beans .factory .annotation .Value ;
8
+ import org .springframework .context .annotation .Configuration ;
7
9
import org .springframework .web .bind .annotation .*;
8
10
9
11
import javax .servlet .http .HttpServletRequest ;
10
12
import java .sql .*;
13
+ import java .util .List ;
11
14
12
15
13
16
/**
16
19
* @desc SQL Injection
17
20
*/
18
21
22
+ @ SuppressWarnings ("Duplicates" )
19
23
@ RestController
20
24
@ RequestMapping ("/sqli" )
21
25
public class SQLI {
22
26
23
27
private static String driver = "com.mysql.jdbc.Driver" ;
24
- private static String url = "jdbc:mysql://localhost:3306/java_sec_code" ;
25
- private static String user = "root" ;
26
- private static String password = "woshishujukumima" ;
28
+ @ Value ("${spring.datasource.url}" )
29
+ private String url ;
30
+ @ Value ("${spring.datasource.username}" )
31
+ private String user ;
32
+ @ Value ("${spring.datasource.password}" )
33
+ private String password ;
27
34
28
35
@ Autowired
29
36
private UserMapper userMapper ;
@@ -36,7 +43,7 @@ public class SQLI {
36
43
* @param username username
37
44
*/
38
45
@ RequestMapping ("/jdbc/vul" )
39
- public static String jdbc_sqli_vul (@ RequestParam ("username" ) String username ){
46
+ public String jdbc_sqli_vul (@ RequestParam ("username" ) String username ){
40
47
String result = "" ;
41
48
try {
42
49
Class .forName (driver );
@@ -88,7 +95,7 @@ public static String jdbc_sqli_vul(@RequestParam("username") String username){
88
95
* @param username username
89
96
*/
90
97
@ RequestMapping ("/jdbc/sec" )
91
- public static String jdbc_sqli_sec (@ RequestParam ("username" ) String username ){
98
+ public String jdbc_sqli_sec (@ RequestParam ("username" ) String username ){
92
99
93
100
String result = "" ;
94
101
try {
@@ -134,6 +141,28 @@ public static String jdbc_sqli_sec(@RequestParam("username") String username){
134
141
return result ;
135
142
}
136
143
144
+ /**
145
+ * vul code
146
+ * http://localhost:8080/sqli/mybatis/vul01?username=joychou' or '1'='1
147
+ *
148
+ * @param username username
149
+ */
150
+ @ GetMapping ("/mybatis/vul01" )
151
+ public List <User > mybatis_vul1 (@ RequestParam ("username" ) String username ) {
152
+ return userMapper .findByUserNameVul (username );
153
+ }
154
+
155
+ /**
156
+ * vul code
157
+ * http://localhost:8080/sqli/mybatis/vul02?username=joychou' or '1'='1' %23
158
+ *
159
+ * @param username username
160
+ */
161
+ @ GetMapping ("/mybatis/vul02" )
162
+ public List <User > mybatis_vul2 (@ RequestParam ("username" ) String username ) {
163
+ return userMapper .findByUserNameVul2 (username );
164
+ }
165
+
137
166
138
167
/**
139
168
* security code
@@ -142,20 +171,18 @@ public static String jdbc_sqli_sec(@RequestParam("username") String username){
142
171
* @param username username
143
172
*/
144
173
@ GetMapping ("/mybatis/sec01" )
145
- public User mybatis_vul1 (@ RequestParam ("username" ) String username ) {
174
+ public User mybatis_sec1 (@ RequestParam ("username" ) String username ) {
146
175
return userMapper .findByUserName (username );
147
176
}
148
177
149
-
150
-
151
178
/**
152
179
* security code
153
180
* http://localhost:8080/sqli/mybatis/sec02?id=1
154
181
*
155
182
* @param id id
156
183
*/
157
184
@ GetMapping ("/mybatis/sec02" )
158
- public User mybatis_v (@ RequestParam ("id" ) Integer id ) {
185
+ public User mybatis_sec2 (@ RequestParam ("id" ) Integer id ) {
159
186
return userMapper .findById (id );
160
187
}
161
188
@@ -165,7 +192,7 @@ public User mybatis_v(@RequestParam("id") Integer id) {
165
192
* http://localhost:8080/sqli/mybatis/sec03
166
193
**/
167
194
@ GetMapping ("/mybatis/sec03" )
168
- public User mybatis_vul2 () {
195
+ public User mybatis_sec3 () {
169
196
return userMapper .OrderByUsername ();
170
197
}
171
198
0 commit comments