-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsetup.py
More file actions
466 lines (370 loc) · 15.5 KB
/
setup.py
File metadata and controls
466 lines (370 loc) · 15.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
#!/usr/bin/env python3
"""
Setup script for ExploitDF Framework
Installation script that sets up the ExploitDF penetration testing framework
for easy command-line access across Windows, Linux, and macOS platforms.
Created for Defronix internship project
"""
import os
import sys
import shutil
import stat
from pathlib import Path
import platform
class ExploitDFInstaller:
def __init__(self):
self.system = platform.system().lower()
self.python_executable = sys.executable
self.install_dir = None
self.script_path = None
def check_requirements(self):
"""Check if system meets requirements"""
print("Checking system requirements...")
# Check Python version
if sys.version_info < (3, 6):
print("ERROR: Python 3.6 or higher is required")
return False
print(f"✓ Python {sys.version.split()[0]} detected")
# Check if we're running as admin/root on Windows/Unix
if self.system == "windows":
try:
import ctypes
if not ctypes.windll.shell32.IsUserAnAdmin():
print("WARNING: Administrator privileges recommended for system-wide installation")
except:
pass
else:
if os.geteuid() != 0:
print("WARNING: Root privileges recommended for system-wide installation")
return True
def determine_install_paths(self):
"""Determine installation paths based on the operating system"""
current_dir = Path(__file__).parent.absolute()
if self.system == "windows":
# Windows installation paths
if os.environ.get('PROGRAMFILES'):
self.install_dir = Path(os.environ['PROGRAMFILES']) / "ExploitDF"
else:
self.install_dir = Path("C:/Program Files/ExploitDF")
# Create batch file for Windows
self.script_path = self.install_dir / "exploitdf.bat"
else:
# Unix-like systems (Linux, macOS)
self.install_dir = Path("/opt/exploitdf")
self.script_path = Path("/usr/local/bin/exploitdf")
print(f"Install directory: {self.install_dir}")
print(f"Script path: {self.script_path}")
def create_directories(self):
"""Create necessary directories"""
print("Creating directories...")
try:
# Create main installation directory
self.install_dir.mkdir(parents=True, exist_ok=True)
# Create modules directory structure
modules_dir = self.install_dir / "modules"
modules_dir.mkdir(exist_ok=True)
# Create subdirectories for different module types
(modules_dir / "auxiliary").mkdir(exist_ok=True)
(modules_dir / "scanners").mkdir(exist_ok=True)
(modules_dir / "auxiliary" / "scanner").mkdir(exist_ok=True)
# Create __init__.py files
(modules_dir / "__init__.py").touch()
(modules_dir / "auxiliary" / "__init__.py").touch()
(modules_dir / "scanners" / "__init__.py").touch()
(modules_dir / "auxiliary" / "scanner" / "__init__.py").touch()
print("✓ Directories created successfully")
except PermissionError:
print("ERROR: Permission denied. Please run with administrator/root privileges")
return False
except Exception as e:
print(f"ERROR: Failed to create directories: {e}")
return False
return True
def copy_files(self):
"""Copy framework files to installation directory"""
print("Copying framework files...")
try:
current_dir = Path(__file__).parent.absolute()
# Copy main framework files
files_to_copy = [
"exploitDF.py",
"BaseModule.py"
]
for filename in files_to_copy:
src = current_dir / filename
dst = self.install_dir / filename
if src.exists():
shutil.copy2(src, dst)
print(f"✓ Copied {filename}")
else:
print(f"WARNING: {filename} not found in current directory")
# Copy any existing modules
src_modules = current_dir / "modules"
if src_modules.exists():
dst_modules = self.install_dir / "modules"
for item in src_modules.rglob("*"):
if item.is_file():
relative_path = item.relative_to(src_modules)
dst_item = dst_modules / relative_path
dst_item.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(item, dst_item)
print(f"✓ Copied module: {relative_path}")
print("✓ Files copied successfully")
except Exception as e:
print(f"ERROR: Failed to copy files: {e}")
return False
return True
def create_launcher_script(self):
"""Create launcher script for the framework"""
print("Creating launcher script...")
try:
if self.system == "windows":
# Create Windows batch file
script_content = f'''@echo off
cd /d "{self.install_dir}"
"{self.python_executable}" exploitdf.py %*
'''
with open(self.script_path, 'w') as f:
f.write(script_content)
# Also add to PATH if possible
self.add_to_windows_path()
else:
# Create Unix shell script
script_content = f'''#!/bin/bash
cd "{self.install_dir}"
exec "{self.python_executable}" exploitDF.py "$@"
'''
with open(self.script_path, 'w') as f:
f.write(script_content)
# Make executable
os.chmod(self.script_path, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
print(f"✓ Launcher script created: {self.script_path}")
except Exception as e:
print(f"ERROR: Failed to create launcher script: {e}")
return False
return True
def add_to_windows_path(self):
"""Add ExploitDF to Windows PATH (if possible)"""
try:
import winreg
# Try to add to system PATH
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment",
0, winreg.KEY_ALL_ACCESS)
current_path, _ = winreg.QueryValueEx(key, "PATH")
install_dir_str = str(self.install_dir)
if install_dir_str not in current_path:
new_path = current_path + ";" + install_dir_str
winreg.SetValueEx(key, "PATH", 0, winreg.REG_EXPAND_SZ, new_path)
print("✓ Added to system PATH")
winreg.CloseKey(key)
except Exception as e:
print(f"WARNING: Could not modify system PATH: {e}")
print(f"You may need to manually add {self.install_dir} to your PATH")
def create_sample_modules(self):
"""Create sample auxiliary and scanner modules"""
print("Creating sample modules...")
try:
modules_dir = self.install_dir / "modules"
# Sample port scanner module
port_scanner_content = '''"""
Sample Port Scanner Module for ExploitDF Framework
"""
from basemodule import ScannerModule
import socket
class PortScannerModule(ScannerModule):
def __init__(self):
super().__init__()
self.info.update({
'name': 'TCP Port Scanner',
'description': 'Simple TCP port scanner',
'author': 'ExploitDF Team',
'version': '1.0',
'type': 'scanner'
})
# Add port-specific options
self.options.update({
'RPORT': '80,443,22,21,25,53,110,993,995',
'THREADS': 10,
'ConnectTimeout': 3
})
self.required_options.add('RPORT')
def scan_target(self, target):
"""Scan a single target for open ports"""
self.print_status(f"Scanning {target}")
ports_string = self.get_option('RPORT')
ports = []
for port_item in ports_string.split(','):
port_item = port_item.strip()
if '-' in port_item:
# Handle port ranges
start, end = port_item.split('-', 1)
ports.extend(range(int(start), int(end) + 1))
else:
ports.append(int(port_item))
open_ports = []
for port in ports:
if self.check_port(target, port):
open_ports.append(port)
self.print_good(f"{target}:{port} - Open")
if open_ports:
self.print_status(f"{target} - Open ports: {','.join(map(str, open_ports))}")
else:
self.print_status(f"{target} - No open ports found")
def check_port(self, host, port):
"""Check if a specific port is open"""
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(self.get_option('ConnectTimeout'))
result = sock.connect_ex((host, port))
sock.close()
return result == 0
except Exception:
return False
'''
scanner_file = modules_dir / "scanners" / "port_scanner.py"
with open(scanner_file, 'w') as f:
f.write(port_scanner_content)
# Sample HTTP title grabber
http_title_content = '''"""
Sample HTTP Title Grabber Module for ExploitDF Framework
"""
from basemodule import AuxiliaryModule
import socket
import re
class HttpTitleModule(AuxiliaryModule):
def __init__(self):
super().__init__()
self.info.update({
'name': 'HTTP Title Grabber',
'description': 'Grab HTTP page titles from web servers',
'author': 'ExploitDF Team',
'version': '1.0',
'type': 'auxiliary'
})
self.options.update({
'RPORT': 80,
'SSL': False,
'URI': '/',
'UserAgent': 'Mozilla/5.0 (ExploitDF)'
})
def run(self):
"""Main execution method"""
if super().run() == False:
return False
targets_string = self.get_option('RHOSTS')
targets = targets_string.split(',') if targets_string else []
for target in targets:
target = target.strip()
if target:
self.grab_title(target)
return True
def grab_title(self, target):
"""Grab the title from a web server"""
try:
port = self.get_option('RPORT')
uri = self.get_option('URI')
user_agent = self.get_option('UserAgent')
sock = self.create_socket(target, port)
if not sock:
return
# Send HTTP request
request = f"""GET {uri} HTTP/1.1\\r
Host: {target}\\r
User-Agent: {user_agent}\\r
Connection: close\\r
\\r
"""
sock.send(request.encode())
response = sock.recv(4096).decode('utf-8', errors='ignore')
sock.close()
# Extract title
title_match = re.search(r'<title>(.*?)</title>', response, re.IGNORECASE | re.DOTALL)
if title_match:
title = title_match.group(1).strip()
self.print_good(f"{target}:{port} - Title: {title}")
else:
self.print_status(f"{target}:{port} - No title found")
except Exception as e:
self.print_error(f"Error connecting to {target}: {e}")
'''
http_file = modules_dir / "auxiliary" / "http_title.py"
with open(http_file, 'w') as f:
f.write(http_title_content)
print("✓ Sample modules created")
except Exception as e:
print(f"ERROR: Failed to create sample modules: {e}")
return False
return True
def run_installation(self):
"""Run the complete installation process"""
print("ExploitDF Framework Installer")
print("=" * 40)
print(f"Installing on: {platform.system()} {platform.release()}")
print()
# Check requirements
if not self.check_requirements():
return False
# Determine paths
self.determine_install_paths()
# Installation steps
steps = [
("Creating directories", self.create_directories),
("Copying framework files", self.copy_files),
("Creating launcher script", self.create_launcher_script),
("Creating sample modules", self.create_sample_modules)
]
for step_name, step_func in steps:
print(f"\n{step_name}...")
if not step_func():
print(f"FAILED: {step_name}")
return False
# Installation complete
print("\n" + "=" * 40)
print("ExploitDF Framework installed successfully!")
print()
print("Usage:")
if self.system == "windows":
print(" exploitdf.bat")
else:
print(" exploitdf")
print()
print("Getting started:")
print(" 1. Run 'exploitdf' from anywhere in your terminal")
print(" 2. Type 'help' to see available commands")
print(" 3. Type 'show auxiliary' to see available modules")
print(" 4. Type 'use <module_name>' to select a module")
print(" 5. Type 'info' to see module information and options")
print()
if self.system == "windows":
print("Note: You may need to restart your command prompt or add")
print(f" {self.install_dir} to your PATH manually")
return True
def main():
"""Main installer entry point"""
installer = ExploitDFInstaller()
# Check command line arguments
if len(sys.argv) > 1:
if sys.argv[1] in ['-h', '--help']:
print("ExploitDF Framework Installer")
print("Usage: python setup.py [options]")
print()
print("Options:")
print(" -h, --help Show this help message")
print(" --uninstall Uninstall ExploitDF Framework")
return
elif sys.argv[1] == '--uninstall':
print("Uninstall functionality not implemented yet")
return
# Run installation
try:
success = installer.run_installation()
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\nInstallation cancelled by user")
sys.exit(1)
except Exception as e:
print(f"\nUnexpected error during installation: {e}")
sys.exit(1)
if __name__ == "__main__":
main()