Skip to content

Commit

Permalink
update shodan scan to save more often
Browse files Browse the repository at this point in the history
update shodan scan to save more often to remove in memory overload
  • Loading branch information
DJensen94 committed Dec 13, 2024
1 parent c62622e commit 9793c39
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/pe_source/data/shodan_db/shodan_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def search_circl(cve):
def search_shodan(thread_name, ips, api, start, end, org_uid, org_name, failed):
"""Search IPs in the Shodan API."""
# Initialize lists to store Shodan results
data = []
risk_data = []
vuln_data = []
# data = []
# risk_data = []
# vuln_data = []

# Build dictionaries for naming conventions and definitions
risky_ports, name_dict, risk_dict, av_dict, ac_dict, ci_dict = get_shodan_dicts()
Expand All @@ -106,6 +106,9 @@ def search_shodan(thread_name, ips, api, start, end, org_uid, org_name, failed):
while try_count < 7:
try:
results = api.host(ip_chunk)
data = []
risk_data = []
vuln_data = []
for r in results:
for d in r["data"]:
# Convert Shodan date string to UTC datetime
Expand Down Expand Up @@ -234,7 +237,10 @@ def search_shodan(thread_name, ips, api, start, end, org_uid, org_name, failed):
"data_source_uid": source_uid,
}
)

all_vulns = vuln_data + risk_data
# Grab the data source uid and add to each dataframe
failed.append(insert_shodan_assets(data, failed))
failed.append(insert_shodan_vulns(all_vulns, failed))
time.sleep(1)
break
except shodan.APIError as e:
Expand Down Expand Up @@ -266,13 +272,13 @@ def search_shodan(thread_name, ips, api, start, end, org_uid, org_name, failed):
)
failed.append("{} chunk {} failed and skipped".format(org_name, count))
break

LOGGER.info("{} {}/{} complete - {}".format(thread_name, count, tot, org_name))

all_vulns = vuln_data + risk_data
# Grab the data source uid and add to each dataframe
failed = insert_shodan_assets(data, failed)
failed = insert_shodan_vulns(all_vulns, failed)
# all_vulns = vuln_data + risk_data
# # Grab the data source uid and add to each dataframe
# failed = insert_shodan_assets(data, failed)
# failed = insert_shodan_vulns(all_vulns, failed)

return failed

Expand Down

0 comments on commit 9793c39

Please sign in to comment.