Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bit4woo committed Apr 19, 2024
1 parent a91ee9e commit f451caa
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 286 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@
<version>2.0b5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/commons-validator/commons-validator -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.8.0</version>
</dependency>


</dependencies>

<artifactId>knife</artifactId>
Expand Down
50 changes: 6 additions & 44 deletions src/burp/BurpExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import manager.ChunkManager;
import manager.DismissedTargetsManager;
import manager.HeaderManager;
import org.apache.commons.lang3.StringUtils;

public class BurpExtender extends GUI implements IBurpExtender, IContextMenuFactory, ITab, IHttpListener, IProxyListener, IExtensionStateListener {

Expand All @@ -54,7 +55,6 @@ public class BurpExtender extends GUI implements IBurpExtender, IContextMenuFact
public static PrintWriter stdout;
public static PrintWriter stderr;
public IContextMenuInvocation invocation;
public int proxyServerIndex = -1;

public static String ExtensionName = "Knife";
public static String Version = bsh.This.class.getPackage().getImplementationVersion();
Expand All @@ -75,15 +75,12 @@ public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) {
configPanel.setViewportView(table);

String content = callbacks.loadExtensionSetting("knifeconfig");
if (content != null) {
config = new Gson().fromJson(content, Config.class);
showToUI(config);
} else {
showToUI(new Gson().fromJson(initConfig(), Config.class));
if (StringUtils.isEmpty(content)) {
content = initConfig();
}
table.setupTypeColumn();//call this function must after table data loaded !!!!
table.tableHeaderLengthInit();

config = new Gson().fromJson(content, Config.class);
showToUI(config);

ChineseTabFactory chntabFactory = new ChineseTabFactory(null, false, helpers, callbacks);

Expand Down Expand Up @@ -171,7 +168,7 @@ public List<JMenuItem> createMenuItems(IContextMenuInvocation invocation) {
Iterator<JMenuItem> it = menu_item_list.iterator();
while (it.hasNext()) {
JMenuItem item = it.next();
if (item.getText() == null || item.getText().equals("")) {
if (StringUtils.isEmpty(item.getText())) {
it.remove();
}
}
Expand Down Expand Up @@ -306,41 +303,6 @@ public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequ
}
}

public static void confirmProxy() {
String proxy = JOptionPane.showInputDialog("Confirm Proxy Of Burp", "127.0.0.1:8080");
if (proxy != null) {
BurpExtender.CurrentProxy = proxy.trim();
}
}

public static String getProxyHost() {
try {
if (CurrentProxy == null || CurrentProxy.equals("") || CurrentProxy.split(":").length != 2) {
confirmProxy();
}
String proxyHost = CurrentProxy.split(":")[0];
return proxyHost;
} catch (Exception e) {
e.printStackTrace();
CurrentProxy = "";//设置为空,以便重新获取。
return null;
}
}

public static int getProxyPort() {
try {
if (CurrentProxy == null || CurrentProxy.equals("") || CurrentProxy.split(":").length != 2) {
confirmProxy();
}
String proxyPort = CurrentProxy.split(":")[1];
return Integer.parseInt(proxyPort);
} catch (Exception e) {
e.printStackTrace();
CurrentProxy = "";//设置为空,以便重新获取。
return -1;
}
}

public List<String> GetSetCookieHeaders(String cookies) {
if (cookies.startsWith("Cookie: ")) {
cookies = cookies.replaceFirst("Cookie: ", "");
Expand Down
82 changes: 82 additions & 0 deletions src/burp/Proxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package burp;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.validator.routines.DomainValidator;
import org.apache.commons.validator.routines.InetAddressValidator;

import javax.swing.*;

public class Proxy {

String host;
int port;

public Proxy(String proxyStr) throws IllegalArgumentException {
if (StringUtils.isEmpty(proxyStr)) {
throw new IllegalArgumentException("input is empty");
}
try {
String[] parts = proxyStr.split(":");
if (parts.length != 2) {
throw new IllegalArgumentException("not valid host:port format");
}
host = parts[0];
if (!isValidIPAddress(host) && !isValidDomainName(host)) {
throw new IllegalArgumentException("host is not valid IP address and domain name");
}
String portStr = parts[1];
port = Integer.parseInt(portStr);
if (port >= 0 && port <= 65535) {
throw new IllegalArgumentException("invalid port range");
}
} catch (Exception e) {
throw new IllegalArgumentException(e.getMessage());
}
}

// 检查是否是合法的IP地址
public static boolean isValidIPAddress(String ipAddress) {
InetAddressValidator validator = InetAddressValidator.getInstance();
return validator.isValidInet4Address(ipAddress);
}

// 检查是否是合法的域名
public static boolean isValidDomainName(String domainName) {
DomainValidator validator = DomainValidator.getInstance();
return validator.isValid(domainName);
}

public static Proxy inputProxy() {
int retry = 3;
while (retry > 0) {
String proxy = JOptionPane.showInputDialog("Confirm Proxy Of Burp", "127.0.0.1:8080");
try {
return new Proxy(proxy);
} catch (IllegalArgumentException e) {
BurpExtender.getStderr().println(e);
retry = retry - 1;
}
}
return null;
}

public String getHost() {
return host;
}

public void setHost(String host) {
this.host = host;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}

public String getProxyStr() {
return host + ":" + port;
}
}
5 changes: 4 additions & 1 deletion src/config/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ public void showToUI(Config config) {
ConfigEntry entry = new ConfigEntry().FromJson(stringEntry);
tableModel.addNewConfigEntry(entry);
}
table.setupTypeColumn();// must setup again when data cleaned

table.setupTypeColumn();
//call this function must after table data loaded !!!!
// must setup again when data cleaned
table.tableHeaderLengthInit();


Expand Down
Loading

0 comments on commit f451caa

Please sign in to comment.