From 77ff733f3ee7532ebfcd43fbc7d19b500f0947ea Mon Sep 17 00:00:00 2001 From: JoyChou Date: Wed, 6 Sep 2017 17:45:41 +0800 Subject: [PATCH] add readme --- ...Maven__commons_codec_commons_codec_1_6.xml | 13 ++ ..._commons_logging_commons_logging_1_1_3.xml | 13 ++ ..._apache_httpcomponents_fluent_hc_4_3_6.xml | 13 ++ ...apache_httpcomponents_httpclient_4_3_6.xml | 13 ++ ...g_apache_httpcomponents_httpcore_4_3_3.xml | 13 ++ .idea/workspace.xml | 216 ++++++++++++------ README.md | 32 +-- pom.xml | 7 + src/main/java/security.java | 4 +- src/main/java/test.java | 13 +- target/classes/security.class | Bin 3890 -> 0 bytes target/classes/test.class | Bin 981 -> 0 bytes trident.iml | 5 + 13 files changed, 254 insertions(+), 88 deletions(-) create mode 100644 .idea/libraries/Maven__commons_codec_commons_codec_1_6.xml create mode 100644 .idea/libraries/Maven__commons_logging_commons_logging_1_1_3.xml create mode 100644 .idea/libraries/Maven__org_apache_httpcomponents_fluent_hc_4_3_6.xml create mode 100644 .idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_3_6.xml create mode 100644 .idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_3_3.xml delete mode 100644 target/classes/security.class delete mode 100644 target/classes/test.class diff --git a/.idea/libraries/Maven__commons_codec_commons_codec_1_6.xml b/.idea/libraries/Maven__commons_codec_commons_codec_1_6.xml new file mode 100644 index 0000000..e8a6a9f --- /dev/null +++ b/.idea/libraries/Maven__commons_codec_commons_codec_1_6.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_logging_commons_logging_1_1_3.xml b/.idea/libraries/Maven__commons_logging_commons_logging_1_1_3.xml new file mode 100644 index 0000000..01c7b8e --- /dev/null +++ b/.idea/libraries/Maven__commons_logging_commons_logging_1_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_httpcomponents_fluent_hc_4_3_6.xml b/.idea/libraries/Maven__org_apache_httpcomponents_fluent_hc_4_3_6.xml new file mode 100644 index 0000000..9773cee --- /dev/null +++ b/.idea/libraries/Maven__org_apache_httpcomponents_fluent_hc_4_3_6.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_3_6.xml b/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_3_6.xml new file mode 100644 index 0000000..04cad1e --- /dev/null +++ b/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_3_6.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_3_3.xml b/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_3_3.xml new file mode 100644 index 0000000..a821fc2 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_3_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0f140c5..ceecfd0 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,14 @@ + + + + + + + @@ -13,14 +20,26 @@ + + + + + - - + + @@ -30,8 +49,8 @@ - - + + @@ -39,11 +58,11 @@ - + - - + + @@ -52,12 +71,14 @@ - + - - - + + + + + @@ -74,6 +95,7 @@ print + dns @@ -87,11 +109,11 @@ @@ -102,10 +124,10 @@ DEFINITION_ORDER - @@ -117,7 +139,7 @@ - Spelling + Android @@ -206,15 +228,15 @@ - + - + - + + + + + + + + - + @@ -693,8 +725,9 @@ - + + @@ -707,38 +740,37 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -756,6 +788,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -779,7 +851,9 @@ - + + + @@ -794,19 +868,11 @@ + - - - - - - - - - - - + + @@ -814,8 +880,8 @@ - - + + @@ -824,8 +890,8 @@ - - + + @@ -833,5 +899,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 21761e4..0152b4a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Trident (三叉戟) +# Trident(三叉戟) > Java Code Security Component (JAVA代码安全组件) @@ -27,16 +27,6 @@ Boolean ret = checkUrl.checkUrlWlist("http://test.joychou.me", urlWList); ## checkSSRF -JAVA默认DNS请求会有30s的缓存,所以默认不存在DNS Rebind问题。除非重新设置TTL为0。 - -如果有大佬能绕过,麻烦提个ISSUE或者PR。 - -我自己测试,以下方法均没绕过。但是,用DNS Rebind方法在调试的时候,均可以测试成功,所以我怀疑设置TTL为0未成功。 - -- DNS Rebind(手动设置JAVA的TTL为0) -- 域名解析2个A记录地址(外网+内网) - - ### 验证逻辑 @@ -52,6 +42,22 @@ JAVA默认DNS请求会有30s的缓存,所以默认不存在DNS Rebind问题。 URL只支持HTTP协议。 ```java -security checkUrl = new security(); -ret = checkUrl.checkSSRF("http://127.0.0.1"); +String url = "http://dns_rebind.joychou.me"; +ret = checkUrl.checkSSRF(url); +if (ret){ + # curl url +} +else { + System.out.println("Bad boy. The url is illegal"); +} ``` + +### 绕过姿势 + + +以上代码在设置TTL为0的情况,可以用以下方法绕过 : + +1. DNS Rebind(手动设置JAVA的TTL为0) +2. 域名解析2个A记录地址(分别为外网和内网) + +也就是说,只要Java不设置TTL为0,该代码逻辑上不存在被绕过风险。 \ No newline at end of file diff --git a/pom.xml b/pom.xml index e15928a..a8c10cc 100644 --- a/pom.xml +++ b/pom.xml @@ -14,5 +14,12 @@ guava 21.0 + + + org.apache.httpcomponents + fluent-hc + 4.3.6 + + \ No newline at end of file diff --git a/src/main/java/security.java b/src/main/java/security.java index 4ee8fcb..c870cbe 100644 --- a/src/main/java/security.java +++ b/src/main/java/security.java @@ -85,7 +85,7 @@ public class security { connection.setUseCaches(false); // 设置为false,手动处理跳转,可以拿到每个跳转的URL connection.setConnectTimeout(3*1000); // 设置连接超时时间为3s //connection.setRequestMethod("GET"); - connection.connect(); // 会解析dns + connection.connect(); // send dns request int responseCode = connection.getResponseCode(); // 发起网络请求 if (responseCode >= 300 && responseCode < 400) { String redirectedUrl = connection.getHeaderField("Location"); @@ -136,7 +136,7 @@ public class security { */ public static String DomainToIP(String domain) throws IOException{ try { - InetAddress IpAddress = InetAddress.getByName(domain); + InetAddress IpAddress = InetAddress.getByName(domain); // send dns request return IpAddress.getHostAddress(); } catch (Exception e) { diff --git a/src/main/java/test.java b/src/main/java/test.java index 4f0284b..cda3bc5 100644 --- a/src/main/java/test.java +++ b/src/main/java/test.java @@ -3,6 +3,7 @@ * Mail: viarus#qq.com * Date: 2017.09.05 */ +import org.apache.http.client.fluent.Request; public class test { public static void main(String[] args) throws Exception { @@ -14,8 +15,14 @@ public class test { System.out.println(ret); // SSRF组件测试 - - ret = checkUrl.checkSSRF("http://127.0.0.1"); - System.out.println(ret); + String url = "http://dns_rebind.joychou.me"; + ret = checkUrl.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"); + } } } diff --git a/target/classes/security.class b/target/classes/security.class deleted file mode 100644 index 1206b8efb282969414da67b730c1b786644a1649..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3890 zcmb7H3wsn-8GdIknc2w&|=nZ0wx3+sL;vokPO}3+0M># zE!0c3YAaMlE7X<}D|m@Yt1hu9t@m25Kf%WzVtv1vy@ZlJD$m1r&iT$c-{t+@^X=r_ zf4_MPKtKKw#l4tOF&jkymWZPoo`@oYtcF|^Hu9o;QZ!B!1-K%LB94jfxQY`|d=w`& zoRaahh^IuHk;`Z0^3y6l9mNWKM#N`Dd``qOB0jI-3o~`12Y<)lks^G zbn_LQlQZWvydXZm8pYS}bqyCZd_%)GHN2?dTTxuZB@r*F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