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
Add bean to parse safedomain
  • Loading branch information
JoyChou93 committed Mar 27, 2020
commit fc1be1bbbbcdfefe61783a47330c99c3366d46ab
1 change: 1 addition & 0 deletions src/main/java/org/joychou/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;



@ServletComponentScan // do filter
@SpringBootApplication
// @EnableEurekaClient // 测试Eureka请打开注释,防止控制台一直有warning
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/joychou/config/CustomCorsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 支持一级域名,因为重写了checkOrigin
String[] allowOrigins = {"joychou.org", "http://test.joychou.me"};
// 为了支持一级域名,重写了checkOrigin
//String[] allowOrigins = {"joychou.org", "http://test.joychou.me"};
registry.addMapping("/cors/sec/webMvcConfigurer") // /**表示所有路由path
.allowedOrigins(allowOrigins)
//.allowedOrigins(allowOrigins)
.allowedMethods("GET", "POST")
.allowCredentials(true);
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/joychou/config/SafeDomainConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.joychou.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
* 为了不要每次调用都解析safedomain的xml,所以将解析动作放在bean里。
*/
@Configuration
public class SafeDomainConfig {

private static final Logger LOGGER = LoggerFactory.getLogger(SafeDomainConfig.class);

@Bean
public SafeDomainParser safeDomainParser() {
try {
LOGGER.info("SafeDomainParser bean inject successfully!!!");
return new SafeDomainParser();
} catch (Exception e) {
LOGGER.error("SafeDomainParser is null " + e.getMessage(), e);
}
return null;
}

}
57 changes: 57 additions & 0 deletions src/main/java/org/joychou/config/SafeDomainParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.joychou.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.util.ArrayList;

public class SafeDomainParser {

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

public SafeDomainParser(){

String safeTag = "safedomain";
String domainSafeTag = "domain";
String safeDomainClassPath = "url" + File.separator + "safe_domain.xml";
ArrayList<String> safeDomains = new ArrayList<>();

try {
// 读取resources目录下的文件
ClassPathResource resource = new ClassPathResource(safeDomainClassPath);
File file = resource.getFile();

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file); // parse xml

NodeList rootNode = doc.getElementsByTagName(safeTag);
Node domainsNode = rootNode.item(0);
NodeList child = domainsNode.getChildNodes();

for (int i = 0; i < child.getLength(); i++){
Node node = child.item(i);
if (node.getNodeName().equals(domainSafeTag)) {
safeDomains.add(node.getTextContent());
}
}

}catch (Exception e){
logger.error(e.toString());
}

WebConfig wc = new WebConfig();
wc.setSafeDomains(safeDomains);
}
}




10 changes: 10 additions & 0 deletions src/main/java/org/joychou/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ArrayList;


