Skip to content

Commit 5247030

Browse files
committed
reCAPTCHA v0.4
reCAPTCHA v0.4, bug fixes: can't display Chinese can't get image when https used can't get code when parameter contains new line charactor
1 parent 3333096 commit 5247030

File tree

5 files changed

+93
-40
lines changed

5 files changed

+93
-40
lines changed

src/burp/BurpExtender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class BurpExtender implements IBurpExtender, ITab, IContextMenuFactory, I
3333
private IExtensionHelpers helpers;
3434

3535
public PrintWriter stdout;//现在这里定义变量,再在registerExtenderCallbacks函数中实例化,如果都在函数中就只是局部变量,不能在这实例化,因为要用到其他参数。
36-
private String ExtenderName = "reCAPTCHA v0.3 by bit4";
36+
private String ExtenderName = "reCAPTCHA v0.4 by bit4";
3737
private String github = "https://github.com/bit4woo/reCAPTCHA";
3838

3939
private String imgName;

src/custom/GUI.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
//public class GUI extends JFrame { //change 1 for test
5959
public class GUI extends JPanel {//change 1 for burp
6060

61-
private String ExtenderName = "reCAPTCHA v0.3 by bit4";
61+
private String ExtenderName = "reCAPTCHA v0.4 by bit4";
6262
private String github = "https://github.com/bit4woo/reCAPTCHA";
6363
private String Abouttypeid = "http://www.ysdm.net/home/PriceType";
6464

@@ -160,28 +160,19 @@ public void actionPerformed(ActionEvent arg0) {
160160
x.httpservice = httpservice;
161161
x.raws =httpRaws;
162162
x.parser();
163-
byte[] bytes;
164-
String imgpath =null;
165163
try {
166-
bytes = x.dorequest();
167-
imgpath = x.writeImageToDisk(bytes);
168-
} catch (Exception e) {
169-
// TODO Auto-generated catch block
170-
e.printStackTrace();
171-
}
172-
173-
imgPath.setText(imgpath);
174-
//label_showimg.setIcon(new ImageIcon(imgpath));
175-
Image image;
176-
try {
177-
image = ImageIO.read(new File(imgpath));
164+
byte[] bytes = x.dorequest();
165+
String imgpath = x.writeImageToDisk(bytes);
166+
imgPath.setText(imgpath);
167+
//label_showimg.setIcon(new ImageIcon(imgpath));
168+
Image image = ImageIO.read(new File(imgpath));
178169
ImageIcon icon = new ImageIcon(image);
179170
label_showimg.setIcon(icon);
180-
} catch (IOException e) {
171+
} catch (Exception e) {
181172
// TODO Auto-generated catch block
182173
e.printStackTrace();
174+
imgPath.setText(e.getMessage());
183175
}
184-
185176

186177
//label_showimg.setIcon(new ImageIcon("D:\\eclipse-workspace\\reCAPTCHA\\www.cnhww.com1509530485395.bmp"));
187178
}
@@ -213,6 +204,7 @@ public void actionPerformed(ActionEvent arg0) {
213204

214205
APIResulttextArea = new JTextArea();
215206
APIResulttextArea.setWrapStyleWord(true);
207+
APIResulttextArea.setFont(new Font("ËÎÌå", Font.BOLD, 12));//use this to display Chinese correctly.!!!
216208
panel_1.add(APIResulttextArea);
217209

218210
panel_5 = new JPanel();

src/custom/RequestHelper.java

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@
88
import java.util.Map;
99
import java.util.stream.Stream;
1010

11+
import javax.net.ssl.HttpsURLConnection;
12+
import javax.net.ssl.SSLContext;
1113
import javax.net.ssl.SSLSocketFactory;
14+
import javax.net.ssl.TrustManager;
15+
import javax.net.ssl.X509TrustManager;
16+
17+
import java.security.cert.CertificateException;
18+
import java.security.cert.X509Certificate;
19+
import javax.net.ssl.*;
20+
1221

1322
import org.apache.commons.io.IOUtils;
1423

@@ -51,6 +60,17 @@ public static void main(String[] args) {
5160
"Connection: close\r\n" +
5261
"Upgrade-Insecure-Requests: 1\r\n" +
5362
"";
63+
//String httpservice = "https://oms.meizu.com:8443";
64+
String raws2 = "GET /cas/captcha.htm HTTP/1.1\r\n" +
65+
"Host: oms.meizu.com:8443\r\n" +
66+
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0\r\n" +
67+
"Accept: */*\r\n" +
68+
"Accept-Language: en-US,en;q=0.5\r\n" +
69+
"Referer: https://oms.meizu.com:8443/cas/login?service=http%3A%2F%2Foms.meizu.com%2Flogin.action\r\n" +
70+
"Cookie: JSESSIONID=9CA93BDD402AD7AA41962C577874B105; MZ_STORE_UUID=7508ed10-fa01-473f-9c1e-20fb05abe416; tj_coid=6391ea46eb6c0d45226b205940b0f353; CSRF_ID=3f7c2d42-8fe1-47e8-95b5-d2a129d9727d; MEIZUSTORECARTCOUNT=%7B%22c%22%3A0%2C%22t%22%3A1509602002356%2C%22s%22%3Afalse%7D\r\n" +
71+
"Connection: close\r\n" +
72+
"Cache-Control: max-age=0\r\n" +
73+
"";
5474
RequestHelper x = new RequestHelper();
5575
x.httpservice = httpservice;
5676
x.raws =raws;
@@ -63,7 +83,7 @@ public static void main(String[] args) {
6383
}
6484
}
6585

66-
public byte[] readStream(InputStream inStream) throws Exception { //这个方法有点问题,图片只有一半
86+
public byte[] readStream(InputStream inStream) throws Exception { //��������е����⣬ͼƬֻ��һ��
6787
int count = 0;
6888
while (count == 0) {
6989
count = inStream.available();
@@ -134,25 +154,68 @@ public void parser() {
134154
}
135155
}
136156

157+
private static TrustManager myX509TrustManager = new X509TrustManager() {
158+
159+
@Override
160+
public X509Certificate[] getAcceptedIssuers() {
161+
return null;
162+
}
163+
164+
@Override
165+
public void checkServerTrusted(X509Certificate[] chain, String authType)
166+
throws CertificateException {
167+
}
168+
169+
@Override
170+
public void checkClientTrusted(X509Certificate[] chain, String authType)
171+
throws CertificateException {
172+
}
173+
};
174+
137175
public byte[] dorequest() throws Exception {
138176

139177

140178
try {
141-
URL url = new URL(this.strurl);
142-
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
143-
for (Map.Entry<String, String> entry : this.headers.entrySet()) {
144-
conn.addRequestProperty(entry.getKey(),entry.getValue());
145-
//conn.addRequestProperty("User-Agent","Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0");
179+
if(this.strurl.startsWith("https:")) {
180+
URL url = new URL(this.strurl);
181+
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
182+
TrustManager[] tm = new TrustManager[]{myX509TrustManager};
183+
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
184+
sslContext.init(null, tm, new java.security.SecureRandom());
185+
// 从上述SSLContext对象中得到SSLSocketFactory对象
186+
SSLSocketFactory ssf = sslContext.getSocketFactory();
187+
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
188+
conn.setSSLSocketFactory(ssf);
189+
for (Map.Entry<String, String> entry : this.headers.entrySet()) {
190+
conn.addRequestProperty(entry.getKey(),entry.getValue());
191+
//conn.addRequestProperty("User-Agent","Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0");
192+
}
193+
conn.setRequestMethod(this.method);
194+
conn.setConnectTimeout(5 * 1000);
195+
conn.setReadTimeout(8*1000);
196+
InputStream inStream = conn.getInputStream();
197+
byte[] btImg = readInputStream(inStream);
198+
return btImg;
199+
}
200+
else {
201+
URL url = new URL(this.strurl);
202+
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
203+
for (Map.Entry<String, String> entry : this.headers.entrySet()) {
204+
conn.addRequestProperty(entry.getKey(),entry.getValue());
205+
//conn.addRequestProperty("User-Agent","Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0");
206+
}
207+
conn.setRequestMethod(this.method);
208+
conn.setConnectTimeout(5 * 1000);
209+
conn.setReadTimeout(8*1000);
210+
InputStream inStream = conn.getInputStream();
211+
byte[] btImg = readInputStream(inStream);
212+
return btImg;
146213
}
147-
conn.setRequestMethod(this.method);
148-
conn.setConnectTimeout(5 * 1000);
149-
conn.setReadTimeout(8*1000);
150-
InputStream inStream = conn.getInputStream();//通过输入流获取图片数据
151-
byte[] btImg = readInputStream(inStream);//得到图片的二进制数据
152-
return btImg;
214+
153215
} catch (Exception e) {
154216
System.out.println(e.getLocalizedMessage());
217+
return (e.toString()).getBytes();
155218
}
156-
return null;
219+
157220
}
158221
}

src/custom/myYunSu.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
public class myYunSu {
1818
public static void main(String[] args) {
19-
String parastring = "username=komi_long&password=komi2016&typeid=2040&timeout=90&softid=1&softkey=b40ffbee5c1cf4e38028c197eb2fc751";
20-
String imgPath = "E:\\wolaidai\\==wininit==\\work\\ecss.pingan.com1509447585218.jpg";
19+
String parastring = "username=xxxx&password=xxxx&typeid=3040&timeout=60&softid=66239&softkey=a44fbc0b1900420681e436fc424cbd86";
20+
String imgPath = "E:\\wolaidai\\==wininit==\\work\\www.cnhww.com1509603432430.bmp";
2121
System.out.print(getCode(imgPath,parastring));
2222
}
2323

2424
public static HashMap<String,String> getConfig(String paraString) {
2525
HashMap<String,String> paraMap = new HashMap<String,String>();
26-
String[] tmp = paraString.split("&");
26+
String[] tmp = paraString.trim().split("&");
2727
for(int i=0;i < tmp.length;i++) {
2828
String key = tmp[i].split("=")[0];
2929
String value = tmp[i].split("=")[1];
@@ -49,12 +49,8 @@ public static String getCode(String imagePath,String paraString) {//GEN-FIRST:ev
4949
if (code != null) {
5050
return code;
5151
}else {
52-
try {
53-
return new String(result.getBytes(), "UTF-8");
54-
} catch (UnsupportedEncodingException e) {
55-
// TODO Auto-generated catch block
56-
e.printStackTrace();
57-
}
52+
return result;
53+
//return new String (result.getBytes("utf-8"),"utf-8");
5854
}
5955
}
6056
return null;

src/test/test.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import java.net.MalformedURLException;
44
import java.net.URL;
5+
import java.nio.charset.Charset;
56
import java.util.HashSet;
67
import java.util.Iterator;
78
import java.util.Set;
89

910
public class test {
1011
public static void main(String[] args){
12+
System.out.println(Charset.defaultCharset());
1113
try {
1214
URL url = new URL("http://www.runoob.com/index.html?language=cn#j2se");
1315
String urlpath = url.getPath();

0 commit comments

Comments
 (0)