Skip to content

Commit

Permalink
SendToのバグ修正
Browse files Browse the repository at this point in the history
  • Loading branch information
t.isayama committed Jun 9, 2022
1 parent 4374676 commit 42512c0
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 119 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
netbeans.org-netbeans-modules-javascript2-requirejs.enabled=true
release_version_major=2.2
release_version_minor=13.3
release_version_minor=13.4
2 changes: 1 addition & 1 deletion help/help-ja.html
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,7 @@ <h3 id="_version">2.9. Version</h3>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2022-02-23 11:52:09 +0900
Last updated 2022-05-16 08:12:08 +0900
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion help/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,7 @@ <h3 id="_version">2.9. Version</h3>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2022-02-23 11:59:31 +0900
Last updated 2022-05-16 08:12:08 +0900
</div>
</div>
</body>
Expand Down
Binary file not shown.
Binary file modified release/YaguraExtender-v2.2.jar
Binary file not shown.
234 changes: 118 additions & 116 deletions src/main/java/yagura/model/SendToServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import extension.helpers.HttpUtil;
import extension.helpers.HttpUtil.DummyOutputStream;
import extension.helpers.StringUtil;
import java.lang.UnsupportedOperationException;
import java.awt.event.ActionEvent;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -78,7 +79,7 @@ protected void sendToServer(IHttpRequestResponse messageInfo) {
Properties prop = getExtendProperty();
String useProxy = prop.getProperty("useProxy", SendToExtend.USE_CUSTOM_PROXY);
if (SendToExtend.USE_CUSTOM_PROXY.equals(useProxy)) {
sendToServerUseJDKClient(messageInfo);
sendToServerUseHttpClient(messageInfo);
} else {
sendToServerUseBurpClient(messageInfo);
}
Expand Down Expand Up @@ -131,124 +132,125 @@ public void run() {
}

protected void sendToServerUseJDKClient(IHttpRequestResponse messageInfo) {
Runnable sendTo = new Runnable() {
@Override
public void run() {
String boundary = HttpUtil.generateBoundary();
HttpURLConnection conn = null;
try {
DummyOutputStream dummy = new DummyOutputStream();
outMultipart(boundary, dummy, messageInfo);
int contentLength = dummy.getSize();

URL url = new URL(getTarget()); // 送信先
// 拡張オプションを取得
Properties prop = getExtendProperty();
String proxyProtocol = prop.getProperty("proxyProtocol", Proxy.Type.DIRECT.name());
Proxy proxy = Proxy.NO_PROXY;
if (!Proxy.Type.DIRECT.name().equals(proxyProtocol)) {
String proxyHost = prop.getProperty("proxyHost", "");
if (Proxy.Type.HTTP.name().equals(proxyProtocol)) {
int proxyPort = ConvertUtil.parseIntDefault(prop.getProperty("proxyPort", "8080"), 8080);
SocketAddress addr = new InetSocketAddress(proxyHost, proxyPort);
proxy = new Proxy(Proxy.Type.HTTP, addr);
}
else if (Proxy.Type.SOCKS.name().equals(proxyProtocol)) {
int proxyPort = ConvertUtil.parseIntDefault(prop.getProperty("proxyPort", "1080"), 1080);
SocketAddress addr = new InetSocketAddress(proxyHost, proxyPort);
proxy = new Proxy(Proxy.Type.SOCKS, addr);
}
}
String proxyUser = prop.getProperty("proxyUser", "");
String proxyPasswd = prop.getProperty("proxyPasswd", "");
Authenticator authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(proxyUser, proxyPasswd.toCharArray());
}
};
// if (!proxyUser.isEmpty()) {
Authenticator.setDefault(authenticator);
throw new UnsupportedOperationException();
// Runnable sendTo = new Runnable() {
// @Override
// public void run() {
// String boundary = HttpUtil.generateBoundary();
// HttpURLConnection conn = null;
// try {
// DummyOutputStream dummy = new DummyOutputStream();
// outMultipart(boundary, dummy, messageInfo);
// int contentLength = dummy.getSize();
//
// URL url = new URL(getTarget()); // 送信先
// // 拡張オプションを取得
// Properties prop = getExtendProperty();
// String proxyProtocol = prop.getProperty("proxyProtocol", Proxy.Type.DIRECT.name());
// Proxy proxy = Proxy.NO_PROXY;
// if (!Proxy.Type.DIRECT.name().equals(proxyProtocol)) {
// String proxyHost = prop.getProperty("proxyHost", "");
// if (Proxy.Type.HTTP.name().equals(proxyProtocol)) {
// int proxyPort = ConvertUtil.parseIntDefault(prop.getProperty("proxyPort", "8080"), 8080);
// SocketAddress addr = new InetSocketAddress(proxyHost, proxyPort);
// proxy = new Proxy(Proxy.Type.HTTP, addr);
// }
// else if (Proxy.Type.SOCKS.name().equals(proxyProtocol)) {
// int proxyPort = ConvertUtil.parseIntDefault(prop.getProperty("proxyPort", "1080"), 1080);
// SocketAddress addr = new InetSocketAddress(proxyHost, proxyPort);
// proxy = new Proxy(Proxy.Type.SOCKS, addr);
// }
// }
// String proxyUser = prop.getProperty("proxyUser", "");
// String proxyPasswd = prop.getProperty("proxyPasswd", "");
// Authenticator authenticator = new Authenticator() {
// @Override
// protected PasswordAuthentication getPasswordAuthentication() {
// return new PasswordAuthentication(proxyUser, proxyPasswd.toCharArray());
// }
// };
//// if (!proxyUser.isEmpty()) {
// Authenticator.setDefault(authenticator);
//// }
//// else {
//// Authenticator.setDefault(null);
//// }
//
//// boolean ignoreValidateCertification = ConvertUtil.parseBooleanDefault(prop.getProperty("ignoreValidateCertification", Boolean.TRUE.toString()), false);
//// if (ignoreValidateCertification) {
// HttpUtil.ignoreSocketFactory();
//// }
//
// conn = (HttpURLConnection) url.openConnection(proxy);
// conn.setFixedLengthStreamingMode(contentLength);
// conn.setRequestMethod("POST");
// conn.setDoOutput(true);
// if (!proxyUser.isEmpty() && Proxy.Type.HTTP.name().equals(proxyProtocol)) {
// byte [] basicAuth = Base64.getEncoder().encode(StringUtil.getBytesRaw(String.format("%s:%s", new Object [] {proxyUser, proxyPasswd})));
// conn.setRequestProperty("Authorization", "Basic " + StringUtil.getStringRaw(basicAuth));
// }
// else {
// Authenticator.setDefault(null);
// conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
// conn.connect();
// OutputStream ostm = null;
// try {
// ostm = conn.getOutputStream();
// outMultipart(boundary, ostm, messageInfo);
// } catch (IOException e) {
// fireSendToErrorEvent(new SendToEvent(this, e.getMessage()));
// } catch (Exception e) {
// fireSendToErrorEvent(new SendToEvent(this, e.getMessage()));
// } finally {
// if (ostm != null) {
// ostm.close();
// }
// }

// boolean ignoreValidateCertification = ConvertUtil.parseBooleanDefault(prop.getProperty("ignoreValidateCertification", Boolean.TRUE.toString()), false);
// if (ignoreValidateCertification) {
HttpUtil.ignoreSocketFactory();
//
// InputStream istm = conn.getInputStream();
// ByteArrayOutputStream bostm = new ByteArrayOutputStream();
// try {
// BufferedInputStream bistm = new BufferedInputStream(istm);
// String decodeMessage;
// byte buf[] = new byte[4096];
// int len;
// while ((len = bistm.read(buf)) != -1) {
// bostm.write(buf, 0, len);
// }
// int statusCode = conn.getResponseCode();
// decodeMessage = StringUtil.getBytesRawString(bostm.toByteArray());
// if (statusCode == HttpURLConnection.HTTP_OK) {
// if (decodeMessage.length() == 0) {
// fireSendToCompleteEvent(new SendToEvent(this, "Success[" + statusCode + "]"));
// } else {
// fireSendToWarningEvent(new SendToEvent(this, "Warning[" + statusCode + "]:" + decodeMessage));
// }
// } else {
// // 200以外
// fireSendToErrorEvent(new SendToEvent(this, "Error[" + statusCode + "]:" + decodeMessage));
// }
//
// } catch (IOException e) {
// fireSendToErrorEvent(new SendToEvent(this, "Error[" + e.getClass().getName() + "]:" + e.getMessage()));
// } finally {
// if (istm != null) {
// istm.close();
// }
// if (bostm != null) {
// bostm.close();
// }
// }

conn = (HttpURLConnection) url.openConnection(proxy);
conn.setFixedLengthStreamingMode(contentLength);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
if (!proxyUser.isEmpty() && Proxy.Type.HTTP.name().equals(proxyProtocol)) {
byte [] basicAuth = Base64.getEncoder().encode(StringUtil.getBytesRaw(String.format("%s:%s", new Object [] {proxyUser, proxyPasswd})));
conn.setRequestProperty("Authorization", "Basic " + StringUtil.getStringRaw(basicAuth));
}
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
conn.connect();
OutputStream ostm = null;
try {
ostm = conn.getOutputStream();
outMultipart(boundary, ostm, messageInfo);
} catch (IOException e) {
fireSendToErrorEvent(new SendToEvent(this, e.getMessage()));
} catch (Exception e) {
fireSendToErrorEvent(new SendToEvent(this, e.getMessage()));
} finally {
if (ostm != null) {
ostm.close();
}
}

InputStream istm = conn.getInputStream();
ByteArrayOutputStream bostm = new ByteArrayOutputStream();
try {
BufferedInputStream bistm = new BufferedInputStream(istm);
String decodeMessage;
byte buf[] = new byte[4096];
int len;
while ((len = bistm.read(buf)) != -1) {
bostm.write(buf, 0, len);
}
int statusCode = conn.getResponseCode();
decodeMessage = StringUtil.getBytesRawString(bostm.toByteArray());
if (statusCode == HttpURLConnection.HTTP_OK) {
if (decodeMessage.length() == 0) {
fireSendToCompleteEvent(new SendToEvent(this, "Success[" + statusCode + "]"));
} else {
fireSendToWarningEvent(new SendToEvent(this, "Warning[" + statusCode + "]:" + decodeMessage));
}
} else {
// 200以外
fireSendToErrorEvent(new SendToEvent(this, "Error[" + statusCode + "]:" + decodeMessage));
}

} catch (IOException e) {
fireSendToErrorEvent(new SendToEvent(this, "Error[" + e.getClass().getName() + "]:" + e.getMessage()));
} finally {
if (istm != null) {
istm.close();
}
if (bostm != null) {
bostm.close();
}
}
} catch (IOException ex) {
fireSendToErrorEvent(new SendToEvent(this, "Error[" + ex.getClass().getName() + "]:" + ex.getMessage()));
} catch (Exception ex) {
fireSendToErrorEvent(new SendToEvent(this, "Error[" + ex.getClass().getName() + "]:" + ex.getMessage()));
} finally {
if (conn != null) {
conn.disconnect();
}
}
}

};
this.threadExecutor.submit(sendTo);
// } catch (IOException ex) {
// fireSendToErrorEvent(new SendToEvent(this, "Error[" + ex.getClass().getName() + "]:" + ex.getMessage()));
// } catch (Exception ex) {
// fireSendToErrorEvent(new SendToEvent(this, "Error[" + ex.getClass().getName() + "]:" + ex.getMessage()));
// } finally {
// if (conn != null) {
// conn.disconnect();
// }
// }
// }
//
// };
// this.threadExecutor.submit(sendTo);
}

protected void sendToServerUseHttpClient(IHttpRequestResponse messageInfo) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/yagura/view/SendToServerExtendDlg.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package yagura.view;

import burp.BurpExtender;
import extension.helpers.ConvertUtil;
import extension.helpers.StringUtil;
import extension.helpers.SwingUtil;
Expand Down

0 comments on commit 42512c0

Please sign in to comment.