/**
* Solve can't get value in filter by @Value when not using embed tomcat.
Expand All @@ -19,6 +21,7 @@ public class WebConfig {
private static String[] referUris;
private static Boolean referSecEnabled = false;
private static String businessCallback;
private static ArrayList<String> safeDomains= new ArrayList<>();

/**
* application.properties里object自动转jsonp的referer校验开关
Expand Down Expand Up @@ -91,4 +94,11 @@ public static String getBusinessCallback(){
return businessCallback;
}


public void setSafeDomains(ArrayList<String> safeDomains){
WebConfig.safeDomains = safeDomains;
}
public static ArrayList<String> getSafeDomains(){
return safeDomains;
}
}
4 changes: 1 addition & 3 deletions src/main/java/org/joychou/controller/Cors.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
public class Cors {

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


@RequestMapping("/vuln/origin")
public static String vuls1(HttpServletRequest request, HttpServletResponse response) {
Expand Down Expand Up @@ -108,7 +106,7 @@ public String seccode(HttpServletRequest request, HttpServletResponse response)

// 如果origin不为空并且origin不在白名单内,认定为不安全。
// 如果origin为空,表示是同域过来的请求或者浏览器直接发起的请求。
if ( origin != null && SecurityUtil.checkURLbyEndsWith(origin, urlwhitelist) == null ) {
if ( origin != null && SecurityUtil.checkURL(origin) == null ) {
return "Origin is not safe.";
}
response.setHeader("Access-Control-Allow-Origin", origin);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/joychou/controller/URLRedirect.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public static void forward(HttpServletRequest request, HttpServletResponse respo

/**
* Safe code of sendRedirect.
* http://localhost:8080/urlRedirect/sendRedirect_seccode?url=http://www.baidu.com
* http://localhost:8080/urlRedirect/sendRedirect/sec?url=http://www.baidu.com
*/
@RequestMapping("/sendRedirect_seccode")
@RequestMapping("/sendRedirect/sec")
@ResponseBody
public static void sendRedirect_seccode(HttpServletRequest request, HttpServletResponse response) throws IOException{
public void sendRedirect_seccode(HttpServletRequest request, HttpServletResponse response)
throws IOException{
String url = request.getParameter("url");
String urlwhitelist[] = {"joychou.org", "joychou.com"};
if (SecurityUtil.checkURLbyEndsWith(url, urlwhitelist) == null) {
if (SecurityUtil.checkURL(url) == null) {
// Redirect to error page.
response.sendRedirect("https://test.joychou.org/error3.html");
return;
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/joychou/controller/jsonp/JSONP.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
* https://github.com/JoyChou93/java-sec-code/wiki/JSONP
*/


@RestController
@RequestMapping("/jsonp")
public class JSONP {

private static String[] urlwhitelist = {"joychou.com", "joychou.org"};
private static String callback = WebConfig.getBusinessCallback();
private String callback = WebConfig.getBusinessCallback();

// get current login username
public static String getUserInfo2JsonStr(HttpServletRequest request) {
Expand Down Expand Up @@ -65,7 +63,7 @@ public String referer(HttpServletRequest request) {
public String emptyReferer(HttpServletRequest request) {
String referer = request.getHeader("referer");

if (null != referer && SecurityUtil.checkURLbyEndsWith(referer, urlwhitelist) == null) {
if (null != referer && SecurityUtil.checkURL(referer) == null) {
return "error";
}
String callback = request.getParameter(this.callback);
Expand Down Expand Up @@ -110,7 +108,7 @@ public ModelAndView mappingJackson2JsonView(HttpServletRequest req) {
public String safecode(HttpServletRequest request) {
String referer = request.getHeader("referer");

if (SecurityUtil.checkURLbyEndsWith(referer, urlwhitelist) == null) {
if (SecurityUtil.checkURL(referer) == null) {
return "error";
}
String callback = request.getParameter(this.callback);
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/joychou/filter/JsonpFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain filter
HttpServletResponse response = (HttpServletResponse) res;

String refer = request.getHeader("referer");
String[] jsonpReferWhitelist = WebConfig.getJsonpReferWhitelist();
StringBuffer url = request.getRequestURL();
String query = request.getQueryString();

Expand All @@ -50,7 +49,7 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain filter
}

// 校验jsonp逻辑,如果不安全,返回forbidden
if (SecurityUtil.checkUrlByGuava(refer, jsonpReferWhitelist) == null ){
if (SecurityUtil.checkURL(refer) == null ){
logger.error("[-] URL: " + url + "?" + query + "\t" + "Referer: " + refer);
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
response.getWriter().write("forbidden");
Expand Down Expand Up @@ -87,7 +86,7 @@ private boolean check(HttpServletRequest req) {
break;
}
}
if (StringUtils.isBlank(reqCallback)){
if(StringUtils.isBlank(reqCallback)){
return false;
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/joychou/filter/OriginFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
@WebFilter(filterName = "OriginFilter", urlPatterns = "/cors/sec/originFilter")
public class OriginFilter implements Filter {

private static String[] urlwhitelist = {"joychou.org", "joychou.me"};

@Override
public void init(FilterConfig filterConfig) throws ServletException {

Expand All @@ -40,7 +38,7 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain filter
logger.info("[+] Origin: " + origin + "\tCurrent url:" + request.getRequestURL());

// 以file协议访问html,origin为字符串的null,所以依然会走安全check逻辑
if ( origin != null && SecurityUtil.checkURLbyEndsWith(origin, urlwhitelist) == null) {
if ( origin != null && SecurityUtil.checkURL(origin) == null) {
logger.error("[-] Origin check error. " + "Origin: " + origin +
"\tCurrent url:" + request.getRequestURL());
response.setStatus(response.SC_FORBIDDEN);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/joychou/filter/ReferFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain filter
String reqCallback = request.getParameter(WebConfig.getBusinessCallback());
if ("GET".equals(request.getMethod()) && StringUtils.isNotBlank(reqCallback) ){
// If the check of referer fails, a 403 forbidden error page will be returned.
if (SecurityUtil.checkURLbyEndsWith(refer, WebConfig.getReferWhitelist()) == null ){
if (SecurityUtil.checkURL(refer) == null ){
logger.info("[-] URL: " + request.getRequestURL() + "?" + request.getQueryString() + "\t"
+ "Referer: " + refer);
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/org/joychou/security/CustomCorsProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,21 @@ protected String checkOrigin(CorsConfiguration config, String requestOrigin) {
if (result != null) {
return result;
}

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

return customCheckOrigin(allowedOrigins, requestOrigin);
return customCheckOrigin(requestOrigin);
}


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

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

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