-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvuln_scanner.py
56 lines (48 loc) · 1.84 KB
/
vuln_scanner.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
import socket
import threading
import requests
class VulnerabilityScanner:
def __init__(self, target, ports):
self.target = target
self.ports = ports
self.open_ports = []
def scan_port(self, port):
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.settimeout(1)
result = sock.connect_ex((self.target, port))
if result == 0:
self.open_ports.append(port)
print(f"Port {port} is open")
else:
print(f"Port {port} is closed")
except Exception as e:
print(f"Error scanning port {port}: {e}")
def scan_ports(self):
threads = []
for port in self.ports:
thread = threading.Thread(target=self.scan_port, args=(port,))
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
def banner_grabbing(self, port):
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.settimeout(1)
sock.connect((self.target, port))
banner = sock.recv(1024).decode().strip()
print(f"Banner from port {port}: {banner}")
except Exception as e:
print(f"Error grabbing banner from port {port}: {e}")
def run(self):
print(f"Scanning {self.target}...")
self.scan_ports()
print("Open ports:", self.open_ports)
for port in self.open_ports:
self.banner_grabbing(port)
if __name__ == "__main__":
target_ip = input("Enter target IP: ")
port_range = range(1, 1025) # Scanning ports 1 to 1024
scanner = VulnerabilityScanner(target_ip, port_range)
scanner.run()