Skip to content

Commit

Permalink
删除多余变量精简代码,添加贡献者
Browse files Browse the repository at this point in the history
  • Loading branch information
c0ny1 committed Mar 18, 2019
1 parent 7b180bd commit 27f2d1d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 33 deletions.
13 changes: 9 additions & 4 deletions src/main/java/burp/BurpExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) {
this.callbacks = callbacks;
this.helpers = callbacks.getHelpers();
callbacks.setExtensionName(String.format("%s %s",extensionName,version));
callbacks.registerContextMenuFactory(new Menu(callbacks));
callbacks.registerContextMenuFactory(new Menu());
callbacks.registerHttpListener(this);
callbacks.registerProxyListener(this);
stdout = new PrintWriter(callbacks.getStdout(),true);
Expand All @@ -32,7 +32,7 @@ public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequ

if(reqInfo.getMethod().equals("POST")){
try {
byte[] request = Transfer.encoding(helpers, messageInfo, Config.getMin_chunked_len(),Config.getMax_chunked_len(),Config.isAddComment(),Config.getMin_comment_len(),Config.getMax_comment_len());
byte[] request = Transfer.encoding(messageInfo, Config.getMin_chunked_len(),Config.getMax_chunked_len(),Config.isAddComment(),Config.getMin_comment_len(),Config.getMax_comment_len());
if (request != null) {
messageInfo.setRequest(request);
}
Expand All @@ -52,7 +52,7 @@ public void processProxyMessage(final boolean messageIsRequest, final IIntercept

if(reqInfo.getMethod().equals("POST")){
try {
byte[] request = Transfer.encoding(helpers, messageInfo, Config.getMin_chunked_len(),Config.getMax_chunked_len(),Config.isAddComment(),Config.getMin_comment_len(),Config.getMax_comment_len());
byte[] request = Transfer.encoding(messageInfo, Config.getMin_chunked_len(),Config.getMax_chunked_len(),Config.isAddComment(),Config.getMin_comment_len(),Config.getMax_comment_len());
if (request != null) {
messageInfo.setRequest(request);
}
Expand All @@ -63,7 +63,11 @@ public void processProxyMessage(final boolean messageIsRequest, final IIntercept
}
}


/**
* 插件是否作用于该套件
* @param toolFlag
* @return
*/
private boolean isValidTool(int toolFlag){
return (Config.isAct_on_all_tools() ||
(Config.isAct_on_proxy() && toolFlag== IBurpExtenderCallbacks.TOOL_PROXY) ||
Expand All @@ -88,6 +92,7 @@ public String getBanner(){
+ "[+] " + extensionName + " v" + version +"\n"
+ "[+] anthor: c0ny1\n"
+ "[+] email: root@gv7.me\n"
+ "[+] contributor: phith0n\n"
+ "[+] github: http://github.com/c0ny1/chunked-coding-converter\n"
+ "[+] ##############################################";
return bannerInfo;
Expand Down
28 changes: 7 additions & 21 deletions src/main/java/burp/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,11 @@
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;


public class Menu implements IContextMenuFactory {
private IBurpExtenderCallbacks callbacks;
private final IExtensionHelpers m_helpers;
private PrintWriter stdout;
private PrintWriter stderr;


public Menu(IBurpExtenderCallbacks callbacks) {
this.callbacks = callbacks;
this.m_helpers = callbacks.getHelpers();
this.stdout = new PrintWriter(callbacks.getStdout(),true);
this.stderr = new PrintWriter(callbacks.getStderr(),true);
}


public List<JMenuItem> createMenuItems(final IContextMenuInvocation invocation) {
List<JMenuItem> menus = new ArrayList();
Expand All @@ -44,7 +30,7 @@ public List<JMenuItem> createMenuItems(final IContextMenuInvocation invocation)

public void actionPerformed(ActionEvent arg0) {
IHttpRequestResponse iReqResp = invocation.getSelectedMessages()[0];
IRequestInfo reqInfo = m_helpers.analyzeRequest(iReqResp.getRequest());
IRequestInfo reqInfo = BurpExtender.helpers.analyzeRequest(iReqResp.getRequest());
// 不对GET请求进行编码
if(!reqInfo.getMethod().equals("POST")){
JOptionPane.showConfirmDialog(null,"GET requests cannot be chunked encoded!","Warning",JOptionPane.CLOSED_OPTION,JOptionPane.WARNING_MESSAGE);
Expand All @@ -58,12 +44,12 @@ public void actionPerformed(ActionEvent arg0) {
}

try {
byte[] request = Transfer.encoding(m_helpers, iReqResp, Config.getMin_chunked_len(),Config.getMax_chunked_len(),Config.isAddComment(),Config.getMin_comment_len(),Config.getMax_comment_len());
byte[] request = Transfer.encoding(iReqResp, Config.getMin_chunked_len(),Config.getMax_chunked_len(),Config.isAddComment(),Config.getMin_comment_len(),Config.getMax_comment_len());
if (request != null) {
iReqResp.setRequest(request);
}
} catch (Exception e) {
stderr.println(e.getMessage());
BurpExtender.stderr.println(e.getMessage());
}
}
});
Expand All @@ -80,12 +66,12 @@ public void actionPerformed(ActionEvent arg0) {
}

try {
byte[] request = Transfer.decoding(m_helpers,iReqResp);
byte[] request = Transfer.decoding(iReqResp);
if (request != null) {
iReqResp.setRequest(request);
}
} catch (Exception e) {
stderr.println(e.getMessage());
BurpExtender.stderr.println(e.getMessage());
}
}
});
Expand All @@ -95,10 +81,10 @@ public void actionPerformed(ActionEvent arg0) {
public void actionPerformed(ActionEvent arg0) {
try {
ConfigDlg dlg = new ConfigDlg();
callbacks.customizeUiComponent(dlg);
BurpExtender.callbacks.customizeUiComponent(dlg);
dlg.setVisible(true);
}catch (Exception e){
e.printStackTrace(stderr);
e.printStackTrace(BurpExtender.stderr);
}
}
});
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/burp/Transfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.util.*;

public class Transfer {
public static byte[] encoding(IExtensionHelpers helpers, IHttpRequestResponse requestResponse,int minChunkedLen, int maxChunkedLen, boolean isComment,int minCommentLen,int maxCommentLen) throws UnsupportedEncodingException {
public static byte[] encoding(IHttpRequestResponse requestResponse,int minChunkedLen, int maxChunkedLen, boolean isComment,int minCommentLen,int maxCommentLen) throws UnsupportedEncodingException {
byte[] request = requestResponse.getRequest();
IRequestInfo requestInfo = helpers.analyzeRequest(request);
IRequestInfo requestInfo = BurpExtender.helpers.analyzeRequest(request);
int bodyOffset = requestInfo.getBodyOffset();
int body_length = request.length - bodyOffset;
String body = new String(request, bodyOffset, body_length, "UTF-8");
Expand All @@ -15,7 +15,7 @@ public static byte[] encoding(IExtensionHelpers helpers, IHttpRequestResponse r
return request;
}

List<String> headers = helpers.analyzeRequest(request).getHeaders();
List<String> headers = BurpExtender.helpers.analyzeRequest(request).getHeaders();
Iterator<String> iter = headers.iterator();
while (iter.hasNext()) {
//不对请求包重复编码
Expand Down Expand Up @@ -44,17 +44,17 @@ public static byte[] encoding(IExtensionHelpers helpers, IHttpRequestResponse r



return helpers.buildHttpMessage(headers,encoding_body.getBytes());
return BurpExtender.helpers.buildHttpMessage(headers,encoding_body.getBytes());
}

public static byte[] decoding(IExtensionHelpers helpers, IHttpRequestResponse requestResponse) throws UnsupportedEncodingException {
public static byte[] decoding(IHttpRequestResponse requestResponse) throws UnsupportedEncodingException {
byte[] request = requestResponse.getRequest();
IRequestInfo requestInfo = helpers.analyzeRequest(request);
IRequestInfo requestInfo = BurpExtender.helpers.analyzeRequest(request);
int bodyOffset = requestInfo.getBodyOffset();
String body = new String(request, bodyOffset, request.length - bodyOffset, "UTF-8");

// Delete Transfer-Encoding header
List<String> headers = helpers.analyzeRequest(request).getHeaders();
List<String> headers = BurpExtender.helpers.analyzeRequest(request).getHeaders();
Iterator<String> iter = headers.iterator();
Boolean isChunked = false;//是否被分块编码过
while (iter.hasNext()) {
Expand All @@ -81,7 +81,7 @@ public static byte[] decoding(IExtensionHelpers helpers, IHttpRequestResponse re
}
}

return helpers.buildHttpMessage(headers,decoding_body.getBytes());
return BurpExtender.helpers.buildHttpMessage(headers,decoding_body.getBytes());
}

/**
Expand Down

0 comments on commit 27f2d1d

Please sign in to comment.