-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsand.py
More file actions
107 lines (91 loc) · 3.35 KB
/
sand.py
File metadata and controls
107 lines (91 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import subprocess
import time
from termcolor import colored
from tabulate import tabulate
import pandas as pd
import matplotlib.pyplot as plt
# Ensure Python version compatibility
required_python_version = (3, 9)
if sys.version_info < required_python_version:
print(colored(f'[!] Please install Python {required_python_version[0]}.{required_python_version[1]} or higher. Exiting.', 'yellow'))
sys.exit(1)
# Define theHarvester command parameters
domain = "https://enginueeur.com"
filename = "custom_results"
sources = "bing,anubis,brave,certspotter,crtsh"
limit = "2000"
dns_server = "1.1.1.1"
takeover_check = True
screenshots_dir = "screenshots_dir"
# Construct theHarvester command
command = [
"theHarvester",
"-d", domain,
"-f", filename,
"-b", sources,
"-l", limit,
"-vv",
"-e", dns_server,
"-t" if takeover_check else "",
"--virtual-host",
"--screenshot", screenshots_dir,
"-s"
]
# Print the script's objective
print(colored("Running theHarvester to gather open-source intelligence.", 'cyan'))
# Execute the theHarvester command
print(colored("Executing theHarvester command with the following options:", 'cyan'))
print(" " + " ".join(command)) # Display the command string
start_time = time.time()
subprocess.run(command)
end_time = time.time()
# Display completion message
print(colored("theHarvester script completed.", 'green'))
# Generate a report
execution_time = end_time - start_time
report_data = [
["Domain", domain],
["Output File", filename],
["Sources", sources],
["Limit", limit],
["DNS Server", dns_server],
["Takeover Check", "Enabled" if takeover_check else "Disabled"],
["Screenshots Dir", screenshots_dir],
["Execution Time", f"{execution_time:.2f} seconds"]
]
report_table = tabulate(report_data, headers=["Parameter", "Value"], tablefmt="grid")
print(colored("\nReport:\n", 'cyan'))
print(report_table)
# Parse theHarvester output and extract source statistics
print(colored("\nParsing theHarvester output...\n", 'cyan'))
with open(filename + '.txt', 'r') as output_file:
lines = output_file.readlines()
source_stats = {}
current_source = None
for line in lines:
if line.startswith("[*] Searching"):
current_source = line.split()[2][:-1]
elif line.strip() == "":
current_source = None
elif current_source and line.startswith("[*]"):
key, value = line[4:].strip().split(": ")
source_stats.setdefault(current_source, {})[key] = value
# Create a pandas DataFrame from the source statistics
df = pd.DataFrame(source_stats).T
df.reset_index(inplace=True)
df.rename(columns={'index': 'Source'}, inplace=True)
# Generate a bar graph depicting subdomains per source
plt.figure(figsize=(10, 6))
plt.bar(df['Source'], df['Hosts'], color='skyblue')
plt.title('Number of Subdomains from Each Source')
plt.xlabel('Source')
plt.ylabel('Number of Subdomains')
plt.xticks(rotation=45, ha='right')
plt.tight_layout()
# Save the graph as an image
graph_filename = 'subdomains_by_source.png'
plt.savefig(graph_filename)
print(colored(f"Bar graph saved as: {graph_filename}\n", 'green'))
# Display the graph
plt.show()
In this improved version, I added a required Python version check, revised comments for clarity, and adjusted code organization to enhance readability. Additionally, I removed unnecessary imports and kept the code structure consistent for better maintenance.