Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
4cffffd
fix cors sec code
JoyChou93 Oct 25, 2018
571e0c3
bug fix
JoyChou93 Oct 26, 2018
e35f30e
add url whitelist vul code
JoyChou93 Oct 31, 2018
ea9ad0e
udpate cors
JoyChou93 Nov 22, 2018
76da576
update cors
JoyChou93 Nov 25, 2018
ca00956
update readme
JoyChou93 Nov 25, 2018
2f6c3cf
add spel, fixes #5
JoyChou93 Jan 17, 2019
56d5ba1
update readme
JoyChou93 Jan 17, 2019
48e347c
add emptyReferer of jsonp
JoyChou93 Jan 28, 2019
674f2f1
适配在IDEA中右键直接运行应用
JoyChou93 Feb 26, 2019
453e194
add jar configure
JoyChou93 Feb 27, 2019
d1963da
Actuators to RCE
JoyChou93 Mar 4, 2019
af76c38
update readme
JoyChou93 Mar 4, 2019
4c21c97
bypass using URL class to getHost
JoyChou93 Mar 6, 2019
3cd29c1
fix bug
JoyChou93 Mar 6, 2019
d1b3d6b
update jsonp
JoyChou93 Apr 9, 2019
5b60e15
add upload file only picture
JoyChou93 Apr 23, 2019
590891b
add csrf
JoyChou93 May 31, 2019
dd3792d
update readme
JoyChou93 May 31, 2019
72a54fa
add csrf whitelist uri and req method
JoyChou93 May 31, 2019
2e542b6
update readme
JoyChou93 May 31, 2019
4a02175
update csrf allowedMethods code
JoyChou93 May 31, 2019
9bed870
csrf in upload file html
JoyChou93 Jun 5, 2019
86d2551
diy csrf error code
JoyChou93 Jun 10, 2019
f0cb9a4
add filter to check referer
JoyChou93 Jun 18, 2019
0746f9d
redirect 403 forbidden page
JoyChou93 Jun 19, 2019
10e0345
add ssrf checker
JoyChou93 Jun 21, 2019
2e91353
update readme
JoyChou93 Jun 21, 2019
a605b1e
update readme
JoyChou93 Jun 21, 2019
edfc1fc
udpate readme
JoyChou93 Jun 21, 2019
12ab307
update readme
JoyChou93 Jun 21, 2019
0e4f22e
Add httpclient SSRF vul code
JoyChou93 Jun 25, 2019
85ca363
update readme
JoyChou93 Jun 28, 2019
6844b0a
add configure code of json to jsonp
JoyChou93 Jul 3, 2019
f37f9b2
add csrf switch
JoyChou93 Jul 3, 2019
d330c45
fix bug
JoyChou93 Jul 3, 2019
f24df6f
add json to jsonp
JoyChou93 Jul 8, 2019
cc94639
add mybatis sql
JoyChou93 Jul 17, 2019
839f532
Add ssti & resolveClass blacklist
JoyChou93 Jul 19, 2019
cc99e47
udpate readme
JoyChou93 Jul 19, 2019
31f5170
add deserialize
JoyChou93 Jul 20, 2019
0a9c978
update readme
JoyChou93 Jul 20, 2019
4763a3a
update readme
JoyChou93 Jul 20, 2019
8a9977d
add auth
JoyChou93 Jul 21, 2019
3e06b52
add index html page
JoyChou93 Jul 22, 2019
a2a5eee
update mybatis readme
JoyChou93 Jul 22, 2019
720da39
add pathTraversal
JoyChou93 Jul 23, 2019
179f45e
update readme
JoyChou93 Jul 23, 2019
6b8b1d1
closes #6
JoyChou93 Jul 24, 2019
a169c10
update readme
JoyChou93 Jul 24, 2019
a0e66f2
update readme
JoyChou93 Jul 24, 2019
467b74f
add docker env & add xtream rce vuln
JoyChou93 Jul 29, 2019
0a9f1ec
update readme
JoyChou93 Jul 29, 2019
ea74d17
add a xxe sink code
JoyChou93 Jul 30, 2019
40cf83b
add command inject
JoyChou93 Jul 31, 2019
301ffa6
update readme
JoyChou93 Jul 31, 2019
1f57fae
fix bug 0.0.0.0 can bypass SSRFChecker
waderwu Sep 3, 2019
1e991c1
Merge remote-tracking branch 'upstream/master'
waderwu Sep 3, 2019
40d64c1
Merge pull request #7 from waderwu/master
JoyChou93 Sep 4, 2019
1cd9a71
add xxe
JoyChou93 Sep 4, 2019
0ece942
Merge pull request #8 from JoyChou93/dev01
JoyChou93 Sep 4, 2019
39f07ff
update readme
JoyChou93 Sep 4, 2019
27df4d1
update readme
JoyChou93 Sep 5, 2019
562b956
add a jsonp case
JoyChou93 Sep 12, 2019
d0ece30
update deserialize getcookie method
JoyChou93 Sep 16, 2019
59a72ef
19/10/15 add more xss&sql vuln code
Oct 15, 2019
da5ea84
19/10/15 rm unuseful code
Oct 15, 2019
05ae55e
Merge pull request #9 from Anemone95/master
JoyChou93 Oct 24, 2019
9821216
add xxe return back filecontent
JoyChou93 Nov 2, 2019
22f0ecd
add cors security code
JoyChou93 Dec 9, 2019
6ae0527
add filter cors fix code
JoyChou93 Dec 19, 2019
85eb3b9
update cors security code
JoyChou93 Dec 26, 2019
9dd930e
update some bugs
JoyChou93 Jan 17, 2020
7b187f2
Add XXE & SSRF Vuln Code
JoyChou93 Feb 14, 2020
0d99385
update mybatis sql injection
JoyChou93 Mar 25, 2020
db6bff2
Bug fix.The method of fix ssrf can cause dos.
JoyChou93 Mar 26, 2020
fc1be1b
Add bean to parse safedomain
JoyChou93 Mar 27, 2020
89cb9d8
fix #13
JoyChou93 Mar 31, 2020
039d0f1
bug fix
JoyChou93 Mar 31, 2020
33748f3
bug fix
JoyChou93 Apr 3, 2020
fa48bad
增加socket hook模块 实现socket层拦截SSRF
liergou9981 Apr 3, 2020
d170c8f
Merge pull request #15 from liergou9981/master
JoyChou93 Apr 4, 2020
335bfef
fix hook socket's bug
JoyChou93 Apr 4, 2020
2aa0b91
bug fix
JoyChou93 Apr 6, 2020
f296f0d
add swagger-ui & ssrf of httpsyncclient
JoyChou93 Apr 10, 2020
ab69c0b
bug fix
JoyChou93 Aug 3, 2020
30dd98b
fixes #23
JoyChou93 Aug 3, 2020
37925a8
add fastjsonp
JoyChou93 Feb 5, 2021
bb94a99
fixes #31
JoyChou93 Feb 25, 2021
1f9da36
add rce
JoyChou93 Mar 26, 2021
ed28104
add log4j
JoyChou93 Mar 31, 2022
707d395
add jwt
JoyChou93 Sep 21, 2022
e4190d6
Add RestTemplate SSRF
JoyChou93 Oct 21, 2022
9acefb2
add jwt
JoyChou93 Nov 21, 2022
da04ccc
add CVE-2022-22978
JoyChou93 Jan 16, 2023
9d66a88
add alibaba security purple team recruitment
JoyChou93 Jan 17, 2023
c3c41b4
fix #25
JoyChou93 Feb 23, 2023
621c300
Add XXE
JoyChou93 Mar 15, 2023
cab74a4
fix #70
JoyChou93 Mar 24, 2023
4ede83a
add jdbc & actuator ak_secret
JoyChou93 Apr 28, 2023
0c253ad
Update index.html
May 24, 2023
8604af5
Merge pull request #76 from wzqs/patch-1
JoyChou93 Jun 7, 2023
920bd93
fix #78
Dec 27, 2023
7bf927a
Merge remote-tracking branch 'origin/master'
Dec 27, 2023
457d703
Add qlexpress and some test cases.
Dec 28, 2023
1d06b16
Add alibaba recruitment.
Jun 28, 2024
4711f4e
Add alibaba recruitment.
Jun 28, 2024
9eb8d69
Set up CI with Azure Pipelines
autumn0914 Apr 10, 2025
bdd032c
Update azure-pipelines.yml for Azure Pipelines
autumn0914 Apr 10, 2025
02d6141
Update azure-pipelines.yml for Azure Pipelines
autumn0914 Apr 10, 2025
18cdd33
Update azure-pipelines.yml for Azure Pipelines
autumn0914 Apr 10, 2025
048cee5
Update azure-pipelines.yml for Azure Pipelines
autumn0914 Apr 10, 2025
5511840
Update azure-pipelines.yml for Azure Pipelines
autumn0914 Apr 10, 2025
d16e5fc
mysql fix
autumn0914 Apr 10, 2025
1722b02
mysql fix
autumn0914 Apr 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update cors security code
  • Loading branch information
