https://github.com/joychou93/trident
Java通用漏洞修复安全组件
https://github.com/joychou93/trident
code component java security
Last synced: 5 months ago
JSON representation
Java通用漏洞修复安全组件
- Host: GitHub
- URL: https://github.com/joychou93/trident
- Owner: JoyChou93
- License: mit
- Created: 2017-09-05T09:15:10.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-03T16:24:14.000Z (about 8 years ago)
- Last Synced: 2025-04-22T07:01:57.905Z (7 months ago)
- Topics: code, component, java, security
- Language: Java
- Homepage: https://github.com/JoyChou93/trident
- Size: 59.6 KB
- Stars: 59
- Watchers: 4
- Forks: 19
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Trident(三叉戟)
> Java Code Security Component (JAVA代码安全组件)
目前支持的功能如下:
1. URL白名单验证 (已完成)
2. checkSSRF (已完成)
3. checkReferer (未做)
4. csrfToken (未做)
5. xssEncode (未做)
6. getRealIP (已完成)
## URL白名单验证
#### URL绕过
URL白名单绕过可查考[https://joychou.org/web/url-whitelist-bypass.html](https://joychou.org/web/url-whitelist-bypass.html)
#### 验证逻辑
1. 取URL一级域名
2. 判断是否在域名白名单列表内
#### 验证代码
合法URL返回true,非法URL返回false。
```java
// URL白名单组件测试
checkURL urlCheck = new checkURL();
String[] urlWList = {"joychou.com", "joychou.me"};
Boolean ret = urlCheck.checkUrlWlist("http://test.joychou.org", urlWList);
System.out.println(ret);
```
## checkSSRF
#### 验证逻辑
1. 取URL的Host
2. 取Host的IP
3. 判断是否是内网IP,是内网IP直接return,不再往下执行
4. 请求URL
5. 如果有跳转,取出跳转URL,执行第1步
#### 验证代码
如果是内网IP,返回false,表示checkSSRF不通过,否则返回true,即合法返回true。URL只支持HTTP协议。
```java
// SSRF组件测试
SSRF check = new SSRF();
String url = "http://dns_rebind.joychou.me";
ret = check.checkSSRF(url);
if (ret){
String con = Request.Get(url).execute().returnContent().toString();
System.out.println(con);
}
else {
System.out.println("Bad boy. The url is illegal");
}
```
#### 绕过姿势
以上代码在设置TTL为0的情况,可以用DNS Rebinding绕过。
但是,只要Java不设置TTL为0,该代码逻辑上不存在被绕过风险。
具体绕过细节可查看[https://joychou.org/web/use-dnsrebinding-to-bypass-ssrf-in-java.html](https://joychou.org/web/use-dnsrebinding-to-bypass-ssrf-in-java.html)
## 获取真实IP
用这份代码,必须保证,前面Proxy有把真实IP放到X-Real-IP头。
```
proxy_set_header X-Real-IP $remote_addr;
```
造成漏洞的代码和配置,详情查看[https://joychou.org/web/how-to-get-real-ip.html](https://joychou.org/web/how-to-get-real-ip.html)