diff --git a/src/InternetSearch/APISearchAction.java b/src/InternetSearch/APISearchAction.java index 09146586..a59369f9 100644 --- a/src/InternetSearch/APISearchAction.java +++ b/src/InternetSearch/APISearchAction.java @@ -7,7 +7,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import javax.swing.AbstractAction; @@ -18,6 +17,7 @@ import org.apache.commons.lang3.StringUtils; +import com.bit4woo.utilbox.utils.DomainUtils; import com.bit4woo.utilbox.utils.IPAddressUtils; import InternetSearch.Client.FoFaClient; @@ -95,75 +95,50 @@ public APISearchAction(AbstractTableModel lineModel, int[] modelRows, int column @Override public final void actionPerformed(ActionEvent e) { - SwingWorker worker = new SwingWorker() { - @Override - protected Map doInBackground() throws Exception { - - Set toSearch = new HashSet<>(); - for (int row : modelRows) { - - String searchType = null; - String searchContent = null; - - if (lineModel.getClass().equals(LineTableModel.class)) { - InfoTuple result = ((LineTableModel) lineModel).getSearchTypeAndValue(row, - columnIndex); - searchType = result.first; - searchContent = result.second; - } + Set toSearch = new HashSet<>(); + for (int row : modelRows) { - if (lineModel.getClass().equals(SearchTableModel.class)) { - InfoTuple result = ((SearchTableModel) lineModel).getSearchTypeAndValue(row, - columnIndex); - searchType = result.first; - searchContent = result.second; - } - - if (lineModel.getClass().equals(TargetTableModel.class)) { - InfoTuple result = ((TargetTableModel) lineModel).getSearchTypeAndValue(row, - columnIndex); - searchType = result.first; - searchContent = result.second; - } + String searchType = null; + String searchContent = null; - ToSearchItem item = new ToSearchItem(searchType, searchContent); + if (lineModel.getClass().equals(LineTableModel.class)) { + InfoTuple result = ((LineTableModel) lineModel).getSearchTypeAndValue(row, + columnIndex); + searchType = result.first; + searchContent = result.second; + } - toSearch.add(item); - } + if (lineModel.getClass().equals(SearchTableModel.class)) { + InfoTuple result = ((SearchTableModel) lineModel).getSearchTypeAndValue(row, + columnIndex); + searchType = result.first; + searchContent = result.second; + } - if (toSearch.size() >= 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; - } + if (lineModel.getClass().equals(TargetTableModel.class)) { + InfoTuple result = ((TargetTableModel) lineModel).getSearchTypeAndValue(row, + columnIndex); + searchType = result.first; + searchContent = result.second; + } - // 把耗时操作放在最后。 - for (ToSearchItem item : toSearch) { - // 可能存在,一个搜索结果还未显示,又有另外一次相同内容搜索出现的情况。但是影响不大,就不管了 - String tabname = item.getTabName(); - if (searchedContent.add(tabname)) { - // 保证单次操作,不对相同项进行重复搜索 - DoSearchAllInOn(item.getSearchType(), item.getSearchContent(), APISearchAction.this.engineList); - System.out.println("begin search " + tabname); - BurpExtender.getStdout().println("begin search " + tabname); - } else { - System.out.println("skip search " + tabname); - BurpExtender.getStdout().println("skip search " + tabname); - // skip后,重新将tab的颜色改回来,以便提示这个tab被再次搜索了 - BurpExtender.getGui().getSearchPanel().changeTabColor(tabname, Color.WHITE); - } - } + ToSearchItem item = new ToSearchItem(searchType, searchContent); - return null; - } + toSearch.add(item); + } - @Override - protected void done() { + if (toSearch.size() >= 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; + } - } - }; - worker.execute(); + // 把耗时操作放在最后。 + for (ToSearchItem item : toSearch) { + // 可能存在,一个搜索结果还未显示,又有另外一次相同内容搜索出现的情况。但是影响不大,就不管了 + DoSearchAllInOnAtBackGround(item.getSearchType(), item.getSearchContent(), APISearchAction.this.engineList); + } } public static List DoSearch(String searchType, String searchContent, String engine) { @@ -194,7 +169,53 @@ public static List DoSearch(String searchType, String searchC // https://api.hunter.io/v2/domain-search?domain=intercom.com return entries; } + + + public static void DoSearchAllInOnAtBackGround(String search_Type, String content, List engineList) { + + String searchType; + if (search_Type == null) { + if (DomainUtils.isValidDomainNoPort(content)) { + searchType = SearchType.SubDomain; + } else if (IPAddressUtils.isValidIPv4NoPort(content)) { + searchType = SearchType.IP; + } else { + searchType = SearchType.OriginalString; + } + }else { + searchType = search_Type; + } + + //避免重复搜索的逻辑 + String tabname = String.format("%s(%s)", searchType, content); + if (searchedContent.add(tabname)) { + // 保证单次操作,不对相同项进行重复搜索 + System.out.println("begin search " + tabname); + BurpExtender.getStdout().println("begin search " + tabname); + } else { + System.out.println("skip search " + tabname); + BurpExtender.getStdout().println("skip search " + tabname); + // skip后,重新将tab的颜色改回来,以便提示这个tab被再次搜索了 + BurpExtender.getGui().getSearchPanel().changeTabColor(tabname, Color.WHITE); + return; + } + + SwingWorker worker = new SwingWorker() { + @Override + protected Void doInBackground() throws Exception { + DoSearchAllInOn(searchType, content, engineList, true, false); + return null; + } + + @Override + protected void done() { + + } + }; + worker.execute(); + } + /** * 多个搜索引擎 进行同类型搜索时使用,比如都搜索子域名 * @@ -203,16 +224,19 @@ public static List DoSearch(String searchType, String searchC * @param engineList * @return */ - public static List DoSearchAllInOn(String searchType, String content, List engineList) { + @Deprecated //使用 DoSearchAllInOnAtBackGround() 方法,不要直接调用这个方法 + private static List DoSearchAllInOn(String searchType, String content, List engineList) { return DoSearchAllInOn(searchType, content, engineList, true, false); } - public static List DoSearchAllInOn(String searchType, String content, List engineList, + @Deprecated //使用 DoSearchAllInOnAtBackGround() 方法,不要直接调用这个方法 + private static List DoSearchAllInOn(String searchType, String content, List engineList, boolean showInGUI, boolean autoAddToTarget) { if (StringUtils.isEmpty(content) || StringUtils.isEmpty(searchType)) { BurpExtender.getStderr().print("nothing to search..."); return null; } + List entries = new ArrayList<>(); for (String engine : engineList) { diff --git a/src/InternetSearch/Client/HunterClient.java b/src/InternetSearch/Client/HunterClient.java index 0c22ae98..5b3f4fd5 100644 --- a/src/InternetSearch/Client/HunterClient.java +++ b/src/InternetSearch/Client/HunterClient.java @@ -104,6 +104,10 @@ public boolean hasNextPage(String respbody, int currentPage) { @Override public String buildSearchUrl(String searchContent, int page) { String key = ConfigManager.getStringConfigByKey(ConfigName.QianxinHunterAPIKey); + if (StringUtils.isEmpty(key)) { + stderr.println(ConfigName.QianxinHunterAPIKey+" not configurated!"); + return null; + } String domainBase64 = new String(Base64.getEncoder().encode(searchContent.getBytes())); String url = String.format( "https://hunter.qianxin.com/openApi/search?&api-key=%s&search=%s&page=%s&page_size=100", key, diff --git a/src/InternetSearch/SearchPanel.java b/src/InternetSearch/SearchPanel.java index e628262c..53075329 100644 --- a/src/InternetSearch/SearchPanel.java +++ b/src/InternetSearch/SearchPanel.java @@ -300,33 +300,6 @@ public Set getAlreadySearchContent() { return result; } - public static void searchAtBackground(String content) { - SwingWorker worker = new SwingWorker() { - @Override - protected Void doInBackground() throws Exception { - String searchType = null; - - if (DomainUtils.isValidDomainNoPort(content)) { - searchType = SearchType.SubDomain; - } else if (IPAddressUtils.isValidIPv4NoPort(content)) { - searchType = SearchType.IP; - } else { - searchType = SearchType.OriginalString; - } - - APISearchAction.DoSearchAllInOn(searchType, content, SearchEngine.getAssetSearchEngineList()); - - return null; - } - - @Override - protected void done() { - - } - }; - worker.execute(); - } - public JPanel createButtonPanel() { JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); @@ -339,7 +312,7 @@ public JPanel createButtonPanel() { buttonSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String content = textFieldSearch.getText(); - searchAtBackground(content); + APISearchAction.DoSearchAllInOnAtBackGround(null, content, SearchEngine.getAssetSearchEngineList()); } }); buttonPanel.add(buttonSearch); @@ -347,37 +320,25 @@ public void actionPerformed(ActionEvent e) { JButton buttonSearchAs = new JButton("Search As"); buttonSearchAs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - 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); - } - } - default: - APISearchAction.DoSearchAllInOn(searchType, content, - SearchEngine.getAssetSearchEngineList()); - } - return null; - } - - @Override - protected void done() { + String content = textFieldSearch.getText(); + String searchType = SearchType.choseSearchType(); + switch (searchType) { + case SearchType.Email: + APISearchAction.DoSearchAllInOnAtBackGround(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); + } } - }; - worker.execute(); + default: + APISearchAction.DoSearchAllInOnAtBackGround(searchType, content, + SearchEngine.getAssetSearchEngineList()); + } } }); buttonPanel.add(buttonSearchAs); diff --git a/src/InternetSearch/SearchResultEntryMenu.java b/src/InternetSearch/SearchResultEntryMenu.java index 90683087..b877d7d6 100644 --- a/src/InternetSearch/SearchResultEntryMenu.java +++ b/src/InternetSearch/SearchResultEntryMenu.java @@ -294,7 +294,7 @@ protected Object doInBackground() throws Exception { this.add(openURLwithBrowserItem); this.add(genPortScanCmd); - + //搜索 this.addSeparator(); SearchEngine.AddSearchMenuItems(this, searchTableModel, modelRows, columnIndex); this.addSeparator(); diff --git a/src/Tools/TextAreaMenu.java b/src/Tools/TextAreaMenu.java index beef6b9d..353a0b8b 100644 --- a/src/Tools/TextAreaMenu.java +++ b/src/Tools/TextAreaMenu.java @@ -16,7 +16,8 @@ import com.bit4woo.utilbox.utils.TextUtils; import GUI.GUIMain; -import InternetSearch.SearchPanel; +import InternetSearch.APISearchAction; +import InternetSearch.SearchEngine; import burp.BurpExtender; import config.ConfigManager; import config.ConfigName; @@ -171,7 +172,10 @@ public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) { for (String item:selectedItems) { try { - SearchPanel.searchAtBackground(item); + //逻辑和search按钮一样 InternetSearch.SearchPanel.createButtonPanel() + + APISearchAction.DoSearchAllInOnAtBackGround(null, item, SearchEngine.getAssetSearchEngineList()); + } catch (Exception e2) { e2.printStackTrace(stderr); }