Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bit4woo committed Oct 27, 2024
1 parent 910a9c8 commit fc556fe
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 164 deletions.
40 changes: 23 additions & 17 deletions src/InternetSearch/Client/FoFaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,27 @@ public List<SearchResultEntry> parseResp(String respbody) {
// host,ip,domain,port,protocol,server
// ["www.xxx.com","11.11.11.11","xxx.com","80","http","nginx/1.20.1"]
SearchResultEntry entry = new SearchResultEntry();
entry.setHost(parts.getString(0));
entry.getIPSet().add(parts.getString(1));
entry.setRootDomain(parts.getString(2));
entry.setPort(Integer.parseInt(parts.getString(3)));
entry.setProtocol(parts.getString(4));
entry.setWebcontainer(parts.getString(5));
entry.setTitle(parts.getString(6));

try {
entry.setAsnNum(Integer.parseInt(parts.getString(7)));
} catch (Exception e) {
entry.setHost(parts.getString(0));
entry.getIPSet().add(parts.getString(1));
entry.setRootDomain(parts.getString(2));
entry.setPort(Integer.parseInt(parts.getString(3)));
entry.setProtocol(parts.getString(4));
entry.setWebcontainer(parts.getString(5));
entry.setTitle(parts.getString(6));
try {
entry.setAsnNum(Integer.parseInt(parts.getString(7)));
} catch (Exception e) {

}
entry.setASNInfo(parts.getString(8));
entry.setSource(getEngineName());
result.add(entry);
} catch (Exception e) {
e.printStackTrace(stderr);
stderr.println(parts.toString());
}
entry.setASNInfo(parts.getString(8));
entry.setSource(getEngineName());
result.add(entry);
}
return result;
}
Expand All @@ -61,15 +67,15 @@ public List<SearchResultEntry> parseResp(String respbody) {
}