JoyChou93 committed Dec 26, 2019
commit 85eb3b9cc51ee43bc410debacd2c18cd1c1375ed
29 changes: 0 additions & 29 deletions src/main/java/org/joychou/config/CorsConfig.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/org/joychou/config/CorsConfig2.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
// bean.setOrder(0);
// return bean;
// }
//}
//}
49 changes: 49 additions & 0 deletions src/main/java/org/joychou/config/CustomCorsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.joychou.config;

import org.joychou.security.CustomCorsProcessor;
import org.springframework.boot.autoconfigure.web.WebMvcRegistrationsAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Configuration
public class CustomCorsConfig extends WebMvcRegistrationsAdapter {

/**
* 设置cors origin白名单。区分http和https,并且默认不会拦截同域请求。
*/
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 支持一级域名,因为重写了checkOrigin
String[] allowOrigins = {"joychou.org", "http://test.joychou.me"};
registry.addMapping("/cors/sec/webMvcConfigurer") // /**表示所有路由path
.allowedOrigins(allowOrigins)
.allowedMethods("GET", "POST")
.allowCredentials(true);
}
};
}


@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
return new CustomRequestMappingHandlerMapping();
}


/**
* 自定义Cors处理器
* 自定义校验origin,支持一级域名校验 && 多级域名
*/
private static class CustomRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
private CustomRequestMappingHandlerMapping() {
setCorsProcessor(new CustomCorsProcessor());
}
}
}
57 changes: 42 additions & 15 deletions src/main/java/org/joychou/controller/Cors.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@
import javax.servlet.http.HttpServletResponse;

