Skip to content

Commit 8e2e4cd

Browse files
authored
Merge pull request #1 from 1nhann/master
转发https的时候不会处理GET,GET请求会被转成POST
2 parents f6fce42 + 70eec79 commit 8e2e4cd

File tree

1 file changed

+69
-14
lines changed

1 file changed

+69
-14
lines changed

src/main/java/burp/HttpAndHttpsProxy.java

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,84 @@ public static Map<String,String> HttpsProxy(String url, List<String> headers,byt
9393
String header_value = h[1].trim();
9494
httpsConn.setRequestProperty(header_key, header_value);
9595
}
96-
// 发送POST请求必须设置如下两行
97-
httpsConn.setDoOutput(true);
98-
httpsConn.setDoInput(true);
96+
//设置控制请求方法的Flag
97+
String methodFlag = "";
98+
// 设置通用的请求属性
99+
for(String header:headers){
100+
if(header.startsWith("GET") ||
101+
header.startsWith("POST") ||
102+
header.startsWith("PUT")){
103+
if(header.startsWith("GET")){
104+
methodFlag = "GET";
105+
}
106+
else if(header.startsWith("POST")||
107+
header.startsWith("PUT")){
108+
methodFlag = "POST";
109+
}//在循环中重复设置了methodFlag,代码非常的丑陋冗余,请见谅
110+
continue;
111+
}//判断结束后以键值对的方式获取header
112+
// https://github.com/c0ny1/passive-scan-client/pull/21
113+
String[] h = header.split(": ");
114+
String header_key = h[0].trim();
115+
String header_value = h[1].trim();
116+
httpsConn.setRequestProperty(header_key, header_value);
117+
}
99118

119+
if (methodFlag.equals("GET")){
120+
// 发送GET请求必须设置如下两行
121+
httpsConn.setDoOutput(false);
122+
httpsConn.setDoInput(true);
100123

101-
// 获取URLConnection对象对应的输出流
102-
out = new PrintWriter(httpsConn.getOutputStream());
124+
// 获取URLConnection对象的连接
125+
httpsConn.connect();
126+
}
127+
else if(methodFlag.equals("POST")){
128+
// 发送POST请求必须设置如下两行
129+
httpsConn.setDoOutput(true);
130+
httpsConn.setDoInput(true);
103131

104-
if(body != null) {
105-
// 发送请求参数
106-
out.print(new String(body));
132+
// 获取URLConnection对象对应的输出流
133+
out = new PrintWriter(httpsConn.getOutputStream());
134+
if(body != null) {
135+
// 发送请求参数
136+
out.print(new String(body));
137+
}
138+
// flush输出流的缓冲
139+
out.flush();
107140
}
108-
// flush输出流的缓冲
109-
out.flush();
110141
// 定义BufferedReader输入流来读取URL的响应
111-
in = new BufferedReader(
112-
new InputStreamReader(httpsConn.getInputStream()));
142+
in = new BufferedReader(new InputStreamReader(httpsConn.getInputStream()));
113143
String line;
114144
while ((line = in.readLine()) != null) {
115145
result += line;
116146
result += "\r\n";
117147
}
148+
149+
150+
151+
152+
// 发送POST请求必须设置如下两行
153+
// httpsConn.setDoOutput(true);
154+
// httpsConn.setDoInput(true);
155+
//
156+
//
157+
// // 获取URLConnection对象对应的输出流
158+
// out = new PrintWriter(httpsConn.getOutputStream());
159+
//
160+
// if(body != null) {
161+
// // 发送请求参数
162+
// out.print(new String(body));
163+
// }
164+
// // flush输出流的缓冲
165+
// out.flush();
166+
// // 定义BufferedReader输入流来读取URL的响应
167+
// in = new BufferedReader(
168+
// new InputStreamReader(httpsConn.getInputStream()));
169+
// String line;
170+
// while ((line = in.readLine()) != null) {
171+
// result += line;
172+
// result += "\r\n";
173+
// }
118174
// 断开连接
119175
httpsConn.disconnect();
120176
//BurpExtender.stdout.println("====result===="+result);
@@ -218,10 +274,9 @@ public static Map<String,String> HttpProxy(String url,List<String> headers,byte[
218274
String[] h = header.split(": ");
219275
String header_key = h[0].trim();
220276
String header_value = h[1].trim();
221-
//BurpExtender.stdout.println("key: " + h[0].trim());
222-
//BurpExtender.stdout.println("value: " + h[1].trim());
223277
httpsConn.setRequestProperty(header_key, header_value);
224278
}
279+
225280
//设置控制请求方法的Flag
226281
String methodFlag = "";
227282
// 设置通用的请求属性

0 commit comments

Comments
 (0)