-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpentest_tool.py
82 lines (72 loc) · 5.49 KB
/
pentest_tool.py
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
# Red Teaming and Penetration Testing Toolkit
# This script provides basic automated scanning and vulnerability analysis capabilities.
print("""
░██████╗░█████╗░███╗░░██╗████████╗██╗░░██╗░█████╗░███╗░░██╗░█████╗░███╗░░░███╗
██╔════╝██╔══██╗████╗░██║╚══██╔══╝██║░░██║██╔══██╗████╗░██║██╔══██╗████╗░████║
╚█████╗░███████║██╔██╗██║░░░██║░░░███████║███████║██╔██╗██║███████║██╔████╔██║
░╚═══██╗██╔══██║██║╚████║░░░██║░░░██╔══██║██╔══██║██║╚████║██╔══██║██║╚██╔╝██║
██████╔╝██║░░██║██║░╚███║░░░██║░░░██║░░██║██║░░██║██║░╚███║██║░░██║██║░╚═╝░██║
╚═════╝░╚═╝░░╚═╝╚═╝░░╚══╝░░░╚═╝░░░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═╝░░╚═╝╚═╝░░░░░╚═╝
██████╗░███████╗███╗░░██╗████████╗███████╗░██████╗████████╗ ████████╗░█████╗░░█████╗░██╗░░░░░
██╔══██╗██╔════╝████╗░██║╚══██╔══╝██╔════╝██╔════╝╚══██╔══╝ ╚══██╔══╝██╔══██╗██╔══██╗██║░░░░░
██████╔╝█████╗░░██╔██╗██║░░░██║░░░█████╗░░╚█████╗░░░░██║░░░ ░░░██║░░░██║░░██║██║░░██║██║░░░░░
██╔═══╝░██╔══╝░░██║╚████║░░░██║░░░██╔══╝░░░╚═══██╗░░░██║░░░ ░░░██║░░░██║░░██║██║░░██║██║░░░░░
██║░░░░░███████╗██║░╚███║░░░██║░░░███████╗██████╔╝░░░██║░░░ ░░░██║░░░╚█████╔╝╚█████╔╝███████╗
╚═╝░░░░░╚══════╝╚═╝░░╚══╝░░░╚═╝░░░╚══════╝╚═════╝░░░░╚═╝░░░ ░░░╚═╝░░░░╚════╝░░╚════╝░╚══════╝""")
import nmap
import os
import subprocess
# Function for network scanning using nmap
def network_scan(target_ip):
nm = nmap.PortScanner()
print(f"Scanning target: {target_ip}")
try:
nm.scan(target_ip, arguments='-sS -sV -O')
for host in nm.all_hosts():
print(f"Host: {host} ({nm[host].hostname()})")
print(f"State: {nm[host].state()}")
for proto in nm[host].all_protocols():
print(f"Protocol: {proto}")
lport = list(nm[host][proto].keys())
for port in sorted(lport):
print(f"Port: {port}\tState: {nm[host][proto][port]['state']}")
except Exception as e:
print(f"Error during network scan: {e}")
# Function for running vulnerability analysis using automated tools
def vulnerability_analysis(target_ip):
print(f"Running vulnerability analysis on {target_ip}")
try:
subprocess.run(["nmap", "--script", "vuln", target_ip], check=True, timeout=300)
except subprocess.CalledProcessError as e:
print(f"Error occurred: {e}")
except subprocess.TimeoutExpired:
print("Vulnerability analysis timed out.")
# Function for launching Metasploit auxiliary scanning module
def metasploit_scan(target_ip):
print("Starting Metasploit auxiliary scan")
commands = f"use auxiliary/scanner/portscan/tcp\nset RHOSTS {target_ip}\nrun\nexit"
with open("msf_script.rc", "w") as script:
script.write(commands)
try:
subprocess.run(["msfconsole", "-r", "msf_script.rc"], check=True)
except subprocess.CalledProcessError as e:
print(f"Error occurred: {e}")
except FileNotFoundError:
print("Metasploit not found. Ensure it is installed and in your PATH.")
# Main execution logic
def main():
target = input("Enter the target IP address: ")
print("\n1. Network Scan")
print("2. Vulnerability Analysis")
print("3. Metasploit Auxiliary Scan")
choice = input("Select an option (1/2/3): ")
if choice == '1':
network_scan(target)
elif choice == '2':
vulnerability_analysis(target)
elif choice == '3':
metasploit_scan(target)
else:
print("Invalid choice!")
if __name__ == "__main__":
main()