Skip to content

Commit

Permalink
搜索逻辑更新
Browse files Browse the repository at this point in the history
  • Loading branch information
bit4woo committed Dec 24, 2024
1 parent a37f87d commit 0c109c8
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 124 deletions.
152 changes: 88 additions & 64 deletions src/InternetSearch/APISearchAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -95,75 +95,50 @@ public APISearchAction(AbstractTableModel lineModel, int[] modelRows, int column

@Override
public final void actionPerformed(ActionEvent e) {
SwingWorker<Map, Map> worker = new SwingWorker<Map, Map>() {
@Override
protected Map doInBackground() throws Exception {

Set<ToSearchItem> toSearch = new HashSet<>();
for (int row : modelRows) {

String searchType = null;
String searchContent = null;

if (lineModel.getClass().equals(LineTableModel.class)) {
InfoTuple<String, String> result = ((LineTableModel) lineModel).getSearchTypeAndValue(row,
columnIndex);
searchType = result.first;
searchContent = result.second;
}
Set<ToSearchItem> toSearch = new HashSet<>();
for (int row : modelRows) {

if (lineModel.getClass().equals(SearchTableModel.class)) {
InfoTuple<String, String> result = ((SearchTableModel) lineModel).getSearchTypeAndValue(row,
columnIndex);
searchType = result.first;
searchContent = result.second;
}

if (lineModel.getClass().equals(TargetTableModel.class)) {
InfoTuple<String, String> 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<String, String> result = ((LineTableModel) lineModel).getSearchTypeAndValue(row,
columnIndex);
searchType = result.first;
searchContent = result.second;
}

toSearch.add(item);
}
if (lineModel.getClass().equals(SearchTableModel.class)) {
InfoTuple<String, String> 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<String, String> 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<SearchResultEntry> DoSearch(String searchType, String searchContent, String engine) {
Expand Down Expand Up @@ -194,7 +169,53 @@ public static List<SearchResultEntry> 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<String> 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<Void, Void> worker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
DoSearchAllInOn(searchType, content, engineList, true, false);
return null;
}

@Override
protected void done() {

}
};
worker.execute();
}


/**
* 多个搜索引擎 进行同类型搜索时使用,比如都搜索子域名
*
Expand All @@ -203,16 +224,19 @@ public static List<SearchResultEntry> DoSearch(String searchType, String searchC
* @param engineList
* @return
*/
public static List<SearchResultEntry> DoSearchAllInOn(String searchType, String content, List<String> engineList) {
@Deprecated //使用 DoSearchAllInOnAtBackGround() 方法,不要直接调用这个方法
private static List<SearchResultEntry> DoSearchAllInOn(String searchType, String content, List<String> engineList) {
return DoSearchAllInOn(searchType, content, engineList, true, false);
}

public static List<SearchResultEntry> DoSearchAllInOn(String searchType, String content, List<String> engineList,
@Deprecated //使用 DoSearchAllInOnAtBackGround() 方法,不要直接调用这个方法
private static List<SearchResultEntry> DoSearchAllInOn(String searchType, String content, List<String> engineList,
boolean showInGUI, boolean autoAddToTarget) {
if (StringUtils.isEmpty(content) || StringUtils.isEmpty(searchType)) {
BurpExtender.getStderr().print("nothing to search...");
return null;
}

List<SearchResultEntry> entries = new ArrayList<>();

for (String engine : engineList) {
Expand Down
4 changes: 4 additions & 0 deletions src/InternetSearch/Client/HunterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
75 changes: 18 additions & 57 deletions src/InternetSearch/SearchPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,33 +300,6 @@ public Set<String> getAlreadySearchContent() {
return result;
}

public static void searchAtBackground(String content) {
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
@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));
Expand All @@ -339,45 +312,33 @@ 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);

JButton buttonSearchAs = new JButton("Search As");
buttonSearchAs.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
@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);
Expand Down
2 changes: 1 addition & 1 deletion src/InternetSearch/SearchResultEntryMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions src/Tools/TextAreaMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 0c109c8

Please sign in to comment.