-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathghosteyes.py
More file actions
executable file
·298 lines (240 loc) · 10.5 KB
/
ghosteyes.py
File metadata and controls
executable file
·298 lines (240 loc) · 10.5 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/env python3
# © Copyright 6lackRaven 2025
# License MIT
import asyncio
import argparse
import json
import sys
from textwrap import dedent
from modules import (
vlan_explorer,
web_scanner,
device_tracker,
reporter,
l2_traceroute,
dhcp_snooper,
)
from core.scanner import NetworkScanner
from core.utils import get_interface_details, validate_cidr
# ---- Colors ----
CRED = "\033[91m"
CGREEN = "\033[92m"
CYELLOW = "\033[93m"
CBLUE = "\033[94m"
CEND = "\033[0m"
VERSION = "v2.1.0"
AUTHOR = "6lackRaven"
def banner():
print(dedent(f"""
{CBLUE}========================================={CEND}
{CGREEN} GhostEyes {VERSION} - Offensive Recon Toolkit{CEND}
{CYELLOW} Author: {AUTHOR}{CEND}
{CBLUE}========================================={CEND}
"""))
def build_parser() -> argparse.ArgumentParser:
description = dedent(f"""\
{CGREEN}GhostEyes {VERSION} - Offensive Reconnaissance Toolkit{CEND}
------------------------------------------------
Commands:
net Network reconnaissance (ARP, VLANs, devices, traceroute, DHCP)
web Web reconnaissance (subdomains, dirs, tech stack)
report Generate reports from previous scans
""")
parser = argparse.ArgumentParser(
description=description,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument("--version", action="store_true", help="Show version info and exit")
parser.add_argument("--examples", action="store_true", help="Show usage examples")
parser.add_argument("--quiet", action="store_true", help="Suppress verbose logs")
subparsers = parser.add_subparsers(dest="command", required=False)
# ---- net ----
net_parser = subparsers.add_parser("net", help="Network reconnaissance")
net_parser.add_argument("-i", "--interface", default="eth0", help="Network interface")
net_group = net_parser.add_mutually_exclusive_group(required=True)
net_group.add_argument("-s", "--scan", metavar="CIDR", help="Scan subnet (e.g., 192.168.1.0/24)")
net_group.add_argument("-v", "--vlan", action="store_true", help="Discover VLANs")
net_group.add_argument("-t", "--track", action="store_true", help="Track live devices")
net_group.add_argument("-r", "--trace", metavar="IP", help="Layer 2 traceroute to target")
net_group.add_argument("-d", "--dhcp", action="store_true", help="Capture DHCP traffic")
net_parser.add_argument("--duration", type=int, default=300, help="Operation duration (seconds)")
net_parser.add_argument("--output", default="scan_net.json", help="Output JSON file")
# ---- web ----
web_parser = subparsers.add_parser("web", help="Web reconnaissance")
web_parser.add_argument("-u", "--url", required=True, help="Target URL")
web_parser.add_argument("-s", "--subdomains", metavar="WORDLIST", help="Subdomain brute-force wordlist")
web_parser.add_argument("-b", "--bruteforce", metavar="WORDLIST", help="Directory brute-force wordlist")
web_parser.add_argument("-T", "--tech", action="store_true", help="Detect technologies")
web_parser.add_argument("-w", "--workers", type=int, default=50, help="Concurrent workers")
web_parser.add_argument("--output", default="scan_web.json", help="Output JSON file")
# ---- report ----
report_parser = subparsers.add_parser("report", help="Generate reports")
report_parser.add_argument("-f", "--file", required=True, help="Scan results file (JSON)")
report_parser.add_argument(
"-t", "--type", choices=["txt", "json", "html", "csv", "all"],
default=["html"], nargs="+", help="Output formats"
)
return parser
def show_examples():
print(dedent(f"""
{CYELLOW}Usage Examples:{CEND}
{CBLUE}# Network ARP scan{CEND}
python ghosteyes.py net -i eth0 --scan 192.168.1.0/24
{CBLUE}# VLAN discovery for 2 minutes{CEND}
python ghosteyes.py net -i eth0 --vlan --duration 120
{CBLUE}# Track devices{CEND}
python ghosteyes.py net -i wlan0 --track --duration 60
{CBLUE}# Web scan with subdomains + tech detection{CEND}
python ghosteyes.py web -u https://example.com -s subdomains.txt -T
{CBLUE}# Generate HTML and JSON reports{CEND}
python ghosteyes.py report -f scan_net.json -t html json
"""))
async def handle_net(args, quiet=False) -> dict:
scan_data = {}
iface_info = await get_interface_details(args.interface)
if not quiet:
print(f"{CYELLOW}Using interface:{CEND} {iface_info.name} ({iface_info.ip})")
if args.scan:
if not validate_cidr(args.scan):
print(f"{CRED}Invalid CIDR format:{CEND} {args.scan}")
return scan_data
if not quiet:
print(f"{CBLUE}Scanning subnet:{CEND} {args.scan}")
scanner = NetworkScanner(args.interface, iface_info)
hosts = await scanner.arp_scan(args.scan)
scan_data["network"] = {host["ip"]: host for host in hosts}
print(f"{CGREEN}Found {len(hosts)} active hosts{CEND}")
elif args.vlan:
if not quiet:
print(f"{CBLUE}Starting VLAN discovery...{CEND}")
vlan_scanner = vlan_explorer.VLANExplorer(args.interface)
vlans = await vlan_scanner.sniff_vlans(duration=args.duration)
print(f"{CGREEN}Discovered VLANs:{CEND} {', '.join(map(str, vlans)) or 'None'}")
if vlans:
scan_data["vlans"] = {}
for vlan in list(vlans)[:3]:
if not quiet:
print(f"{CBLUE}Scanning VLAN {vlan}...{CEND}")
result = await vlan_scanner.discover_vlan_devices(vlan)
scan_data["vlans"][vlan] = list(result.devices)
elif args.track:
if not quiet:
print(f"{CBLUE}Tracking devices for {args.duration} seconds...{CEND}")
tracker = device_tracker.DeviceTracker(interface=args.interface, refresh_interval=10)
devices = await tracker.start_monitoring(duration=args.duration)
scan_data["devices"] = devices
print(f"{CGREEN}Tracked {len(devices)} devices{CEND}")
elif args.trace:
if not quiet:
print(f"{CBLUE}Tracing path to {args.trace}...{CEND}")
tracer = l2_traceroute.Layer2Traceroute(args.interface)
path = await tracer.trace(args.trace)
scan_data["trace"] = [hop._asdict() for hop in path]
for i, hop in enumerate(path):
print(f"Hop {i+1}: {hop.ip} ({hop.mac}) - {hop.vendor}")
elif args.dhcp:
if not quiet:
print(f"{CBLUE}Capturing DHCP traffic for {args.duration} seconds...{CEND}")
snooper = dhcp_snooper.DHCPSnooper(args.interface)
await snooper.capture_dhcp(duration=args.duration)
scan_data["dhcp"] = snooper.leases
print(f"{CGREEN}Captured {len(snooper.leases)} DHCP transactions{CEND}")
return scan_data
async def handle_web(args, quiet=False) -> dict:
scan_data = {}
if not quiet:
print(f"{CBLUE}Starting web reconnaissance on {args.url}{CEND}")
async with web_scanner.WebScanner() as scanner:
results = {}
if args.subdomains:
if not quiet:
print(f"{CYELLOW}Enumerating subdomains...{CEND}")
with open(args.subdomains) as f:
wordlist = [line.strip() for line in f if line.strip()]
domain = web_scanner.extract_domain(args.url)
subdomains = await scanner.subdomain_scan(domain, wordlist, workers=args.workers)
results["subdomains"] = subdomains
print(f"{CGREEN}Found {len(subdomains)} valid subdomains{CEND}")
if args.bruteforce:
if not quiet:
print(f"{CYELLOW}Brute-forcing directories...{CEND}")
with open(args.bruteforce) as f:
wordlist = [line.strip() for line in f if line.strip()]
paths = await scanner.dir_bruteforce(args.url, wordlist, workers=args.workers)
results["paths"] = paths
print(f"{CGREEN}Found {len(paths)} accessible paths{CEND}")
if args.tech:
if not quiet:
print(f"{CYELLOW}Detecting technologies...{CEND}")
tech = await scanner.tech_detect(args.url)
results["tech"] = tech
print(f"{CGREEN}Technology stack identified{CEND}")
scan_data["web"] = {args.url: results}
return scan_data
def handle_report(args):
print(f"{CBLUE}Generating report from {args.file}{CEND}")
try:
with open(args.file) as f:
scan_data = json.load(f)
except FileNotFoundError:
print(f"{CRED}File not found:{CEND} {args.file}")
return
except json.JSONDecodeError:
print(f"{CRED}Invalid JSON format in {args.file}{CEND}")
return
rb = reporter.ReportBuilder(scan_data)
formats = args.type
if "all" in formats:
formats = ["txt", "json", "html", "csv"]
output_files = []
for fmt in formats:
if fmt == "txt":
output_files.append(rb.to_txt())
elif fmt == "json":
output_files.append(rb.to_json())
elif fmt == "html":
output_files.append(rb.to_html())
elif fmt == "csv":
output_files.append(rb.to_csv())
print(f"{CGREEN}Generated reports:{CEND} {', '.join(output_files)}")
async def async_main(args):
try:
quiet = args.quiet
if args.command == "net":
scan_data = await handle_net(args, quiet)
elif args.command == "web":
scan_data = await handle_web(args, quiet)
elif args.command == "report":
handle_report(args)
return
else:
print(f"{CRED}Unknown command. Use -h for help.{CEND}")
return
if args.command != "report" and scan_data:
filename = args.output
with open(filename, "w") as f:
json.dump(scan_data, f, indent=2)
print(f"{CYELLOW}Scan results saved to {filename}{CEND}")
except PermissionError:
print(f"{CRED}Permission denied - try running with sudo{CEND}")
except KeyboardInterrupt:
print(f"{CYELLOW}\nOperation cancelled by user{CEND}")
except Exception as e:
print(f"{CRED}Critical error:{CEND} {str(e)}")
sys.exit(1)
def main():
banner()
parser = build_parser()
args = parser.parse_args()
if args.version:
print(f"GhostEyes {VERSION} by {AUTHOR}")
return
if args.examples:
show_examples()
return
if not args.command:
parser.print_help()
return
asyncio.run(async_main(args))
if __name__ == "__main__":
main()