diff --git a/pom.xml b/pom.xml index 89a82fd8..7feb3fbe 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,7 @@ **/Deprecated/** **/test/** + **/toElastic/** @@ -93,10 +94,11 @@ burp-extender-api [1.7.22,) + com.github.bit4woo - burp-api-common - master-SNAPSHOT + java_utilbox + main-SNAPSHOT @@ -136,7 +138,7 @@ org.xerial sqlite-jdbc - 3.36.0.1 + 3.41.2.2 @@ -176,35 +178,35 @@ 2.0b6 - + - + - + - + org.apache.lucene lucene-core diff --git a/src/ASN/ASNEntry.java b/src/ASN/ASNEntry.java index 2358f559..2368111e 100644 --- a/src/ASN/ASNEntry.java +++ b/src/ASN/ASNEntry.java @@ -4,7 +4,7 @@ import inet.ipaddr.IPAddress; import inet.ipaddr.IPAddressSeqRange; import inet.ipaddr.IPAddressString; -import utils.IPAddressUtils; +import com.bit4woo.utilbox.utils.IPAddressUtils; import org.apache.commons.lang3.StringUtils; import java.util.List; @@ -139,7 +139,7 @@ public boolean contains(String IP){ try { String start = prefix.split("-")[0]; String end = prefix.split("-")[1]; - return IPAddressUtils.checkIPIsInGivenRange(IP,start,end);// + return IPAddressUtils.IsInRange(IP,start,end);// } catch (AddressStringException e) { e.printStackTrace(); return false; diff --git a/src/ASN/ASNQuery.java b/src/ASN/ASNQuery.java index 75ddb199..526871c1 100644 --- a/src/ASN/ASNQuery.java +++ b/src/ASN/ASNQuery.java @@ -17,7 +17,7 @@ import com.github.kevinsawicki.http.HttpRequest; import burp.BurpExtender; -import utils.IPAddressUtils; +import com.bit4woo.utilbox.utils.IPAddressUtils; public class ASNQuery { public static final String localdir = @@ -200,7 +200,7 @@ private static void batchQueryFromApi(List ipSet){ * @return ASNEntry{asn='3215', asname_long='AS3215', asname_short='', prefix='2.0.0.0-2.15.255.255', geo='FR'} */ public ASNEntry query(String singleIP){ - if (IPAddressUtils.isValidIP(singleIP)){ + if (IPAddressUtils.isValidIPv4NoPort(singleIP)){ //1.从缓存查询 ASNEntry result = queryFromRecent(singleIP); //2.从本地数据库文件查询 diff --git a/src/Deprecated/DirBruterProducer.java b/src/Deprecated/DirBruterProducer.java index a687ddc2..b6baab1a 100644 --- a/src/Deprecated/DirBruterProducer.java +++ b/src/Deprecated/DirBruterProducer.java @@ -71,7 +71,7 @@ public void run() { IHttpRequestResponse messageinfo = callbacks.makeHttpRequest(service, request); int leftTaskNum = pathDict.size(); stdout.println(String.format("%s tasks left, Runner Checking: %s",leftTaskNum,url.toString())); - Getter getter = new Getter(helpers); + HelperPlus getter = BurpExtender.getHelperPlus(); if (messageinfo !=null) { byte[] response = messageinfo.getResponse(); int status = getter.getStatusCode(messageinfo); diff --git a/src/Deprecated/GatewayBypassChecker.java b/src/Deprecated/GatewayBypassChecker.java index 7d3998ce..cece8575 100644 --- a/src/Deprecated/GatewayBypassChecker.java +++ b/src/Deprecated/GatewayBypassChecker.java @@ -28,7 +28,7 @@ public class GatewayBypassChecker extends Thread {//Producer do public PrintWriter stdout = new PrintWriter(callbacks.getStdout(), true); public PrintWriter stderr = new PrintWriter(callbacks.getStderr(), true); public IExtensionHelpers helpers = callbacks.getHelpers(); - public HelperPlus getter = new HelperPlus(helpers); + public HelperPlus getter = BurpExtender.getHelperPlus(); LineTableModel runnerTableModel; diff --git a/src/Deprecated/RootDomainForBrute.java b/src/Deprecated/RootDomainForBrute.java index f73150bb..8fe4f2d2 100644 --- a/src/Deprecated/RootDomainForBrute.java +++ b/src/Deprecated/RootDomainForBrute.java @@ -71,7 +71,7 @@ public HashMap> query(String domain){ HashMap> result = new HashMap(); for (String server:nameServers){ try { - result = DomainNameUtils.dnsquery(domain,server); + result = DomainUtils.dnsquery(domain,server); return result; }catch (Exception e){ ;//do nothing diff --git a/src/Deprecated/ThreadBruteDomain.java b/src/Deprecated/ThreadBruteDomain.java index a0444554..db344939 100644 --- a/src/Deprecated/ThreadBruteDomain.java +++ b/src/Deprecated/ThreadBruteDomain.java @@ -63,7 +63,7 @@ public void Do(){ stdout.println("checking wildcard DNS record"); for (String rootDomain: rootDomains){ String badDomain = "domain-hunter-pro-test."+rootDomain; - Set ipset = DomainNameUtils.dnsquery(badDomain).get("IP"); + Set ipset = DomainUtils.dnsquery(badDomain).get("IP"); badRecords.put(rootDomain,ipset); } diff --git a/src/InternetSearch/APISearchAction.java b/src/InternetSearch/APISearchAction.java index 6e816785..07f08942 100644 --- a/src/InternetSearch/APISearchAction.java +++ b/src/InternetSearch/APISearchAction.java @@ -4,23 +4,31 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import javax.swing.AbstractAction; import javax.swing.Action; +import javax.swing.JOptionPane; import javax.swing.SwingWorker; import javax.swing.table.AbstractTableModel; -import InternetSearch.Client.*; import org.apache.commons.lang3.StringUtils; +import com.bit4woo.utilbox.utils.IPAddressUtils; + +import InternetSearch.Client.FoFaClient; +import InternetSearch.Client.HunterClient; +import InternetSearch.Client.HunterIoClient; +import InternetSearch.Client.QuakeClient; +import InternetSearch.Client.ShodanClient; +import InternetSearch.Client.ZoomEyeClient; import burp.BurpExtender; -import burp.IPAddressUtils; import domain.DomainManager; import domain.target.TargetTableModel; import title.LineTableModel; -import utils.GrepUtils; public class APISearchAction extends AbstractAction { @@ -84,8 +92,9 @@ public final void actionPerformed(ActionEvent e) { SwingWorker worker = new SwingWorker() { @Override protected Map doInBackground() throws Exception { - + Set searchedContent = new HashSet(); if (modelRows.length >= 50) { + JOptionPane.showMessageDialog(null, "too many items selected!! should less than 50","Alert",JOptionPane.WARNING_MESSAGE); stderr.print("too many items selected!! should less than 50"); return null; } @@ -112,8 +121,15 @@ protected Map doInBackground() throws Exception { searchContent = result.second; } - DoSearchAllInOn(searchType, searchContent, APISearchAction.this.engineList); - + String tabname = String.format("%s(%s)", searchType, searchContent); + if (searchedContent.add(tabname)) { + //保证单次操作,不对相同项进行重复搜索 + Set already = BurpExtender.getGui().getSearchPanel().getAlreadySearchContent(); + if (!already.contains(tabname)) { + //保证已经存在的搜索内容不再重复 + DoSearchAllInOn(searchType, searchContent, APISearchAction.this.engineList); + } + } } return null; } @@ -196,9 +212,9 @@ public static List DoSearchAllInOn(String searchType, String String host = entry.getHost(); String rootDomain = entry.getRootDomain(); result.addIfValid(host); - List ips = GrepUtils.grepIPAndPort(host); + List ips = IPAddressUtils.grepIPv4MayPort(host); for (String ip : ips) { - if (IPAddressUtils.isValidIP(ip)) { + if (IPAddressUtils.isValidIPv4MayPort(ip)) { result.getSpecialPortTargets().add(ip); } } diff --git a/src/InternetSearch/BrowserSearchAction.java b/src/InternetSearch/BrowserSearchAction.java index 2406bcbb..1cfff65d 100644 --- a/src/InternetSearch/BrowserSearchAction.java +++ b/src/InternetSearch/BrowserSearchAction.java @@ -14,8 +14,9 @@ import burp.BurpExtender; import domain.target.TargetTableModel; import title.LineTableModel; -import utils.DomainNameUtils; -import utils.IPAddressUtils; +import com.bit4woo.utilbox.utils.DomainUtils; +import com.bit4woo.utilbox.utils.IPAddressUtils; +import com.bit4woo.utilbox.utils.SystemUtils; @@ -80,7 +81,7 @@ public final void actionPerformed(ActionEvent e) { String url = buildSearchUrl(engine,searchContent); try { - Commons.browserOpen(url, null); + SystemUtils.browserOpen(url, null); } catch (Exception err) { err.printStackTrace(BurpExtender.getStderr()); } @@ -130,13 +131,13 @@ else if (engine.equalsIgnoreCase(SearchEngine.ASN_INFO_BGP_HE_NET)) { //https://bgp.he.net/dns/shopee.com //https://bgp.he.net/net/143.92.111.0/24 //https://bgp.he.net/ip/143.92.127.1 - if (IPAddressUtils.isValidIP(searchContent)){ + if (IPAddressUtils.isValidIPv4NoPort(searchContent)){ url = "https://bgp.he.net/ip/"+searchContent; } if (IPAddressUtils.isValidSubnet(searchContent)){ url = "https://bgp.he.net/net/"+searchContent; } - if (DomainNameUtils.isValidDomain(searchContent)){ + if (DomainUtils.isValidDomainNoPort(searchContent)){ url = "https://bgp.he.net/dns/"+searchContent; } } diff --git a/src/InternetSearch/Client/BaseClient.java b/src/InternetSearch/Client/BaseClient.java index 60c534b6..ee9dc10d 100644 --- a/src/InternetSearch/Client/BaseClient.java +++ b/src/InternetSearch/Client/BaseClient.java @@ -5,14 +5,14 @@ import java.util.ArrayList; import java.util.List; -import InternetSearch.SearchEngine; -import InternetSearch.SearchType; import org.apache.commons.lang3.StringUtils; +import com.bit4woo.utilbox.utils.UrlUtils; + import InternetSearch.HttpClientOfBurp; +import InternetSearch.SearchEngine; import InternetSearch.SearchResultEntry; import burp.BurpExtender; -import utils.URLUtils; /** * 什么时候使用Interface,什么时候使用abstract class? @@ -54,7 +54,7 @@ public List Search(String searchContent, String searchType) { String searchDork = buildSearchDork(searchContent, searchType); this.url = buildSearchUrl(searchDork, page); this.raw = buildRawData(searchDork, page); - if (URLUtils.isVaildUrl(url)) { + if (UrlUtils.isVaildUrl(url)) { String body = HttpClientOfBurp.doRequest(new URL(url), raw); this.resp_body = body; if (body.length() <= 0) { diff --git a/src/InternetSearch/Client/ZoomEyeClient.java b/src/InternetSearch/Client/ZoomEyeClient.java index e26e5973..3d71eb9d 100644 --- a/src/InternetSearch/Client/ZoomEyeClient.java +++ b/src/InternetSearch/Client/ZoomEyeClient.java @@ -4,7 +4,9 @@ import java.io.IOException; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; @@ -35,24 +37,15 @@ public List parseResp(String respbody) { for (Object item : results) { JSONObject entryitem = (JSONObject) item; - + Set ipSet = getIPSet(entryitem); SearchResultEntry entry = new SearchResultEntry(); - try { - //title:xxx 获得的是IP string - entry.getIPSet().add(entryitem.getString("ip")); - }catch(Exception e) { - //site:xxx.com 获得的是IP List - JSONArray ipList = entryitem.getJSONArray("ip"); - for (int i = 0; i < ipList.length(); i++) { - String element = ipList.getString(i); - entry.getIPSet().add(element); - } - } - + + entry.getIPSet().addAll(ipSet); + try { entry.setHost(entryitem.getString("rdns")); } catch (Exception e) { - entry.setHost(entryitem.getString("ip")); + entry.setHost((String)(ipSet.toArray())[0]); } int port = entryitem.getJSONObject("portinfo").getInt("port"); @@ -76,6 +69,23 @@ public List parseResp(String respbody) { return result; } + public static Set getIPSet(JSONObject entryitem){ + Set result = new HashSet(); + + try { + //title:xxx 获得的是IP string + result.add(entryitem.getString("ip")); + }catch(Exception e) { + //site:xxx.com 获得的是IP List + JSONArray ipList = entryitem.getJSONArray("ip"); + for (int i = 0; i < ipList.length(); i++) { + String element = ipList.getString(i); + result.add(element); + } + } + return result; + } + @Override public boolean hasNextPage(String respbody,int currentPage) { // "size":83,"page":1, diff --git a/src/InternetSearch/HttpClientOfBurp.java b/src/InternetSearch/HttpClientOfBurp.java index 62a77a3b..d487d325 100644 --- a/src/InternetSearch/HttpClientOfBurp.java +++ b/src/InternetSearch/HttpClientOfBurp.java @@ -3,9 +3,10 @@ import java.net.URL; import java.util.Date; +import com.bit4woo.utilbox.burp.HelperPlus; + import base.Commons; import burp.BurpExtender; -import burp.HelperPlus; import burp.IBurpExtenderCallbacks; import burp.IExtensionHelpers; import burp.IHttpRequestResponse; @@ -56,7 +57,7 @@ public static String doRequest(URL url,byte[] byteRequest) { IHttpService service =getHttpService(url); IHttpRequestResponse message = callbacks.makeHttpRequest(service, byteRequest); - HelperPlus getter = new HelperPlus(helpers); + HelperPlus getter = BurpExtender.getHelperPlus(); int code = getter.getStatusCode(message); if (ConfigManager.getBooleanConfigByKey(ConfigName.ApiReqToTitle) diff --git a/src/InternetSearch/SearchPanel.java b/src/InternetSearch/SearchPanel.java index 3af59f06..1ab51878 100644 --- a/src/InternetSearch/SearchPanel.java +++ b/src/InternetSearch/SearchPanel.java @@ -12,8 +12,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import javax.swing.JButton; import javax.swing.JFrame; @@ -28,14 +30,15 @@ import javax.swing.SwingWorker; import javax.swing.border.EmptyBorder; +import com.bit4woo.utilbox.utils.DomainUtils; +import com.bit4woo.utilbox.utils.IPAddressUtils; +import com.bit4woo.utilbox.utils.SystemUtils; +import com.bit4woo.utilbox.utils.UrlUtils; import com.google.gson.Gson; import GUI.GUIMain; import burp.BurpExtender; -import burp.IPAddressUtils; import title.WebIcon; -import utils.DomainNameUtils; -import utils.URLUtils; public class SearchPanel extends JPanel { @@ -63,8 +66,8 @@ public static void test() { test.setPort(88); test.setProtocol("https"); - SearchTableModel searchTableModel= new SearchTableModel(null,new ArrayList(Collections.singletonList(test))); - SearchTable searchTable = new SearchTable(null,searchTableModel); + SearchTableModel searchTableModel = new SearchTableModel(null, new ArrayList(Collections.singletonList(test))); + SearchTable searchTable = new SearchTable(null, searchTableModel); frame.getContentPane().add(searchTable); }); @@ -82,17 +85,17 @@ public static void test1() { test.setHost("8.8.8.8"); test.setPort(88); test.setProtocol("https"); - spanel.addSearchTab("111",new ArrayList(Collections.singletonList(test)),new ArrayList(Collections.singletonList("xxx"))); + spanel.addSearchTab("111", new ArrayList(Collections.singletonList(test)), new ArrayList(Collections.singletonList("xxx"))); }); } public SearchPanel(GUIMain guiMain) { this.guiMain = guiMain; - try{ + try { stdout = new PrintWriter(BurpExtender.getCallbacks().getStdout(), true); stderr = new PrintWriter(BurpExtender.getCallbacks().getStderr(), true); - }catch (Exception e){ + } catch (Exception e) { stdout = new PrintWriter(System.out, true); stderr = new PrintWriter(System.out, true); } @@ -102,23 +105,23 @@ public SearchPanel(GUIMain guiMain) { this.add(createButtonPanel(), BorderLayout.NORTH); centerPanel = new JTabbedPane(); - this.add(centerPanel,BorderLayout.CENTER); + this.add(centerPanel, BorderLayout.CENTER); } - public void addSearchTab(String tabName,List entries,List engines) { + public void addSearchTab(String tabName, List entries, List engines) { JPanel containerpanel = new JPanel();//Tab的最外层容器面板 containerpanel.setLayout(new BorderLayout(0, 0)); - SearchTableModel searchTableModel= new SearchTableModel(this.guiMain,entries); - SearchTable searchTable = new SearchTable(this.guiMain,searchTableModel); - JScrollPane scrollPane = new JScrollPane(searchTable,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + SearchTableModel searchTableModel = new SearchTableModel(this.guiMain, entries); + SearchTable searchTable = new SearchTable(this.guiMain, searchTableModel); + JScrollPane scrollPane = new JScrollPane(searchTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);//table area JLabel status = new JLabel("^_^"); - status.setText(getStatusInfo(entries,engines)); + status.setText(getStatusInfo(entries, engines)); - containerpanel.add(scrollPane,BorderLayout.CENTER); - containerpanel.add(status,BorderLayout.SOUTH); + containerpanel.add(scrollPane, BorderLayout.CENTER); + containerpanel.add(status, BorderLayout.SOUTH); //用一个panel实现tab那个小块 @@ -143,28 +146,28 @@ public void addSearchTab(String tabName,List entries,List entries,List engines) { - Map status = new HashMap<>(); - for (String engine:engines) { + public String getStatusInfo(List entries, List engines) { + Map status = new HashMap<>(); + for (String engine : engines) { status.put(engine, 0); } - int unknown=0; - for (SearchResultEntry entry:entries){ + int unknown = 0; + for (SearchResultEntry entry : entries) { String source = entry.getSource(); if (engines.contains(source)) { int num = status.get(source); status.put(source, num + 1); - }else { + } else { unknown++; } } - if (unknown>0) { + if (unknown > 0) { status.put("unknown", unknown); } @@ -188,7 +191,7 @@ public void actionPerformed(ActionEvent e) { } // 显示右键菜单 - private void showPopupMenu(JTabbedPane tabbedPane,MouseEvent e) { + private void showPopupMenu(JTabbedPane tabbedPane, MouseEvent e) { JPopupMenu popupMenu = new JPopupMenu(); int tabIndex = tabbedPane.indexAtLocation(e.getX(), e.getY()); @@ -235,9 +238,30 @@ public void actionPerformed(ActionEvent e) { }); popupMenu.add(closeTabsToRightMenuItem); + + JMenuItem copyTabNameMenuItem = new JMenuItem("Copy Tab Name"); + copyTabNameMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JPanel panel = ((JPanel) tabbedPane.getTabComponentAt(tabIndex)); + JLabel lab = (JLabel) panel.getComponent(0); + SystemUtils.writeToClipboard(lab.getText()); + } + }); + popupMenu.add(copyTabNameMenuItem); + // 显示右键菜单 popupMenu.show(tabbedPane, e.getX(), e.getY()); } + + public Set getAlreadySearchContent(){ + HashSet result = new HashSet(); + for (int i = centerPanel.getTabCount() - 1; i >= 0; i--) { + JPanel panel = ((JPanel) centerPanel.getTabComponentAt(i)); + JLabel lab = (JLabel) panel.getComponent(0); + result.add(lab.getText()); + } + return result; + } public JPanel createButtonPanel() { JPanel buttonPanel = new JPanel(); @@ -250,21 +274,21 @@ public JPanel createButtonPanel() { JButton buttonSearch = new JButton("Search"); buttonSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - SwingWorker worker = new SwingWorker() { + SwingWorker worker = new SwingWorker() { @Override protected Void doInBackground() throws Exception { String content = textFieldSearch.getText(); - String searchType=null; + String searchType = null; - if(DomainNameUtils.isValidDomain(content)) { + if (DomainUtils.isValidDomainNoPort(content)) { searchType = SearchType.SubDomain; - }else if (IPAddressUtils.isValidIP(content)) { + } else if (IPAddressUtils.isValidIPv4NoPort(content)) { searchType = SearchType.IP; - }else { + } else { searchType = SearchType.OriginalString; } - APISearchAction.DoSearchAllInOn(searchType,content,SearchEngine.getAssetSearchEngineList()); + APISearchAction.DoSearchAllInOn(searchType, content, SearchEngine.getAssetSearchEngineList()); return null; } @@ -272,7 +296,7 @@ protected Void doInBackground() throws Exception { @Override protected void done() { - } + } }; worker.execute(); } @@ -283,25 +307,25 @@ protected void done() { JButton buttonSearchAs = new JButton("Search As"); buttonSearchAs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - SwingWorker worker = new SwingWorker() { + SwingWorker worker = new SwingWorker() { @Override protected Void doInBackground() throws Exception { String content = textFieldSearch.getText(); String searchType = SearchType.choseSearchType(); - switch (searchType){ - case SearchType.Email: - APISearchAction.DoSearchAllInOn(searchType,content,SearchEngine.getEmailSearchEngineList()); - break; - case SearchType.IconHash: - if (URLUtils.isVaildUrl(content)){ - byte[] imageData = WebIcon.getFavicon(content); - if (imageData.length>0){ - content = WebIcon.getHash(imageData); - } + switch (searchType) { + case SearchType.Email: + APISearchAction.DoSearchAllInOn(searchType, content, SearchEngine.getEmailSearchEngineList()); + break; + case SearchType.IconHash: + if (UrlUtils.isVaildUrl(content)) { + byte[] imageData = WebIcon.getFavicon(content); + if (imageData.length > 0) { + content = WebIcon.getHash(imageData); } - default: - APISearchAction.DoSearchAllInOn(searchType,content,SearchEngine.getAssetSearchEngineList()); + } + default: + APISearchAction.DoSearchAllInOn(searchType, content, SearchEngine.getAssetSearchEngineList()); } return null; } diff --git a/src/InternetSearch/SearchResultEntry.java b/src/InternetSearch/SearchResultEntry.java index eb13758a..87e71911 100644 --- a/src/InternetSearch/SearchResultEntry.java +++ b/src/InternetSearch/SearchResultEntry.java @@ -1,6 +1,5 @@ package InternetSearch; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -8,12 +7,12 @@ import org.apache.commons.lang3.StringUtils; +import com.bit4woo.utilbox.utils.DomainUtils; +import com.bit4woo.utilbox.utils.IPAddressUtils; +import com.bit4woo.utilbox.utils.UrlUtils; + import burp.BurpExtender; -import burp.IPAddressUtils; import domain.DomainManager; -import utils.DomainNameUtils; -import utils.GrepUtils; -import utils.URLUtils; public class SearchResultEntry { private int port = -1; @@ -56,18 +55,18 @@ public String getHost() { } public void setHost(String host) { - if (URLUtils.isVaildUrl(host)) { + if (UrlUtils.isVaildUrl(host)) { this.uri = host; - this.host = URLUtils.getHost(host); - }else if(DomainNameUtils.isValidDomain(host)){//包含端口的 - Set hosts = GrepUtils.grepDomainNoPort(host); + this.host = UrlUtils.getHost(host); + }else if(DomainUtils.isValidDomainMayPort(host)){//包含端口的 + List hosts = DomainUtils.grepDomainNoPort(host); if (hosts.size()>0) { - this.host = new ArrayList<>(hosts).get(0); + this.host = hosts.get(0); } }else { - List hosts = GrepUtils.grepIP(host); + List hosts = IPAddressUtils.grepIPv4NoPort(host); if (hosts.size()>0) { - this.host = new ArrayList<>(hosts).get(0); + this.host = hosts.get(0); } } if (StringUtils.isEmpty(this.host)) { @@ -75,8 +74,8 @@ public void setHost(String host) { } if (StringUtils.isEmpty(rootDomain)) { - if(DomainNameUtils.isValidDomain(host)) { - this.rootDomain = DomainNameUtils.getRootDomain(host); + if(DomainUtils.isValidDomainMayPort(host)) { + this.rootDomain = DomainUtils.getRootDomain(host); } } } @@ -94,8 +93,8 @@ public String getRootDomain() { } public void setRootDomain(String rootDomain) { - if(DomainNameUtils.isValidDomain(rootDomain)) { - this.rootDomain = DomainNameUtils.getRootDomain(rootDomain); + if(DomainUtils.isValidDomainMayPort(rootDomain)) { + this.rootDomain = DomainUtils.getRootDomain(rootDomain); }else{ this.rootDomain = rootDomain; } @@ -195,7 +194,7 @@ private String buildUri() { sb.append(":").append(port); } try { - uri = URLUtils.getUrlWithDefaultPort(sb.toString()); + uri = UrlUtils.getFullUrlWithDefaultPort(sb.toString()); } catch (Exception e) { uri = sb.toString(); } @@ -224,14 +223,14 @@ public void setTitle(String title) { public void AddToTarget() { DomainManager domainResult = BurpExtender.getGui().getDomainPanel().getDomainResult(); - if (IPAddressUtils.isValidIP(this.host)) { + if (IPAddressUtils.isValidIPv4NoPort(this.host)) { domainResult.getSpecialPortTargets().add(this.host); if (this.port >=0 && this.port <= 65535) { domainResult.getSpecialPortTargets().add(this.host+":"+this.port); } } - if (DomainNameUtils.isValidDomain(this.host)) { + if (DomainUtils.isValidDomainMayPort(this.host)) { domainResult.addToTargetAndSubDomain(this.host,true); if (this.port >=0 && this.port <= 65535) { domainResult.addToTargetAndSubDomain(this.host+":"+this.port,true); diff --git a/src/InternetSearch/SearchResultEntryMenu.java b/src/InternetSearch/SearchResultEntryMenu.java index af890bac..7921094d 100644 --- a/src/InternetSearch/SearchResultEntryMenu.java +++ b/src/InternetSearch/SearchResultEntryMenu.java @@ -4,22 +4,19 @@ import java.io.PrintWriter; import java.util.HashSet; import java.util.List; -import java.util.Set; import javax.swing.AbstractAction; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.SwingWorker; +import com.bit4woo.utilbox.utils.SystemUtils; + import GUI.GUIMain; import base.Commons; import burp.BurpExtender; -import burp.IPAddressUtils; -import burp.SystemUtils; import config.ConfigManager; import config.ConfigName; -import domain.DomainManager; -import utils.GrepUtils; import utils.PortScanUtils; public class SearchResultEntryMenu extends JPopupMenu { @@ -122,7 +119,7 @@ public void actionPerformed(ActionEvent actionEvent) { return; } for (String url:urls){ - Commons.browserOpen(url,ConfigManager.getStringConfigByKey(ConfigName.BrowserPath)); + SystemUtils.browserOpen(url,ConfigManager.getStringConfigByKey(ConfigName.BrowserPath)); } } catch (Exception e1) diff --git a/src/InternetSearch/SearchTable.java b/src/InternetSearch/SearchTable.java index 30ea6bf8..b6158e1f 100644 --- a/src/InternetSearch/SearchTable.java +++ b/src/InternetSearch/SearchTable.java @@ -18,10 +18,11 @@ import org.apache.commons.lang3.StringUtils; +import com.bit4woo.utilbox.utils.SystemUtils; + import GUI.GUIMain; import base.Commons; import burp.BurpExtender; -import burp.SystemUtils; import config.ConfigManager; import config.ConfigName; @@ -152,7 +153,7 @@ public void mouseClicked(MouseEvent e) { if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://")) { url = "http://"+url;//针对DNS记录中URL字段是host的情况 } - Commons.browserOpen(url,ConfigManager.getStringConfigByKey(ConfigName.BrowserPath)); + SystemUtils.browserOpen(url,ConfigManager.getStringConfigByKey(ConfigName.BrowserPath)); }catch (Exception e1){ e1.printStackTrace(stderr); } @@ -160,7 +161,7 @@ public void mouseClicked(MouseEvent e) { }else if (modelCol == HeadList.indexOf(SearchTableHead.Favicon)) { try { - Commons.browserOpen(selecteEntry.getIcon_url(),ConfigManager.getStringConfigByKey(ConfigName.BrowserPath)); + SystemUtils.browserOpen(selecteEntry.getIcon_url(),ConfigManager.getStringConfigByKey(ConfigName.BrowserPath)); } catch (Exception e1) { e1.printStackTrace(); } diff --git a/src/InternetSearch/SearchTableModel.java b/src/InternetSearch/SearchTableModel.java index 05435d51..db18b079 100644 --- a/src/InternetSearch/SearchTableModel.java +++ b/src/InternetSearch/SearchTableModel.java @@ -8,10 +8,11 @@ import javax.swing.ImageIcon; import javax.swing.table.AbstractTableModel; +import com.bit4woo.utilbox.utils.IPAddressUtils; + import GUI.GUIMain; import base.IndexedHashMap; import burp.BurpExtender; -import burp.IPAddressUtils; public class SearchTableModel extends AbstractTableModel { @@ -238,7 +239,7 @@ else if (columnIndex == HeadList.indexOf(SearchTableHead.Server)){ else if (columnIndex == HeadList.indexOf(SearchTableHead.IP)){ if (entry.getIPSet().iterator().hasNext()) { String value = entry.getIPSet().iterator().next(); - if (IPAddressUtils.isValidIP(value) && !IPAddressUtils.isPrivateIPv4(value)) { + if (IPAddressUtils.isPublicIPv4NoPort(value)) { return new InfoTuple<>(SearchType.IP, value); } } @@ -267,7 +268,7 @@ else if (columnIndex == HeadList.indexOf(SearchTableHead.ASNInfo) || columnIndex } else { String value = entry.getHost(); - if (IPAddressUtils.isValidIP(value)) { + if (IPAddressUtils.isValidIPv4NoPort(value)) { return new InfoTuple<>(SearchType.IP, value); }else { return new InfoTuple<>(SearchType.SubDomain, value); diff --git a/src/Tools/JSONHandler.java b/src/Tools/JSONHandler.java index 168f393e..c553cc22 100644 --- a/src/Tools/JSONHandler.java +++ b/src/Tools/JSONHandler.java @@ -78,7 +78,7 @@ public static ArrayList grepValueFromJson(String jsonString,String keyNa } }else { String reg = String.format("\"%s\":[\\s]*[\"]{0,1}(.*?)[\"]{0,1}[,}]+", keyName); - + //JSON 标准中定义了字符串必须使用双引号(")来包裹,因此在合法的 JSON 中,字符串不能使用单引号 Pattern pattern = Pattern.compile(reg); Matcher matcher = pattern.matcher(jsonString); while (matcher.find()) {//多次查找 diff --git a/src/Tools/SuperJTextArea.java b/src/Tools/SuperJTextArea.java index aa5a6525..dcba27df 100644 --- a/src/Tools/SuperJTextArea.java +++ b/src/Tools/SuperJTextArea.java @@ -33,7 +33,7 @@ public class SuperJTextArea extends JTextArea { public static int maxLength = 100000; public static History history = new History(5,false); - final String tempFilePath = FileUtils.getTempDirectory() + File.separator + "ContentIsInTmpFile.txt"; + public static final String tempFilePath = FileUtils.getTempDirectory() + File.separator + "ContentIsInTmpFile.txt"; /** * @param useTempFile 当文件内容过大时,将文件内容存入零时文件,避免程序卡死 @@ -270,12 +270,8 @@ public String getTipsToShow() { */ public void showPreValue() { String preValue = history.moveUP(); - if (preValue.equals(getText())) { - showPreValue(); - }else { - BurpExtender.getStdout().print("preValue"+preValue); - setText(preValue); - } + BurpExtender.getStdout().print("preValue"+preValue); + setText(preValue); } /** diff --git a/src/Tools/TextAreaMenu.java b/src/Tools/TextAreaMenu.java index 2b32e7a0..db1e25aa 100644 --- a/src/Tools/TextAreaMenu.java +++ b/src/Tools/TextAreaMenu.java @@ -2,7 +2,6 @@ import java.awt.event.ActionEvent; import java.io.PrintWriter; -import java.util.ArrayList; import java.util.List; import javax.swing.AbstractAction; @@ -10,10 +9,11 @@ import javax.swing.JPopupMenu; import javax.swing.JTextArea; +import com.bit4woo.utilbox.utils.IPAddressUtils; +import com.bit4woo.utilbox.utils.TextUtils; + import GUI.GUIMain; -import base.Commons; import burp.BurpExtender; -import burp.IPAddressUtils; import config.ConfigManager; import config.ConfigName; import domain.DomainManager; @@ -23,18 +23,9 @@ public class TextAreaMenu extends JPopupMenu { PrintWriter stdout; PrintWriter stderr; - private GUIMain guiMain; - private JTextArea textArea; - private List selectedItems = new ArrayList<>();; TextAreaMenu(GUIMain guiMain,JTextArea textArea){ - this.guiMain = guiMain; - this.textArea = textArea; String selectedText = textArea.getSelectedText(); - if (selectedText != null && !selectedText.equalsIgnoreCase("")){ - selectedItems = Commons.textToLines(selectedText); - } - try{ stdout = new PrintWriter(BurpExtender.getCallbacks().getStdout(), true); @@ -44,7 +35,7 @@ public class TextAreaMenu extends JPopupMenu { stderr = new PrintWriter(System.out, true); } - List selectedItems = Commons.textToLines(selectedText); + List selectedItems = TextUtils.textToLines(selectedText); if (selectedItems.size() > 0){ JMenuItem goToItem = new JMenuItem(new AbstractAction(selectedItems.size()+" items selected") { @@ -93,8 +84,28 @@ public void actionPerformed(ActionEvent actionEvent) { DomainManager domainResult = guiMain.getDomainPanel().getDomainResult(); for (String item:selectedItems) { try { - if (IPAddressUtils.isValidIP(item)) { + if (IPAddressUtils.isValidIPv4MayPort(item)) { + domainResult.getSpecialPortTargets().add(item); + } + } catch (Exception e2) { + e2.printStackTrace(stderr); + } + } + guiMain.getDomainPanel().saveDomainDataToDB(); + } + }); + + + JMenuItem addToTarget = new JMenuItem(new AbstractAction("Add To Target") { + @Override + public void actionPerformed(ActionEvent actionEvent) { + DomainManager domainResult = guiMain.getDomainPanel().getDomainResult(); + for (String item:selectedItems) { + try { + if (IPAddressUtils.isValidIPv4MayPort(item)) { domainResult.getSpecialPortTargets().add(item); + }else { + domainResult.addToTargetAndSubDomain(item,true); } } catch (Exception e2) { e2.printStackTrace(stderr); @@ -105,7 +116,6 @@ public void actionPerformed(ActionEvent actionEvent) { }); this.add(genPortScanCmd); - this.add(addTosubdomain); - this.add(addToCustomAsset); + this.add(addToTarget); } } diff --git a/src/Tools/ToolPanel.java b/src/Tools/ToolPanel.java index fb130cff..910235fe 100644 --- a/src/Tools/ToolPanel.java +++ b/src/Tools/ToolPanel.java @@ -18,7 +18,6 @@ import java.net.URI; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; import java.util.Base64; import java.util.Collections; import java.util.HashMap; @@ -35,6 +34,7 @@ import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; @@ -45,18 +45,22 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.StringEscapeUtils; +import com.bit4woo.utilbox.utils.DomainUtils; +import com.bit4woo.utilbox.utils.EmailUtils; +import com.bit4woo.utilbox.utils.IPAddressUtils; +import com.bit4woo.utilbox.utils.JsonUtils; +import com.bit4woo.utilbox.utils.SwingUtils; +import com.bit4woo.utilbox.utils.SystemUtils; +import com.bit4woo.utilbox.utils.TextUtils; +import com.bit4woo.utilbox.utils.UrlUtils; + import GUI.GUIMain; import base.BackGroundButton; -import base.Commons; import burp.BurpExtender; import config.ConfigManager; import config.ConfigName; -import config.ConfigPanel; import domain.CertInfo; import title.WebIcon; -import utils.DomainNameUtils; -import utils.GrepUtils; -import utils.IPAddressUtils; /** * 所有配置的修改,界面的操作,都立即写入LineConfig对象,如有必要保存到磁盘,再调用一次SaveConfig函数,思路要清晰 @@ -136,7 +140,6 @@ public ToolPanel(GUIMain guiMain) { */ - ///////////////////////BodyPane////////////// @@ -148,14 +151,41 @@ public ToolPanel(GUIMain guiMain) { //searchResultTextArea = searhResultPanel.getTextArea(); - JScrollPanelWithHeaderForTool InputPanel = new JScrollPanelWithHeaderForTool("Input","",true,true); + JScrollPanelWithHeaderForTool InputPanel = new JScrollPanelWithHeaderForTool("Input", "", true, true); inputTextArea = InputPanel.getTextArea(); - inputTextArea.addMouseListener(new TextAreaMouseListener(guiMain,inputTextArea)); + inputTextArea.addMouseListener(new TextAreaMouseListener(guiMain, inputTextArea)); + inputTextArea.getDocument().addDocumentListener(new DocumentListener() { + + @Override + public void insertUpdate(DocumentEvent e) { + inputTextAreaChanged = true; + } + + @Override + public void removeUpdate(DocumentEvent e) { + inputTextAreaChanged = true; + } + + @Override + public void changedUpdate(DocumentEvent e) { + inputTextAreaChanged = true; + } + }); - JScrollPanelWithHeaderForTool OutPanel = new JScrollPanelWithHeaderForTool("OutPut","",false,false); + InputPanel.getHeadLabel().addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { // 判断是否是双击事件 + // 在双击时执行的操作 + inputTextArea.setText(SuperJTextArea.tempFilePath); + } + } + }); + + JScrollPanelWithHeaderForTool OutPanel = new JScrollPanelWithHeaderForTool("OutPut", "", false, false); outputTextArea = OutPanel.getTextArea(); - outputTextArea.addMouseListener(new TextAreaMouseListener(guiMain,outputTextArea)); + outputTextArea.addMouseListener(new TextAreaMouseListener(guiMain, outputTextArea)); JPanel buttonPanel = createButtons(); @@ -166,7 +196,6 @@ public ToolPanel(GUIMain guiMain) { //BodyPane.add(buttonPanel); - ///////////////////////////FooterPanel////////////////// JPanel footerPanel = new JPanel(); @@ -228,10 +257,9 @@ protected void action() { String content = inputTextArea.getText(); //stdout.println(content); if (null != content) { - Set domains = GrepUtils.grepDomain(content); - ArrayList tmpList = new ArrayList(domains); - Collections.sort(tmpList, new DomainComparator()); - outputTextArea.setText(String.join(System.lineSeparator(), tmpList)); + List domains = DomainUtils.grepDomainAndPort(content); + Collections.sort(domains, new DomainComparator()); + outputTextArea.setText(String.join(System.lineSeparator(), domains)); guiMain.getDomainPanel().getDomainResult().addIfValid(domains); } } @@ -243,10 +271,9 @@ protected void action() { String content = inputTextArea.getText(); //stdout.println(content); if (null != content) { - Set domains = GrepUtils.grepDomainNoPort(content); - ArrayList tmpList = new ArrayList(domains); - Collections.sort(tmpList, new DomainComparator()); - outputTextArea.setText(String.join(System.lineSeparator(), tmpList)); + List domains = DomainUtils.grepDomainNoPort(content); + Collections.sort(domains, new DomainComparator()); + outputTextArea.setText(String.join(System.lineSeparator(), domains)); guiMain.getDomainPanel().getDomainResult().addIfValid(domains); } } @@ -258,19 +285,52 @@ protected void action() { protected void action() { String content = inputTextArea.getText(); if (null != content) { - List urls = GrepUtils.grepURL(content); + List urls = UrlUtils.grepUrls(content); outputTextArea.setText(String.join(System.lineSeparator(), urls)); } } }; + JButton btnFindUrlsWithProtocol = new BackGroundButton("Find URL With Protocol") { + @Override + protected void action() { + String content = inputTextArea.getText(); + if (null != content) { + List urls = UrlUtils.grepUrlsWithProtocol(content); + outputTextArea.setText(String.join(System.lineSeparator(), urls)); + } + } + }; + + + JButton btnFindUrlsInQuotes = new BackGroundButton("Find URL In Quotes('|\")") { + @Override + protected void action() { + String content = inputTextArea.getText(); + if (null != content) { + List urls = UrlUtils.grepUrlsInQuotes(content); + outputTextArea.setText(String.join(System.lineSeparator(), urls)); + } + } + }; - JButton btnFindUrls1 = new BackGroundButton("Find URL 1") { + JButton btnFindUrlsNotStartWithSlash = new BackGroundButton("Find URL(img/a.png)") { @Override protected void action() { String content = inputTextArea.getText(); if (null != content) { - List urls = GrepUtils.grepURL1(content); + List urls = UrlUtils.grepUrlPathNotStartWithSlash(content); + outputTextArea.setText(String.join(System.lineSeparator(), urls)); + } + } + }; + + JButton btnFindUrlsNotStartWithSlashInQuotes = new BackGroundButton("Find URL(\"img/a.png\")") { + @Override + protected void action() { + String content = inputTextArea.getText(); + if (null != content) { + List urls = UrlUtils.grepUrlPathNotStartWithSlashInQuotes(content); outputTextArea.setText(String.join(System.lineSeparator(), urls)); } } @@ -281,13 +341,13 @@ protected void action() { protected void action() { String content = inputTextArea.getText(); if (null != content) { - List lines = Commons.getLinesFromTextArea(inputTextArea); - List result = new ArrayList(); + List lines = SwingUtils.getLinesFromTextArea(inputTextArea); + List result = new ArrayList<>(); - for (String item:lines) { - if (GrepUtils.uselessExtension(item)) { + for (String item : lines) { + if (UrlUtils.uselessExtension(item)) { continue; - }else { + } else { result.add(item); } }//不在使用set方法去重,以便保持去重后的顺序! @@ -303,7 +363,7 @@ protected void action() { protected void action() { String content = inputTextArea.getText(); if (null != content) { - List iplist = GrepUtils.grepIP(content); + List iplist = IPAddressUtils.grepIPv4NoPort(content); outputTextArea.setText(String.join(System.lineSeparator(), iplist)); } } @@ -314,7 +374,7 @@ protected void action() { protected void action() { String content = inputTextArea.getText(); if (null != content) { - List iplist = GrepUtils.grepPublicIP(content); + List iplist = IPAddressUtils.grepPublicIPv4NoPort(content); outputTextArea.setText(String.join(System.lineSeparator(), iplist)); } } @@ -326,7 +386,7 @@ protected void action() { protected void action() { String content = inputTextArea.getText(); if (null != content) { - List iplist = GrepUtils.grepPrivateIP(content); + List iplist = IPAddressUtils.grepPrivateIPv4NoPort(content); outputTextArea.setText(String.join(System.lineSeparator(), iplist)); } } @@ -338,7 +398,7 @@ protected void action() { protected void action() { String content = inputTextArea.getText(); if (null != content) { - List iplist = GrepUtils.grepIPAndPort(content); + List iplist = IPAddressUtils.grepIPv4MayPort(content); outputTextArea.setText(String.join(System.lineSeparator(), iplist)); } } @@ -350,9 +410,9 @@ protected void action() { String content = inputTextArea.getText(); if (null != content) { List result = new ArrayList(); - List lines = Commons.textToLines(content); - for (String line:lines) { - List portlist = GrepUtils.grepPort(line); + List lines = TextUtils.textToLines(content); + for (String line : lines) { + List portlist = IPAddressUtils.grepPort(line); result.addAll(portlist); } outputTextArea.setText(String.join(System.lineSeparator(), result)); @@ -361,22 +421,22 @@ protected void action() { }; - JButton btnMasscanResultToNmap = new BackGroundButton("Masscan->Nmap"){ + JButton btnMasscanResultToNmap = new BackGroundButton("Masscan->Nmap") { @Override protected void action() { String content = inputTextArea.getText(); if (StringUtils.isNotEmpty(content)) { - List lines = Commons.textToLines(content); - HashMap> ipAndPorts = new HashMap>(); + List lines = TextUtils.textToLines(content); + HashMap> ipAndPorts = new HashMap>(); List nmapCmds = new ArrayList(); - for (String line:lines) { + for (String line : lines) { if (line.contains("Discovered open port")) { try { String port = line.split(" ")[3].split("/")[0]; String host = line.split(" ")[5]; - Set ports = ipAndPorts.get(host); + Set ports = ipAndPorts.get(host); if (ports == null) { ports = new HashSet(); } @@ -388,8 +448,8 @@ protected void action() { } } - for (String host:ipAndPorts.keySet()) { - nmapCmds.add("nmap -v -A -p "+String.join(",", ipAndPorts.get(host))+" "+host); + for (String host : ipAndPorts.keySet()) { + nmapCmds.add("nmap -v -A -p " + String.join(",", ipAndPorts.get(host)) + " " + host); } outputTextArea.setText(String.join(System.lineSeparator(), nmapCmds)); @@ -398,22 +458,22 @@ protected void action() { }; - JButton btnMasscanResultToHttp = new BackGroundButton("Masscan->Http"){ + JButton btnMasscanResultToHttp = new BackGroundButton("Masscan->Http") { @Override protected void action() { String content = inputTextArea.getText(); if (StringUtils.isNotEmpty(content)) { - List lines = Commons.textToLines(content); + List lines = TextUtils.textToLines(content); List result = new ArrayList(); - for (String line:lines) { + for (String line : lines) { if (line.contains("Discovered open port")) { try { String port = line.split(" ")[3].split("/")[0]; String host = line.split(" ")[5]; - result.add("http://"+host+":"+port); - result.add("https://"+host+":"+port); + result.add("http://" + host + ":" + port); + result.add("https://" + host + ":" + port); } catch (Exception e1) { e1.printStackTrace(); } @@ -426,7 +486,7 @@ protected void action() { }; - JButton btnNmapResultToHttp = new BackGroundButton("Nmap->Http"){ + JButton btnNmapResultToHttp = new BackGroundButton("Nmap->Http") { @Override protected void action() { @@ -434,22 +494,22 @@ protected void action() { if (StringUtils.isNotEmpty(content)) { List result = new ArrayList(); - List iplist = GrepUtils.grepIP(content); - List lines = Commons.textToLines(content); + List iplist = IPAddressUtils.grepIPv4NoPort(content); + List lines = TextUtils.textToLines(content); - for (String line:lines) { + for (String line : lines) { if (line.toLowerCase().contains("ssl")) { - List portlist = GrepUtils.grepPort(line); - for (String port:portlist) { - for (String host:iplist) { - result.add("https://"+host+":"+port); + List portlist = IPAddressUtils.grepPort(line); + for (String port : portlist) { + for (String host : iplist) { + result.add("https://" + host + ":" + port); } } - }else if (line.toLowerCase().contains("http")) { - List portlist = GrepUtils.grepPort(line); - for (String port:portlist) { - for (String host:iplist) { - result.add("http://"+host+":"+port); + } else if (line.toLowerCase().contains("http")) { + List portlist = IPAddressUtils.grepPort(line); + for (String port : portlist) { + for (String host : iplist) { + result.add("http://" + host + ":" + port); } } } @@ -461,7 +521,7 @@ protected void action() { }; - JButton btnNmapResultToHttp1 = new BackGroundButton("Nmap->Http 1"){ + JButton btnNmapResultToHttp1 = new BackGroundButton("Nmap->Http 1") { @Override protected void action() { @@ -470,13 +530,13 @@ protected void action() { List result = new ArrayList(); - List iplist = GrepUtils.grepIP(content); - List portlist = GrepUtils.grepPort(content); + List iplist = IPAddressUtils.grepIPv4NoPort(content); + List portlist = IPAddressUtils.grepPort(content); - for (String host:iplist) { - for (String port:portlist) { - result.add("http://"+host+":"+port); - result.add("https://"+host+":"+port); + for (String host : iplist) { + for (String port : portlist) { + result.add("http://" + host + ":" + port); + result.add("https://" + host + ":" + port); } } outputTextArea.setText(String.join(System.lineSeparator(), result)); @@ -485,13 +545,12 @@ protected void action() { }; - JButton btnFindSubnet = new BackGroundButton("Find Subnet") { @Override protected void action() { String content = inputTextArea.getText(); if (null != content) { - List subnets = GrepUtils.grepSubnet(content); + List subnets = IPAddressUtils.grepSubnet(content); outputTextArea.setText(String.join(System.lineSeparator(), subnets)); } } @@ -503,7 +562,7 @@ protected void action() { protected void action() { String content = inputTextArea.getText(); if (null != content) { - Set emails = GrepUtils.grepEmail(content); + List emails = EmailUtils.grepEmail(content); outputTextArea.setText(String.join(System.lineSeparator(), emails)); guiMain.getDomainPanel().getDomainResult().addIfValidEmail(emails); } @@ -511,7 +570,7 @@ protected void action() { }; - JButton btnOpenurls = new BackGroundButton("OpenURLs"){ + JButton btnOpenurls = new BackGroundButton("OpenURLs") { List urls = new ArrayList<>(); Iterator it = urls.iterator(); private int totalNumber; @@ -520,7 +579,7 @@ protected void action() { @Override protected void action() { if (inputTextAreaChanged) {//default is true - urls = Commons.getLinesFromTextArea(inputTextArea); + urls = SwingUtils.getLinesFromTextArea(inputTextArea); totalNumber = urls.size(); left = urls.size(); it = urls.iterator(); @@ -536,15 +595,15 @@ protected void action() { url = "http://" + url; URL tmpUrl = new URL(url); if (tmpUrl.getPort() == -1) { - Commons.browserOpen(url, browserPath); - Commons.browserOpen(url.replaceFirst("http://", "https://"), browserPath); + SystemUtils.browserOpen(url, browserPath); + SystemUtils.browserOpen(url.replaceFirst("http://", "https://"), browserPath); } else if (Integer.toString(tmpUrl.getPort()).endsWith("443")) { - Commons.browserOpen(url.replaceFirst("http://", "https://"), browserPath); + SystemUtils.browserOpen(url.replaceFirst("http://", "https://"), browserPath); } else { - Commons.browserOpen(url, browserPath); + SystemUtils.browserOpen(url, browserPath); } } else { - Commons.browserOpen(url, browserPath); + SystemUtils.browserOpen(url, browserPath); } i--; left--; @@ -557,12 +616,11 @@ protected void action() { }; - JButton btnCertDomains = new BackGroundButton("GetCertDomains") { @Override protected void action() { ArrayList result = new ArrayList(); - List urls = Commons.getLinesFromTextArea(inputTextArea); + List urls = SwingUtils.getLinesFromTextArea(inputTextArea); Iterator it = urls.iterator(); while (it.hasNext()) { String url = it.next(); @@ -579,7 +637,7 @@ protected void action() { @Override protected void action() { ArrayList result = new ArrayList(); - List urls = Commons.getLinesFromTextArea(inputTextArea); + List urls = SwingUtils.getLinesFromTextArea(inputTextArea); Iterator it = urls.iterator(); while (it.hasNext()) { String url = it.next(); @@ -595,7 +653,7 @@ protected void action() { @Override protected void action() { ArrayList result = new ArrayList(); - List urls = Commons.getLinesFromTextArea(inputTextArea); + List urls = SwingUtils.getLinesFromTextArea(inputTextArea); Iterator it = urls.iterator(); while (it.hasNext()) { String url = it.next(); @@ -612,11 +670,11 @@ protected void action() { protected void action() { try { ArrayList result = new ArrayList(); - List urls = Commons.getLinesFromTextArea(inputTextArea); + List urls = SwingUtils.getLinesFromTextArea(inputTextArea); Iterator it = urls.iterator(); while (it.hasNext()) { String url = it.next(); - String hash = WebIcon.getHash(url,null); + String hash = WebIcon.getHash(url, null); result.add(hash); System.out.println(url + " " + hash); } @@ -629,19 +687,19 @@ protected void action() { }; - JButton getIPAddressButton = new BackGroundButton("GetIPAddress") { + JButton dnsQueryButton = new BackGroundButton("DNS Query") { @Override protected void action() { try { ArrayList result = new ArrayList(); - List domains = Commons.getLinesFromTextArea(inputTextArea); + List domains = SwingUtils.getLinesFromTextArea(inputTextArea); Iterator it = domains.iterator(); while (it.hasNext()) { String domain = it.next(); - if (IPAddressUtils.isValidIP(domain)) {//目标是一个IP + if (IPAddressUtils.isValidIPv4NoPort(domain)) {//目标是一个IP result.add(domain); - } else if (DomainNameUtils.isValidDomain(domain)) {//目标是域名 - HashMap> temp = DomainNameUtils.dnsquery(domain,null); + } else if (DomainUtils.isValidDomainNoPort(domain)) {//目标是域名 + HashMap> temp = DomainUtils.dnsQuery(domain, null); Set IPSet = temp.get("IP"); result.addAll(IPSet); } @@ -660,7 +718,7 @@ protected void action() { protected void action() { try { String content = inputTextArea.getText(); - List result = GrepUtils.grepChinese(content); + List result = TextUtils.grepChinese(content); outputTextArea.setText(String.join(System.lineSeparator(), result)); } catch (Exception e1) { outputTextArea.setText(e1.getMessage()); @@ -670,12 +728,12 @@ protected void action() { }; - JButton rows2List = new BackGroundButton("Rows To List"){ + JButton rows2List = new BackGroundButton("Rows To List") { @Override protected void action() { try { - List content = Commons.getLinesFromTextArea(inputTextArea); + List content = SwingUtils.getLinesFromTextArea(inputTextArea); outputTextArea.setText(content.toString()); } catch (Exception e1) { outputTextArea.setText(e1.getMessage()); @@ -685,12 +743,12 @@ protected void action() { }; - JButton rows2Array = new BackGroundButton("Rows To Array"){ + JButton rows2Array = new BackGroundButton("Rows To Array") { @Override protected void action() { try { - List content = Commons.getLinesFromTextArea(inputTextArea); + List content = SwingUtils.getLinesFromTextArea(inputTextArea); for (int i = 0; i < content.size(); i++) { content.set(i, "\"" + content.get(i) + "\""); } @@ -704,18 +762,18 @@ protected void action() { }; - JButton removeDuplicate = new BackGroundButton("Deduplicate"){ + JButton removeDuplicate = new BackGroundButton("Deduplicate") { @Override protected void action() { try { - List content = Commons.getLinesFromTextArea(inputTextArea); + List content = SwingUtils.getLinesFromTextArea(inputTextArea); List result = new ArrayList(); - for (String item:content) { + for (String item : content) { if (result.contains(item)) { continue; - }else { + } else { result.add(item); } }//不在使用set方法去重,以便保持去重后的顺序! @@ -729,12 +787,12 @@ protected void action() { }; - JButton sort = new BackGroundButton("Sort"){ + JButton sort = new BackGroundButton("Sort") { @Override protected void action() { try { - List content = Commons.getLinesFromTextArea(inputTextArea); + List content = SwingUtils.getLinesFromTextArea(inputTextArea); Set contentSet = new HashSet<>(content); List tmplist = new ArrayList<>(contentSet); @@ -749,16 +807,16 @@ protected void action() { }; - JButton sortReverse = new BackGroundButton("Sort(Reverse Str)"){ + JButton sortReverse = new BackGroundButton("Sort(Reverse Str)") { @Override protected void action() { try { - List content = Commons.getLinesFromTextArea(inputTextArea); + List content = SwingUtils.getLinesFromTextArea(inputTextArea); Set contentSet = new HashSet<>(content); List tmplist = new ArrayList<>(contentSet); - Collections.sort(tmplist,new ReverseStrComparator()); + Collections.sort(tmplist, new ReverseStrComparator()); String output = String.join(System.lineSeparator(), tmplist); outputTextArea.setText(output); } catch (Exception e1) { @@ -769,12 +827,12 @@ protected void action() { }; - JButton sortByLength = new BackGroundButton("Sort by Length"){ + JButton sortByLength = new BackGroundButton("Sort by Length") { @Override protected void action() { try { - List content = Commons.getLinesFromTextArea(inputTextArea); + List content = SwingUtils.getLinesFromTextArea(inputTextArea); Set contentSet = new HashSet<>(content); List tmplist = new ArrayList<>(contentSet); @@ -819,7 +877,7 @@ protected void action() { return; } else { history = toFind; - List content = Commons.getLinesFromTextArea(inputTextArea); + List content = SwingUtils.getLinesFromTextArea(inputTextArea); for (String item : content) { if (item.toLowerCase().contains(toFind.toLowerCase().trim())) { result.add(item); @@ -851,7 +909,7 @@ protected void action() { return; } else { history = toFind; - List content = Commons.getLinesFromTextArea(inputTextArea); + List content = SwingUtils.getLinesFromTextArea(inputTextArea); for (String item : content) { if (!item.toLowerCase().contains(toFind.toLowerCase().trim())) { result.add(item); @@ -882,7 +940,15 @@ protected void action() { String content = inputTextArea.getText(); Matcher matcher = pRegex.matcher(content); while (matcher.find()) {//多次查找 - result.add(matcher.group()); + // 判断是否有捕获组 + if (matcher.groupCount() > 0) { + // 获取第一个捕获组的匹配结果 + String group1 = matcher.group(1); + // 将匹配结果添加到列表中 + result.add(group1); + }else { + result.add(matcher.group()); + } } outputTextArea.setText(String.join(System.lineSeparator(), result)); } @@ -912,7 +978,7 @@ protected void action() { toAddSuffix = ""; } - List content = Commons.getLinesFromTextArea(inputTextArea); + List content = SwingUtils.getLinesFromTextArea(inputTextArea); for (String item : content) { item = toAddPrefix + item + toAddSuffix; result.add(item); @@ -932,8 +998,8 @@ protected void action() { try { String Prefix = JOptionPane.showInputDialog("prefix to remove", null); String Suffix = JOptionPane.showInputDialog("suffix to remove", null); - List content = Commons.getLinesFromTextArea(inputTextArea); - List result = Commons.removePrefixAndSuffix(content, Prefix, Suffix); + List content = SwingUtils.getLinesFromTextArea(inputTextArea); + List result = TextUtils.removePrefixAndSuffix(content, Prefix, Suffix); outputTextArea.setText(String.join(System.lineSeparator(), result)); } catch (Exception e1) { outputTextArea.setText(e1.getMessage()); @@ -944,7 +1010,7 @@ protected void action() { }; - JButton btnReplace = new BackGroundButton("ReplaceFirstStr"){ + JButton btnReplaceFirstStr = new BackGroundButton("ReplaceFirst(Str)") { @Override protected void action() { @@ -963,8 +1029,42 @@ protected void action() { to = ""; } - replace = Pattern.quote(replace); - List content = Commons.getLinesFromTextArea(inputTextArea); + replace = Pattern.quote(replace);//输入的内容就完全是普通字符串,不再是正则表达式了 + List content = SwingUtils.getLinesFromTextArea(inputTextArea); + for (String item : content) { + item = item.replaceFirst(replace, to); + result.add(item); + } + outputTextArea.setText(String.join(System.lineSeparator(), result)); + } + } catch (Exception e1) { + outputTextArea.setText(e1.getMessage()); + e1.printStackTrace(stderr); + } + } + }; + + JButton btnReplaceFirstRegex = new BackGroundButton("ReplaceFirst(Regex)") { + + @Override + protected void action() { + try { + String replace = JOptionPane.showInputDialog("regex (from)", null); + String to = JOptionPane.showInputDialog("replacement (to)", null); + ArrayList result = new ArrayList(); + if (replace == null && to == null) { + return; + } else { + if (replace == null) { + replace = ""; + } + + if (to == null) { + to = ""; + } + + //replace = Pattern.quote(replace); + List content = SwingUtils.getLinesFromTextArea(inputTextArea); for (String item : content) { item = item.replaceFirst(replace, to); result.add(item); @@ -976,16 +1076,82 @@ protected void action() { e1.printStackTrace(stderr); } } + }; + + JButton btnReplaceAllStr = new BackGroundButton("ReplaceAll(Str)") { + + @Override + protected void action() { + try { + String replace = JOptionPane.showInputDialog("string (from)", null); + String to = JOptionPane.showInputDialog("replacement (to)", null); + ArrayList result = new ArrayList(); + if (replace == null && to == null) { + return; + } else { + if (replace == null) { + replace = ""; + } + + if (to == null) { + to = ""; + } + + List content = SwingUtils.getLinesFromTextArea(inputTextArea); + for (String item : content) { + item = item.replace(replace, to); + result.add(item); + } + outputTextArea.setText(String.join(System.lineSeparator(), result)); + } + } catch (Exception e1) { + outputTextArea.setText(e1.getMessage()); + e1.printStackTrace(stderr); + } + } + }; + + JButton btnReplaceAllRegex = new BackGroundButton("ReplaceAll(Regex)") { + + @Override + protected void action() { + try { + String replace = JOptionPane.showInputDialog("regex (from)", null); + String to = JOptionPane.showInputDialog("replacement (to)", null); + ArrayList result = new ArrayList(); + if (replace == null && to == null) { + return; + } else { + if (replace == null) { + replace = ""; + } + if (to == null) { + to = ""; + } + + List content = SwingUtils.getLinesFromTextArea(inputTextArea); + for (String item : content) { + item = item.replaceAll(replace, to); + result.add(item); + } + outputTextArea.setText(String.join(System.lineSeparator(), result)); + } + } catch (Exception e1) { + outputTextArea.setText(e1.getMessage()); + e1.printStackTrace(stderr); + } + } }; - JButton btnIPsToCIDR = new BackGroundButton("IPs To CIDR"){ + + JButton btnIPsToCIDR = new BackGroundButton("IPs To CIDR") { @Override protected void action() { try { - List IPs = Commons.getLinesFromTextArea(inputTextArea); + List IPs = SwingUtils.getLinesFromTextArea(inputTextArea); Set subnets = IPAddressUtils.toSmallerSubNets(new HashSet(IPs)); List tmplist = new ArrayList<>(subnets);//排序 @@ -1000,12 +1166,12 @@ protected void action() { }; - JButton btnCIDRToIPs = new BackGroundButton("CIDR To IPs"){ + JButton btnCIDRToIPs = new BackGroundButton("CIDR To IPs") { @Override protected void action() { try { - List subnets = Commons.getLinesFromTextArea(inputTextArea); + List subnets = SwingUtils.getLinesFromTextArea(inputTextArea); List IPs = IPAddressUtils.toIPList(subnets);// 当前所有title结果计算出的IP集合 outputTextArea.setText(String.join(System.lineSeparator(), IPs)); } catch (Exception e1) { @@ -1017,7 +1183,7 @@ protected void action() { }; - JButton unescapeJava = new BackGroundButton("UnescapeJava"){ + JButton unescapeJava = new BackGroundButton("UnescapeJava") { @Override protected void action() { @@ -1032,7 +1198,7 @@ protected void action() { }; - JButton unescapeHTML = new BackGroundButton("UnescapeHTML"){ + JButton unescapeHTML = new BackGroundButton("UnescapeHTML") { @Override protected void action() { @@ -1047,7 +1213,7 @@ protected void action() { }; - JButton ToUnicode = new BackGroundButton("To Unicode"){ + JButton ToUnicode = new BackGroundButton("To Unicode") { @Override protected void action() { @@ -1058,6 +1224,7 @@ protected void action() { e1.printStackTrace(stderr); } } + public String convertToUnicode(String text) { StringBuilder unicodeStringBuilder = new StringBuilder(); for (char c : text.toCharArray()) { @@ -1067,7 +1234,7 @@ public String convertToUnicode(String text) { } }; - JButton Base64ToFile = new BackGroundButton("Base64ToFile"){ + JButton Base64ToFile = new BackGroundButton("Base64ToFile") { @Override protected void action() { @@ -1110,7 +1277,7 @@ public File saveDialog() { }; - JButton splitButton = new BackGroundButton("Split"){ + JButton splitButton = new BackGroundButton("Split") { @Override protected void action() { @@ -1125,31 +1292,29 @@ protected void action() { }; - JButton combineButton = new BackGroundButton("Combine"){ + JButton combineButton = new BackGroundButton("Combine") { @Override protected void action() { String separator = JOptionPane.showInputDialog("input connect char", null); if (separator != null) {// && !separator.trim().equals("") - List items = Commons.getLinesFromTextArea(inputTextArea); + List items = SwingUtils.getLinesFromTextArea(inputTextArea); outputTextArea.setText(String.join(separator, items)); } } - }; - JButton toLowerCaseButton = new BackGroundButton("toLowerCase"){ + JButton toLowerCaseButton = new BackGroundButton("toLowerCase") { @Override protected void action() { outputTextArea.setText(inputTextArea.getText().toLowerCase()); } - }; - JButton OpenFileButton = new BackGroundButton("Open File"){ + JButton OpenFileButton = new BackGroundButton("Open File") { @Override protected void action() { @@ -1161,16 +1326,81 @@ protected void action() { statusLabel.setText("your input is not a valid path or file"); } } + }; + + JButton setRemoveAllButton = new BackGroundButton("Remove All(diff)") { + + @Override + protected void action() { + // 创建一个 JTextArea + JTextArea textArea = new JTextArea(10, 20); // 设置行数和列数 + // 将 JTextArea 放入 JScrollPane 中,以便可以滚动查看 + JScrollPane scrollPane = new JScrollPane(textArea); + // 显示包含 JTextArea 的对话框 + int result = JOptionPane.showOptionDialog( + null, // parentComponent + scrollPane, // message + "items to remove", // title + JOptionPane.OK_CANCEL_OPTION, // optionType + JOptionPane.PLAIN_MESSAGE, // messageType + null, // icon + null, // options + null // initialValue + ); + + // 处理用户输入 + if (result == JOptionPane.OK_OPTION) { + List itemsToRemove = SwingUtils.getLinesFromTextArea(textArea); + List items = SwingUtils.getLinesFromTextArea(inputTextArea); + items.removeAll(itemsToRemove); + outputTextArea.setText(String.join(System.lineSeparator(), items)); + } + } + }; + + JButton cartesianProductButton = new BackGroundButton("Cartesian Product") { + + @Override + protected void action() { + // 创建一个 JTextArea + JTextArea textArea = new JTextArea(10, 20); // 设置行数和列数 + // 将 JTextArea 放入 JScrollPane 中,以便可以滚动查看 + JScrollPane scrollPane = new JScrollPane(textArea); + // 显示包含 JTextArea 的对话框 + int result = JOptionPane.showOptionDialog( + null, // parentComponent + scrollPane, // message + "item list", // title + JOptionPane.OK_CANCEL_OPTION, // optionType + JOptionPane.PLAIN_MESSAGE, // messageType + null, // icon + null, // options + null // initialValue + ); + + // 处理用户输入 + if (result == JOptionPane.OK_OPTION) { + List out = new ArrayList<>(); + List items2 = SwingUtils.getLinesFromTextArea(textArea); + List items = SwingUtils.getLinesFromTextArea(inputTextArea); + for (String aa : items) { + for (String bb : items2) { + out.add(aa + bb); + } + } + outputTextArea.setText(String.join(System.lineSeparator(), out)); + } + } }; - JButton testButton = new BackGroundButton("test"){ + JButton testButton = new BackGroundButton("test") { @Override protected void action() { try { - outputTextArea.setText(WebIcon.getHash(inputTextArea.getText(),null)); + outputTextArea.setText(WebIcon.getHash(inputTextArea.getText(), null)); } catch (Exception e1) { outputTextArea.setText(e1.getMessage()); e1.printStackTrace(stderr); @@ -1179,14 +1409,14 @@ protected void action() { }; - JButton trimButton = new BackGroundButton("Trim/Strip"){ + JButton trimButton = new BackGroundButton("Trim/Strip") { @Override protected void action() { try { ArrayList result = new ArrayList(); - List items = Commons.getLinesFromTextArea(inputTextArea); - for (String item:items) { + List items = SwingUtils.getLinesFromTextArea(inputTextArea); + for (String item : items) { item = StringUtils.strip(item); result.add(item); } @@ -1217,25 +1447,21 @@ public void actionPerformed(ActionEvent e) { } } }); + */ - JButton JsonBeautify = new BackGroundButton("Beautify Json"); - - JsonBeautify.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + JButton JsonBeautify = new BackGroundButton("Beautify Json") { + protected void action() { String text = ((SuperJTextArea) inputTextArea).getTextAsDisplay(); try { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - String json = gson.toJson(text); - outputTextArea.setText(json); + outputTextArea.setText(JsonUtils.pretty(text)); } catch (Exception e1) { e1.printStackTrace(stderr); statusLabel.setText("your input is not a valid json"); } } - }); - */ + }; + //buttonPanel,里面放操作按钮 JPanel buttonPanel = new JPanel(); @@ -1260,7 +1486,12 @@ public void actionPerformed(ActionEvent e) { cloumnIndex = 0; buttonPanel.add(btnFindUrls, new bagLayout(++rowIndex, ++cloumnIndex)); - buttonPanel.add(btnFindUrls1, new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(btnFindUrlsWithProtocol, new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(btnFindUrlsInQuotes, new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(btnFindUrlsNotStartWithSlash, new bagLayout(rowIndex, ++cloumnIndex)); + + cloumnIndex = 0; + buttonPanel.add(btnFindUrlsNotStartWithSlashInQuotes, new bagLayout(++rowIndex, ++cloumnIndex)); buttonPanel.add(btnCleanUrl, new bagLayout(rowIndex, ++cloumnIndex)); cloumnIndex = 0; @@ -1275,10 +1506,10 @@ public void actionPerformed(ActionEvent e) { buttonPanel.add(btnFindEmail, new bagLayout(rowIndex, ++cloumnIndex)); cloumnIndex = 0; - buttonPanel.add(btnMasscanResultToNmap,new bagLayout(++rowIndex, ++cloumnIndex)); - buttonPanel.add(btnMasscanResultToHttp,new bagLayout(rowIndex, ++cloumnIndex)); - buttonPanel.add(btnNmapResultToHttp,new bagLayout(rowIndex, ++cloumnIndex)); - buttonPanel.add(btnNmapResultToHttp1,new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(btnMasscanResultToNmap, new bagLayout(++rowIndex, ++cloumnIndex)); + buttonPanel.add(btnMasscanResultToHttp, new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(btnNmapResultToHttp, new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(btnNmapResultToHttp1, new bagLayout(rowIndex, ++cloumnIndex)); cloumnIndex = 0; buttonPanel.add(btnGrepJson, new bagLayout(++rowIndex, ++cloumnIndex)); @@ -1289,8 +1520,8 @@ public void actionPerformed(ActionEvent e) { //网络请求类 cloumnIndex = 0; buttonPanel.add(btnOpenurls, new bagLayout(++rowIndex, ++cloumnIndex)); - buttonPanel.add(getIPAddressButton, new bagLayout(rowIndex, ++cloumnIndex)); - buttonPanel.add(grepChineseButton,new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(dnsQueryButton, new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(grepChineseButton, new bagLayout(rowIndex, ++cloumnIndex)); cloumnIndex = 0; buttonPanel.add(btnCertDomains, new bagLayout(++rowIndex, ++cloumnIndex)); @@ -1308,25 +1539,31 @@ public void actionPerformed(ActionEvent e) { cloumnIndex = 0; buttonPanel.add(removeDuplicate, new bagLayout(++rowIndex, ++cloumnIndex)); - buttonPanel.add(btnReplace, new bagLayout(rowIndex, ++cloumnIndex)); buttonPanel.add(trimButton, new bagLayout(rowIndex, ++cloumnIndex)); + cloumnIndex = 0; + buttonPanel.add(btnReplaceFirstStr, new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(btnReplaceFirstRegex, new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(btnReplaceAllStr, new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(btnReplaceAllRegex, new bagLayout(rowIndex, ++cloumnIndex)); cloumnIndex = 0; - buttonPanel.add(sort,new bagLayout(++rowIndex, ++cloumnIndex)); - buttonPanel.add(sortReverse,new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(sort, new bagLayout(++rowIndex, ++cloumnIndex)); + buttonPanel.add(sortReverse, new bagLayout(rowIndex, ++cloumnIndex)); buttonPanel.add(sortByLength, new bagLayout(rowIndex, ++cloumnIndex)); cloumnIndex = 0; buttonPanel.add(btnAddPrefix, new bagLayout(++rowIndex, ++cloumnIndex)); buttonPanel.add(btnRemovePrefix, new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(setRemoveAllButton, new bagLayout(rowIndex, ++cloumnIndex)); + buttonPanel.add(cartesianProductButton, new bagLayout(rowIndex, ++cloumnIndex)); cloumnIndex = 0; buttonPanel.add(unescapeJava, new bagLayout(++rowIndex, ++cloumnIndex)); buttonPanel.add(unescapeHTML, new bagLayout(rowIndex, ++cloumnIndex)); buttonPanel.add(ToUnicode, new bagLayout(rowIndex, ++cloumnIndex)); //buttonPanel.add(JsonSimplify, new bagLayout(rowIndex, ++cloumnIndex) ); - //buttonPanel.add(JsonBeautify, new bagLayout(rowIndex, ++cloumnIndex) ); + buttonPanel.add(JsonBeautify, new bagLayout(rowIndex, ++cloumnIndex) ); cloumnIndex = 0; buttonPanel.add(toLowerCaseButton, new bagLayout(++rowIndex, ++cloumnIndex)); @@ -1338,17 +1575,9 @@ public void actionPerformed(ActionEvent e) { buttonPanel.add(OpenFileButton, new bagLayout(++rowIndex, ++cloumnIndex)); buttonPanel.add(testButton, new bagLayout(rowIndex, ++cloumnIndex)); - return buttonPanel; } - public static Set getSetFromTextArea(JTextArea textarea) { - //user input maybe use "\n" in windows, so the System.lineSeparator() not always works fine! - Set domainList = new HashSet<>(Arrays.asList(textarea.getText().replaceAll(" ", "").replaceAll("\r\n", "\n").split("\n"))); - domainList.remove(""); - return domainList; - } - public static String getContentFromFile(String filename) { File tmpfile = new File(filename); if (tmpfile.exists() && tmpfile.isFile()) { diff --git a/src/Tools/portScanner.java b/src/Tools/portScanner.java index c9da590d..93f63957 100644 --- a/src/Tools/portScanner.java +++ b/src/Tools/portScanner.java @@ -7,6 +7,7 @@ import java.nio.charset.Charset; import java.util.List; +import com.bit4woo.utilbox.utils.SystemUtils; import org.apache.commons.io.FileUtils; import base.Commons; @@ -95,7 +96,7 @@ public static void findAbsolutePath(String cmd) throws Exception { //linux which //mac which where - if (Commons.isWindows()) { + if (SystemUtils.isWindows()) { cmd = "where "+cmd; }else { cmd = "which "+cmd; diff --git a/src/base/Commons.java b/src/base/Commons.java index ada7d24b..4dc8e29d 100644 --- a/src/base/Commons.java +++ b/src/base/Commons.java @@ -1,55 +1,16 @@ package base; -import java.awt.Component; -import java.awt.Desktop; -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.StringSelection; -import java.io.File; -import java.io.IOException; +import burp.IHttpRequestResponse; +import org.apache.commons.lang3.StringUtils; + import java.net.MalformedURLException; -import java.net.URI; import java.net.URL; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; import java.util.Date; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.swing.JOptionPane; -import javax.swing.JTextArea; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.net.util.SubnetUtils; - -import com.ibm.icu.text.CharsetDetector; -import com.ibm.icu.text.CharsetMatch; - -import burp.BurpExtender; -import burp.HelperPlus; -import burp.IExtensionHelpers; -import burp.IHttpRequestResponse; public class Commons { - public static String set2string(Set set){ - Iterator iter = set.iterator(); - StringBuilder result = new StringBuilder(); - while(iter.hasNext()) - { - //System.out.println(iter.next()); - result.append(iter.next()).append("\n"); - } - return result.toString(); - } - public static boolean isResponseNull(IHttpRequestResponse message){ try { int x = message.getResponse().length; @@ -60,25 +21,6 @@ public static boolean isResponseNull(IHttpRequestResponse message){ } } - /** - * 对于信息收集来说,没有用的文件 - * js是有用的 - * pdf\doc\excel等也是有用的,可以收集到其中的域名 - * rar\zip文件即使其中包含了有用信息,是无法直接读取的 - * @param urlpath - * @return - */ - public static boolean uselessExtension(String urlpath) { - String extensions = "css|jpeg|gif|jpg|png|rar|zip|svg|jpeg|ico|woff|woff2|ttf|otf"; - String[] extList = extensions.split("\\|"); - for ( String item:extList) { - if(urlpath.endsWith("."+item)) { - return true; - } - } - return false; - } - public static String getNowTimeString() { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); @@ -97,201 +39,6 @@ public static int getNowMinute(){ return cal.get(Calendar.MINUTE); } - public static void browserOpen(Object url,String browser) throws Exception{ - String urlString = null; - URI uri = null; - if (url instanceof String) { - urlString = (String) url; - uri = new URI((String)url); - }else if (url instanceof URL) { - uri = ((URL)url).toURI(); - urlString = url.toString(); - } - if(browser == null ||browser.equalsIgnoreCase("default") || browser.equalsIgnoreCase("")) { - //whether null must be the first - Desktop desktop = Desktop.getDesktop(); - if(Desktop.isDesktopSupported()&&desktop.isSupported(Desktop.Action.BROWSE)){ - desktop.browse(uri); - } - }else { - String[] cmdArray = new String[] {browser,urlString}; - - //runtime.exec(browser+" "+urlString);//当命令中有空格时会有问题 - Runtime.getRuntime().exec(cmdArray); - } - } - - - public static byte[] buildCookieRequest(IExtensionHelpers helpers,String cookie, byte[] request) { - if (StringUtils.isNotEmpty(cookie)){ - if (!cookie.startsWith("Cookie: ")){ - cookie = "Cookie: "+cookie; - } - List newHeader = helpers.analyzeRequest(request).getHeaders(); - int bodyOffset = helpers.analyzeRequest(request).getBodyOffset(); - byte[] byte_body = Arrays.copyOfRange(request, bodyOffset, request.length); - newHeader.add(cookie); - request = helpers.buildHttpMessage(newHeader,byte_body); - } - return request; - } - /** - * 尝试在响应包中寻找meta charset的标签,来判别响应包的编码 - * - * 一些常见格式: - * - - - - - - - - */ - static String detectCharsetInBody(byte[] requestOrResponse){ - String body = new String(requestOrResponse); - if (body.split("\r\n\r\n").length >=2 ) { - body = body.split("\r\n\r\n")[1]; - } - if (body.length() >1000) { - body = body.substring(0,1000); - } - String pattern = "charset=(.*?)[\"/\\s>]+";//加? 非贪婪模式 - //String patternExtract = "charset=(.*?)>"; - - Pattern metaCharset = Pattern.compile(pattern); - Matcher matcher = metaCharset.matcher(body); - //System.out.println(body); - if (matcher.find()) {//多次查找 - String charset = matcher.group(1); - return charset; - } - return null; - } - - /** - * utf8 utf-8都是可以的。 - * @param requestOrResponse - * @return - */ - public static String detectCharset(byte[] requestOrResponse){ - IExtensionHelpers helpers = BurpExtender.getCallbacks().getHelpers(); - HelperPlus getter = new HelperPlus(helpers); - boolean isRequest = true; - if (new String(requestOrResponse).startsWith("HTTP/")) {//response - isRequest = false; - } - - String contentType = getter.getHeaderValueOf(isRequest,requestOrResponse,"Content-Type"); - - //1、尝试从contentTpye中获取 - if (contentType != null){ - if (contentType.toLowerCase().contains("charset=")) { - String tmpcharSet = contentType.toLowerCase().split("charset=")[1]; - if (tmpcharSet.contains(",")) { - tmpcharSet = tmpcharSet.split(",")[0]; - } - if (tmpcharSet != null && tmpcharSet.length() >0) { - return tmpcharSet; - } - } - } - - if (!isRequest) { - String tmpCharset = detectCharsetInBody(requestOrResponse); - System.out.println("响应包中编码识别结果:"+tmpCharset); - if (null != tmpCharset) { - return tmpCharset; - } - } - - - //2、尝试使用ICU4J进行编码的检测 - CharsetDetector detector = new CharsetDetector(); - detector.setText(requestOrResponse); - CharsetMatch cm = detector.detect(); - System.out.println("ICU4J检测到编码:"+cm.getName()); - if (cm != null) { - return cm.getName(); - } - - //3、http post的默认编码 - return "ISO-8859-1"; - } - - - public static List Port_prompt(Component prompt, String str){ - String defaultPorts = "8080,8000,8443"; - String user_input = JOptionPane.showInputDialog(prompt, str,defaultPorts); - if (StringUtils.isEmpty(user_input)) return null; - List portList = new ArrayList(); - for (String port: user_input.trim().split(",")) { - int portint = Integer.parseInt(port); - portList.add(portint); - } - return portList; - } - - public static boolean isWindows() { - String OS_NAME = System.getProperties().getProperty("os.name").toLowerCase(); - if (OS_NAME.contains("windows")) { - return true; - } else { - return false; - } - } - - public static ArrayList regexFind(String regex,String content) { - ArrayList result = new ArrayList(); - Pattern pRegex = Pattern.compile(regex); - Matcher matcher = pRegex.matcher(content); - while (matcher.find()) {//多次查找 - result.add(matcher.group()); - } - return result; - } - - public static String replaceLast(String string, String toReplace, String replacement) { - int pos = string.lastIndexOf(toReplace); - if (pos > -1) { - return string.substring(0, pos) - + replacement - + string.substring(pos + toReplace.length()); - } else { - return string; - } - } - - - public static void writeToClipboard(String text) { - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - StringSelection selection = new StringSelection(text); - clipboard.setContents(selection, null); - } - - public static boolean isWindows10() { - String OS_NAME = System.getProperties().getProperty("os.name").toLowerCase(); - if (OS_NAME.equalsIgnoreCase("windows 10")) { - return true; - } - return false; - } - - public static boolean isMac(){ - String os = System.getProperty("os.name").toLowerCase(); - //Mac - return (os.indexOf( "mac" ) >= 0); - } - - public static boolean isUnix(){ - String os = System.getProperty("os.name").toLowerCase(); - //linux or unix - return (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0); - } - - public static void OpenFolder(String path) throws IOException { - Desktop.getDesktop().open(new File(path)); - } /* *将形如 https://www.runoob.com的URL统一转换为 @@ -322,130 +69,7 @@ public static String formateURLString(String urlString) { } return urlString; } - - public static Set getSetFromTextArea(JTextArea textarea) { - Set domainList = new HashSet<>(textToLines(textarea.getText())); - domainList.remove(""); - return domainList; - } - - public static List getLinesFromTextArea(JTextArea textarea){ - return textToLines(textarea.getText()); - } - - - /** - * 换行符的可能性有三种,都必须考虑到 - * @param input - * @return - */ - public static List textToLines(String input){ - String[] lines = input.split("(\r\n|\r|\n)", -1); - List result = new ArrayList(); - for(String line: lines) { - line = line.trim(); - if (!line.equalsIgnoreCase("")) { - result.add(line.trim()); - } - } - return result; - } - - - public static List removePrefixAndSuffix(List input,String Prefix,String Suffix) { - ArrayList result = new ArrayList(); - if (Prefix == null && Suffix == null) { - return result; - } else { - if (Prefix == null) { - Prefix = ""; - } - - if (Suffix == null) { - Suffix = ""; - } - - List content = input; - for (String item:content) { - if (item.startsWith(Prefix)) { - //https://stackoverflow.com/questions/17225107/convert-java-string-to-string-compatible-with-a-regex-in-replaceall - String tmp = Pattern.quote(Prefix);//自动实现正则转义 - item = item.replaceFirst(tmp, ""); - } - if (item.endsWith(Suffix)) { - String tmp = Pattern.quote(reverse(Suffix));//自动实现正则转义 - item = reverse(item).replaceFirst(tmp, ""); - item = reverse(item); - } - result.add(item); - } - return result; - } - } - - public static String reverse(String str) { - if (str == null) { - return null; - } - return new StringBuffer(str).reverse().toString(); - } - - public static void test1() { - SubnetUtils net = new SubnetUtils("143.92.67.34/24"); - System.out.println(net.getInfo().isInRange("143.92.67.34:6443")); - } - public static void test2() { - Set IPSet = new HashSet(); - IPSet.add("192.168.1.225"); - IPSet.add("192.168.1.128"); - IPSet.add("192.168.1.129"); - IPSet.add("192.168.1.155"); - IPSet.add("192.168.1.224"); - IPSet.add("192.168.1.130"); - - } - - public static void test4() { - String Prefix = "\""; - // String Prefix = Pattern.quote("\""); - System.out.println(Prefix); - System.out.println("\"aaaa\"".replaceFirst(Prefix, "")); - } - - public static void test5() { - String aa = "10.12.12.12/"; - System.out.println(aa.split("/").length); - } - - public static void test6() { - String aa = "10. 12. 12.12/"; - System.out.println(aa.trim()); - } - - public static void test8() { - System.out.println(uselessExtension("abc.css")); - } - - public static void test9() throws Exception { - byte[] body = FileUtils.readFileToByteArray(new File("/private/tmp/response.html")); - System.out.println(detectCharsetInBody(body)); - } - - public static void test10() throws IOException { - System.out.println(detectCharsetInBody(FileUtils.readFileToByteArray(new File("F://response.txt")))); - } - - public static void testCharset() { - String aaa = "\n" - + " \n" - + " The page is not found\n" - + " \n" - + "