44import org .joychou .mapper .UserMapper ;
55import org .joychou .dao .User ;
66import org .springframework .beans .factory .annotation .Autowired ;
7+ import org .springframework .beans .factory .annotation .Value ;
8+ import org .springframework .context .annotation .Configuration ;
79import org .springframework .web .bind .annotation .*;
810
911import javax .servlet .http .HttpServletRequest ;
1012import java .sql .*;
13+ import java .util .List ;
1114
1215
1316/**
1619 * @desc SQL Injection
1720 */
1821
22+ @ SuppressWarnings ("Duplicates" )
1923@ RestController
2024@ RequestMapping ("/sqli" )
2125public class SQLI {
2226
2327 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 ;
2734
2835 @ Autowired
2936 private UserMapper userMapper ;
@@ -36,7 +43,7 @@ public class SQLI {
3643 * @param username username
3744 */
3845 @ RequestMapping ("/jdbc/vul" )
39- public static String jdbc_sqli_vul (@ RequestParam ("username" ) String username ){
46+ public String jdbc_sqli_vul (@ RequestParam ("username" ) String username ){
4047 String result = "" ;
4148 try {
4249 Class .forName (driver );
@@ -88,7 +95,7 @@ public static String jdbc_sqli_vul(@RequestParam("username") String username){
8895 * @param username username
8996 */
9097 @ RequestMapping ("/jdbc/sec" )
91- public static String jdbc_sqli_sec (@ RequestParam ("username" ) String username ){
98+ public String jdbc_sqli_sec (@ RequestParam ("username" ) String username ){
9299
93100 String result = "" ;
94101 try {
@@ -134,6 +141,28 @@ public static String jdbc_sqli_sec(@RequestParam("username") String username){
134141 return result ;
135142 }
136143
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+
137166
138167 /**
139168 * security code
@@ -142,20 +171,18 @@ public static String jdbc_sqli_sec(@RequestParam("username") String username){
142171 * @param username username
143172 */
144173 @ GetMapping ("/mybatis/sec01" )
145- public User mybatis_vul1 (@ RequestParam ("username" ) String username ) {
174+ public User mybatis_sec1 (@ RequestParam ("username" ) String username ) {
146175 return userMapper .findByUserName (username );
147176 }
148177
149-
150-
151178 /**
152179 * security code
153180 * http://localhost:8080/sqli/mybatis/sec02?id=1
154181 *
155182 * @param id id
156183 */
157184 @ GetMapping ("/mybatis/sec02" )
158- public User mybatis_v (@ RequestParam ("id" ) Integer id ) {
185+ public User mybatis_sec2 (@ RequestParam ("id" ) Integer id ) {
159186 return userMapper .findById (id );
160187 }
161188
@@ -165,7 +192,7 @@ public User mybatis_v(@RequestParam("id") Integer id) {
165192 * http://localhost:8080/sqli/mybatis/sec03
166193 **/
167194 @ GetMapping ("/mybatis/sec03" )
168- public User mybatis_vul2 () {
195+ public User mybatis_sec3 () {
169196 return userMapper .OrderByUsername ();
170197 }
171198
0 commit comments