/**
* @author JoyChou ([email protected])
* @date 2018.10.24
* @desc https://github.com/JoyChou93/java-sec-code/wiki/CORS
* @author JoyChou ([email protected]) @2018.10.24
* https://github.com/JoyChou93/java-sec-code/wiki/CORS
*/

@RestController
@RequestMapping("/cors")
public class Cors {

protected static String info = "{\"name\": \"JoyChou\", \"phone\": \"18200001111\"}";
protected static String[] urlwhitelist = {"joychou.com", "joychou.me"};
private static String info = "{\"name\": \"JoyChou\", \"phone\": \"18200001111\"}";
private static String[] urlwhitelist = {"joychou.org", "joychou.me"};


@RequestMapping("/vuln/origin")
private static String vuls1(HttpServletRequest request, HttpServletResponse response) {
public static String vuls1(HttpServletRequest request, HttpServletResponse response) {
String origin = request.getHeader("origin");
response.setHeader("Access-Control-Allow-Origin", origin); // 设置Origin值为Header中获取到的
response.setHeader("Access-Control-Allow-Credentials", "true"); // cookie
return info;
}

@RequestMapping("/vuln/setHeader")
private static String vuls2(HttpServletResponse response) {
public static String vuls2(HttpServletResponse response) {
// 后端设置Access-Control-Allow-Origin为*的情况下,跨域的时候前端如果设置withCredentials为true会异常
response.setHeader("Access-Control-Allow-Origin", "*");
return info;
Expand All @@ -41,40 +41,67 @@ private static String vuls2(HttpServletResponse response) {

@CrossOrigin("*")
@RequestMapping("/vuln/crossOrigin")
private static String vuls3(HttpServletResponse response) {
public static String vuls3() {
return info;
}


/**
* 重写Cors的checkOrigin校验方法
* 支持自定义checkOrigin,让其额外支持一级域名
* 代码:org/joychou/security/CustomCorsProcessor
*/
@CrossOrigin(origins = {"joychou.org", "http://test.joychou.me"})
@RequestMapping("/sec/crossOrigin")
public static String secCrossOrigin() {
return info;
}


// https://github.com/JoyChou93/java-sec-code/blob/master/src/main/java/org/joychou/config/webMvcConfigurer.java
/**
* WebMvcConfigurer设置Cors
* 支持自定义checkOrigin
* 代码:org/joychou/config/CorsConfig.java
*/
@RequestMapping("/sec/webMvcConfigurer")
public CsrfToken getCsrfToken_01(CsrfToken token) {
return token;
}


// https://github.com/JoyChou93/java-sec-code/blob/master/src/main/java/org/joychou/security/WebSecurityConfig.java
/**
* spring security设置cors
* 不支持自定义checkOrigin,因为spring security优先于setCorsProcessor执行
* 代码:org/joychou/security/WebSecurityConfig.java
*/
@RequestMapping("/sec/httpCors")
public CsrfToken getCsrfToken_02(CsrfToken token) {
return token;
}


// https://github.com/JoyChou93/java-sec-code/blob/master/src/main/java/org/joychou/filter/SecCorsFilter.java
@RequestMapping("/sec/corsFitler")
/**
* 自定义filter设置cors
* 支持自定义checkOrigin
* 代码:org/joychou/filter/OriginFilter.java
*/
@RequestMapping("/sec/originFilter")
public CsrfToken getCsrfToken_03(CsrfToken token) {
return token;
}


// https://github.com/JoyChou93/java-sec-code/blob/master/src/main/java/org/joychou/filter/CorsFilter.java
@RequestMapping("/sec/Filter")
/**
* CorsFilter设置cors。
* 不支持自定义checkOrigin,因为corsFilter优先于setCorsProcessor执行
* 代码:org/joychou/filter/BaseCorsFilter.java
*/
@RequestMapping("/sec/corsFilter")
public CsrfToken getCsrfToken_04(CsrfToken token) {
return token;
}


// http://localhost:8080/cors/sec/checkOrigin
@RequestMapping("/sec/checkOrigin")
public String seccode(HttpServletRequest request, HttpServletResponse response) {
String origin = request.getHeader("Origin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,26 @@

/**
* 由于CorsFilter和spring security冲突,所以改为下面的代码。
* CorsFilter可以参考config/CorsConfig2的代码。
*/
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class SecCorsFilter extends CorsFilter {
public class BaseCorsFilter extends CorsFilter {

public SecCorsFilter() {
public BaseCorsFilter() {
super(configurationSource());
}

private static UrlBasedCorsConfigurationSource configurationSource() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("http://test.joychou.org");
config.addAllowedOrigin("https://test.joychou.org");
config.addAllowedOrigin("joychou.org"); // 不支持
config.addAllowedOrigin("http://test.joychou.me");
config.addAllowedHeader("*");
config.addAllowedMethod("GET");
config.addAllowedMethod("POST");

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/cors/sec/corsFitler", config);
source.registerCorsConfiguration("/cors/sec/corsFilter", config);

return source;
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/joychou/filter/OriginFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
* 推荐使用该全局方案修复Cors跨域漏洞,因为可以校验一级域名。
* @author JoyChou @ 2019.12.19
*
*
*/

@WebFilter(filterName = "OriginFilter", urlPatterns = "/cors/sec/Filter")
@WebFilter(filterName = "OriginFilter", urlPatterns = "/cors/sec/originFilter")
public class OriginFilter implements Filter {

private static String[] urlwhitelist = {"joychou.org", "joychou.me"};
Expand All @@ -41,7 +41,10 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain filter

// 以file协议访问html,origin为字符串的null,所以依然会走安全check逻辑
if ( origin != null && SecurityUtil.checkURLbyEndsWith(origin, urlwhitelist) == null) {
logger.error("[-] Origin check error.");
logger.error("[-] Origin check error. " + "Origin: " + origin +
"\tCurrent url:" + request.getRequestURL());
response.setStatus(response.SC_FORBIDDEN);
response.getWriter().println("Invaid cors config by joychou.");
return;
}

Expand Down
60 changes: 60 additions & 0 deletions src/main/java/org/joychou/security/CustomCorsProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.joychou.security;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.DefaultCorsProcessor;

import java.util.List;

public class CustomCorsProcessor extends DefaultCorsProcessor {

private static final Logger logger = LoggerFactory.getLogger(CustomCorsProcessor.class);


/**
* 跨域请求,会通过此方法检测请求源是否被允许
*
* @param config CORS 配置
* @param requestOrigin 请求源
* @return 如果请求源被允许,返回请求源;否则返回 null
*/
@Override
protected String checkOrigin(CorsConfiguration config, String requestOrigin) {

// 支持checkOrigin原装的域名配置
String result = super.checkOrigin(config, requestOrigin);
if (result != null) {
return result;
}

List<String> allowedOrigins = config.getAllowedOrigins();
if (StringUtils.isBlank(requestOrigin)
|| CollectionUtils.isEmpty(allowedOrigins)) {
return null;
}

return customCheckOrigin(allowedOrigins, requestOrigin);
}


/**
* 用host的endsWith来校验requestOrigin
*/
private String customCheckOrigin(List<String> allowedOrigins, String requestOrigin) {

// list转String[]
String[] arrayAllowOrigins = allowedOrigins.toArray(new String[allowedOrigins.size()]);

if ( SecurityUtil.checkURLbyEndsWith(requestOrigin, arrayAllowOrigins) != null) {
logger.info("[+] Origin: " + requestOrigin );
return requestOrigin;
}
logger.error("[-] Origin: " + requestOrigin );
return null;
}


}
6 changes: 3 additions & 3 deletions src/main/java/org/joychou/security/WebSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected void configure(HttpSecurity http) throws Exception {
.ignoringAntMatchers(csrfExcludeUrl) // 不进行csrf校验的uri,多个uri使用逗号分隔
.csrfTokenRepository(new CookieCsrfTokenRepository());
http.exceptionHandling().accessDeniedHandler(new CsrfAccessDeniedHandler());
// http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
// http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());«

http.cors();

Expand All @@ -85,8 +85,8 @@ CorsConfigurationSource corsConfigurationSource()
{
// Set cors origin white list
ArrayList<String> allowOrigins = new ArrayList<String>();
allowOrigins.add("http://test.joychou.org");
allowOrigins.add("https://test.joychou.org"); // 区分http和https,并且默认不会拦截同域请求。
allowOrigins.add("joychou.org");
allowOrigins.add("https://test.joychou.me"); // 区分http和https,并且默认不会拦截同域请求。

CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(allowOrigins);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<p>
<a th:href="@{/codeinject?filepath=/tmp;cat /etc/passwd}">CmdInject</a>&nbsp;&nbsp;
<a th:href="@{/jsonp/getToken?_callback=test}">JSONP</a>&nbsp;&nbsp;
<a th:href="@{cors/sec/Filter}">Cors</a>&nbsp;&nbsp;
<a th:href="@{cors/sec/originFilter}">Cors</a>&nbsp;&nbsp;
<a th:href="@{/path_traversal/vul?filepath=../../../../../etc/passwd}">PathTraversal</a>&nbsp;&nbsp;
<a th:href="@{/sqli/jdbc/vul?username=joychou}">SqlInject</a>&nbsp;&nbsp;
<a th:href="@{/ssrf/urlConnection?url=file:///etc/passwd}">SSRF</a>&nbsp;&nbsp;
Expand Down