@Override
public boolean hasNextPage(String respbody,int currentPage) {
public boolean hasNextPage(String respbody, int currentPage) {
// "size":83,"page":1,
try {
ArrayList<String> result = JsonUtils.grepValueFromJson(respbody, "size");
if (result.size() >= 1) {
int total = Integer.parseInt(result.get(0));
if (total > currentPage * 2000) {//size=2000
if (total > currentPage * 2000) {// size=2000
return true;
}
}
}
} catch (Exception e) {
e.printStackTrace(stderr);
Expand All @@ -78,7 +84,7 @@ public boolean hasNextPage(String respbody,int currentPage) {
}

/*
https://en.fofa.info/api
* https://en.fofa.info/api
*/
@Override
public String buildSearchUrl(String searchContent, int page) {
Expand All @@ -89,7 +95,7 @@ public String buildSearchUrl(String searchContent, int page) {
return null;
}
searchContent = new String(Base64.getEncoder().encode(searchContent.getBytes()));
//[820001] 没有权限搜索icon_hash字段
// [820001] 没有权限搜索icon_hash字段
String url = String.format(
"https://fofa.info/api/v1/search/all?email=%s&key=%s&page=1&size=2000&fields=host,ip,domain,port,protocol,server,title,as_number,as_organization&qbase64=%s",
email, key, searchContent);
Expand Down
58 changes: 31 additions & 27 deletions src/InternetSearch/Client/HunterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

public class HunterClient extends BaseClient {


@Override
public String getEngineName() {
return SearchEngine.QIANXIN_HUNTER;
Expand All @@ -32,42 +31,47 @@ public List<SearchResultEntry> parseResp(String respbody) {
try {
JSONObject obj = new JSONObject(respbody);
int code = obj.getInt("code");
if (code ==200 || code ==40205) {
if (code == 200 || code == 40205) {
JSONObject data = obj.getJSONObject("data");
if (!data.get("arr").toString().equals("null")) {
//"arr":null 这里有点反直觉
// "arr":null 这里有点反直觉
JSONArray items = data.getJSONArray("arr");
for (Object item : items) {
JSONObject entryitem = (JSONObject) item;
SearchResultEntry entry = new SearchResultEntry();

String url = entryitem.getString("url");
String ip = entryitem.getString("ip");
if (StringUtils.isNotEmpty(url)) {
entry.setHost(url);
}else {
entry.setHost(ip);
}
try {
String url = entryitem.getString("url");
String ip = entryitem.getString("ip");
if (StringUtils.isNotEmpty(url)) {
entry.setHost(url);
} else {
entry.setHost(ip);
}

entry.getIPSet().add(ip);
entry.setRootDomain(entryitem.getString("domain"));
entry.setPort(entryitem.getInt("port"));
entry.setProtocol(entryitem.getString("protocol"));
entry.getIPSet().add(ip);
entry.setRootDomain(entryitem.getString("domain"));
entry.setPort(entryitem.getInt("port"));
entry.setProtocol(entryitem.getString("protocol"));

String component =entryitem.get("component").toString();
try {
ArrayList<String> names = JsonUtils.grepValueFromJson(component, "name");
entry.setWebcontainer(String.join(",",names));
} catch (JSONException e) {
entry.setWebcontainer(component);
String component = entryitem.get("component").toString();
try {
ArrayList<String> names = JsonUtils.grepValueFromJson(component, "name");
entry.setWebcontainer(String.join(",", names));
} catch (JSONException e) {
entry.setWebcontainer(component);
}
entry.setTitle(entryitem.getString("web_title"));
entry.setASNInfo(entryitem.getString("as_org"));
entry.setSource(getEngineName());
result.add(entry);
} catch (Exception e) {
e.printStackTrace(stderr);
stderr.println(entryitem.toString());
}
entry.setTitle(entryitem.getString("web_title"));
entry.setASNInfo(entryitem.getString("as_org"));
entry.setSource(getEngineName());
result.add(entry);
}
return result;
}
return result;
}
} catch (Exception e) {
e.printStackTrace(stderr);
Expand All @@ -77,14 +81,14 @@ public List<SearchResultEntry> parseResp(String respbody) {
}

@Override
public boolean hasNextPage(String respbody,int currentPage) {
public boolean hasNextPage(String respbody, int currentPage) {
try {
ArrayList<String> result = JsonUtils.grepValueFromJson(respbody, "total");
if (result.size() >= 1) {
int total = Integer.parseInt(result.get(0));
if (total > currentPage * 100) {
return true;
}
}
}
} catch (Exception e) {
e.printStackTrace(stderr);
Expand Down
88 changes: 41 additions & 47 deletions src/InternetSearch/Client/QuakeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,68 +36,62 @@ public List<SearchResultEntry> parseResp(String respbody) {
if (code.equals("0")) {
JSONArray results = obj.getJSONArray("data");
for (Object item : results) {

JSONObject entryitem = (JSONObject) item;

SearchResultEntry entry = new SearchResultEntry();

try {
entry.getIPSet().add(entryitem.getString("ip"));
} catch (Exception e1) {
e1.printStackTrace();
}

try {
entry.setRootDomain(entryitem.getString("domain"));
} catch (Exception e1) {
e1.printStackTrace();
}

int port = entryitem.getInt("port");
entry.setPort(port);

String serviceName = entryitem.getJSONObject("service").getString("name");
String protocol;
if (serviceName.equalsIgnoreCase("http/ssl")) {
protocol = "https";
} else if (serviceName.equalsIgnoreCase("http")) {
protocol = "http";
} else {
protocol = serviceName;
}
int port = entryitem.getInt("port");
entry.setPort(port);

String serviceName = entryitem.getJSONObject("service").getString("name");
String protocol;
if (serviceName.equalsIgnoreCase("http/ssl")) {
protocol = "https";
} else if (serviceName.equalsIgnoreCase("http")) {
protocol = "http";
} else {
protocol = serviceName;
}

entry.setProtocol(protocol);
entry.setProtocol(protocol);

if (serviceName.equalsIgnoreCase("http/ssl") || serviceName.equalsIgnoreCase("http")) {
String host = entryitem.getJSONObject("service").getJSONObject("http").getString("host");
String server = entryitem.getJSONObject("service").getJSONObject("http").getString("server");
String title = entryitem.getJSONObject("service").getJSONObject("http").getString("title");
if (serviceName.equalsIgnoreCase("http/ssl") || serviceName.equalsIgnoreCase("http")) {
String host = entryitem.getJSONObject("service").getJSONObject("http").getString("host");
String server = entryitem.getJSONObject("service").getJSONObject("http")
.getString("server");
String title = entryitem.getJSONObject("service").getJSONObject("http").getString("title");

entry.setHost(host);
entry.setWebcontainer(server);
entry.setTitle(title);
} else {
entry.setHost(entryitem.getString("domain"));
}
entry.setHost(host);
entry.setWebcontainer(server);
entry.setTitle(title);
} else {
entry.setHost(entryitem.getString("domain"));
}

try {
int asn = entryitem.getInt("asn");
entry.setAsnNum(asn);
} catch (Exception e) {
try {
int asn = entryitem.getInt("asn");
entry.setAsnNum(asn);
} catch (Exception e) {

}
}

try {
String asn_org = entryitem.getJSONObject("location").getString("asname");
if (asn_org != null) {
entry.setASNInfo(asn_org);
}
} catch (Exception e) {

try {
String asn_org = entryitem.getJSONObject("location").getString("asname");
if (asn_org != null) {
entry.setASNInfo(asn_org);
}
} catch (Exception e) {

entry.setSource(getEngineName());
result.add(entry);
} catch (Exception e) {
e.printStackTrace(stderr);
stderr.println(entryitem.toString());
}

entry.setSource(getEngineName());
result.add(entry);
}
return result;
}
Expand Down
48 changes: 27 additions & 21 deletions src/InternetSearch/Client/ShodanClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,37 @@ public String getEngineName() {
return SearchEngine.SHODAN;
}

//https://developer.shodan.io/api
// https://developer.shodan.io/api
@Override
public List<SearchResultEntry> parseResp(String respbody) {
List<SearchResultEntry> result = new ArrayList<SearchResultEntry>();
try {
JSONObject obj = new JSONObject(respbody);
JSONArray results = obj.getJSONArray("matches");
if (results != null) {

for (Object item : results) {
JSONObject entryitem = (JSONObject) item;
SearchResultEntry entry = new SearchResultEntry();

entry.setHost(entryitem.getJSONArray("hostnames").getString(0));
entry.getIPSet().add(entryitem.getString("ip_str"));
entry.setRootDomain(entryitem.getJSONArray("domains").getString(0));
entry.setPort(entryitem.getInt("port"));

entry.setASNInfo(entryitem.getString("asn"));
if (entryitem.getJSONObject("http")!=null) {
entry.setWebcontainer(entryitem.getJSONObject("http").getString("server"));
entry.setWebcontainer(entryitem.getJSONObject("http").getString("title"));
}
entry.setProtocol(entryitem.getJSONObject("_shodan").getString("module"));
try {
entry.setHost(entryitem.getJSONArray("hostnames").getString(0));
entry.getIPSet().add(entryitem.getString("ip_str"));
entry.setRootDomain(entryitem.getJSONArray("domains").getString(0));
entry.setPort(entryitem.getInt("port"));

entry.setSource(getEngineName());
result.add(entry);
entry.setASNInfo(entryitem.getString("asn"));
if (entryitem.getJSONObject("http") != null) {
entry.setWebcontainer(entryitem.getJSONObject("http").getString("server"));
entry.setWebcontainer(entryitem.getJSONObject("http").getString("title"));
}
entry.setProtocol(entryitem.getJSONObject("_shodan").getString("module"));

entry.setSource(getEngineName());
result.add(entry);
} catch (Exception e) {
e.printStackTrace(stderr);
stderr.println(entryitem.toString());
}
}
return result;
}
Expand All @@ -58,14 +63,14 @@ public List<SearchResultEntry> parseResp(String respbody) {
}

@Override
public boolean hasNextPage(String respbody,int currentPage) {
public boolean hasNextPage(String respbody, int currentPage) {
// 使用“页面”访问第一页之后的结果。 对于第一页之后的每 100 个结果,将扣除 1 个查询积分。
try {
int size=100;
int size = 100;
ArrayList<String> result = JsonUtils.grepValueFromJson(respbody, "total");
if (result.size() >= 1) {
int total = Integer.parseInt(result.get(0));
if (total > currentPage * size) {//size=100
if (total > currentPage * size) {// size=100
return true;
}
}
Expand All @@ -82,9 +87,10 @@ public String buildSearchUrl(String searchContent, int page) {
stderr.println("shodan key not configurated!");
return null;
}
//curl -X GET "https://api.shodan.io/shodan/host/search?key=xxxxx&query=product:nginx&facets=country"
String url = String.format(
"https://api.shodan.io/shodan/host/search?key=%s&query=%s&page=%s",key,searchContent,page);
// curl -X GET
// "https://api.shodan.io/shodan/host/search?key=xxxxx&query=product:nginx&facets=country"
String url = String.format("https://api.shodan.io/shodan/host/search?key=%s&query=%s&page=%s", key,
searchContent, page);
return url;
}

Expand Down
Loading

0 comments on commit fc556fe

Please sign in to comment.